]> git.eshelyaron.com Git - emacs.git/commitdiff
* lisp/progmodes/prog-mode.el (prettify-symbols-unprettify-at-point):
authorArtur Malabarba <bruce.connor.am@gmail.com>
Thu, 1 Oct 2015 00:38:20 +0000 (01:38 +0100)
committerArtur Malabarba <bruce.connor.am@gmail.com>
Thu, 1 Oct 2015 01:14:14 +0000 (02:14 +0100)
Support unprettifying when point is after a symbol.

* etc/NEWS: Document `prettify-symbols-unprettify-at-point'

etc/NEWS
lisp/progmodes/prog-mode.el

index 26f0474a9fc8f2705567b6e92a9a1cdb937d76b9..ac9a600ab106d1b7e98fa2319cbf545bb2fc0fbe 100644 (file)
--- 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'.
index e092e2406278790fd4d6052b0d6b245d6069d022..1192cb11ac4b5ec1568c731328c7462c9ead5a1b 100644 (file)
@@ -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.