]> git.eshelyaron.com Git - emacs.git/commitdiff
* lisp/progmodes/python.el (python-shell-font-lock-post-command-hook):
authorFabián Ezequiel Gallina <fgallina@gnu.org>
Sun, 27 Jul 2014 01:00:26 +0000 (22:00 -0300)
committerFabián Ezequiel Gallina <fgallina@gnu.org>
Sun, 27 Jul 2014 01:00:26 +0000 (22:00 -0300)
Safeguard current point and undo history.

lisp/ChangeLog
lisp/progmodes/python.el

index d10aab5e1ef12317f63c2b84c375e29ec167d467..6713626c45739ec73aeea95bcd419091d6f098d7 100644 (file)
@@ -1,3 +1,8 @@
+2014-07-27  Fabián Ezequiel Gallina  <fgallina@gnu.org>
+
+       * progmodes/python.el (python-shell-font-lock-post-command-hook):
+       Safeguard current point and undo history.
+
 2014-07-26  Fabián Ezequiel Gallina  <fgallina@gnu.org>
 
        Robust shell syntax highlighting.  (Bug#18084, Bug#16875)
index d8866a1c9305bb056b42f1392ad1a0ee5953040c..2d4276b2f2b420c3b5c5c91a849a63bdda0ef690 100644 (file)
@@ -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.