From dc80df310933f9f5f9b9bf065e72ee79a6b16134 Mon Sep 17 00:00:00 2001 From: memeplex Date: Thu, 3 Jan 2019 02:31:52 -0300 Subject: [PATCH] Fix font lock output filter bugs #33959 and #32390 Improves multiline input detection heuristic. Fixes multiline input for ipython. Avoid adding spurious empty lines to the font lock buffer. Filter ansi color from output before matching. --- lisp/progmodes/python.el | 27 +++++++++++++-------------- 1 file changed, 13 insertions(+), 14 deletions(-) diff --git a/lisp/progmodes/python.el b/lisp/progmodes/python.el index 27d31ab..e98d88e 100644 --- a/lisp/progmodes/python.el +++ b/lisp/progmodes/python.el @@ -2556,20 +2556,18 @@ python-shell-font-lock-cleanup-buffer (defun python-shell-font-lock-comint-output-filter-function (output) "Clean up the font-lock buffer after any OUTPUT." - (if (and (not (string= "" output)) - ;; Is end of output and is not just a prompt. - (not (member - (python-shell-comint-end-of-output-p - (ansi-color-filter-apply output)) - '(nil 0)))) - ;; If output is other than an input prompt then "real" output has - ;; been received and the font-lock buffer must be cleaned up. - (python-shell-font-lock-cleanup-buffer) - ;; Otherwise just add a newline. - (python-shell-font-lock-with-font-lock-buffer - (goto-char (point-max)) - (newline))) - output) + (unless (string= output "") + (if (let ((output (ansi-color-filter-apply output))) + (and (python-shell-comint-end-of-output-p output) + (not (string-match "\\.\\.\\." output)))) + ;; If output ends with an initial (not continuation) input prompt + ;; then the font-lock buffer must be cleaned up. + (python-shell-font-lock-cleanup-buffer) + ;; Otherwise just add a newline. + (python-shell-font-lock-with-font-lock-buffer + (goto-char (point-max)) + (newline))) + output)) (defun python-shell-font-lock-post-command-hook () "Fontifies current line in shell buffer." @@ -2597,6 +2595,7 @@ python-shell-font-lock-post-command-hook (point-max)))) (replacement-length (length replacement)) (i 0)) + ;; Inject text properties to get input fontified. (while (not (= i replacement-length)) (let* ((plist (text-properties-at i replacement)) -- 2.20.1