From ef29dc9b14374bc9f5ef322460625fd44da07410 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Fabi=C3=A1n=20Ezequiel=20Gallina?= Date: Sat, 26 Jul 2014 22:00:26 -0300 Subject: [PATCH] * lisp/progmodes/python.el (python-shell-font-lock-post-command-hook): Safeguard current point and undo history. --- lisp/ChangeLog | 5 +++++ lisp/progmodes/python.el | 44 ++++++++++++++++++++++++++------------------ 2 files changed, 31 insertions(+), 18 deletions(-) diff --git a/lisp/ChangeLog b/lisp/ChangeLog index d10aab5e1ef..6713626c457 100644 --- a/lisp/ChangeLog +++ b/lisp/ChangeLog @@ -1,3 +1,8 @@ +2014-07-27 Fabián Ezequiel Gallina + + * progmodes/python.el (python-shell-font-lock-post-command-hook): + Safeguard current point and undo history. + 2014-07-26 Fabián Ezequiel Gallina Robust shell syntax highlighting. (Bug#18084, Bug#16875) diff --git a/lisp/progmodes/python.el b/lisp/progmodes/python.el index d8866a1c930..2d4276b2f2b 100644 --- a/lisp/progmodes/python.el +++ b/lisp/progmodes/python.el @@ -2190,24 +2190,32 @@ goes wrong and syntax highlighting in the shell gets messed up." (when (and (python-util-comint-last-prompt) (> (point) (cdr (python-util-comint-last-prompt)))) (let ((input (buffer-substring-no-properties - (cdr (python-util-comint-last-prompt)) (point-max)))) - (delete-region (cdr (python-util-comint-last-prompt)) (point-max)) - (insert - (python-shell-font-lock-with-font-lock-buffer - (delete-region (line-beginning-position) - (line-end-position)) - (insert input) - ;; Ensure buffer is fontified, keeping it - ;; compatible with Emacs < 24.4. - (if (fboundp 'font-lock-ensure) - (funcall 'font-lock-ensure) - (font-lock-default-fontify-buffer)) - ;; Replace FACE text properties with FONT-LOCK-FACE so they - ;; are not overwritten by current buffer's font-lock - (python-util-text-properties-replace-name - 'face 'font-lock-face) - (buffer-substring (line-beginning-position) - (line-end-position)))))))) + (cdr (python-util-comint-last-prompt)) (point-max))) + (old-input (python-shell-font-lock-with-font-lock-buffer + (buffer-substring-no-properties + (line-beginning-position) (point-max)))) + (current-point (point)) + (buffer-undo-list t)) + ;; When input hasn't changed, do nothing. + (when (not (string= input old-input)) + (delete-region (cdr (python-util-comint-last-prompt)) (point-max)) + (insert + (python-shell-font-lock-with-font-lock-buffer + (delete-region (line-beginning-position) + (line-end-position)) + (insert input) + ;; Ensure buffer is fontified, keeping it + ;; compatible with Emacs < 24.4. + (if (fboundp 'font-lock-ensure) + (funcall 'font-lock-ensure) + (font-lock-default-fontify-buffer)) + ;; Replace FACE text properties with FONT-LOCK-FACE so + ;; they are not overwritten by comint buffer's font lock. + (python-util-text-properties-replace-name + 'face 'font-lock-face) + (buffer-substring (line-beginning-position) + (line-end-position)))) + (goto-char current-point)))))) (defun python-shell-font-lock-turn-on (&optional msg) "Turn on shell font-lock. -- 2.11.4.GIT