diff options
author | Gerd Moellmann <gerd@gnu.org> | 2001-04-18 14:18:44 +0000 |
---|---|---|
committer | Gerd Moellmann <gerd@gnu.org> | 2001-04-18 14:18:44 +0000 |
commit | 80c40c6fbc6dd223134f647e7d7237de92e64541 (patch) | |
tree | 1a20eefcd86a959c64fd6dba6d6c759e25f3fb25 /lisp/comint.el | |
parent | 90200fccb14964c16f140e28d8b99a26266de30c (diff) | |
download | emacs-80c40c6fbc6dd223134f647e7d7237de92e64541.tar.gz |
(comint-cr-magic): New function.
(toplevel): Add it to comint-preoutput-filter-functions.
Diffstat (limited to 'lisp/comint.el')
-rw-r--r-- | lisp/comint.el | 24 |
1 files changed, 24 insertions, 0 deletions
diff --git a/lisp/comint.el b/lisp/comint.el index aadf85f7261..7a5e7ad8928 100644 --- a/lisp/comint.el +++ b/lisp/comint.el @@ -1496,6 +1496,30 @@ This variable is permanent-local.") (overlay-put comint-last-prompt-overlay 'evaporate t) (setq comint-last-prompt-overlay nil))) +(defun comint-cr-magic (string) + "Handle carriage returns in comint output. +Translate carraige return/linefeed sequences to linefeeds. +Let single carriage returns delete to the beginning of the line." + (save-match-data + ;; CR LF -> LF + (while (string-match "\r\n" string) + (setq string (replace-match "\n" nil t string))) + ;; Let a single CR act like a carriage return on a real terminal. + ;; Delete everything from the beginning of the line to the + ;; insertion point. + (when (string-match ".*\r" string) + (setq string (replace-match "" nil t string)) + (save-excursion + (save-restriction + (widen) + (let ((inhibit-field-text-motion t) + (buffer-read-only nil)) + (goto-char (process-mark (get-buffer-process (current-buffer)))) + (delete-region (line-beginning-position) (point)))))) + string)) + +(add-hook 'comint-preoutput-filter-functions 'comint-cr-magic) + ;; The purpose of using this filter for comint processes ;; is to keep comint-last-input-end from moving forward ;; when output is inserted. |