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#75116: [PATCH] Make 'yank-media' autoselect the best media type Date: Mon, 06 Jan 2025 10:07:12 +0530 Message-ID: <87bjwkbls7.fsf@gmail.com> References: <87o70yeiih.fsf@gmail.com> <86r05uxx4i.fsf@gnu.org> <871pxtcxiq.fsf@gmail.com> <86r05sro63.fsf@gnu.org> Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="25252"; mail-complaints-to="usenet@ciao.gmane.io" User-Agent: Gnus/5.13 (Gnus v5.13) Cc: yantar92@posteo.net, pinmacs@cas.cat, rpluim@gmail.com, 75116@debbugs.gnu.org To: Eli Zaretskii Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Mon Jan 06 05:39:50 2025 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 1tUeu6-0006QU-Go for geb-bug-gnu-emacs@m.gmane-mx.org; Mon, 06 Jan 2025 05:39:50 +0100 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1tUeta-00050P-Mh; Sun, 05 Jan 2025 23:39:18 -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 1tUetZ-0004zz-6Q for bug-gnu-emacs@gnu.org; Sun, 05 Jan 2025 23:39:17 -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 1tUetY-0000mX-U8 for bug-gnu-emacs@gnu.org; Sun, 05 Jan 2025 23:39:16 -0500 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=debbugs.gnu.org; s=debbugs-gnu-org; h=MIME-Version:Date:References:In-Reply-To:From:To:Subject; bh=tTHFTRC+TzVIOzrDkrMMGwvsD0Z/2iYHmKKTiGRG8VU=; b=AektJ5XbloDK2lRCNTFW2jLF1H/w72O/dUUKbEy5pOwh2xFHe+NZbxOzfGgfDLEjhS36tX+Dyo1Os9aLd4CCUKfY/iCUR6+G5VXBnICwzGGoGx9aeIyWyw6ogHS9OsBzDdYvf07JOZ6IjVrcsAKVKQucHvk6dik/Ql0ndck4Q2dMCW4LL/8dWrTMzvZelRLGfAcDi5VnaH73YmyRNWaDwjn0lF0UY+wQcjS6IYNf71iHEe4VegbtwT7Et/Epmm0hhMCwyPydXQjuGClTCkg57rDvGJX+7wplHfj0xd0qt4TQ1tufSJzhbRJLVQySTjFMyZCrCniLFDSrYpmWmKMYzw==; Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1tUetY-00039x-Fv for bug-gnu-emacs@gnu.org; Sun, 05 Jan 2025 23:39:16 -0500 X-Loop: help-debbugs@gnu.org Resent-From: Visuwesh Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Mon, 06 Jan 2025 04:39:16 +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.173613835012136 (code B ref 75116); Mon, 06 Jan 2025 04:39:16 +0000 Original-Received: (at 75116) by debbugs.gnu.org; 6 Jan 2025 04:39:10 +0000 Original-Received: from localhost ([127.0.0.1]:36347 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1tUetQ-00039A-8T for submit@debbugs.gnu.org; Sun, 05 Jan 2025 23:39:10 -0500 Original-Received: from mail-pj1-x1041.google.com ([2607:f8b0:4864:20::1041]:53366) by debbugs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.84_2) (envelope-from ) id 1tUes0-0002qN-Vr for 75116@debbugs.gnu.org; Sun, 05 Jan 2025 23:39:04 -0500 Original-Received: by mail-pj1-x1041.google.com with SMTP id 98e67ed59e1d1-2ef28f07dbaso15694666a91.2 for <75116@debbugs.gnu.org>; Sun, 05 Jan 2025 20:37:40 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1736138258; x=1736743058; darn=debbugs.gnu.org; h=content-transfer-encoding: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=tTHFTRC+TzVIOzrDkrMMGwvsD0Z/2iYHmKKTiGRG8VU=; b=P/JIz6234YtBVX5R4mpDE4yqoQKvh4Esfrwp9mt3ohu4pbBbgtsE9y/DB2GsGz8E16 J5HdQHH/nQsmj+K4GElGStJ5tQSv5obR3ygwH8QVOiXObFxsDKj1qVzb5VcmsEMMzCHK UbGdZhGBgL9KQlbxCxO4Ig0Ssd3ls62u7M8Ug/Y1Lrhboga6YZj2VkTqhJkO3AqosaYm 5Z//4RR6j3oWqKlpDUFZlHc2cOk7W0OeEcTVPekbv68RxyrMAZyo6PtGF52js98mZh6O iY4MeUG9iqGB1N3bVKIk+AqdbHgRo4m1m20RpmnbcmdbHTwb4hDHIhwygr3pdjnnpMpl tTPw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1736138258; x=1736743058; h=content-transfer-encoding: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=tTHFTRC+TzVIOzrDkrMMGwvsD0Z/2iYHmKKTiGRG8VU=; b=Uvc1jP42rpvyjTekJYvFturAsSLC6N4XkR6UddRthKkJfgDw3FdTrgmWAIIM0rcfx1 m9S0OGV2wdMr00s72K5X3w2zSBsMKcyu8BmiZ0+Cub5a0VAtzkGIUfdG0iNXzJJlU2sd 3qNl2JNUmLA4g6CLMvtWcvyCZC07EQDpAQi7+PgIVHDDijA1/gG8ZMSLXwkdprGSPJ0q EWeHILxH/3EWQMgJ+Eea7pa3Ixz1rDQEBYQbYzI+7leyr0TuOZS4yQ/74OX+wOOPhe3C RHmdQhqijlbrneiWI2fEGUSREsyHDfupg0GcxuqDvrFfOoXooGGQv6/zqlbIeraA3GMU VPPQ== X-Gm-Message-State: AOJu0Yw5b2s/yOaBq2WMOkw5+B4nY25tvVHOMo8eauDbAURxtgHaMUrw 6Elq8ApeArxsZ9/nL9xfnPklqe14knsTDLRiVQ5e9j/9Cj/GBbzK X-Gm-Gg: ASbGncuJZ9djfb7GZcCvOmgYqxzsOTxKbeA1lHtRQzdq7SCeXYTiWAe1yJw9EpnwK+0 nuQfqY2gku3xqHHYslYCUUM6gj/kZXlwwcYf9tSi2+FR8k05HTTs/zLgAfBcvKONtIIog5Lyp3u xkgjYSvZPurR96OfAjTADgCCgqiFow7MDi0iHOgMITXnzCGxQcN3RR5cBUtqVJ/LhJP5ZoNsaaE g0ClPOu8qZN7NRuv+F2a5N1eMjFNRP4cg0aaPhexw+SDrZ5W0ITWQ== X-Google-Smtp-Source: AGHT+IHOPrLJxNs1EayEDMk4imH7bu5GpAAgkZHgw1w33et3kXuzuRJ8bWpF8LKc/FWTMJ/S/0ynOg== X-Received: by 2002:a17:90b:2d44:b0:2ee:df57:b194 with SMTP id 98e67ed59e1d1-2f452e3c70amr76553358a91.21.1736138258421; Sun, 05 Jan 2025 20:37:38 -0800 (PST) Original-Received: from localhost ([49.204.136.228]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-219dc9f7d83sm284422595ad.226.2025.01.05.20.37.37 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 05 Jan 2025 20:37:38 -0800 (PST) In-Reply-To: <86r05sro63.fsf@gnu.org> (Eli Zaretskii's message of "Sat, 28 Dec 2024 14:24:04 +0200") 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:298628 Archived-At: [=E0=AE=9A=E0=AE=A9=E0=AE=BF =E0=AE=9F=E0=AE=BF=E0=AE=9A=E0=AE=AE=E0=AF=8D= =E0=AE=AA=E0=AE=B0=E0=AF=8D 28, 2024] Eli Zaretskii wrote: >> >> +(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 manag= er. >> >> + ,(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.=20=20 >>=20 >> These are media types for which support for yank-media already exists: > > I thought we should have here as many media types as possible, > regardless of their support, because this variable expresses the > relative priorities of the types. Major modes which add handlers > should not need to also modify the value of this variable > unnecessarily, no? I agree with you but I am limited by my awareness of these potential media types. I would be happy to add more if someone points me to them. >> > Also, aren't at least some of the types system-dependent? >>=20 >> Yes, definitely. x/special-gnome-files and >> application/x-libreoffice-tsvc are system- and software-dependent resp. >> This was one of my comments addressed in the message I posted to >> emacs-devel: >>=20 >> The mimetype used for cut/copied files only works in Linux >> environments. If other platforms can present such file:// links in >> the clipboard and Emacs supports it, we would need to add it to the >> list too. >>=20 >> If we want platform-agnostic types, I assume we need an abstraction >> layer on top that would present the clipboard data in a uniform manner. >> I do not have the means to work on this since I only use Linux systems. > > I just thought about having the value depend on the platform. Ah, understood. >> >> + (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 t= ype, >> >> + ;; just call the handler. >> >> + ((and (null pref-type) (length=3D 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. >>=20 >> I want to ensure we are on the same page wrt UI here: >>=20 >> User asks to autoselect: >> 1. autoselect-function (a-s-f) returns one media type: we yank it. > > Yes. > >> 2. a-s-f returns multiple media types: we ask the user which one >> to yank. > > No, we use the first one. Doesn't this mean there is pratically no difference between (1) and (2)? Ihor, is this okay? Or did you have something else in mind when you asked for the possibility to return multiple types? >> 3. a-s-f returns nil. We show a message and do what? > > We show a message and do nothing. > >> User asks not to autoselect: >> 4. (length all-types) =3D 1: We show the media type and ask if she >> wants to yank it. > > Yes. > >> 5. (length all-types) > 1: We ask for the media type to yank. > > Yes. > >> Excepting case (3), does the other cases sound good? > > See above regarding my opinions. Thank you, they are clear now.