From: Carlos Pita <carlosjosepita@gmail.com>
To: 33959@debbugs.gnu.org
Subject: bug#33959:
Date: Thu, 3 Jan 2019 02:38:52 -0300 [thread overview]
Message-ID: <CAELgYhfVDbh_QbdP73piY-xfbEMy=8sY2_Bk6GSCqpfrukQpNw@mail.gmail.com> (raw)
In-Reply-To: <CAELgYheP044D__P6BOBix17Zn40OHtjecV7Eg9FcNtynDPbfyQ@mail.gmail.com>
[-- Attachment #1: Type: text/plain, Size: 1160 bytes --]
> but I see no reason to not call (erase-buffer) altogether.
>
> Do you?
Yes, obviously, multiline input, I forgot.
Nevertheless I found the origin of the problem. Somehow when company
is enabled in the shell buffer
python-shell-font-lock-comint-output-filter-function is getting empty
strings as output and then the ";; Otherwise just add a newline."
clause is activated.
No matter the reason why empty output is being passed to the filter,
it's wrong for the filter to add a new line to the font lock buffer if
this happens.
I'm attaching two patches, since
python-shell-font-lock-comint-output-filter-function is an old friend
of mine and we have spent many nights together now:
1. The first one (Avoid-spurious...) strictly fixes this issue by
moving the not-empty condition to the top and doing everything else
unless not-empty. Period. That works.
2. The second one (Fix-font-lock...) combines 1 with my previous patch
for fixing ipython multiline input (#32390) since both changes
overlap.
I suggest to directly apply patch 2 since it improves prompt detection
heuristic and fixes two bugs. Then you can close this and #32390.
Regards
--
Carlos
[-- Attachment #2: 0001-Avoid-spurious-empty-lines-in-font-lock-buffer-fixes.patch --]
[-- Type: text/x-patch, Size: 2290 bytes --]
From d816a29f5a9cdcebd8f69ad0a6555eaca051587e Mon Sep 17 00:00:00 2001
From: memeplex <carlosjosepita@gmail.com>
Date: Thu, 3 Jan 2019 02:28:30 -0300
Subject: [PATCH] Avoid spurious empty lines in font lock buffer, fixes #33959
---
lisp/progmodes/python.el | 27 ++++++++++++++-------------
1 file changed, 14 insertions(+), 13 deletions(-)
diff --git a/lisp/progmodes/python.el b/lisp/progmodes/python.el
index 27d31ab..81a6e89 100644
--- a/lisp/progmodes/python.el
+++ b/lisp/progmodes/python.el
@@ -2556,19 +2556,19 @@ 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)))
+ (unless (string= "" output)
+ (if ;; 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)
(defun python-shell-font-lock-post-command-hook ()
@@ -2597,6 +2597,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
[-- Attachment #3: 0001-Fix-font-lock-output-filter-bugs-33959-and-32390.patch --]
[-- Type: text/x-patch, Size: 2484 bytes --]
From dc80df310933f9f5f9b9bf065e72ee79a6b16134 Mon Sep 17 00:00:00 2001
From: memeplex <carlosjosepita@gmail.com>
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
next prev parent reply other threads:[~2019-01-03 5:38 UTC|newest]
Thread overview: 23+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-01-03 2:08 bug#33959: 26.1.90; python.el font-lock buffer wreaks havoc when eldoc is enabled Carlos Pita
2019-01-03 2:34 ` bug#33959: Carlos Pita
2019-01-03 4:40 ` bug#33959: Carlos Pita
2019-01-03 5:38 ` Carlos Pita [this message]
2019-04-05 2:36 ` bug#33959: 26.1.90; python.el font-lock buffer wreaks havoc when company is enabled Noam Postavsky
2019-04-16 21:47 ` Carlos Pita
2019-04-16 22:04 ` Noam Postavsky
2019-04-16 22:08 ` Carlos Pita
2019-04-16 22:14 ` Carlos Pita
2019-04-16 23:01 ` Noam Postavsky
2019-04-16 23:51 ` Noam Postavsky
2019-05-11 3:51 ` Noam Postavsky
2019-04-05 2:55 ` bug#33959: 26.1.90; python.el font-lock buffer wreaks havoc when eldoc " Noam Postavsky
2019-04-16 20:42 ` Carlos Pita
2019-10-13 19:39 ` bug#33959: Carlos Pita
2019-10-13 19:44 ` bug#33959: Lars Ingebrigtsen
2019-10-13 19:51 ` bug#33959: Carlos Pita
2019-10-15 0:34 ` bug#33959: 26.1.90; python.el font-lock buffer wreaks havoc when company is enabled Noam Postavsky
2019-10-15 0:52 ` Carlos Pita
2019-10-15 0:58 ` Carlos Pita
2019-10-16 20:35 ` Carlos Pita
2019-10-21 20:56 ` Carlos Pita
2019-10-23 0:18 ` Noam Postavsky
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
List information: https://www.gnu.org/software/emacs/
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to='CAELgYhfVDbh_QbdP73piY-xfbEMy=8sY2_Bk6GSCqpfrukQpNw@mail.gmail.com' \
--to=carlosjosepita@gmail.com \
--cc=33959@debbugs.gnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this public inbox
https://git.savannah.gnu.org/cgit/emacs.git
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).