aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGerd Moellmann2001-05-28 13:01:24 +0000
committerGerd Moellmann2001-05-28 13:01:24 +0000
commit3db6f8cad4d4dc0fc29662ed86f806e56429597e (patch)
treef5db59aa667da6e615fba125de7bbb6053cf0d7b
parent393d2dbf4a1fb21303b3933270f620a24baae719 (diff)
downloademacs-3db6f8cad4d4dc0fc29662ed86f806e56429597e.tar.gz
emacs-3db6f8cad4d4dc0fc29662ed86f806e56429597e.zip
(comint-carriage-motion): Renamed from
`comint-cr-magic'. Operate on the buffer instead of the string (for use as a comint post-output filter, instead of as a pre-output filter). Handle backspaces too. Add to the `comint-output-filter-functions' hook instead of `comint-preoutput-filter-functions'.
-rw-r--r--lisp/comint.el54
1 files changed, 34 insertions, 20 deletions
diff --git a/lisp/comint.el b/lisp/comint.el
index 04dd848a539..dbd520ba569 100644
--- a/lisp/comint.el
+++ b/lisp/comint.el
@@ -1495,29 +1495,43 @@ This variable is permanent-local.")
1495 (overlay-put comint-last-prompt-overlay 'evaporate t) 1495 (overlay-put comint-last-prompt-overlay 'evaporate t)
1496 (setq comint-last-prompt-overlay nil))) 1496 (setq comint-last-prompt-overlay nil)))
1497 1497
1498(defun comint-cr-magic (string) 1498(defun comint-carriage-motion (string)
1499 "Handle carriage returns in comint output. 1499 "Handle carriage returns in comint output.
1500Translate carraige return/linefeed sequences to linefeeds. 1500Translate carraige return/linefeed sequences to linefeeds.
1501Let single carriage returns delete to the beginning of the line." 1501Let single carriage returns delete to the beginning of the line.
1502Let backspaces delete the previous character.
1503
1504This function should be in the list `comint-output-filter-functions'."
1502 (save-match-data 1505 (save-match-data
1503 ;; CR LF -> LF 1506 ;; We first check to see if STRING contains any magic characters, to
1504 (while (string-match "\r\n" string) 1507 ;; avoid overhead in the common case where it does not
1505 (setq string (replace-match "\n" nil t string))) 1508 (when (string-match "[\r\b]" string)
1506 ;; Let a single CR act like a carriage return on a real terminal. 1509 (let ((pmark (process-mark (get-buffer-process (current-buffer)))))
1507 ;; Delete everything from the beginning of the line to the 1510 (save-excursion
1508 ;; insertion point. 1511 (save-restriction
1509 (when (string-match ".*\r" string) 1512 (widen)
1510 (setq string (replace-match "" nil t string)) 1513 (let ((inhibit-field-text-motion t)
1511 (save-excursion 1514 (buffer-read-only nil))
1512 (save-restriction 1515 ;; CR LF -> LF
1513 (widen) 1516 ;; Note that this won't work properly when the CR and LF
1514 (let ((inhibit-field-text-motion t) 1517 ;; are in different output chunks, but this is probably an
1515 (buffer-read-only nil)) 1518 ;; exceedingly rare case (because they are generally
1516 (goto-char (process-mark (get-buffer-process (current-buffer)))) 1519 ;; written as a unit), and to delay interpretation of a
1517 (delete-region (line-beginning-position) (point)))))) 1520 ;; trailing CR in a chunk would result in odd interactive
1518 string)) 1521 ;; behavior (and this case is probably far more common).
1519 1522 (goto-char comint-last-output-start)
1520(add-hook 'comint-preoutput-filter-functions 'comint-cr-magic) 1523 (while (re-search-forward "\r$" pmark t)
1524 (delete-char -1))
1525 ;; bare CR -> delete preceding line
1526 (goto-char comint-last-output-start)
1527 (while (search-forward "\r" pmark t)
1528 (delete-region (point) (line-beginning-position)))
1529 ;; BS -> delete preceding character
1530 (goto-char comint-last-output-start)
1531 (while (search-forward "\b" pmark t)
1532 (delete-char -2)))))))))
1533
1534(add-hook 'comint-output-filter-functions 'comint-carriage-motion)
1521 1535
1522;; The purpose of using this filter for comint processes 1536;; The purpose of using this filter for comint processes
1523;; is to keep comint-last-input-end from moving forward 1537;; is to keep comint-last-input-end from moving forward