aboutsummaryrefslogtreecommitdiffstats
path: root/lisp/progmodes/python.el
diff options
context:
space:
mode:
authorFabián Ezequiel Gallina2015-02-08 00:25:20 -0300
committerFabián Ezequiel Gallina2015-02-08 00:25:20 -0300
commit52df70a887ae8b187decb6c92cad32cf11f4c788 (patch)
treef9d14b63a886d1fd33de6b90156e15c32c016cfd /lisp/progmodes/python.el
parentb480a6adda9cfd76c3f38970e257654de9eff4f2 (diff)
downloademacs-52df70a887ae8b187decb6c92cad32cf11f4c788.tar.gz
emacs-52df70a887ae8b187decb6c92cad32cf11f4c788.zip
python.el: Make shell font-lock respect markers.
Fixes: debbugs:19650 * lisp/progmodes/python.el (python-shell-font-lock-cleanup-buffer): Use `erase-buffer`. (python-shell-font-lock-comint-output-filter-function): Handle newlines. (python-shell-font-lock-post-command-hook): Respect markers on text fontification.
Diffstat (limited to 'lisp/progmodes/python.el')
-rw-r--r--lisp/progmodes/python.el86
1 files changed, 42 insertions, 44 deletions
diff --git a/lisp/progmodes/python.el b/lisp/progmodes/python.el
index 72a76a461a6..897af2c236c 100644
--- a/lisp/progmodes/python.el
+++ b/lisp/progmodes/python.el
@@ -2333,57 +2333,55 @@ goes wrong and syntax highlighting in the shell gets messed up."
2333 (interactive) 2333 (interactive)
2334 (python-shell-with-shell-buffer 2334 (python-shell-with-shell-buffer
2335 (python-shell-font-lock-with-font-lock-buffer 2335 (python-shell-font-lock-with-font-lock-buffer
2336 (delete-region (point-min) (point-max))))) 2336 (erase-buffer))))
2337 2337
2338(defun python-shell-font-lock-comint-output-filter-function (output) 2338(defun python-shell-font-lock-comint-output-filter-function (output)
2339 "Clean up the font-lock buffer after any OUTPUT." 2339 "Clean up the font-lock buffer after any OUTPUT."
2340 (when (and (not (string= "" output)) 2340 (if (and (not (string= "" output))
2341 ;; Is end of output and is not just a prompt. 2341 ;; Is end of output and is not just a prompt.
2342 (not (member 2342 (not (member
2343 (python-shell-comint-end-of-output-p 2343 (python-shell-comint-end-of-output-p
2344 (ansi-color-filter-apply output)) 2344 (ansi-color-filter-apply output))
2345 '(nil 0)))) 2345 '(nil 0))))
2346 ;; If output is other than an input prompt then "real" output has 2346 ;; If output is other than an input prompt then "real" output has
2347 ;; been received and the font-lock buffer must be cleaned up. 2347 ;; been received and the font-lock buffer must be cleaned up.
2348 (python-shell-font-lock-cleanup-buffer)) 2348 (python-shell-font-lock-cleanup-buffer)
2349 ;; Otherwise just add a newline.
2350 (python-shell-font-lock-with-font-lock-buffer
2351 (goto-char (point-max))
2352 (newline)))
2349 output) 2353 output)
2350 2354
2351(defun python-shell-font-lock-post-command-hook () 2355(defun python-shell-font-lock-post-command-hook ()
2352 "Fontifies current line in shell buffer." 2356 "Fontifies current line in shell buffer."
2353 (if (eq this-command 'comint-send-input) 2357 (when (and (python-util-comint-last-prompt)
2354 ;; Add a newline when user sends input as this may be a block. 2358 (> (point) (cdr (python-util-comint-last-prompt))))
2355 (python-shell-font-lock-with-font-lock-buffer 2359 (let ((input (buffer-substring-no-properties
2356 (goto-char (line-end-position)) 2360 (cdr (python-util-comint-last-prompt)) (point-max)))
2357 (newline)) 2361 (pos (point))
2358 (when (and (python-util-comint-last-prompt) 2362 (buffer-undo-list t))
2359 (> (point) (cdr (python-util-comint-last-prompt)))) 2363 ;; Keep all markers untouched, this prevents `hippie-expand' and
2360 (let ((input (buffer-substring-no-properties 2364 ;; others from getting confused. Bug#19650.
2361 (cdr (python-util-comint-last-prompt)) (point-max))) 2365 (insert-before-markers
2362 (old-input (python-shell-font-lock-with-font-lock-buffer 2366 (python-shell-font-lock-with-font-lock-buffer
2363 (buffer-substring-no-properties 2367 (delete-region (line-beginning-position)
2364 (line-beginning-position) (point-max)))) 2368 (line-end-position))
2365 (current-point (point)) 2369 (insert input)
2366 (buffer-undo-list t)) 2370 ;; Ensure buffer is fontified, keeping it
2367 ;; When input hasn't changed, do nothing. 2371 ;; compatible with Emacs < 24.4.
2368 (when (not (string= input old-input)) 2372 (if (fboundp 'font-lock-ensure)
2369 (delete-region (cdr (python-util-comint-last-prompt)) (point-max)) 2373 (funcall 'font-lock-ensure)
2370 (insert 2374 (font-lock-default-fontify-buffer))
2371 (python-shell-font-lock-with-font-lock-buffer 2375 ;; Replace FACE text properties with FONT-LOCK-FACE so
2372 (delete-region (line-beginning-position) 2376 ;; they are not overwritten by comint buffer's font lock.
2373 (line-end-position)) 2377 (python-util-text-properties-replace-name
2374 (insert input) 2378 'face 'font-lock-face)
2375 ;; Ensure buffer is fontified, keeping it 2379 (buffer-substring (line-beginning-position)
2376 ;; compatible with Emacs < 24.4. 2380 (line-end-position))))
2377 (if (fboundp 'font-lock-ensure) 2381 ;; Remove non-fontified original text.
2378 (funcall 'font-lock-ensure) 2382 (delete-region pos (cdr (python-util-comint-last-prompt)))
2379 (font-lock-default-fontify-buffer)) 2383 ;; Point should be already at pos, this is for extra safety.
2380 ;; Replace FACE text properties with FONT-LOCK-FACE so 2384 (goto-char pos))))
2381 ;; they are not overwritten by comint buffer's font lock.
2382 (python-util-text-properties-replace-name
2383 'face 'font-lock-face)
2384 (buffer-substring (line-beginning-position)
2385 (line-end-position))))
2386 (goto-char current-point))))))
2387 2385
2388(defun python-shell-font-lock-turn-on (&optional msg) 2386(defun python-shell-font-lock-turn-on (&optional msg)
2389 "Turn on shell font-lock. 2387 "Turn on shell font-lock.