Fix movement to the left in picture-mode
authorEli Zaretskii <eliz@gnu.org>
Sun, 10 Nov 2024 08:56:40 +0000 (10:56 +0200)
committerEshel Yaron <me@eshelyaron.com>
Fri, 15 Nov 2024 12:40:45 +0000 (13:40 +0100)
* lisp/textmodes/picture.el (picture-insert): Measure width by
counting columns on display, not by using 'string-width', because
the latter is inaccurate when TABs are involved.  (Bug#74255)

(cherry picked from commit 7dabfe9465c623043e4ea1abe618a6169c155d04)

lisp/textmodes/picture.el

index 481dbe8cb8a14a99243dc93d0330ab50240dcb92..37d1e59ac6e2156fb348e62350148ca8886afc96 100644 (file)
@@ -264,9 +264,14 @@ Use \"\\[command-apropos] picture-movement\" to see commands which control motio
          (move-to-column picture-desired-column t))
       (let ((col (+ picture-desired-column width)))
        (or (eolp)
-           (let ((pos (point)))
-             (move-to-column col t)
-             (let ((old-width (string-width (buffer-substring pos (point)))))
+           (let ((pos (point))
+                  (col0 (current-column))
+                  col1)
+             (setq col1 (move-to-column col t))
+              ;; We count columns, not width, because move-to-column
+              ;; could insert TABs, which width depends on horizontal
+              ;; position.
+             (let ((old-width (- (max col0 col1) (min col0 col1))))
                (delete-region pos (point))
                (when (> old-width width)
                  (insert-char ?  (- old-width width))