aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorArtur Malabarba2015-10-01 01:38:20 +0100
committerArtur Malabarba2015-10-01 02:14:14 +0100
commitcbae4820f9a328250c06d3c6a5d34864c800cacb (patch)
tree1ebed1b4ab13326d5b156b0edfd714d757a25852
parent4a6780ea89009806928617a5ccf0e21d646452a7 (diff)
downloademacs-cbae4820f9a328250c06d3c6a5d34864c800cacb.tar.gz
emacs-cbae4820f9a328250c06d3c6a5d34864c800cacb.zip
* 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'
-rw-r--r--etc/NEWS6
-rw-r--r--lisp/progmodes/prog-mode.el49
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.
318** Prog mode has some support for multi-mode indentation. 318** Prog mode has some support for multi-mode indentation.
319See `prog-indentation-context' and `prog-widen'. 319See `prog-indentation-context' and `prog-widen'.
320 320
321** Prettify Symbols mode supports custom composition predicates. By 321** Prettify Symbols mode
322*** Prettify Symbols mode supports custom composition predicates. By
322overriding the default `prettify-symbols-compose-predicate', modes can 323overriding the default `prettify-symbols-compose-predicate', modes can
323specify in which contexts a symbol map be composed to some unicode 324specify in which contexts a symbol map be composed to some unicode
324character. `prettify-symbols-default-compose-p' is the default which 325character. `prettify-symbols-default-compose-p' is the default which
325is suitable for most programming languages such as C or Lisp (but not 326is suitable for most programming languages such as C or Lisp (but not
326(La)TeX). 327(La)TeX).
327 328
329*** Symbols are not prettified while point is inside them.
330New variable `prettify-symbols-unprettify-at-point' configures this.
331
328** New `xterm-screen-extra-capabilities' config. 332** New `xterm-screen-extra-capabilities' config.
329 333
330** The `save-place' variable is replaced by a `save-place-mode'. 334** 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."
189 189
190(defvar-local prettify-symbols--current-symbol-bounds nil) 190(defvar-local prettify-symbols--current-symbol-bounds nil)
191 191
192(defun prettify-symbols--post-command-hook ()
193 (if-let ((c (get-text-property (point) 'composition))
194 (s (get-text-property (point) 'prettify-symbols-start))
195 (e (get-text-property (point) 'prettify-symbols-end)))
196 (with-silent-modifications
197 (setq prettify-symbols--current-symbol-bounds (list s e))
198 (remove-text-properties s e '(composition)))
199 (when (and prettify-symbols--current-symbol-bounds
200 (or (< (point) (car prettify-symbols--current-symbol-bounds))
201 (>= (point) (cadr prettify-symbols--current-symbol-bounds))))
202 (apply #'font-lock-flush prettify-symbols--current-symbol-bounds)
203 (setq prettify-symbols--current-symbol-bounds nil))))
204
205(defcustom prettify-symbols-unprettify-at-point t 192(defcustom prettify-symbols-unprettify-at-point t
206 "If non-nil, show the non-prettified version of a symbol when point is on it. 193 "If non-nil, show the non-prettified version of a symbol when point is on it.
207The prettification will be reapplied as soon as point moves away 194If set to the symbol `right-edge', also unprettify if point
208from the symbol. If set to nil, the prettification persists even 195is immediately after the symbol. The prettification will be
209when point is on the symbol." 196reapplied as soon as point moves away from the symbol. If
210 :type 'boolean 197set to nil, the prettification persists even when point is
198on the symbol."
199 :type '(choice (const :tag "Never unprettify" nil)
200 (const :tag "Unprettify when point is inside" t)
201 (const :tag "Unprettify when point is inside or at right edge" right-edge))
211 :group 'prog-mode) 202 :group 'prog-mode)
212 203
204(defun prettify-symbols--post-command-hook ()
205 (cl-labels ((get-prop-as-list
206 (prop)
207 (remove nil
208 (list (get-text-property (point) prop)
209 (when (and (eq prettify-symbols-unprettify-at-point 'right-edge)
210 (not (bobp)))
211 (get-text-property (1- (point)) prop))))))
212 (if-let ((c (get-prop-as-list 'composition))
213 (s (get-prop-as-list 'prettify-symbols-start))
214 (e (get-prop-as-list 'prettify-symbols-end))
215 (s (apply #'min s))
216 (e (apply #'max e)))
217 (with-silent-modifications
218 (setq prettify-symbols--current-symbol-bounds (list s e))
219 (remove-text-properties s e '(composition)))
220 (when (and prettify-symbols--current-symbol-bounds
221 (or (< (point) (car prettify-symbols--current-symbol-bounds))
222 (> (point) (cadr prettify-symbols--current-symbol-bounds))
223 (and (not (eq prettify-symbols-unprettify-at-point 'right-edge))
224 (= (point) (cadr prettify-symbols--current-symbol-bounds)))))
225 (apply #'font-lock-flush prettify-symbols--current-symbol-bounds)
226 (setq prettify-symbols--current-symbol-bounds nil)))))
227
213;;;###autoload 228;;;###autoload
214(define-minor-mode prettify-symbols-mode 229(define-minor-mode prettify-symbols-mode
215 "Toggle Prettify Symbols mode. 230 "Toggle Prettify Symbols mode.