diff options
| -rw-r--r-- | lisp/ChangeLog | 12 | ||||
| -rw-r--r-- | lisp/progmodes/python.el | 90 |
2 files changed, 53 insertions, 49 deletions
diff --git a/lisp/ChangeLog b/lisp/ChangeLog index 12d4c944f47..f7dcb840bd6 100644 --- a/lisp/ChangeLog +++ b/lisp/ChangeLog | |||
| @@ -1,3 +1,15 @@ | |||
| 1 | 2015-02-10 Fabián Ezequiel Gallina <fgallina@gnu.org> | ||
| 2 | |||
| 3 | python.el: Improved shell font lock respecting markers. (Bug#19650) | ||
| 4 | |||
| 5 | * progmodes/python.el | ||
| 6 | (python-shell-font-lock-get-or-create-buffer): Use special buffer name. | ||
| 7 | (python-shell-font-lock-with-font-lock-buffer): Enable font lock. | ||
| 8 | (python-shell-font-lock-post-command-hook): Fontify by copying text | ||
| 9 | properties from fontified buffer to shell, keeping markers unchanged. | ||
| 10 | (python-shell-font-lock-turn-off): Fix typo. | ||
| 11 | (python-util-text-properties-replace-name): Delete function. | ||
| 12 | |||
| 1 | 2015-02-09 Simen Heggestøyl <simenheg@gmail.com> (tiny change) | 13 | 2015-02-09 Simen Heggestøyl <simenheg@gmail.com> (tiny change) |
| 2 | 14 | ||
| 3 | * textmodes/css-mode.el (css-smie-rules): Fix paren indent (bug#19815). | 15 | * textmodes/css-mode.el (css-smie-rules): Fix paren indent (bug#19815). |
diff --git a/lisp/progmodes/python.el b/lisp/progmodes/python.el index 303c36c3932..1889affbf6f 100644 --- a/lisp/progmodes/python.el +++ b/lisp/progmodes/python.el | |||
| @@ -2297,7 +2297,7 @@ Signals an error if no shell buffer is available for current buffer." | |||
| 2297 | (let ((process-name | 2297 | (let ((process-name |
| 2298 | (process-name (get-buffer-process (current-buffer))))) | 2298 | (process-name (get-buffer-process (current-buffer))))) |
| 2299 | (generate-new-buffer | 2299 | (generate-new-buffer |
| 2300 | (format "*%s-font-lock*" process-name)))))) | 2300 | (format " *%s-font-lock*" process-name)))))) |
| 2301 | 2301 | ||
| 2302 | (defun python-shell-font-lock-kill-buffer () | 2302 | (defun python-shell-font-lock-kill-buffer () |
| 2303 | "Kill the font-lock buffer safely." | 2303 | "Kill the font-lock buffer safely." |
| @@ -2320,6 +2320,8 @@ also `with-current-buffer'." | |||
| 2320 | (setq python-shell--font-lock-buffer | 2320 | (setq python-shell--font-lock-buffer |
| 2321 | (python-shell-font-lock-get-or-create-buffer))) | 2321 | (python-shell-font-lock-get-or-create-buffer))) |
| 2322 | (set-buffer python-shell--font-lock-buffer) | 2322 | (set-buffer python-shell--font-lock-buffer) |
| 2323 | (when (not font-lock-mode) | ||
| 2324 | (font-lock-mode 1)) | ||
| 2323 | (set (make-local-variable 'delay-mode-hooks) t) | 2325 | (set (make-local-variable 'delay-mode-hooks) t) |
| 2324 | (let ((python-indent-guess-indent-offset nil)) | 2326 | (let ((python-indent-guess-indent-offset nil)) |
| 2325 | (when (not (derived-mode-p 'python-mode)) | 2327 | (when (not (derived-mode-p 'python-mode)) |
| @@ -2354,36 +2356,43 @@ goes wrong and syntax highlighting in the shell gets messed up." | |||
| 2354 | 2356 | ||
| 2355 | (defun python-shell-font-lock-post-command-hook () | 2357 | (defun python-shell-font-lock-post-command-hook () |
| 2356 | "Fontifies current line in shell buffer." | 2358 | "Fontifies current line in shell buffer." |
| 2357 | (when (and (python-util-comint-last-prompt) | 2359 | (let ((prompt-end (cdr (python-util-comint-last-prompt)))) |
| 2358 | (> (point) (cdr (python-util-comint-last-prompt)))) | 2360 | (when (and prompt-end (> (point) prompt-end)) |
| 2359 | (let ((input (buffer-substring-no-properties | 2361 | (let* ((input (buffer-substring-no-properties |
| 2360 | (cdr (python-util-comint-last-prompt)) (point-max))) | 2362 | prompt-end (point-max))) |
| 2361 | (pos (point)) | 2363 | (start-pos prompt-end) |
| 2362 | (buffer-undo-list t) | 2364 | (buffer-undo-list t) |
| 2363 | (font-lock-buffer-pos nil)) | 2365 | (font-lock-buffer-pos nil) |
| 2364 | ;; Keep all markers untouched, this prevents `hippie-expand' and | 2366 | (replacement |
| 2365 | ;; others from getting confused. Bug#19650. | 2367 | (python-shell-font-lock-with-font-lock-buffer |
| 2366 | (insert-before-markers | 2368 | (delete-region (line-beginning-position) |
| 2367 | (python-shell-font-lock-with-font-lock-buffer | 2369 | (point-max)) |
| 2368 | (delete-region (line-beginning-position) | 2370 | (setq font-lock-buffer-pos (point)) |
| 2369 | (point-max)) | 2371 | (insert input) |
| 2370 | (setq font-lock-buffer-pos (point)) | 2372 | ;; Ensure buffer is fontified, keeping it |
| 2371 | (insert input) | 2373 | ;; compatible with Emacs < 24.4. |
| 2372 | ;; Ensure buffer is fontified, keeping it | 2374 | (if (fboundp 'font-lock-ensure) |
| 2373 | ;; compatible with Emacs < 24.4. | 2375 | (funcall 'font-lock-ensure) |
| 2374 | (if (fboundp 'font-lock-ensure) | 2376 | (font-lock-default-fontify-buffer)) |
| 2375 | (funcall 'font-lock-ensure) | 2377 | (buffer-substring font-lock-buffer-pos |
| 2376 | (font-lock-default-fontify-buffer)) | 2378 | (point-max)))) |
| 2377 | ;; Replace FACE text properties with FONT-LOCK-FACE so | 2379 | (replacement-length (length replacement)) |
| 2378 | ;; they are not overwritten by comint buffer's font lock. | 2380 | (i 0)) |
| 2379 | (python-util-text-properties-replace-name | 2381 | ;; Inject text properties to get input fontified. |
| 2380 | 'face 'font-lock-face) | 2382 | (while (not (= i replacement-length)) |
| 2381 | (buffer-substring font-lock-buffer-pos | 2383 | (let* ((plist (text-properties-at i replacement)) |
| 2382 | (point-max)))) | 2384 | (next-change (or (next-property-change i replacement) |
| 2383 | ;; Remove non-fontified original text. | 2385 | replacement-length)) |
| 2384 | (delete-region pos (cdr (python-util-comint-last-prompt))) | 2386 | (plist (let ((face (plist-get plist 'face))) |
| 2385 | ;; Point should be already at pos, this is for extra safety. | 2387 | (if (not face) |
| 2386 | (goto-char pos)))) | 2388 | plist |
| 2389 | ;; Replace FACE text properties with | ||
| 2390 | ;; FONT-LOCK-FACE so input is fontified. | ||
| 2391 | (plist-put plist 'face nil) | ||
| 2392 | (plist-put plist 'font-lock-face face))))) | ||
| 2393 | (set-text-properties | ||
| 2394 | (+ start-pos i) (+ start-pos next-change) plist) | ||
| 2395 | (setq i next-change))))))) | ||
| 2387 | 2396 | ||
| 2388 | (defun python-shell-font-lock-turn-on (&optional msg) | 2397 | (defun python-shell-font-lock-turn-on (&optional msg) |
| 2389 | "Turn on shell font-lock. | 2398 | "Turn on shell font-lock. |
| @@ -2416,7 +2425,7 @@ With argument MSG show deactivation message." | |||
| 2416 | '(face nil font-lock-face nil))) | 2425 | '(face nil font-lock-face nil))) |
| 2417 | (set (make-local-variable 'python-shell--font-lock-buffer) nil) | 2426 | (set (make-local-variable 'python-shell--font-lock-buffer) nil) |
| 2418 | (remove-hook 'post-command-hook | 2427 | (remove-hook 'post-command-hook |
| 2419 | #'python-shell-font-lock-post-command-hook'local) | 2428 | #'python-shell-font-lock-post-command-hook 'local) |
| 2420 | (remove-hook 'kill-buffer-hook | 2429 | (remove-hook 'kill-buffer-hook |
| 2421 | #'python-shell-font-lock-kill-buffer 'local) | 2430 | #'python-shell-font-lock-kill-buffer 'local) |
| 2422 | (remove-hook 'comint-output-filter-functions | 2431 | (remove-hook 'comint-output-filter-functions |
| @@ -4606,23 +4615,6 @@ returned as is." | |||
| 4606 | n (1- n))) | 4615 | n (1- n))) |
| 4607 | (reverse acc)))) | 4616 | (reverse acc)))) |
| 4608 | 4617 | ||
| 4609 | (defun python-util-text-properties-replace-name | ||
| 4610 | (from to &optional start end) | ||
| 4611 | "Replace properties named FROM to TO, keeping its value. | ||
| 4612 | Arguments START and END narrow the buffer region to work on." | ||
| 4613 | (save-excursion | ||
| 4614 | (goto-char (or start (point-min))) | ||
| 4615 | (while (not (eobp)) | ||
| 4616 | (let ((plist (text-properties-at (point))) | ||
| 4617 | (next-change (or (next-property-change (point) (current-buffer)) | ||
| 4618 | (or end (point-max))))) | ||
| 4619 | (when (plist-get plist from) | ||
| 4620 | (let* ((face (plist-get plist from)) | ||
| 4621 | (plist (plist-put plist from nil)) | ||
| 4622 | (plist (plist-put plist to face))) | ||
| 4623 | (set-text-properties (point) next-change plist (current-buffer)))) | ||
| 4624 | (goto-char next-change))))) | ||
| 4625 | |||
| 4626 | (defun python-util-strip-string (string) | 4618 | (defun python-util-strip-string (string) |
| 4627 | "Strip STRING whitespace and newlines from end and beginning." | 4619 | "Strip STRING whitespace and newlines from end and beginning." |
| 4628 | (replace-regexp-in-string | 4620 | (replace-regexp-in-string |