emacs-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

master 97ef20e: Handle errors in `comint-strip-ctrl-m' in some cases


From: Lars Ingebrigtsen
Subject: master 97ef20e: Handle errors in `comint-strip-ctrl-m' in some cases
Date: Tue, 2 Feb 2021 10:11:24 -0500 (EST)

branch: master
commit 97ef20e250126bbf2206f92864f87c85f1d3b6ec
Author: Lars Ingebrigtsen <larsi@gnus.org>
Commit: Lars Ingebrigtsen <larsi@gnus.org>

    Handle errors in `comint-strip-ctrl-m' in some cases
    
    * lisp/comint.el (comint-strip-ctrl-m): Don't signal errors when
    used noninteractively (bug#33115).
---
 lisp/comint.el | 26 +++++++++++++++++---------
 1 file changed, 17 insertions(+), 9 deletions(-)

diff --git a/lisp/comint.el b/lisp/comint.el
index 4323079..a9633d0 100644
--- a/lisp/comint.el
+++ b/lisp/comint.el
@@ -2253,15 +2253,23 @@ This function could be on 
`comint-output-filter-functions' or bound to a key."
   "Strip trailing `^M' characters from the current output group.
 This function could be on `comint-output-filter-functions' or bound to a key."
   (interactive)
-  (let ((pmark (process-mark (get-buffer-process (current-buffer)))))
-    (save-excursion
-      (condition-case nil
-         (goto-char
-          (if (called-interactively-p 'interactive)
-              comint-last-input-end comint-last-output-start))
-       (error nil))
-      (while (re-search-forward "\r+$" pmark t)
-       (replace-match "" t t)))))
+  (let ((process (get-buffer-process (current-buffer))))
+    (if (not process)
+        ;; This function may be used in
+        ;; `comint-output-filter-functions', and in that case, if
+        ;; there's no process, then we should do nothing.  If
+        ;; interactive, report an error.
+        (when (called-interactively-p 'interactive)
+          (error "No process in the current buffer"))
+      (let ((pmark (process-mark process)))
+        (save-excursion
+          (condition-case nil
+             (goto-char
+              (if (called-interactively-p 'interactive)
+                  comint-last-input-end comint-last-output-start))
+           (error nil))
+          (while (re-search-forward "\r+$" pmark t)
+           (replace-match "" t t)))))))
 (define-obsolete-function-alias 'shell-strip-ctrl-m #'comint-strip-ctrl-m 
"27.1")
 
 (defun comint-show-maximum-output ()



reply via email to

[Prev in Thread] Current Thread [Next in Thread]