summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNoam Postavsky <npostavs@gmail.com>2018-03-11 20:47:12 -0400
committerNoam Postavsky <npostavs@gmail.com>2018-03-13 21:58:38 -0400
commit4c33ad4a244db59bfe128aa54380904efdc775ba (patch)
tree95211f134f4c33187a4a9344b13dda2db93d0c8b
parente0f18aa07fb900c1bb0fe25386336fd6a73c9b0d (diff)
downloademacs-4c33ad4a244db59bfe128aa54380904efdc775ba.tar.gz
Fix line-wrapping for term.el (Bug#30775)
* lisp/term.el (term-emulate-terminal): Leave line-wrapping state if point was moved after we entered it. * test/lisp/term-tests.el (term-line-wrapping-then-motion): New test.
-rw-r--r--lisp/term.el11
-rw-r--r--test/lisp/term-tests.el12
2 files changed, 20 insertions, 3 deletions
diff --git a/lisp/term.el b/lisp/term.el
index 93da33ea5b0..91eab771cf0 100644
--- a/lisp/term.el
+++ b/lisp/term.el
@@ -2891,9 +2891,11 @@ See `term-prompt-regexp'."
;; If the last char was written in last column,
;; back up one column, but remember we did so.
;; Thus we emulate xterm/vt100-style line-wrapping.
- (cond ((eq (term-current-column) term-width)
- (term-move-columns -1)
- (setq term-do-line-wrapping t)))
+ (when (eq (term-current-column) term-width)
+ (term-move-columns -1)
+ ;; We check after ctrl sequence handling if point
+ ;; was moved (and leave line-wrapping state if so).
+ (setq term-do-line-wrapping (point)))
(setq term-current-column nil)
(setq i funny))
(pcase-exhaustive (and (<= ctl-end str-length) (aref str i))
@@ -2993,6 +2995,9 @@ See `term-prompt-regexp'."
(substring str i ctl-end)))))
;; Ignore NUL, Shift Out, Shift In.
((or ?\0 #xE #xF 'nil) nil))
+ ;; Leave line-wrapping state if point was moved.
+ (unless (eq term-do-line-wrapping (point))
+ (setq term-do-line-wrapping nil))
(if (term-handling-pager)
(progn
;; Finish stuff to get ready to handle PAGER.
diff --git a/test/lisp/term-tests.el b/test/lisp/term-tests.el
index 234dfa1f0d5..8aaa61a210b 100644
--- a/test/lisp/term-tests.el
+++ b/test/lisp/term-tests.el
@@ -124,6 +124,18 @@ line6\r
40 12 (list "\eAnSiTc /f" "oo/\n") 'default-directory)
"/foo/"))))
+(ert-deftest term-line-wrapping-then-motion ()
+ "Make sure we reset the line-wrapping state after moving cursor.
+A real-life example is the default zsh prompt which writes spaces
+to the end of line (triggering line-wrapping state), and then
+sends a carriage return followed by another space to overwrite
+the first character of the line."
+ (let* ((width 10)
+ (strs (list "x" (make-string (1- width) ?_)
+ "\r_")))
+ (should (equal (term-test-screen-from-input width 12 strs)
+ (make-string width ?_)))))
+
(provide 'term-tests)
;;; term-tests.el ends here