Function: python-shell-font-lock-post-command-hook
python-shell-font-lock-post-command-hook is a byte-compiled function
defined in python.el.gz.
Signature
(python-shell-font-lock-post-command-hook)
Documentation
Fontifies current line in shell buffer.
Source Code
;; Defined in /usr/src/emacs/lisp/progmodes/python.el.gz
(defun python-shell-font-lock-post-command-hook ()
"Fontifies current line in shell buffer."
(let ((prompt-end (cdr (python-util-comint-last-prompt))))
(when (and prompt-end (> (point) prompt-end)
(process-live-p (get-buffer-process (current-buffer))))
(let* ((input (buffer-substring-no-properties
prompt-end (point-max)))
(deactivate-mark nil)
(start-pos prompt-end)
(buffer-undo-list t)
(font-lock-buffer-pos nil)
(replacement
(python-shell-font-lock-with-font-lock-buffer
(delete-region (line-beginning-position)
(point-max))
(setq font-lock-buffer-pos (point))
(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))
(buffer-substring font-lock-buffer-pos
(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))
(next-change (or (next-property-change i replacement)
replacement-length))
(plist (let ((face (plist-get plist 'face)))
(if (not face)
plist
;; Replace FACE text properties with
;; FONT-LOCK-FACE so input is fontified.
(plist-put plist 'face nil)
(plist-put plist 'font-lock-face face)))))
(set-text-properties
(+ start-pos i) (+ start-pos next-change) plist)
(setq i next-change)))))))