From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Eli Zaretskii Newsgroups: gmane.emacs.bugs Subject: bug#75116: [PATCH] Make 'yank-media' autoselect the best media type Date: Thu, 26 Dec 2024 17:49:33 +0200 Message-ID: <86r05uxx4i.fsf@gnu.org> References: <87o70yeiih.fsf@gmail.com> Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="2122"; mail-complaints-to="usenet@ciao.gmane.io" Cc: yantar92@posteo.net, pinmacs@cas.cat, rpluim@gmail.com, 75116@debbugs.gnu.org To: Visuwesh Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Thu Dec 26 16:50:23 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 1tQq7z-0000PH-49 for geb-bug-gnu-emacs@m.gmane-mx.org; Thu, 26 Dec 2024 16:50:23 +0100 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1tQq7h-0001oh-8x; Thu, 26 Dec 2024 10:50:05 -0500 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 1tQq7e-0001n5-Uu for bug-gnu-emacs@gnu.org; Thu, 26 Dec 2024 10:50:03 -0500 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 1tQq7e-0001gk-Lx for bug-gnu-emacs@gnu.org; Thu, 26 Dec 2024 10:50:02 -0500 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=debbugs.gnu.org; s=debbugs-gnu-org; h=References:In-Reply-To:From:Date:To:Subject; bh=aicOYiONo00StYYTvonTjNyrkYhTCL3SH4x2D+NFFrM=; b=M2ulnqrgNKyovvb0J0M/pSRP0D4vgmDe1BJzYo8/o5+6V5C8SvFHl9CB5fGh6VVDSmAs6WIQ5OHRTJw9VtdiTeD3ZsRyMmNIwWn9meMXr5Ob2uQsh5cGf+94V2MAenCoABxra52RzHUxkUgIGV9lJQqrtHM9a/sQI+F76pkS80k36faCUGQiIWMkgkk00uYZ3damhXNYCLNCcHDAVgT7/8k63tdIv1Laiq4Ay/nxr5R0MgOS5w/XrXPcUd/BuPP5Z6F8SZtyW4UnAEEHWzvwRF47lpyRdmO5emNg3G1WW8AjAS4l9GyeiVPb/5lTOgVuYtl4ExEYFVssFBGiFiACdw==; Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1tQq7e-0004id-9W for bug-gnu-emacs@gnu.org; Thu, 26 Dec 2024 10:50:02 -0500 X-Loop: help-debbugs@gnu.org Resent-From: Eli Zaretskii Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Thu, 26 Dec 2024 15:50:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 75116 X-GNU-PR-Package: emacs X-GNU-PR-Keywords: patch Original-Received: via spool by 75116-submit@debbugs.gnu.org id=B75116.173522818618107 (code B ref 75116); Thu, 26 Dec 2024 15:50:02 +0000 Original-Received: (at 75116) by debbugs.gnu.org; 26 Dec 2024 15:49:46 +0000 Original-Received: from localhost ([127.0.0.1]:41927 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1tQq7O-0004hz-0Z for submit@debbugs.gnu.org; Thu, 26 Dec 2024 10:49:46 -0500 Original-Received: from eggs.gnu.org ([209.51.188.92]:40630) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1tQq7K-0004hl-Bo for 75116@debbugs.gnu.org; Thu, 26 Dec 2024 10:49:44 -0500 Original-Received: from fencepost.gnu.org ([2001:470:142:3::e]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1tQq7D-0001eP-6v; Thu, 26 Dec 2024 10:49:35 -0500 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=gnu.org; s=fencepost-gnu-org; h=References:Subject:In-Reply-To:To:From:Date: mime-version; bh=aicOYiONo00StYYTvonTjNyrkYhTCL3SH4x2D+NFFrM=; b=F2i1NgDrzWoi jMrCrpPtsJnBYrwLWafvy7lfxjprGE/3vmIeRvDBtcHzNy0GJ0rinxvHnjcbYdNmIncSJhPGGrxjV z2o4ROOBF/w0BTTLOUPCEfz80NaMLyqWyD+TodnfLRTHxZNa2VjqVNuVzdLAH5l69FB19ynkfMJE3 7zHqATVuobxncahG0Yel7+lzD2VZc/Cr+vvx9C+OfILaG6UV2nppYYHjmZA81bUPm/4YYSo+bYz4H AIb54G2pC4wWIL2UrK/LlsbQlmGGcSDAGJAfxPLRF+Zs6+Jw58q/UjbAZNXiSBOqkIwjnstZ/Mmzq y8LxZoRXT4cfhG4TNciATw==; In-Reply-To: <87o70yeiih.fsf@gmail.com> (message from Visuwesh on Thu, 26 Dec 2024 17:57:50 +0530) 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:297773 Archived-At: > Cc: Ihor Radchenko , pinmacs@cas.cat, rpluim@gmail.com, Eli Zaretskii > From: Visuwesh > Date: Thu, 26 Dec 2024 17:57:50 +0530 > > This is a continuation of the long thread in emacs-devel: > https://yhetil.org/emacs-devel/79fc91f3-c2c3-44db-9817-595808917f26@cas.cat/ > > This message provides a summary: > https://yhetil.org/87r06cj2nd.fsf@gmail.com > > Ihor wrote: > > > The only comment is that leaving an option to return a list of types > > rather than only a single type will make things more flexible. > > And this is now done in the attached patch. Thanks. > Before I go about writing NEWS and updating the manual, what do you > think about the attached instead? Some comments below. > I think the variable > yank-media-preferred-types gives a more granular control for major-mode > authors than (add-function (local 'yank-media-autoselect-function) ...) Maybe. But one of my comments is exactly about that: I don't quite understand your intent for how major modes should use this variable (since neither the doc string nor the comments spell that out). Would you please explain your thoughts on that? > +(defvar yank-media-preferred-types > + `(;; Check first since LibreOffice also puts a PNG image in the > + ;; clipboard when a table cell is copied. > + application/x-libreoffice-tsvc > + ;; Give PNG more priority. > + image/png > + image/jpeg > + ;; These are files copied/cut to the clipboard from a file manager. > + ,(lambda (mimetypes) > + (seq-find (lambda (type) > + (string-match-p "x-special/\\(gnome\\|KDE\\|mate\\)-files" > + (symbol-name type))) > + mimetypes)) > + ;; FIXME: We should have a way to handle text/rtf. > + text/html) Not sure I understand the value you suggest. It seems to lack many important types. Also, aren't at least some of the types system-dependent? > + "List of mime types in the order of preference. > +Each element in the list should be a symbol to choose the mime type > +denoted by it, or a function of one argument, the mime types available, > +and should return the mime types to use.") If this is intended for major modes to override, we should say so in the doc string. > +(defvar yank-media-autoselect-function #'yank-media-autoselect-function > + "Function to auto select the best mime types when many are available. ^^^^ I suggest "more than one" there. "Many" could be misinterpreted to exclude the case of just two possible types. > + (setq pref-type (and (null noselect) > + (funcall yank-media-autoselect-function > + (mapcar #'car all-types)))) > + (cond > + ;; We have one preferred mime type so use it unconditionally. > + ((and pref-type (symbolp pref-type)) > + (funcall (cdr (assq pref-type all-types)) pref-type > + (yank-media--get-selection pref-type))) > + ;; The user chose to not autoselect and there's just a single type, > + ;; just call the handler. > + ((and (null pref-type) (length= all-types 1)) > + (funcall (cdar all-types) (caar all-types) > + (yank-media--get-selection (caar all-types)))) This goes against what the doc string says. And I think the doc string describes a better behavior: if the user asked not to auto-select, we shouldn't, even if there's just one type available. We should instead ask the user whether to yank that type, because the user could decide she doesn't want that type, even it it's the only one. Also, I think we should show some message if yank-media-autoselect-function returns nil. AFAIU, the code you posted silently does nothing, which IMO is not the best UI. > I know that I have to update the Info node (info "(elisp) Yanking > Media"). Does (info "(emacs) Clipboard") need any update too? IMO, yes. In fact, I think the user-facing part of the description of yank-media should be moved to the Emacs user manual, the "Clipboard" node.