From: Eli Zaretskii <eliz@gnu.org>
To: Liu Hui <liuhui1610@gmail.com>
Cc: 45837@debbugs.gnu.org
Subject: bug#45837: 28.0.50; incorrect cursor position in visual-line-mode when word-wrap-by-category is t
Date: Thu, 14 Jan 2021 15:51:47 +0200 [thread overview]
Message-ID: <83v9bzbp8s.fsf@gnu.org> (raw)
In-Reply-To: <CAOQTW-PgkF5P-TeFeXtY27wwsrefgg42Es0Nj6FSKGYYjYR7bQ@mail.gmail.com> (message from Liu Hui on Thu, 14 Jan 2021 12:51:12 +0800)
> From: Liu Hui <liuhui1610@gmail.com>
> Date: Thu, 14 Jan 2021 12:51:12 +0800
> Cc: 45837@debbugs.gnu.org
>
> BTW, in the case above, if the line wraps after a non-whitespace
> character, C-k does not delete this character. How about the following
> change to kill-visual-line?
Yes, good catch. However, this is not entirely right, as the code you
suggest should be _instead_ of skipping the whitespace that follows,
not _in_addition_ to it (imagine that the line is wrapped at a
non-whitespace character followed by whitespace). And while looking
into adapting your patch to avoid removing more than the user
intended, I found more issues with the existing code. So I'm
proposing the patch below instead, which should correctly handle the
following use cases:
. visual line that ends in one or more whitespace characters, and the
following visual line begins with one or more whitespace characters
. visual line that ends with a non-whitespace character (under
word-wrap-by-category) that is followed by one or more whitespace
characters
. line that is continued on the next visual line (visual-line-mode is
off)
. visual line that is wrapped in the middle of a display string or an
overlay string with embedded whitespace characters
. visual line that is wrapped in the middle of intangible text
(The patch also fixes some minor issues with the documentation of this
command.)
WDYT?
diff --git a/lisp/simple.el b/lisp/simple.el
index 54c35c04be..e7421c069f 100644
--- a/lisp/simple.el
+++ b/lisp/simple.el
@@ -5606,7 +5606,9 @@ zap-to-char
;; kill-line and its subroutines.
(defcustom kill-whole-line nil
- "If non-nil, `kill-line' with no arg at start of line kills the whole line."
+ "If non-nil, `kill-line' with no arg at start of line kills the whole line.
+This variable also affects `kill-visual-line' in the same way as
+it does `kill-line'."
:type 'boolean
:group 'killing)
@@ -7319,6 +7321,9 @@ kill-visual-line
If ARG is zero, kill the text before point on the current visual
line.
+If `kill-whole-line' is non-nil, and this command is invoked at
+start of a line that ands in a newline, kill the newline as well.
+
If you want to append the killed line to the last killed text,
use \\[append-next-kill] before \\[kill-line].
@@ -7331,18 +7336,26 @@ kill-visual-line
;; Like in `kill-line', it's better to move point to the other end
;; of the kill before killing.
(let ((opoint (point))
- (kill-whole-line (and kill-whole-line (bolp))))
+ (kill-whole-line (and kill-whole-line (bolp)))
+ (orig-y (cdr (nth 2 (posn-at-point)))))
(if arg
(vertical-motion (prefix-numeric-value arg))
(end-of-visual-line 1)
(if (= (point) opoint)
(vertical-motion 1)
- ;; Skip any trailing whitespace at the end of the visual line.
- ;; We used to do this only if `show-trailing-whitespace' is
- ;; nil, but that's wrong; the correct thing would be to check
- ;; whether the trailing whitespace is highlighted. But, it's
- ;; OK to just do this unconditionally.
- (skip-chars-forward " \t")))
+ ;; The first condition below verifies we are still on the same
+ ;; screen line, i.e. that the line isn't continued, and that
+ ;; end-of-visual-line didn't overshoot due to complications
+ ;; like display or overlay strings, intangible text, etc.:
+ ;; otherwise, we don't want to kill a character that's
+ ;; unrelated to the place where the visual line wrapped.
+ (and (= (cdr (nth 2 (posn-at-point))) orig-y)
+ ;; Make sure we delete the character where the line wraps
+ ;; under visual-line-mode.
+ (or (looking-at-p "[ \t]")
+ (and word-wrap-by-category
+ (aref (char-category-set (following-char)) ?\|)))
+ (forward-char))))
(kill-region opoint (if (and kill-whole-line (= (following-char) ?\n))
(1+ (point))
(point)))))
next prev parent reply other threads:[~2021-01-14 13:51 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-01-13 2:27 bug#45837: 28.0.50; incorrect cursor position in visual-line-mode when word-wrap-by-category is t Liu Hui
2021-01-13 14:47 ` Eli Zaretskii
2021-01-14 4:51 ` Liu Hui
2021-01-14 13:51 ` Eli Zaretskii [this message]
2021-01-15 7:28 ` Liu Hui
2021-01-15 8:15 ` Eli Zaretskii
2021-01-18 17:14 ` Eli Zaretskii
2021-01-21 3:07 ` Liu Hui
2021-01-21 14:22 ` 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
List information: https://www.gnu.org/software/emacs/
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=83v9bzbp8s.fsf@gnu.org \
--to=eliz@gnu.org \
--cc=45837@debbugs.gnu.org \
--cc=liuhui1610@gmail.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 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).