From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Visuwesh Newsgroups: gmane.emacs.bugs 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 Message-ID: <87frt2qwri.fsf@gmail.com> References: <87a5trjprx.fsf@gmail.com> <875xtzro7j.fsf@gmail.com> <86v81ybksc.fsf@gnu.org> Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="23749"; mail-complaints-to="usenet@ciao.gmane.io" User-Agent: Gnus/5.13 (Gnus v5.13) Cc: 65892@debbugs.gnu.org To: Eli Zaretskii Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Mon Jun 24 15:48:26 2024 Return-path: Envelope-to: geb-bug-gnu-emacs@m.gmane-mx.org Original-Received: from lists.gnu.org ([209.51.188.17]) by ciao.gmane.io with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1sLk3W-00060W-8Q for geb-bug-gnu-emacs@m.gmane-mx.org; Mon, 24 Jun 2024 15:48:26 +0200 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1sLk3A-0002p8-S7; Mon, 24 Jun 2024 09:48:05 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1sLk37-0002mn-Ak for bug-gnu-emacs@gnu.org; Mon, 24 Jun 2024 09:48:01 -0400 Original-Received: from debbugs.gnu.org ([2001:470:142:5::43]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1sLk36-0004fm-U1 for bug-gnu-emacs@gnu.org; Mon, 24 Jun 2024 09:48:01 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1sLk37-0004XM-N0 for bug-gnu-emacs@gnu.org; Mon, 24 Jun 2024 09:48:01 -0400 X-Loop: help-debbugs@gnu.org Resent-From: Visuwesh Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Mon, 24 Jun 2024 13:48:01 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 65892 X-GNU-PR-Package: emacs X-GNU-PR-Keywords: patch Original-Received: via spool by 65892-submit@debbugs.gnu.org id=B65892.171923684117368 (code B ref 65892); Mon, 24 Jun 2024 13:48:01 +0000 Original-Received: (at 65892) by debbugs.gnu.org; 24 Jun 2024 13:47:21 +0000 Original-Received: from localhost ([127.0.0.1]:58726 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1sLk2T-0004W3-1s for submit@debbugs.gnu.org; Mon, 24 Jun 2024 09:47:21 -0400 Original-Received: from mail-pf1-f196.google.com ([209.85.210.196]:42179) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1sLk2R-0004Vm-KK for 65892@debbugs.gnu.org; Mon, 24 Jun 2024 09:47:20 -0400 Original-Received: by mail-pf1-f196.google.com with SMTP id d2e1a72fcca58-7067435d376so900541b3a.0 for <65892@debbugs.gnu.org>; Mon, 24 Jun 2024 06:47:18 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1719236772; x=1719841572; darn=debbugs.gnu.org; h=mime-version:user-agent:message-id:date:references:in-reply-to :subject:cc:to:from:from:to:cc:subject:date:message-id:reply-to; bh=l4ixoOtT7sOoDUXZAwH+ulg/k4Mu1QoK3ylzoR+XWRU=; b=eyw+ZP5D9MCiDjoerRkcJRbTXOcqwS6+835//4XIvQ3nq6twst1BI+6dJD59rlfTnj xNqocltIVs+4X7ZobjgZLFxcwtNjXdTajclz95oUelaETUukAvUjDRZ68EwEWnK/L4Ci IhtwB5hrKgN1L33nqgtKIEAm9+HYTfewVKWSS36bGwV9Olx6mR64xiBGOZzecgv0uj2J dOMe0nqLlICYxBoBGcB6tueXQKk36bEv3PjmYM/rElsCPBUa7vsVJL3cgg8BhVb5sBfJ EOLlM0gMTYBc16EAP4EduVwf9wbPLuG8peS3N5muSDEkfk612h6HN7lHEBIYnaYxt2sc eh3Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1719236772; x=1719841572; h=mime-version:user-agent:message-id:date:references:in-reply-to :subject:cc:to:from:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=l4ixoOtT7sOoDUXZAwH+ulg/k4Mu1QoK3ylzoR+XWRU=; b=erKq8JlF324qClfi78O+zUjDNdvrldv8R6XMEmuiGscFsctp3AIbdCCKkNvSMwJFRq 3+keIGsVcHiIT2KKqxSpkxJI578aUXM4NDMkuk1WW/gVKsZAAnnz2BjvqUTSGBKllqZs ui6jYIpk8s0dOtWHGwxDJG1oBaj69DR4Nj0V2vicZ4HT1ka6U0Lk6YUEB817Gv4JDULC lzqWDUxVWP98Xjo6yaPJYB7WHSnpe40XbBXf9Kkpk8gec1o/OVTGfY8TacZTNNc8XzmR GqXArVBaZUl5+A1tt4+SX1MSYJAcmH650cz8VY4Jn/vd75SD5AVtQL2dKywrVyllaHz0 Cq6g== X-Gm-Message-State: AOJu0YzAejLUPiz7Iyo0fjIsvb+RlwSjiRICJ7+MMm4IgLHBr7snz6AY LF9/WsMI0CYUydeboIZCXJVpbXCZxO9/2vJ3MMtuDB+7/DXdXlWo X-Google-Smtp-Source: AGHT+IFMnKPbEvdMS2HkmixXb67HUuBXLs2NdTu2W6+m2GZWInTKOKoUZqrVLlskRL7NpMZhPCuTHg== X-Received: by 2002:a05:6a21:8186:b0:1b6:a692:8488 with SMTP id adf61e73a8af0-1bcec974010mr6054408637.14.1719236772398; Mon, 24 Jun 2024 06:46:12 -0700 (PDT) Original-Received: from localhost ([103.232.241.147]) by smtp.gmail.com with ESMTPSA id 41be03b00d2f7-716b4d54ea2sm5525007a12.54.2024.06.24.06.46.11 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 24 Jun 2024 06:46:11 -0700 (PDT) In-Reply-To: <86v81ybksc.fsf@gnu.org> (Eli Zaretskii's message of "Mon, 24 Jun 2024 15:13:55 +0300") X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-BeenThere: bug-gnu-emacs@gnu.org List-Id: "Bug reports for GNU Emacs, the Swiss army knife of text editors" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Original-Sender: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Xref: news.gmane.io gmane.emacs.bugs:287842 Archived-At: --=-=-= Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable [=E0=AE=A4=E0=AE=BF=E0=AE=99=E0=AF=8D=E0=AE=95=E0=AE=B3=E0=AF=8D =E0=AE=9C= =E0=AF=82=E0=AE=A9=E0=AF=8D 24, 2024] Eli Zaretskii wrote: >> From: Visuwesh >> Date: Mon, 24 Jun 2024 09:23:20 +0530 >>=20 >> 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.=20=20 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. --=-=-= Content-Type: text/x-diff Content-Disposition: attachment; filename=0001-Fix-yank-media-when-clipboard-selection-is-wiped-aft.patch >From 0aa3efd2e05dcc228e042b43fce6f997fd8afc1c Mon Sep 17 00:00:00 2001 From: Visuwesh 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 --=-=-=--