diff options
| author | Fabián Ezequiel Gallina | 2014-07-26 22:00:26 -0300 |
|---|---|---|
| committer | Fabián Ezequiel Gallina | 2014-07-26 22:00:26 -0300 |
| commit | ef29dc9b14374bc9f5ef322460625fd44da07410 (patch) | |
| tree | cdd4ef24bfb135978367d4a313cc60010b99147e /lisp/progmodes/python.el | |
| parent | 60cc81af68080a8d1edb7584ce0966754595e187 (diff) | |
| download | emacs-ef29dc9b14374bc9f5ef322460625fd44da07410.tar.gz emacs-ef29dc9b14374bc9f5ef322460625fd44da07410.zip | |
* lisp/progmodes/python.el (python-shell-font-lock-post-command-hook):
Safeguard current point and undo history.
Diffstat (limited to 'lisp/progmodes/python.el')
| -rw-r--r-- | lisp/progmodes/python.el | 44 |
1 files changed, 26 insertions, 18 deletions
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." | |||
| 2190 | (when (and (python-util-comint-last-prompt) | 2190 | (when (and (python-util-comint-last-prompt) |
| 2191 | (> (point) (cdr (python-util-comint-last-prompt)))) | 2191 | (> (point) (cdr (python-util-comint-last-prompt)))) |
| 2192 | (let ((input (buffer-substring-no-properties | 2192 | (let ((input (buffer-substring-no-properties |
| 2193 | (cdr (python-util-comint-last-prompt)) (point-max)))) | 2193 | (cdr (python-util-comint-last-prompt)) (point-max))) |
| 2194 | (delete-region (cdr (python-util-comint-last-prompt)) (point-max)) | 2194 | (old-input (python-shell-font-lock-with-font-lock-buffer |
| 2195 | (insert | 2195 | (buffer-substring-no-properties |
| 2196 | (python-shell-font-lock-with-font-lock-buffer | 2196 | (line-beginning-position) (point-max)))) |
| 2197 | (delete-region (line-beginning-position) | 2197 | (current-point (point)) |
| 2198 | (line-end-position)) | 2198 | (buffer-undo-list t)) |
| 2199 | (insert input) | 2199 | ;; When input hasn't changed, do nothing. |
| 2200 | ;; Ensure buffer is fontified, keeping it | 2200 | (when (not (string= input old-input)) |
| 2201 | ;; compatible with Emacs < 24.4. | 2201 | (delete-region (cdr (python-util-comint-last-prompt)) (point-max)) |
| 2202 | (if (fboundp 'font-lock-ensure) | 2202 | (insert |
| 2203 | (funcall 'font-lock-ensure) | 2203 | (python-shell-font-lock-with-font-lock-buffer |
| 2204 | (font-lock-default-fontify-buffer)) | 2204 | (delete-region (line-beginning-position) |
| 2205 | ;; Replace FACE text properties with FONT-LOCK-FACE so they | 2205 | (line-end-position)) |
| 2206 | ;; are not overwritten by current buffer's font-lock | 2206 | (insert input) |
| 2207 | (python-util-text-properties-replace-name | 2207 | ;; Ensure buffer is fontified, keeping it |
| 2208 | 'face 'font-lock-face) | 2208 | ;; compatible with Emacs < 24.4. |
| 2209 | (buffer-substring (line-beginning-position) | 2209 | (if (fboundp 'font-lock-ensure) |
| 2210 | (line-end-position)))))))) | 2210 | (funcall 'font-lock-ensure) |
| 2211 | (font-lock-default-fontify-buffer)) | ||
| 2212 | ;; Replace FACE text properties with FONT-LOCK-FACE so | ||
| 2213 | ;; they are not overwritten by comint buffer's font lock. | ||
| 2214 | (python-util-text-properties-replace-name | ||
| 2215 | 'face 'font-lock-face) | ||
| 2216 | (buffer-substring (line-beginning-position) | ||
| 2217 | (line-end-position)))) | ||
| 2218 | (goto-char current-point)))))) | ||
| 2211 | 2219 | ||
| 2212 | (defun python-shell-font-lock-turn-on (&optional msg) | 2220 | (defun python-shell-font-lock-turn-on (&optional msg) |
| 2213 | "Turn on shell font-lock. | 2221 | "Turn on shell font-lock. |