From 97ef20e250126bbf2206f92864f87c85f1d3b6ec Mon Sep 17 00:00:00 2001 From: Lars Ingebrigtsen Date: Tue, 2 Feb 2021 16:11:13 +0100 Subject: [PATCH] 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 432307934a7..a9633d08ba1 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 () -- 2.39.5