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.devel Subject: Re: yank-media: allow users to limit image types that can be inserted Date: Thu, 31 Oct 2024 14:16:07 +0530 Message-ID: <87v7x8y81c.fsf@gmail.com> References: <79fc91f3-c2c3-44db-9817-595808917f26@cas.cat> <87zfnywki8.fsf@gmail.com> <86setqfnmq.fsf@gnu.org> <87frpqflv4.fsf@gmail.com> <86ikumfjri.fsf@gnu.org> <877cb2fj0c.fsf@gmail.com> <86cykufhw7.fsf@gnu.org> <3a015d0f-549a-401f-be1c-651c9dbd5d9a@cas.cat> <8634lqfcaf.fsf@gnu.org> <87ikulwsd6.fsf@gmail.com> <86o74ddzxp.fsf@gnu.org> <87msiqvkph.fsf@localhost> <86ed42bs03.fsf@gnu.org> <874j4yot7x.fsf@localhost> <861q01c3h9.fsf@gnu.org> <87wmht3n17.fsf@gmail.com> <86v7xdamck.fsf@gnu.org> <87sesh37ya.fsf@gmail.com> <86iktd8o9h.fsf@gnu.org> <87iktb171d.fsf@gmail.com> <861pzw4r3j.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="25515"; 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, emacs-devel@gnu.org To: Eli Zaretskii Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane-mx.org@gnu.org Thu Oct 31 09:47:00 2024 Return-path: Envelope-to: ged-emacs-devel@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 1t6QpW-0006PX-Vy for ged-emacs-devel@m.gmane-mx.org; Thu, 31 Oct 2024 09:46:59 +0100 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1t6Qor-0006yn-4P; Thu, 31 Oct 2024 04:46:17 -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 1t6Qoq-0006ye-8q for emacs-devel@gnu.org; Thu, 31 Oct 2024 04:46:16 -0400 Original-Received: from mail-pl1-x644.google.com ([2607:f8b0:4864:20::644]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1t6Qoo-000227-4V; Thu, 31 Oct 2024 04:46:15 -0400 Original-Received: by mail-pl1-x644.google.com with SMTP id d9443c01a7336-20c7ee8fe6bso6310715ad.2; Thu, 31 Oct 2024 01:46:13 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1730364372; x=1730969172; darn=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=k4dEuiyMG90sG2+ZSvMlppyBvysMQvjDI3hk+/kaTbg=; b=UFLuwGKnGcHoDLDZ6TQ/HV9rMQ2o/3SPs3zDSIw7gTTd8w4jw7xoB8KtDJi6TI/kvT klFtFuhyrLJeD5O9Ks3/QUvAIKGiBRNTs0J1otEO0n9/0RR8TaDculDSj1rGxH42tLtP psGTWumrt+W2jzz3vdjtkI++3QG167L5k37rUweFlY1I/eKRTzUzn0z5TpMR9Hw6h7BW lLyqORfsgrSUly8LkC/AJJKqSAz0YK8mrPwCHe7/pHvsL7udqpP2u+rM3mhNmU5KAX5f gJg21PTMPm4mUFhL7pMVBGDrj8CUhgOmlBlgG7fxYzOtMlKD+OlqUWF3YJfbxZrQW632 CVXQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1730364372; x=1730969172; 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=k4dEuiyMG90sG2+ZSvMlppyBvysMQvjDI3hk+/kaTbg=; b=lIjPigYQR2/HE+X5dSuY34wUMWpHMxXi8aLkkwt1Fd6Rvdf07MV5ZoNJi1031N2GFs 1Hyrb9GmFT87uBqP49JwHNBxsXu6z0y5GLBg7YmIij1sm0IW0fHQRHkB3cAHbaa5xXrI bNwX97mf2hrLtTKJxoQoiCLl+TaMmBsEO0IKc/hI3UowwHuOL8rNmvBf20ziSr3jugwK AdR4sR1pEbgCmX38qtkiIJXWHfEQ8vVlLaF5eCHQYIE2t61Rjc/XlUnvrZWGfGHiox0Z nIB8ZuaQEEsm1MFBPCIVn316D2jEJIK3F6vE+LXv/0R1MA39UM8uDkBsq76f73uqzKHe 8h2A== X-Forwarded-Encrypted: i=1; AJvYcCXMxPGdPIay2fLV9NOF80XgB3oom92nivpQiOboXmNaQZNKCw6AWGtFsyZIe/EuEPmbDeY4PkgMGq6uXA==@gnu.org X-Gm-Message-State: AOJu0Yw/05jqHDCSS4TT5RxmesSZN+Q6HLiabk0giHiLkrfKJOvvdVRK KUwR9VE4XDMeEaqpuifpledcQTpq6w0DEOQkISRQSiIEsermNaEDNfJoa3iJsQs= X-Google-Smtp-Source: AGHT+IF9WIyZUm5RvrTha4+Xs66NeXq6qy21SiLvlpyGPCu96vBLyx3OGMLwTeEWytX6yL3TZPnNFQ== X-Received: by 2002:a17:902:ce87:b0:210:e75f:e6b0 with SMTP id d9443c01a7336-210e75fe74fmr146413485ad.40.1730364371768; Thu, 31 Oct 2024 01:46:11 -0700 (PDT) Original-Received: from localhost ([1.7.159.70]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-211056edc71sm5970625ad.60.2024.10.31.01.46.10 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 31 Oct 2024 01:46:11 -0700 (PDT) In-Reply-To: <861pzw4r3j.fsf@gnu.org> (Eli Zaretskii's message of "Thu, 31 Oct 2024 10:24:48 +0200") Received-SPF: pass client-ip=2607:f8b0:4864:20::644; envelope-from=visuweshm@gmail.com; helo=mail-pl1-x644.google.com X-Spam_score_int: 22 X-Spam_score: 2.2 X-Spam_bar: ++ X-Spam_report: (2.2 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_FROM=0.001, FREEMAIL_REPLY=1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_SBL_CSS=3.335, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=no autolearn_force=no X-Spam_action: no action X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: "Emacs development discussions." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-devel-bounces+ged-emacs-devel=m.gmane-mx.org@gnu.org Original-Sender: emacs-devel-bounces+ged-emacs-devel=m.gmane-mx.org@gnu.org Xref: news.gmane.io gmane.emacs.devel:324959 Archived-At: [=E0=AE=B5=E0=AE=BF=E0=AE=AF=E0=AE=BE=E0=AE=B4=E0=AE=A9=E0=AF=8D =E0=AE=85= =E0=AE=95=E0=AF=8D=E0=AE=9F=E0=AF=8B=E0=AE=AA=E0=AE=B0=E0=AF=8D 31, 2024] E= li Zaretskii wrote: >> From: Visuwesh >> Cc: yantar92@posteo.net, pinmacs@cas.cat, rpluim@gmail.com, >> emacs-devel@gnu.org >> Date: Tue, 29 Oct 2024 16:59:34 +0530 >>=20 >> > My suggestion does not require any need to know those ugly details. >> > It just suggests to remove from the list the handlers a mode doesn't >> > want. Removing the, say, image/png handler from the list does not >> > require any knowledge how that handler accesses the clipboard nor how >> > it extracts PNG images from the clipboard. It just requires to know >> > the (trivial) fact that an image/png handler can interpret the >> > clipboard data as a PNG image. >> > >> > So I don't think I understand your reasoning. What did I miss? >>=20 >> That the user does want PNG images is a "soft preference." If the >> clipboard only has image/png, the user would have the image/png data >> instead of none at all. You offered a solution for this: bind >> yank-media--registered-handlers in a custom command but having a >> variable would make it easy for the user to have a _global_ preference >> across major-modes. > > This (and the patch you suggest) completes the full circle of this > discussion: it started when I said that such a global preference makes > very little sense to me, based on my experience with yanking different > data types in other applications. Users have no reason for such > preferences, as they almost never have enough reasons to prefer one > type over the others _globally_. The preference only makes sense in > each specific case, and then asking the user to choose is exactly TRT, > which we already do. At least for images, I see a value in having a global preference. You also seem to agree on this point. >> >> The major-mode authors would simply write handlers for all relevant >> >> data types and leave it to the user to choose the preferred type if >> >> more than one of them is handled by the major-mode. >> > >> > AFAIU, we were talking about situations where the major mode "knows >> > better" than the user, and doesn't want to leave the choice to users. >>=20 >> No, the major-mode does not "know better" than user. > > It might, though. And it already does, in fact: the few modes which > support yank-media only register some of the handlers, but not others. > Did you ask yourself why message.el registers only the handler for > images, but not, say, for text/html? A major mode which doesn't > support embedded images will probably refrain from installing image/* > handlers, etc. Sure but it doesn't help when the major-mode can support multiple image formats but the user wants a specific format always.=20=20 >> It simply wants to respect the "soft" preferences of the user. > > If we think such global preferences might make sense, we need to > describe and discuss the use cases and reasons for having such > preferences. Until now, the only reason I've heard was the desire to > save some typing, i.e. let Emacs yank the one "preferred" media type > without asking. If that is the reason, we could have instead a > feature whereby "the best" or "the most appropriate" media type is > yanked without asking; for example if yank-media is invoked with a > prefix argument. (Or maybe the other way around: without the argument > yank-media would yank "the best" media type.) This is what many other > applications do, except that they do it when you type Ctrl-V, whereas > we decided, and for good reasons, not to change how C-y work (though I > don't see why some optional feature could not make C-y call > yank-media). I agree that it would be good to have yank-media choose the most appropriate format itself. >> > I don't understand how. TARGETS include stuff like image/png and >> > text/html; how does looking at that defeat any abstractions, and what >> > abstractions are those? We cannot consider TARGETS to be an opaque >> > object anyway because then we won't be able to ask the user which of >> > the MIME types she wants to yank, nor apply any advance preferences of >> > the user. >>=20 >> The MIME type the user wants to yank is asked by _yank-media_ currently. >> The major-mode has no part in this conversation, and this is exactly >> what we want to change. > > Major mode _does_ have a part: it registers only the handlers it wants > to support. So it determines, up front, which media types will be > available, even if more of them are in the clipboard. I agree but its participation could be improved. When you copy a cell from LibreOffice's Excel clone, it puts both image/png and a TSV data type in your clipboard. Taking the example of Org which has a handler registered for image/png: if it registers a handler for the TSV data type, the user would be asked to choose between image/png and TSV when she copies a table cell. The intent of registering image/png is a hindrance here. Having a separate command for yanking a table cell would remove the convenience of having a single command that does TRT. >> Without the patch applied, copying an image from Firefox and using >> yank-media in an Org buffer asks me if I want image/png or image/jpeg. > > Please tell me why on earth would you prefer PNG to JPEG when yanking, > or vice versa. The result is an image displayed in the buffer, which > is neither PNG nor JPEG. Why does it matter _for_you_personally_ > which intermediate format will Emacs use as part of the yanking > process? You answered the question yourself: For example, JPEG is generally inferior because it's lossy, so we could have that hypothetical variant of yank-media which doesn't ask questions to always prefer PNG to JPEG if both are possible. >> With that patch applied, and after evaluating=20 >>=20 >> (setq-local >> yank-media-preferred-type-function >> (lambda (types) >> (if (memq 'image/png types) >> (list 'image/png) >> types))) >>=20 >> in an Org buffer, or message-mode buffer, I don't get asked that >> question. Afterwards, I copy a JPEG image using xclip then do >> yank-media. This yanks the image without asking me anything. This would >> not be possible had Org or message-mode only registered a handler for >> image/png. > > If we want to avoid the question when several image formats are > available, we could teach Org, or Emacs in general, which formats to > prefer. For example, JPEG is generally inferior because it's lossy, > so we could have that hypothetical variant of yank-media which doesn't > ask questions to always prefer PNG to JPEG if both are possible. This > is IMO better than asking the users to decide that for Emacs. I agree, but can we, at least, agree that it should be easy to override it completely? What do you think about adding a patch like I proposed but also having a "sensible" default definition of yank-media-preferred-type-function? (for some definition of sensible.) > Anyway, since with this message we've made a full circle, let me > summarize my opinions on this: > > . I think we should add to Emacs rules for preferring one media > format over the others when several are available and supported > . Such rules should be customized by major modes based on their > features and preferences (e.g., a mode that has no support for > faces might prefer plain text to other textual formats) (1) and (2) would be best done with the help of user feedback. A patch like the one I proposed would help to kick-start it. IMO, coming up with such rules is a long game that requires user feedback (like the one that started this whole thread). Due to the number of users and its relevance, Org is a good ground for obtaining user feedback on this subject. > . I think we should have a variant of yank-media that yanks "the > best" of the available formats without asking, based on the above > rules I like your idea of reusing C-u for this. > If after all of this people still want a global "preference", I won't > mount the barricades to fight that, although, as I explained, such a > global preference makes little sense to me, and sounds like an > inferior replacement for the missing built-in preference rules I think > we should have. The built-in preference rules is already a global "preference" from where I stand. Only that, the OP wanted control over these rules.