Subject: Re: bug#67925: 29.1; delete-rectangle fails on multi-column characters

From: [email-masked]
Date: Thu, 21 Dec 2023 16:30:39 +0900

Eli Zaretskii <[email-masked]> writes:

>> From: [email-masked]
>> Date: Wed, 20 Dec 2023 19:58:49 +0900
>> 
>> 
>> If a multi-column character is crossing the start column of a intended
>> rectangle, no characters are deleted in the same line.
>> 
>> For example, type 'C-x r d'(delete-rectangle) from column 1 to column 4
>> of the text below, the second line characters are not deleted.
>> 
>> 01234
>> 一二4
>> 01234
>> 
>> result:
>> 04
>> 一二4
>> 04
>> 
>> This does not apply to #'kill-rectangle.
>> kill-rectangle result:
>> 04
>> 一4
>> 04
>
> Thanks.  Does the patch below give good results?
>
> diff --git a/lisp/rect.el b/lisp/rect.el
> index 8dc188b..9049e32 100644
> --- a/lisp/rect.el
> +++ b/lisp/rect.el
> @@ -212,7 +212,10 @@ rectangle-dimensions
>        (cons width height))))
>  
>  (defun delete-rectangle-line (startcol endcol fill)
> -  (when (= (move-to-column startcol (if fill t 'coerce)) startcol)
> +  ;; We use >= here, not =, for characters that use more than one
> +  ;; column on display, when STARTCOL is in the middle of such a
> +  ;; character.
> +  (when (>= (move-to-column startcol (if fill t 'coerce)) startcol)
>      (delete-region (point)
>  		   (progn (move-to-column endcol 'coerce)
>  			  (point)))))

This patch gives similar result of kill-rectangle.
In the example above, I want all '4' characters moved to same column.

And TAB characters crossing the end column are not edited correctly
with delete-rectangle if indent-tabs-mode is on.

012345678
	8(TAB at head)
012345678

The text above is edited to the text below.
45678
	8(TAB at head)
45678

If indent-tabs-mode is off, the result is the text below.
45678
    8(four SPCs)
45678