unofficial mirror of emacs-devel@gnu.org 
 help / color / mirror / code / Atom feed
* Re: master c9a8a47ba4: Add new user option 'yank-transform-functions'
       [not found] ` <20220519221545.35270C009A8@vcs2.savannah.gnu.org>
@ 2022-05-24 15:24   ` Stefan Monnier
  2022-05-24 16:02     ` Lars Ingebrigtsen
  2022-05-24 16:07     ` Robert Pluim
  0 siblings, 2 replies; 5+ messages in thread
From: Stefan Monnier @ 2022-05-24 15:24 UTC (permalink / raw)
  To: Lars Ingebrigtsen; +Cc: emacs-devel

Lars Ingebrigtsen [2022-05-19 18:15:45] wrote:
>     * lisp/simple.el (yank-transform-functions): New user option.
>     (yank): Mention it.

Hmm... why is this a user option?
[ Also, tho less importantly: Why is it a list of functions instead of
  being symmetric with Emacs-28's `kill-transform-function`?  ]

Are users expected to be able to make use of this with Custom?  How?

> +@defopt yank-transform-functions
> +This variable is a list of functions.  Each function is called (in
> +order) with the string to be yanked as the parameter, and should
> +return a (possibly transformed) string.  This variable can be set
> +globally, but can also be used to create new commands that are
> +variations on @code{yank}.  For instance, to create a command that
> +works like @code{yank}, but cleans up whitespace before inserting, you
> +could say something like:
> +
> +@lisp
> +(defun yank-with-clean-whitespace ()
> +  (interactive)
> +  (let ((yank-transform-functions
> +	 '(string-clean-whitespace)))
> +    (call-interactively #'yank)))
> +@end lisp
> +@end defopt

This example doesn't call for a `defcustom` but for a `defvar`, no?


        Stefan




^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: master c9a8a47ba4: Add new user option 'yank-transform-functions'
  2022-05-24 15:24   ` master c9a8a47ba4: Add new user option 'yank-transform-functions' Stefan Monnier
@ 2022-05-24 16:02     ` Lars Ingebrigtsen
  2022-05-24 16:15       ` Stefan Monnier
  2022-05-24 16:07     ` Robert Pluim
  1 sibling, 1 reply; 5+ messages in thread
From: Lars Ingebrigtsen @ 2022-05-24 16:02 UTC (permalink / raw)
  To: Stefan Monnier; +Cc: emacs-devel

Stefan Monnier <monnier@iro.umontreal.ca> writes:

>>     * lisp/simple.el (yank-transform-functions): New user option.
>>     (yank): Mention it.
>
> Hmm... why is this a user option?
> [ Also, tho less importantly: Why is it a list of functions instead of
>   being symmetric with Emacs-28's `kill-transform-function`?  ]
>
> Are users expected to be able to make use of this with Custom?  How?

It's a list of functions because it's a defcustom, really.  I envisioned
that people might be wanting to add other things to it to (say) record
yanked text, for instance.

>> +@lisp
>> +(defun yank-with-clean-whitespace ()
>> +  (interactive)
>> +  (let ((yank-transform-functions
>> +	 '(string-clean-whitespace)))
>> +    (call-interactively #'yank)))
>> +@end lisp
>> +@end defopt
>
> This example doesn't call for a `defcustom` but for a `defvar`, no?

It's in the lispref manual.

-- 
(domestic pets only, the antidote for overdose, milk.)
   bloggy blog: http://lars.ingebrigtsen.no



^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: master c9a8a47ba4: Add new user option 'yank-transform-functions'
  2022-05-24 15:24   ` master c9a8a47ba4: Add new user option 'yank-transform-functions' Stefan Monnier
  2022-05-24 16:02     ` Lars Ingebrigtsen
@ 2022-05-24 16:07     ` Robert Pluim
  2022-05-24 17:13       ` Lars Ingebrigtsen
  1 sibling, 1 reply; 5+ messages in thread
From: Robert Pluim @ 2022-05-24 16:07 UTC (permalink / raw)
  To: Stefan Monnier; +Cc: Lars Ingebrigtsen, emacs-devel

>>>>> On Tue, 24 May 2022 11:24:26 -0400, Stefan Monnier <monnier@iro.umontreal.ca> said:

    Stefan> Lars Ingebrigtsen [2022-05-19 18:15:45] wrote:
    >> * lisp/simple.el (yank-transform-functions): New user option.
    >> (yank): Mention it.

    Stefan> Hmm... why is this a user option?
    Stefan> [ Also, tho less importantly: Why is it a list of functions instead of
    Stefan>   being symmetric with Emacs-28's `kill-transform-function`?  ]

Presumably because that makes it easier for users to modify.

    Stefan> Are users expected to be able to make use of this with Custom?  How?

I was expecting a set of pre-defined functions along the lines of

- 'yank-remove-whitespace
- 'yank-remove-non-ascii
- 'yank-replace-nbsp-and-similar

etc.


Robert
-- 



^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: master c9a8a47ba4: Add new user option 'yank-transform-functions'
  2022-05-24 16:02     ` Lars Ingebrigtsen
@ 2022-05-24 16:15       ` Stefan Monnier
  0 siblings, 0 replies; 5+ messages in thread
From: Stefan Monnier @ 2022-05-24 16:15 UTC (permalink / raw)
  To: Lars Ingebrigtsen; +Cc: emacs-devel

Lars Ingebrigtsen [2022-05-24 18:02:11] wrote:
> Stefan Monnier <monnier@iro.umontreal.ca> writes:
>>>     * lisp/simple.el (yank-transform-functions): New user option.
>>>     (yank): Mention it.
>>
>> Hmm... why is this a user option?
>> [ Also, tho less importantly: Why is it a list of functions instead of
>>   being symmetric with Emacs-28's `kill-transform-function`?  ]
>>
>> Are users expected to be able to make use of this with Custom?  How?
>
> It's a list of functions because it's a defcustom, really.

[ FWIW, `kill-transform-function` is also a defcustom, tho I'd argue it
  would be better defined as a `defvar` for the same kinds of
  reasons.  ]

> I envisioned that people might be wanting to add other things to it to
> (say) record yanked text, for instance.

"Record yanked text" doesn't seem like a very compelling example.
I've never heard of anyone requesting such a feature or anything nearby.
And I'd expect such a feature to come in the form of a minor mode
instead (whose code then programmatically sets this var).

The problem with making it a defcustom is that packages can't
programmatically modify this var without risks of interfering
with Custom (e.g. the famous "CHANGED OUTSIDE CUSTOMIZE").

>>> +@lisp
>>> +(defun yank-with-clean-whitespace ()
>>> +  (interactive)
>>> +  (let ((yank-transform-functions
>>> +	 '(string-clean-whitespace)))
>>> +    (call-interactively #'yank)))
>>> +@end lisp
>>> +@end defopt
>> This example doesn't call for a `defcustom` but for a `defvar`, no?
> It's in the lispref manual.

Right, but it's the only example I can find (and any uses of Custom on
this var during the above command may result in an incorrect value
being saved in the user's init file).

[ FWIW, this discussion is prompted by my trying to use this var in
  `nhexl-mode` where it would be set rather than being let-bound.  ]


        Stefan




^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: master c9a8a47ba4: Add new user option 'yank-transform-functions'
  2022-05-24 16:07     ` Robert Pluim
@ 2022-05-24 17:13       ` Lars Ingebrigtsen
  0 siblings, 0 replies; 5+ messages in thread
From: Lars Ingebrigtsen @ 2022-05-24 17:13 UTC (permalink / raw)
  To: Robert Pluim; +Cc: Stefan Monnier, emacs-devel

Robert Pluim <rpluim@gmail.com> writes:

>     Stefan> Are users expected to be able to make use of this with Custom?  How?
>
> I was expecting a set of pre-defined functions along the lines of
>
> - 'yank-remove-whitespace
> - 'yank-remove-non-ascii
> - 'yank-replace-nbsp-and-similar

Yes, I was thinking that we'd grow functions like that after a while.
However, it's pretty situational whether you'd want these, so perhaps
this is unneeded flexibility/complexity.

That is, I can see people wanting to (say) make `C-u 2 C-y' yank without
whitespace, so they write a `yank-remove-whitespace-when-c-u-2' and put
it into here...  But on the other hand, just advising `yank' is probably
easier, really.

So perhaps this should really be a defvar with a single function, so
that modes can set it buffer-locally, for instance.

Stefan Monnier <monnier@iro.umontreal.ca> writes:

>> I envisioned that people might be wanting to add other things to it to
>> (say) record yanked text, for instance.
>
> "Record yanked text" doesn't seem like a very compelling example.
> I've never heard of anyone requesting such a feature or anything nearby.

Oh, there's been some talk about clipboard managers and the like, and
this would be a simple way to have an equivalent thing (if you're
yanking from other programs; otherwise you'd use the "kill" hook).

> And I'd expect such a feature to come in the form of a minor mode
> instead (whose code then programmatically sets this var).

Yes, that's probably true.

> The problem with making it a defcustom is that packages can't
> programmatically modify this var without risks of interfering
> with Custom (e.g. the famous "CHANGED OUTSIDE CUSTOMIZE").

Hm, yes.  I think I agree that it should be a defvar.

-- 
(domestic pets only, the antidote for overdose, milk.)
   bloggy blog: http://lars.ingebrigtsen.no



^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2022-05-24 17:13 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
     [not found] <165299854484.648.782279094390042574@vcs2.savannah.gnu.org>
     [not found] ` <20220519221545.35270C009A8@vcs2.savannah.gnu.org>
2022-05-24 15:24   ` master c9a8a47ba4: Add new user option 'yank-transform-functions' Stefan Monnier
2022-05-24 16:02     ` Lars Ingebrigtsen
2022-05-24 16:15       ` Stefan Monnier
2022-05-24 16:07     ` Robert Pluim
2022-05-24 17:13       ` Lars Ingebrigtsen

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).