[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
comint-ctrl-m: handle ^M intelligently in subprocess output
From: |
bobg |
Subject: |
comint-ctrl-m: handle ^M intelligently in subprocess output |
Date: |
Tue, 3 Apr 2001 17:28:48 -0700 |
Tired of seeing your shell buffers full of garbage like this?
0% done, 1:40 remaining...^M2% done, 1:38 remaining...^M4% done, 1:36
remaining...^M6% done, 1:34 remaining...^M8% done, 1:32 remaining...^M10% done,
1:30 remaining...^M12% done, 1:28 remaining...^M14% done, 1:26
remaining...^M16% done, 1:24 remaining...^M18% done, 1:22 remaining...^M20%
done, 1:20 remaining...^M22% done, 1:18 remaining...^M24% done, 1:16
remaining...^M26% done, 1:14 remaining...^M28% done, 1:12 remaining...^M30%
done, 1:10 remaining...^M32% done, 1:08 remaining...^M34% done, 1:06
remaining...^M36% done, 1:04 remaining...^M38% done, 1:02 remaining...^M40%
done, 1:00 remaining...^M42% done, 0:58 remaining...^M44% done, 0:56
remaining...^M46% done, 0:54 remaining...^M48% done, 0:52 remaining...^M50%
done, 0:50 remaining...^M52% done, 0:48 remaining...^M54% done, 0:46
remaining...^M56% done, 0:44 remaining...^M58% done, 0:42 remaining...^M60%
done, 0:40 remaining...^M62% done, 0:38 remaining...^M64% done, 0:36
remaining...^M66% done, 0:34 remaining...^M68% done, 0:32 remaining...^M70%
done, 0:30 remaining...^M72% done, 0:28 remaining...^M74% done, 0:26
remaining...^M76% done, 0:24 remaining...^M78% done, 0:22 remaining...^M80%
done, 0:20 remaining...^M82% done, 0:18 remaining...^M84% done, 0:16
remaining...^M86% done, 0:14 remaining...^M88% done, 0:12 remaining...^M90%
done, 0:10 remaining...^M92% done, 0:08 remaining...^M94% done, 0:06
remaining...^M96% done, 0:04 remaining...^M98% done, 0:02 remaining...^M100%
done, 0:00 remaining...
Just switch on comint-ctrl-m-mode and stop giving your xterm-using
friends a reason to feel superior.
You can
(add-hook 'shell-mode-hook 'turn-on-comint-ctrl-m-mode)
in your .emacs if you like.
(Sorry I haven't packaged this up as a proper .el file with comments
and documentation and everything, but hey, it's tiny, and it's free.)
(defun crlf-to-lf (str)
(save-match-data
(while (string-match "\r\n" str)
(setq str (replace-match "\n" nil t str))))
str)
(defun comint-ctrl-m-magic (str)
(setq str (crlf-to-lf str))
(save-match-data
(when (string-match ".*\r" str)
(setq str (replace-match "" nil t str))
(save-excursion
(goto-char (point-max))
(forward-line 0)
(delete-region (point) (point-max)))))
str)
(defvar comint-ctrl-m-mode nil)
(make-variable-buffer-local 'comint-ctrl-m-mode)
(defun comint-ctrl-m-mode (&optional arg)
(interactive "P")
(setq comint-ctrl-m-mode
(if (null arg)
(not comint-ctrl-m-mode)
(> (prefix-numeric-value arg) 0)))
(funcall (if comint-ctrl-m-mode
'add-hook
'remove-hook)
'comint-preoutput-filter-functions
'comint-ctrl-m-magic))
(defun turn-on-comint-ctrl-m-mode () (comint-ctrl-m-mode 1))
(if (not (assq 'comint-ctrl-m-mode minor-mode-alist))
(setq minor-mode-alist
(cons '(comint-ctrl-m-mode " ^M")
minor-mode-alist)))
- comint-ctrl-m: handle ^M intelligently in subprocess output,
bobg <=