From cbae4820f9a328250c06d3c6a5d34864c800cacb Mon Sep 17 00:00:00 2001 From: Artur Malabarba Date: Thu, 1 Oct 2015 01:38:20 +0100 Subject: [PATCH] * lisp/progmodes/prog-mode.el (prettify-symbols-unprettify-at-point): Support unprettifying when point is after a symbol. * etc/NEWS: Document `prettify-symbols-unprettify-at-point' --- etc/NEWS | 6 ++++- lisp/progmodes/prog-mode.el | 49 ++++++++++++++++++++++++------------- 2 files changed, 37 insertions(+), 18 deletions(-) diff --git a/etc/NEWS b/etc/NEWS index 26f0474a9fc..ac9a600ab10 100644 --- a/etc/NEWS +++ b/etc/NEWS @@ -318,13 +318,17 @@ standards. ** Prog mode has some support for multi-mode indentation. See `prog-indentation-context' and `prog-widen'. -** Prettify Symbols mode supports custom composition predicates. By +** Prettify Symbols mode +*** Prettify Symbols mode supports custom composition predicates. By overriding the default `prettify-symbols-compose-predicate', modes can specify in which contexts a symbol map be composed to some unicode character. `prettify-symbols-default-compose-p' is the default which is suitable for most programming languages such as C or Lisp (but not (La)TeX). +*** Symbols are not prettified while point is inside them. +New variable `prettify-symbols-unprettify-at-point' configures this. + ** New `xterm-screen-extra-capabilities' config. ** The `save-place' variable is replaced by a `save-place-mode'. diff --git a/lisp/progmodes/prog-mode.el b/lisp/progmodes/prog-mode.el index e092e240627..1192cb11ac4 100644 --- a/lisp/progmodes/prog-mode.el +++ b/lisp/progmodes/prog-mode.el @@ -189,27 +189,42 @@ Regexp match data 0 points to the chars." (defvar-local prettify-symbols--current-symbol-bounds nil) -(defun prettify-symbols--post-command-hook () - (if-let ((c (get-text-property (point) 'composition)) - (s (get-text-property (point) 'prettify-symbols-start)) - (e (get-text-property (point) 'prettify-symbols-end))) - (with-silent-modifications - (setq prettify-symbols--current-symbol-bounds (list s e)) - (remove-text-properties s e '(composition))) - (when (and prettify-symbols--current-symbol-bounds - (or (< (point) (car prettify-symbols--current-symbol-bounds)) - (>= (point) (cadr prettify-symbols--current-symbol-bounds)))) - (apply #'font-lock-flush prettify-symbols--current-symbol-bounds) - (setq prettify-symbols--current-symbol-bounds nil)))) - (defcustom prettify-symbols-unprettify-at-point t "If non-nil, show the non-prettified version of a symbol when point is on it. -The prettification will be reapplied as soon as point moves away -from the symbol. If set to nil, the prettification persists even -when point is on the symbol." - :type 'boolean +If set to the symbol `right-edge', also unprettify if point +is immediately after the symbol. The prettification will be +reapplied as soon as point moves away from the symbol. If +set to nil, the prettification persists even when point is +on the symbol." + :type '(choice (const :tag "Never unprettify" nil) + (const :tag "Unprettify when point is inside" t) + (const :tag "Unprettify when point is inside or at right edge" right-edge)) :group 'prog-mode) +(defun prettify-symbols--post-command-hook () + (cl-labels ((get-prop-as-list + (prop) + (remove nil + (list (get-text-property (point) prop) + (when (and (eq prettify-symbols-unprettify-at-point 'right-edge) + (not (bobp))) + (get-text-property (1- (point)) prop)))))) + (if-let ((c (get-prop-as-list 'composition)) + (s (get-prop-as-list 'prettify-symbols-start)) + (e (get-prop-as-list 'prettify-symbols-end)) + (s (apply #'min s)) + (e (apply #'max e))) + (with-silent-modifications + (setq prettify-symbols--current-symbol-bounds (list s e)) + (remove-text-properties s e '(composition))) + (when (and prettify-symbols--current-symbol-bounds + (or (< (point) (car prettify-symbols--current-symbol-bounds)) + (> (point) (cadr prettify-symbols--current-symbol-bounds)) + (and (not (eq prettify-symbols-unprettify-at-point 'right-edge)) + (= (point) (cadr prettify-symbols--current-symbol-bounds))))) + (apply #'font-lock-flush prettify-symbols--current-symbol-bounds) + (setq prettify-symbols--current-symbol-bounds nil))))) + ;;;###autoload (define-minor-mode prettify-symbols-mode "Toggle Prettify Symbols mode. -- 2.39.2