# HG changeset patch # User Gerd Moellmann # Date 987603524 0 # Node ID b5ddd589d14354fd8eadeed2af8cc56eee7b43e3 # Parent f6daa641d91fa8284f80e18067469098f37bcf1a (comint-cr-magic): New function. (toplevel): Add it to comint-preoutput-filter-functions. diff -r f6daa641d91f -r b5ddd589d143 lisp/comint.el --- a/lisp/comint.el Wed Apr 18 14:11:21 2001 +0000 +++ b/lisp/comint.el Wed Apr 18 14:18:44 2001 +0000 @@ -1496,6 +1496,30 @@ (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.