all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: Eli Zaretskii <eliz@gnu.org>
To: awrhygty@outlook.com
Cc: 67925@debbugs.gnu.org
Subject: bug#67925: 29.1; delete-rectangle fails on multi-column characters
Date: Thu, 21 Dec 2023 10:42:35 +0200	[thread overview]
Message-ID: <831qbggd50.fsf@gnu.org> (raw)
In-Reply-To: <TYZPR01MB3920B781C31D1E33C79B1E89C395A@TYZPR01MB3920.apcprd01.prod.exchangelabs.com> (awrhygty@outlook.com)

> From: awrhygty@outlook.com
> Cc: 67925@debbugs.gnu.org
> Date: Thu, 21 Dec 2023 16:30:39 +0900
> 
> Eli Zaretskii <eliz@gnu.org> writes:
> 
> > 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.

How can that be done, when the first character takes 2 or more
columns?  Deleting the first character is IMO wrong, since the other
lines leave the first character intact.  Adding SPC to other lines is
also wrong, since delete-rectangle is not supposed to _add_ columns.

So I think the effect you see after the patch I proposed is the only
reasonable outcome.  If that is not good enough for keeping the layout
of some table (as you hint in your original report, without showing
any details about the mode used in that case), then Lisp programs
which allow you to keep such tables aligned should be modified to do
something that cannot be done in general by delete-rectangle.

IOW, the general issue in delete-rectangle cannot do anything smarter
than the above, I think, and any solution specific to some particular
implementation or use of rectangles will have to be fixed by code
specific to that particular implementation (if that is some mode that
is part of Emacs).

> 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

This is a separate issue with the original code.  It also happens with
kill-rectangle, btw.  We could fix it by temporarily binding
indent-tabs-mode to nil inside these commands -- would that be
acceptable?  The result will be that the killed rectangle includes
spaces, not the leading TAB.





  reply	other threads:[~2023-12-21  8:42 UTC|newest]

Thread overview: 17+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-12-20 10:58 bug#67925: 29.1; delete-rectangle fails on multi-column characters awrhygty
2023-12-20 14:09 ` Eli Zaretskii
2023-12-21  7:30   ` awrhygty
2023-12-21  8:42     ` Eli Zaretskii [this message]
2023-12-21 14:26       ` awrhygty
2023-12-21 16:46         ` Eli Zaretskii
2023-12-21 21:12           ` Stefan Monnier via Bug reports for GNU Emacs, the Swiss army knife of text editors
2023-12-22  7:56           ` Juri Linkov
2023-12-22 11:45             ` Eli Zaretskii
2023-12-22 14:27             ` Stefan Monnier via Bug reports for GNU Emacs, the Swiss army knife of text editors
2023-12-23 17:30               ` Juri Linkov
2023-12-23 18:07                 ` Eli Zaretskii
2023-12-24  8:31                   ` Juri Linkov
2023-12-24 14:52                     ` Stefan Kangas
2023-12-28  9:01                       ` Eli Zaretskii
2024-01-03 19:00                         ` awrhygty
2024-01-03 19:31                           ` Eli Zaretskii

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=831qbggd50.fsf@gnu.org \
    --to=eliz@gnu.org \
    --cc=67925@debbugs.gnu.org \
    --cc=awrhygty@outlook.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/emacs.git
	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.