From: Visuwesh <visuweshm@gmail.com>
To: Eli Zaretskii <eliz@gnu.org>
Cc: 65892@debbugs.gnu.org
Subject: bug#65892: 30.0.50; yank-media fails for clipboard selection that are wiped after being accessed
Date: Mon, 24 Jun 2024 19:16:09 +0530 [thread overview]
Message-ID: <87frt2qwri.fsf@gmail.com> (raw)
In-Reply-To: <86v81ybksc.fsf@gnu.org> (Eli Zaretskii's message of "Mon, 24 Jun 2024 15:13:55 +0300")
[-- Attachment #1: Type: text/plain, Size: 1902 bytes --]
[திங்கள் ஜூன் 24, 2024] Eli Zaretskii wrote:
>> From: Visuwesh <visuweshm@gmail.com>
>> Date: Mon, 24 Jun 2024 09:23:20 +0530
>>
>> I apologise for neglecting to speak out loud before the emacs-30 branch
>> cut. Is there a chance to get this patch in emacs-30? I am using this
>> patch ever since I sent it to debbugs and I do not face any issue wrt
>> the pcmanfm issue shown here and other applications which do not wipe
>> the clipboard. It would be nice to have it in emacs-30 especially with
>> org-mode gaining yank-media support for files copied/cut from a file
>> manager.
>
> I can be convinced to make such changes on the release branch only if
> all they do is make a function whose return value was not interesting
> to return a useful value. But the patch does more than that: it
> introduces pcase-dolist and replaces some FOO with (car FOO) in at
> least 3 occasions.
Thanks for the review and consideration, Eli. The patch only touched
the return value of a helper function.
> Such changes make me uncomfortable, especially given that this is a
> case where Emacs needs to jump through hoops to work around
> misfeatures of some 3rd-party utility.
I suspect similar behaviour will be shown by other file managers.
> Can you rewrite the patch so that it will be clear at a glance that it
> cannot possibly cause any harm because it just causes the same code
> return a value? If you can, we have a chance of installing this on
> the emacs-30 branch.
I hope the attached patch makes the intent clear. I added a doc-string
to the internal function too, and removed pcase-dolist and extra car to
make the code simpler.
> And, btw, I wonder whether enough people use pcmanfm for us to bother
> about this issue.
AFAIK, pcmanfm is fairly popular among the window manager users crowd
due to its light-weight.
[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: 0001-Fix-yank-media-when-clipboard-selection-is-wiped-aft.patch --]
[-- Type: text/x-diff, Size: 3924 bytes --]
From 0aa3efd2e05dcc228e042b43fce6f997fd8afc1c Mon Sep 17 00:00:00 2001
From: Visuwesh <visuweshm@gmail.com>
Date: Tue, 12 Sep 2023 22:21:58 +0530
Subject: [PATCH] Fix yank-media when clipboard selection is wiped after access
Certain applications wipes the clipboard selection after is accessed
once e.g., pcmanfm with cut files which makes yank-media pass nil to
the chosen yank-media handler eventually breaking it. (bug#65892)
* lisp/yank-media.el (yank-media--find-matching-media): Make it return
the selection. Also document the return type.
(yank-media): Pass the returned selection from above to the handler
instead of refetching the selection from the clipboard.
---
lisp/yank-media.el | 39 +++++++++++++++++++++++----------------
1 file changed, 23 insertions(+), 16 deletions(-)
diff --git a/lisp/yank-media.el b/lisp/yank-media.el
index abc137d9c38..830ff40c667 100644
--- a/lisp/yank-media.el
+++ b/lisp/yank-media.el
@@ -44,26 +44,31 @@ yank-media
(let ((all-types nil))
(pcase-dolist (`(,handled-type . ,handler)
yank-media--registered-handlers)
- (dolist (type (yank-media--find-matching-media handled-type))
- (push (cons type handler) all-types)))
+ (dolist (sel (yank-media--find-matching-media handled-type))
+ (push (list (car sel) handler (cdr sel)) all-types)))
(unless all-types
(user-error
"No handler in the current buffer for anything on the clipboard"))
;; We have a handler in the current buffer; if there's just
;; matching type, just call the handler.
(if (length= all-types 1)
- (funcall (cdar all-types) (caar all-types)
- (yank-media--get-selection (caar all-types)))
+ (funcall (nth 1 (car all-types)) (nth 0 (car all-types))
+ (nth 2 (car all-types)))
;; More than one type the user for what type to insert.
- (let ((type
- (intern
- (completing-read "Several types available, choose one: "
- (mapcar #'car all-types) nil t))))
- (funcall (alist-get type all-types)
- type (yank-media--get-selection type))))))
+ (let* ((type
+ (intern
+ (completing-read "Several types available, choose one: "
+ (mapcar #'car all-types) nil t)))
+ (chosen-sel (assq type all-types)))
+ (funcall (nth 1 chosen-sel) (nth 0 chosen-sel)
+ (nth 2 chosen-sel))))))
(defun yank-media--find-matching-media (handled-type)
- (seq-filter
+ "Return list of clipboard data with mime-type matched by HANDLED-TYPE.
+Each element in the list is a cons pair (TYPE . SELECTION) where TYPE is
+the mime-type of the clipboard selection, and SELECTION is the clipboard
+selection data as a string."
+ (seq-keep
(lambda (type)
(pcase-let ((`(,major ,minor) (split-string (symbol-name type) "/")))
(if (and (equal major "image")
@@ -73,11 +78,13 @@ yank-media--find-matching-media
;; `image/x-win-bitmap'.
nil
;; Check that the handler wants this type.
- (and (if (symbolp handled-type)
- (eq handled-type type)
- (string-match-p handled-type (symbol-name type)))
- ;; An element may be in TARGETS but be empty.
- (yank-media--get-selection type)))))
+ (let ((selection (and (if (symbolp handled-type)
+ (eq handled-type type)
+ (string-match-p handled-type (symbol-name type)))
+ ;; An element may be in TARGETS but be empty.
+ (yank-media--get-selection type))))
+ (and selection
+ (cons type selection))))))
(gui-get-selection 'CLIPBOARD 'TARGETS)))
(defun yank-media--get-selection (data-type)
--
2.43.0
next prev parent reply other threads:[~2024-06-24 13:46 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-09-12 16:54 bug#65892: 30.0.50; yank-media fails for clipboard selection that are wiped after being accessed Visuwesh
2024-06-24 3:53 ` Visuwesh
2024-06-24 12:13 ` Eli Zaretskii
2024-06-24 13:46 ` Visuwesh [this message]
2024-06-25 3:45 ` Po Lu via Bug reports for GNU Emacs, the Swiss army knife of text editors
2024-06-25 4:36 ` Visuwesh
2024-06-25 12:59 ` Eli Zaretskii
2024-06-28 4:20 ` Visuwesh
2024-06-28 8:59 ` Po Lu via Bug reports for GNU Emacs, the Swiss army knife of text editors
2024-06-28 10:03 ` Visuwesh
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
List information: https://www.gnu.org/software/emacs/
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=87frt2qwri.fsf@gmail.com \
--to=visuweshm@gmail.com \
--cc=65892@debbugs.gnu.org \
--cc=eliz@gnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this public inbox
https://git.savannah.gnu.org/cgit/emacs.git
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).