bug#42865: 28.0.50; Add new 'copy-region-quietly' defcustom

classic Classic list List threaded Threaded
25 messages Options
12
Reply | Threaded
Open this post in threaded view
|

bug#42865: 28.0.50; Add new 'copy-region-quietly' defcustom

Sean Whitton
Tags: patch

Hello,

I want to have a way to suppress swapping point and mark when copying an
inactive region, as I find that distracting.  Here is a patch adding a
new defcustom to achieve that.

--
Sean Whitton

0001-Add-new-defcustom-copy-region-quietly.patch (4K) Download Attachment
Reply | Threaded
Open this post in threaded view
|

bug#42865: 28.0.50; Add new 'copy-region-quietly' defcustom

Lars Ingebrigtsen
Sean Whitton <[hidden email]> writes:

> +(defcustom copy-region-quietly nil
> +  "Whether the copying of an inactive region is indicated visually.
> +If nil, behave as per the documentation of `indicate-copied-region'.
> +`no-swap' means inhibit briefly swapping point and mark.
> +`no-message' means inhibit displaying a message.
> +Any other value means inhibit both swapping and message-displaying."
> +  :type '(choice :tag "Copy region quietly"
> +                 (const :tag "Default behavior" nil)
> +                 (const :tag "Don't swap point and mark" no-swap)
> +                 (const :tag "Don't display a message" no-message)
> +                 (const
> +                  :tag
> +                  "Don't swap point and mark or display a message"
> +                  t))
> +  :group 'killing)

Thanks for the patch.

The change looks reasonable to me, but I'm not quite sure of how useful
this is.  Does many people want to tweak the behaviour of this command
to this extent?

Perhaps somebody else on the bug tracker has opinions here.

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



Reply | Threaded
Open this post in threaded view
|

bug#42865: 28.0.50; Add new 'copy-region-quietly' defcustom

Juri Linkov-2
>> +(defcustom copy-region-quietly nil
>> +  "Whether the copying of an inactive region is indicated visually.
>> +If nil, behave as per the documentation of `indicate-copied-region'.
>> +`no-swap' means inhibit briefly swapping point and mark.
>> +`no-message' means inhibit displaying a message.
>> +Any other value means inhibit both swapping and message-displaying."
>> +  :type '(choice :tag "Copy region quietly"
>> +                 (const :tag "Default behavior" nil)
>> +                 (const :tag "Don't swap point and mark" no-swap)
>> +                 (const :tag "Don't display a message" no-message)
>> +                 (const
>> +                  :tag
>> +                  "Don't swap point and mark or display a message"
>> +                  t))
>> +  :group 'killing)
>
> Thanks for the patch.
>
> The change looks reasonable to me, but I'm not quite sure of how useful
> this is.  Does many people want to tweak the behaviour of this command
> to this extent?
>
> Perhaps somebody else on the bug tracker has opinions here.

When I needed to customize the behaviour of 'indicate-copied-region',
I relied on advice-add like this:

(advice-add 'kill-ring-save :after
            (lambda (&rest _args)
              (let ((text (substring-no-properties (current-kill 0))))
                (message "Copied text \"%s\""
                         ;; Don't show newlines literally
                         (query-replace-descr
                          (if (> (length text) 64)
                              (concat (substring text 0 64) "..." (substring text -16))
                            text)))))
            '((name . indicate-copied-region)))

that tries to fix the problem of multi-line messages that abruptly changes
the window configuration by resizing the echo area after text copying.
This problem is caused by the fact that 'indicate-copied-region' displays
the constant number of copied characters, including newlines.

Regarding a new option to disable such messages at all, it seems this is
a more general question because AFAIR, in the past, users asked for a way
to disable messages for many other commands, such as "Wrote ..." of 'save-buffer',
etc.

Maybe there should be a new feature allowing to disable messages selectively
for different commands?  Maybe just by putting a symbol property on the
command symbol.

Regarding disabling the "swapping point and mark" feature: since
'indicate-copied-region' uses 'blink-matching-delay', shouldn't this
behaviour be disabled by the existing option 'blink-matching-paren-on-screen'
in 'indicate-copied-region' as well (in addition to 'blink-matching-open'
where it's used originally)?



Reply | Threaded
Open this post in threaded view
|

bug#42865: 28.0.50; Add new 'copy-region-quietly' defcustom

Lars Ingebrigtsen
Juri Linkov <[hidden email]> writes:

> Regarding a new option to disable such messages at all, it seems this
> is a more general question because AFAIR, in the past, users asked for
> a way to disable messages for many other commands, such as "Wrote ..."
> of 'save-buffer', etc.
>
> Maybe there should be a new feature allowing to disable messages selectively
> for different commands?  Maybe just by putting a symbol property on the
> command symbol.

Many commands can issue different messages, while it's normally just the
specific "everything went well" thing users want to disable.  So I think
that may be confusing, interface wise?

But perhaps not?  If the symbol wasn't `silent' but instead
`no-normal-message' or something, then that could be used to disable any
messaging in the command on the "happy path".

> Regarding disabling the "swapping point and mark" feature: since
> 'indicate-copied-region' uses 'blink-matching-delay', shouldn't this
> behaviour be disabled by the existing option 'blink-matching-paren-on-screen'
> in 'indicate-copied-region' as well (in addition to 'blink-matching-open'
> where it's used originally)?

Hm...  I'd think paren blinking and copy-region blinking would be
something people would want to control separately.

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



Reply | Threaded
Open this post in threaded view
|

bug#42865: 28.0.50; Add new 'copy-region-quietly' defcustom

Sean Whitton
In reply to this post by Lars Ingebrigtsen
Hello Lars,

On Tue 18 Aug 2020 at 03:37PM +02, Lars Ingebrigtsen wrote:

> Sean Whitton <[hidden email]> writes:
>
>> +(defcustom copy-region-quietly nil
>> +  "Whether the copying of an inactive region is indicated visually.
>> +If nil, behave as per the documentation of `indicate-copied-region'.
>> +`no-swap' means inhibit briefly swapping point and mark.
>> +`no-message' means inhibit displaying a message.
>> +Any other value means inhibit both swapping and message-displaying."
>> +  :type '(choice :tag "Copy region quietly"
>> +                 (const :tag "Default behavior" nil)
>> +                 (const :tag "Don't swap point and mark" no-swap)
>> +                 (const :tag "Don't display a message" no-message)
>> +                 (const
>> +                  :tag
>> +                  "Don't swap point and mark or display a message"
>> +                  t))
>> +  :group 'killing)
>
> Thanks for the patch.
>
> The change looks reasonable to me, but I'm not quite sure of how useful
> this is.  Does many people want to tweak the behaviour of this command
> to this extent?
>
> Perhaps somebody else on the bug tracker has opinions here.

I just want to turn off the cursor blinking, but I thought I ought to
try to come up with a slightly more general solution just in case
someone wants it.

Currently I have (fset 'indicate-copied-region #'ignore) in my init file
but this is not a great way to customise something like this, hence my
patch.

It certainly seems plausible to me that others would want to turn off
the cursor blinking, but I'm not sure about how many people care about
the message.  If you think it would be better I could come up with a
simpler patch which only turns off blinking.

--
Sean Whitton



Reply | Threaded
Open this post in threaded view
|

bug#42865: 28.0.50; Add new 'copy-region-quietly' defcustom

Sean Whitton
In reply to this post by Juri Linkov-2
Hello,

On Wed 19 Aug 2020 at 04:16AM +03, Juri Linkov wrote:

> Regarding a new option to disable such messages at all, it seems this is
> a more general question because AFAIR, in the past, users asked for a way
> to disable messages for many other commands, such as "Wrote ..." of 'save-buffer',
> etc.
>
> Maybe there should be a new feature allowing to disable messages selectively
> for different commands?  Maybe just by putting a symbol property on the
> command symbol.

I agree that would be a cool feature.  In my own case, I just want to
get rid of the cursor blinking when copying the region.

> Regarding disabling the "swapping point and mark" feature: since
> 'indicate-copied-region' uses 'blink-matching-delay', shouldn't this
> behaviour be disabled by the existing option 'blink-matching-paren-on-screen'
> in 'indicate-copied-region' as well (in addition to 'blink-matching-open'
> where it's used originally)?

I'd like to have paren blinking turned on (it's too useful even if I
generally dislike blinking) but copy region blinking turned off (not
useful to me and visually distracting).

--
Sean Whitton



Reply | Threaded
Open this post in threaded view
|

bug#42865: 28.0.50; Add new 'copy-region-quietly' defcustom

Lars Ingebrigtsen
In reply to this post by Sean Whitton
Sean Whitton <[hidden email]> writes:

> It certainly seems plausible to me that others would want to turn off
> the cursor blinking, but I'm not sure about how many people care about
> the message.  If you think it would be better I could come up with a
> simpler patch which only turns off blinking.

The two behaviours are related (they are both ways of saying "we copied
this region"), so thinking about this a bit more, I think your patch
makes sense as is.

Let's give it a few more days to see whether anybody else has any views
on this before committing, though.

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



Reply | Threaded
Open this post in threaded view
|

bug#42865: 28.0.50; Add new 'copy-region-quietly' defcustom

Juri Linkov-2
In reply to this post by Lars Ingebrigtsen
>> Regarding a new option to disable such messages at all, it seems this
>> is a more general question because AFAIR, in the past, users asked for
>> a way to disable messages for many other commands, such as "Wrote ..."
>> of 'save-buffer', etc.
>>
>> Maybe there should be a new feature allowing to disable messages selectively
>> for different commands?  Maybe just by putting a symbol property on the
>> command symbol.
>
> Many commands can issue different messages, while it's normally just the
> specific "everything went well" thing users want to disable.  So I think
> that may be confusing, interface wise?
>
> But perhaps not?  If the symbol wasn't `silent' but instead
> `no-normal-message' or something, then that could be used to disable any
> messaging in the command on the "happy path".

Generally, different error levels should specify the message priority
(debug, info, warning, error).  I'm not quite sure what functions
correspond to these levels in Emacs.  Definitely, errors should be raised
by the function 'error', but it seems most messages are informational.

Anyway, here is a patch that allows disabling messages for particular
commands with e.g.

  (put 'kill-ring-save 'inhibit-message t)

diff --git a/src/xdisp.c b/src/xdisp.c
index ad03ac4605..9cbbec61f6 100644
--- a/src/xdisp.c
+++ b/src/xdisp.c
@@ -10984,7 +10984,7 @@ message3 (Lisp_Object m)
       message_dolog (buffer, nbytes, true, multibyte);
       SAFE_FREE ();
     }
-  if (! inhibit_message)
+  if (! inhibit_message && NILP (Fget (Vthis_command, Qinhibit_message)))
     message3_nolog (m);
 }
 
@@ -34348,6 +34353,7 @@ syms_of_xdisp (void)
 
   DEFSYM (Qredisplay_internal_xC_functionx, "redisplay_internal (C function)");
 
+  DEFSYM (Qinhibit_message, "inhibit-message");
   DEFVAR_BOOL("inhibit-message", inhibit_message,
               doc:  /* Non-nil means calls to `message' are not displayed.
 They are still logged to the *Messages* buffer.





Reply | Threaded
Open this post in threaded view
|

bug#42865: 28.0.50; Add new 'copy-region-quietly' defcustom

Juri Linkov-2
In reply to this post by Lars Ingebrigtsen
>> Regarding disabling the "swapping point and mark" feature: since
>> 'indicate-copied-region' uses 'blink-matching-delay', shouldn't this
>> behaviour be disabled by the existing option 'blink-matching-paren-on-screen'
>> in 'indicate-copied-region' as well (in addition to 'blink-matching-open'
>> where it's used originally)?
>
> Hm...  I'd think paren blinking and copy-region blinking would be
> something people would want to control separately.

Then for consistency with the existing defcustom
'blink-matching-paren-on-screen' the new defcustom's name could be
'blink-copy-region' or something like this.



Reply | Threaded
Open this post in threaded view
|

bug#42865: 28.0.50; Add new 'copy-region-quietly' defcustom

Lars Ingebrigtsen
Juri Linkov <[hidden email]> writes:

> Then for consistency with the existing defcustom
> 'blink-matching-paren-on-screen' the new defcustom's name could be
> 'blink-copy-region' or something like this.

Probably, if we add a separate functionality to disable the messaging...

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



Reply | Threaded
Open this post in threaded view
|

bug#42865: 28.0.50; Add new 'copy-region-quietly' defcustom

Juri Linkov-2
In reply to this post by Juri Linkov-2
> I think we'd have to introduce a new function, like...
>
> (defun information (name &rest args)
>   (when (information-wanted name)
>     (apply #'message args)))
>
> that would allow inhibiting messages based on names and or levels

This looks like the existing function 'user-error' that
doesn't enter the debugger when 'debug-on-error' is t.
Does the name 'user-message' make more sense?

But the problem is that it would be a huge endeavor
to replace all 'message' calls with a new function call.

So maybe a better route is to add a list of ignored messages like
'debug-ignored-errors' contains a list of regexps that match messages
to ignore.

Then this will disable display of the copy-region message:

  (add-to-list 'ignored-messages "^Saved text")



Reply | Threaded
Open this post in threaded view
|

bug#42865: 28.0.50; Add new 'copy-region-quietly' defcustom

Lars Ingebrigtsen
Juri Linkov <[hidden email]> writes:

> This looks like the existing function 'user-error' that
> doesn't enter the debugger when 'debug-on-error' is t.
> Does the name 'user-message' make more sense?

Yeah, that makes sense.

> But the problem is that it would be a huge endeavor
> to replace all 'message' calls with a new function call.

Well, we wouldn't want to do that -- we'd only replace the ones that
somebody thinks outputs a superfluous message.

> So maybe a better route is to add a list of ignored messages like
> 'debug-ignored-errors' contains a list of regexps that match messages
> to ignore.
>
> Then this will disable display of the copy-region message:
>
>   (add-to-list 'ignored-messages "^Saved text")

I'm not in favour of that -- different code can output the same message,
and it may be superfluous only from a specific function.

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



Reply | Threaded
Open this post in threaded view
|

bug#42865: 28.0.50; Add new 'copy-region-quietly' defcustom

Juri Linkov-2
>> This looks like the existing function 'user-error' that
>> doesn't enter the debugger when 'debug-on-error' is t.
>> Does the name 'user-message' make more sense?
>
> Yeah, that makes sense.

Then like 'signal' uses 'ERROR-SYMBOL' as an error symbol, not string,
'user-message' should use a symbol as well, e.g. in 'indicate-copied-region':

  (user-message
   'indicate-copied-region
   "Saved text until \"%s\"" (buffer-substring-no-properties (- mark len) mark))

then users put a property on that symbol:

  (put 'indicate-copied-region 'inhibit-message t)

to disable the message.



Reply | Threaded
Open this post in threaded view
|

bug#42865: 28.0.50; Add new 'copy-region-quietly' defcustom

Lars Ingebrigtsen
Juri Linkov <[hidden email]> writes:

> Then like 'signal' uses 'ERROR-SYMBOL' as an error symbol, not string,
> 'user-message' should use a symbol as well, e.g. in 'indicate-copied-region':
>
>   (user-message
>    'indicate-copied-region
>    "Saved text until \"%s\"" (buffer-substring-no-properties (- mark len) mark))
>
> then users put a property on that symbol:
>
>   (put 'indicate-copied-region 'inhibit-message t)
>
> to disable the message.

Or we could have inhibit-message also be a list of symbols to inhibit?
That would allow easier defcustomizing, perhaps?

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



Reply | Threaded
Open this post in threaded view
|

bug#42865: 28.0.50; Add new 'copy-region-quietly' defcustom

Stefan Kangas-2
Lars Ingebrigtsen <[hidden email]> writes:

> Juri Linkov <[hidden email]> writes:
>
>> Then like 'signal' uses 'ERROR-SYMBOL' as an error symbol, not string,
>> 'user-message' should use a symbol as well, e.g. in 'indicate-copied-region':
>>
>>   (user-message
>>    'indicate-copied-region
>>    "Saved text until \"%s\"" (buffer-substring-no-properties (- mark len) mark))
>>
>> then users put a property on that symbol:
>>
>>   (put 'indicate-copied-region 'inhibit-message t)
>>
>> to disable the message.
>
> Or we could have inhibit-message also be a list of symbols to inhibit?
> That would allow easier defcustomizing, perhaps?

Maybe it's less messy (and easier to document) if we just introduce a
new defcustom `inhibit-user-message'?



Reply | Threaded
Open this post in threaded view
|

bug#42865: 28.0.50; Add new 'copy-region-quietly' defcustom

Lars Ingebrigtsen
Stefan Kangas <[hidden email]> writes:

> Maybe it's less messy (and easier to document) if we just introduce a
> new defcustom `inhibit-user-message'?

Yes, probably.

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



Reply | Threaded
Open this post in threaded view
|

bug#42865: 28.0.50; Add new 'copy-region-quietly' defcustom

Juri Linkov-2
In reply to this post by Lars Ingebrigtsen
>> Then like 'signal' uses 'ERROR-SYMBOL' as an error symbol, not string,
>> 'user-message' should use a symbol as well, e.g. in 'indicate-copied-region':
>>
>>   (user-message
>>    'indicate-copied-region
>>    "Saved text until \"%s\"" (buffer-substring-no-properties (- mark len) mark))
>>
>> then users put a property on that symbol:
>>
>>   (put 'indicate-copied-region 'inhibit-message t)
>>
>> to disable the message.
>
> Or we could have inhibit-message also be a list of symbols to inhibit?

Or a list of regexps for those users who want to inhibit message strings
directly by a regexp instead of messing with an intermediate layer of symbols :)

IOW, I still prefer the simplicity of such regexps as

  (add-to-list 'inhibit-message "^Saved text until")

and can't imagine a situation why I'd want to inhibit such message
for one command but not for another.



Reply | Threaded
Open this post in threaded view
|

bug#42865: 28.0.50; Add new 'copy-region-quietly' defcustom

Stefan Kangas-2
Juri Linkov <[hidden email]> writes:

> IOW, I still prefer the simplicity of such regexps as
>
>   (add-to-list 'inhibit-message "^Saved text until")
>
> and can't imagine a situation why I'd want to inhibit such message
> for one command but not for another.

One package says: "Saved text until end"

Another one says: "Saved text until end... failed, retry to avoid data
loss"

And then you have the joy when the message text changes...

Best regards,
Stefan Kangas



Reply | Threaded
Open this post in threaded view
|

bug#42865: 28.0.50; Add new 'copy-region-quietly' defcustom

Juri Linkov-2
>> IOW, I still prefer the simplicity of such regexps as
>>
>>   (add-to-list 'inhibit-message "^Saved text until")
>>
>> and can't imagine a situation why I'd want to inhibit such message
>> for one command but not for another.
>
> One package says: "Saved text until end"
>
> Another one says: "Saved text until end... failed, retry to avoid data
> loss"

Then it could match the whole message with $ at the end.

  (add-to-list 'inhibit-message "^Saved text until end$")

> And then you have the joy when the message text changes...

The message text changes not often.  But the symbol approach is much worse
because it takes the freedom from users - in case of symbols the developers
decide whether to allow the users to inhibit messages or not.  When developers
allow to inhibit some messages by adding a new symbol to the message function,
then it takes many years until the users can start using new symbols to
inhibit messages after the next release.

OTOH, in case of regexps, the users decide what text they want to inhibit
without waiting for developers adding new symbols.

For example, in https://debbugs.gnu.org/21893#23
I needed to inhibit the message from view-end-message.
With a regexp this would be very easy:

  (add-to-list 'inhibit-message "^End of buffer")

But currently I use such complicated advice:

  (advice-add 'view-end-message :around
              (lambda (orig-fun &rest args)
                (let ((inhibit-message t))
                  (apply orig-fun args)))
              '((name . non-verbose-view-end-message)))

Also using regexps will obsolete many such ad-hoc options as
'view-inhibit-help-message'.



Reply | Threaded
Open this post in threaded view
|

bug#42865: 28.0.50; Add new 'copy-region-quietly' defcustom

Stefan Kangas-2
Juri Linkov <[hidden email]> writes:

> The message text changes not often.  But the symbol approach is much worse
> because it takes the freedom from users - in case of symbols the developers
> decide whether to allow the users to inhibit messages or not.  When developers
> allow to inhibit some messages by adding a new symbol to the message function,
> then it takes many years until the users can start using new symbols to
> inhibit messages after the next release.

I think you convinced me, thanks.  I still think people will shoot
themselves in the foot, but OTOH we are hardly strangers to that.

Let's hear what others have to say.



12