emacs-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Patch for beginning-of-visual-line and end-of-visual-line


From: Justin Burkett
Subject: Patch for beginning-of-visual-line and end-of-visual-line
Date: Fri, 11 Aug 2017 13:24:54 -0400

Hi,

I found (what seems like) a bug in these two functions. The docstrings
advertise that they should stop if they reach the beginning or end of
buffer and they don't. As a test cast, try

(beginning-of-visual-line 2)

in a buffer with one line. According to the docstring, point should be
at the end of the buffer, but it ends up at the beginning for me in
Emacs 25.2.1.

Here's a patch that works for me.

Justin

diff --git a/lisp/simple.el b/lisp/simple.el
index 3d23fc3..04d8030 100644
--- a/lisp/simple.el
+++ b/lisp/simple.el
@@ -6682,9 +6682,10 @@ To ignore intangibility, bind
`inhibit-point-motion-hooks' to t."
   (if (/= n 1)
       (let ((line-move-visual t))
  (line-move (1- n) t)))
-  ;; Unlike `move-beginning-of-line', `move-end-of-line' doesn't
-  ;; constrain to field boundaries, so we don't either.
-  (vertical-motion (cons (window-width) 0)))
+  (unless (or (bobp) (eobp))
+    ;; Unlike `move-beginning-of-line', `move-end-of-line' doesn't
+    ;; constrain to field boundaries, so we don't either.
+    (vertical-motion (cons (window-width) 0))))

 (defun beginning-of-visual-line (&optional n)
   "Move point to beginning of current visual line.
@@ -6697,9 +6698,10 @@ To ignore intangibility, bind
`inhibit-point-motion-hooks' to t."
     (if (/= n 1)
  (let ((line-move-visual t))
   (line-move (1- n) t)))
-    (vertical-motion 0)
-    ;; Constrain to field boundaries, like `move-beginning-of-line'.
-    (goto-char (constrain-to-field (point) opoint (/= n 1)))))
+    (unless (or (bobp) (eobp))
+      (vertical-motion 0)
+      ;; Constrain to field boundaries, like `move-beginning-of-line'.
+      (goto-char (constrain-to-field (point) opoint (/= n 1))))))

 (defun kill-visual-line (&optional arg)
   "Kill the rest of the visual line.



reply via email to

[Prev in Thread] Current Thread [Next in Thread]