branch: master
commit 398543707c0845353290ee0f1911ba15c1349a59
Author: Jackson Ray Hamilton <[email protected]>
Commit: Jackson Ray Hamilton <[email protected]>
Use a mode hook for detecting entering Prettify Symbols mode.
---
context-coloring.el | 28 +++++-----------------------
1 file changed, 5 insertions(+), 23 deletions(-)
diff --git a/context-coloring.el b/context-coloring.el
index f7104ed..1429f66 100644
--- a/context-coloring.el
+++ b/context-coloring.el
@@ -427,24 +427,6 @@ permissible.")
(defvar context-coloring-interruptable-p t
"When non-nil, coloring may be interrupted by user input.")
-(defvar context-coloring-mode)
-
-(defun context-coloring-around-font-lock-flush (oldfun &rest r)
- "Advice around `font-lock-flush' for this mode only."
- (if context-coloring-mode
- (apply #'context-coloring-font-lock-flush r)
- (apply oldfun r)))
-
-(defun context-coloring-font-lock-flush (&optional start end)
- "Reimplementation of `font-lock-flush' for this mode.
-The original relies on Font Lock variables that would be messy to
-maintain here."
- (let* ((start (or start (point-min)))
- (end (or end (point-max)))
- (length (- end start)))
- (context-coloring-change-function start end length)
- (context-coloring-maybe-colorize-with-buffer (current-buffer))))
-
;;;###autoload
(define-minor-mode context-coloring-mode
"Toggle contextual code coloring.
@@ -482,11 +464,10 @@ Feature inspired by Douglas Crockford."
(font-lock-set-defaults)
;; Safely change the value of this function as necessary.
(make-local-variable 'font-lock-syntactic-face-function)
- ;; Improve integration with modes relying on Font Lock. Here, attempts
- ;; to refontify in Font Lock contexts will instead refontifiy in
Context
- ;; Coloring contexts. This is necessary for `prettify-symbols-mode'
- ;; integration.
- (advice-add #'font-lock-flush :around
#'context-coloring-around-font-lock-flush)
+ ;; Improve integration with `prettify-symbols-mode'. It relies on Font
+ ;; Lock's automatic fontification to apply it's changes on mode change,
+ ;; so Context Coloring has to make those changes manually.
+ (add-hook 'prettify-symbols-mode-hook
#'context-coloring-maybe-fontify-keywords nil t)
(let ((setup (plist-get dispatch :setup)))
(when setup
(funcall setup))
@@ -501,6 +482,7 @@ Feature inspired by Douglas Crockford."
(let ((teardown (plist-get dispatch :teardown)))
(when teardown
(funcall teardown)))))
+ (remove-hook 'prettify-symbols-mode-hook
#'context-coloring-maybe-fontify-keywords t)
(turn-on-font-lock-if-desired))))
(provide 'context-coloring)