(let ((process-name
(process-name (get-buffer-process (current-buffer)))))
(generate-new-buffer
- (format "*%s-font-lock*" process-name))))))
+ (format " *%s-font-lock*" process-name))))))
(defun python-shell-font-lock-kill-buffer ()
"Kill the font-lock buffer safely."
(setq python-shell--font-lock-buffer
(python-shell-font-lock-get-or-create-buffer)))
(set-buffer python-shell--font-lock-buffer)
+ (when (not font-lock-mode)
+ (font-lock-mode 1))
(set (make-local-variable 'delay-mode-hooks) t)
(let ((python-indent-guess-indent-offset nil))
(when (not (derived-mode-p 'python-mode))
(defun python-shell-font-lock-post-command-hook ()
"Fontifies current line in shell buffer."
- (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)))
- (pos (point))
- (buffer-undo-list t)
- (font-lock-buffer-pos nil))
- ;; Keep all markers untouched, this prevents `hippie-expand' and
- ;; others from getting confused. Bug#19650.
- (insert-before-markers
- (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))
- ;; 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 font-lock-buffer-pos
- (point-max))))
- ;; Remove non-fontified original text.
- (delete-region pos (cdr (python-util-comint-last-prompt)))
- ;; Point should be already at pos, this is for extra safety.
- (goto-char pos))))
+ (let ((prompt-end (cdr (python-util-comint-last-prompt))))
+ (when (and prompt-end (> (point) prompt-end))
+ (let* ((input (buffer-substring-no-properties
+ prompt-end (point-max)))
+ (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)))))))
(defun python-shell-font-lock-turn-on (&optional msg)
"Turn on shell font-lock.
'(face nil font-lock-face nil)))
(set (make-local-variable 'python-shell--font-lock-buffer) nil)
(remove-hook 'post-command-hook
- #'python-shell-font-lock-post-command-hook'local)
+ #'python-shell-font-lock-post-command-hook 'local)
(remove-hook 'kill-buffer-hook
#'python-shell-font-lock-kill-buffer 'local)
(remove-hook 'comint-output-filter-functions
n (1- n)))
(reverse acc))))
-(defun python-util-text-properties-replace-name
- (from to &optional start end)
- "Replace properties named FROM to TO, keeping its value.
-Arguments START and END narrow the buffer region to work on."
- (save-excursion
- (goto-char (or start (point-min)))
- (while (not (eobp))
- (let ((plist (text-properties-at (point)))
- (next-change (or (next-property-change (point) (current-buffer))
- (or end (point-max)))))
- (when (plist-get plist from)
- (let* ((face (plist-get plist from))
- (plist (plist-put plist from nil))
- (plist (plist-put plist to face)))
- (set-text-properties (point) next-change plist (current-buffer))))
- (goto-char next-change)))))
-
(defun python-util-strip-string (string)
"Strip STRING whitespace and newlines from end and beginning."
(replace-regexp-in-string