Subject: Re: bug#64104: Subject: 30.0.50; uncomment-region-default-1

From: Andreas Röhler <[email-masked]>
Date: Sun, 18 Jun 2023 15:00:19 +0200

Am 18.06.23 um 07:53 schrieb Eli Zaretskii:
>> From: Stefan Monnier <[email-masked]>
>> Cc: Andreas Röhler <[email-masked]>,
>>    [email-masked]
>> Date: Sat, 17 Jun 2023 14:39:08 -0400
>>
>>>> C-u comment-dwim RET with an active region of the following Python code:
>>>>
>>>> ---
>>>> # for i in text:
>>>> #     print("(i): {}".format(str(i)))
>>>> ---
>>>>
>>>> results in error saying
>>>>
>>>> uncomment-region-default-1: Beginning of buffer
>>> Stefan, any comments?
>> - The error we give is not very user-friendly, so it might be good to
>>    catch it and re-raise it as something more meaning ful the specific
>>    operation performed.
>>
>> - I have the vague impression that in some earlier version of that code we
>>    would not signal an error but just remove as many comment markers as
>>    possible (but no more than requested).
>>    That could be a more friendly behavior.
> I'll leave the bug open, then.  Patches to improve this command are
> welcome.

Unfortunately don't have a trivial fix.

Suggest a simplified caller:

(defun comment-dwim (arg)
   "Call the comment command you want (Do What I Mean).

Comment or uncomment the current line, or, if active, the region.

With \\[universal-argument] copy line or region before changing it.

You can configure `comment-style' to change the way regions are commented."
   (interactive "*P")
   (comment-normalize-vars)
   (when (eq 4 (prefix-numeric-value))
     (copy-region-as-kill (or (region-beginning) 
(line-beginning-position)) (or (region-end) (line-end-position))))
   (comment-or-uncomment-region (or (region-beginning) 
(line-beginning-position)) (or (region-end)) (line-end-position)))