]> git.eshelyaron.com Git - emacs.git/commitdiff
Stop term-erase-in-line disturbing markers
authorDaniel Colascione <dancol@dancol.org>
Sat, 8 Mar 2025 00:22:56 +0000 (16:22 -0800)
committerEshel Yaron <me@eshelyaron.com>
Sun, 9 Mar 2025 10:25:08 +0000 (11:25 +0100)
* lisp/term.el (term-erase-in-line): do nothing if there's nothing to
do; insert new newlines before deleting old ones.

(cherry picked from commit 062c6ab3dd5a1ce85fb7cb0fc84b65aa2cf60369)

lisp/term.el

index 0048e0c690856dd63e3e4fd6a62e0e5516f3ae7b..2773dcb6ba6b326934116cecd922c74e229c9a31 100644 (file)
@@ -4019,19 +4019,24 @@ The top-most line is line 0."
          (wrapped (and (zerop (term-horizontal-column))
                        (not (zerop (term-current-column))))))
       (term-vertical-motion 1)
-      (delete-region saved-point (point))
-      ;; wrapped is true if we're at the beginning of screen line,
-      ;; but not a buffer line.  If we delete the current screen line
-      ;; that will make the previous line no longer wrap, and (because
-      ;; of the way Emacs display works) point will be at the end of
-      ;; the previous screen line rather then the beginning of the
-      ;; current one.  To avoid that, we make sure that current line
-      ;; contain a space, to force the previous line to continue to wrap.
-      ;; We could do this always, but it seems preferable to not add the
-      ;; extra space when wrapped is false.
-      (when wrapped
-       (insert ? ))
-      (insert ?\n)
+      ;; Do nothing if we have nothing to delete
+      (unless (and (eq saved-point (1- (point)))
+                   (eq (char-before) ?\n)
+                   (not wrapped))
+        ;; Insert before deletion to preserve markers.
+        ;; wrapped is true if we're at the beginning of screen line,
+        ;; but not a buffer line.  If we delete the current screen line
+        ;; that will make the previous line no longer wrap, and (because
+        ;; of the way Emacs display works) point will be at the end of
+        ;; the previous screen line rather then the beginning of the
+        ;; current one.  To avoid that, we make sure that current line
+        ;; contain a space, to force the previous line to continue to wrap.
+        ;; We could do this always, but it seems preferable to not add the
+        ;; extra space when wrapped is false.
+        (when wrapped
+         (insert-before-markers ? ))
+        (insert-before-markers ?\n)
+        (delete-region saved-point (point)))
       (put-text-property saved-point (point) 'font-lock-face 'default)
       (goto-char saved-point))))