branch: master
commit a1a62560ac27bd4eefe50de1e0a5df691f646fef
Author: Jackson Ray Hamilton <[email protected]>
Commit: Jackson Ray Hamilton <[email protected]>
Set up post-colorize hooks.
In particular, this allows for symbol prettification post-colorize while
prettify-symbols-mode is enabled. Generally, it may allow for other modes
utilizing Font Lock to apply their fontifications too.
---
context-coloring.el | 54 ++++++++++++++++++++++++++++++++++++++++++---------
1 file changed, 45 insertions(+), 9 deletions(-)
diff --git a/context-coloring.el b/context-coloring.el
index 2e4e867..814466b 100644
--- a/context-coloring.el
+++ b/context-coloring.el
@@ -41,6 +41,14 @@
"Join a list of STRINGS with the string DELIMITER."
(mapconcat #'identity strings delimiter))
+(defun context-coloring-check-predicates (predicates)
+ "Call PREDICATES until one returns t, otherwise return nil."
+ (let ((satisfied-p nil))
+ (while (and predicates
+ (not satisfied-p))
+ (setq satisfied-p (funcall (pop predicates))))
+ satisfied-p))
+
;;; Faces
@@ -311,7 +319,11 @@ override `context-coloring-default-delay'.
`context-coloring-mode' is enabled.
`:teardown' - Arbitrary code to tear down this dispatch when
-`context-coloring-mode' is disabled.")
+`context-coloring-mode' is disabled.
+
+`:async-p' - Hint that code will be colorized asynchronously.
+Please call `context-coloring-after-colorize' when colorization
+completes.")
(defun context-coloring-find-dispatch (predicate)
"Find the first dispatch satisfying PREDICATE."
@@ -345,18 +357,46 @@ override `context-coloring-default-delay'.
"Set up environment for colorization."
(context-coloring-update-maximum-face))
+(defvar context-coloring-after-colorize-hook nil
+ "Functions to run after colorizing.")
+
+(defun context-coloring-after-colorize ()
+ "Do final business after colorization."
+ (run-hooks 'context-coloring-after-colorize-hook))
+
(defun context-coloring-dispatch ()
"Determine how to color the current buffer, and color it."
(let* ((dispatch (context-coloring-get-current-dispatch))
- (colorizer (plist-get dispatch :colorizer)))
+ (colorizer (plist-get dispatch :colorizer))
+ (async-p (plist-get dispatch :async-p)))
(context-coloring-before-colorize)
(when colorizer
(catch 'interrupted
- (funcall colorizer)))))
+ (funcall colorizer)))
+ (unless async-p
+ (context-coloring-after-colorize))))
;;; Colorization
+(defvar context-coloring-fontify-keywords-predicates
+ (list
+ (lambda () prettify-symbols-mode))
+ "Cases where the whole buffer should have keywords fontified.
+Necessary in cases where a mode relies on fontifications in
+regions where Context Coloring doesn't happen to touch.")
+
+(defun context-coloring-maybe-fontify-keywords ()
+ "Determine if the buffer ought to have keywords fontified."
+ (when (context-coloring-check-predicates
+ context-coloring-fontify-keywords-predicates)
+ (with-silent-modifications
+ (save-excursion
+ (font-lock-fontify-keywords-region (point-min) (point-max))))))
+
+(add-hook 'context-coloring-after-colorize-hook
+ #'context-coloring-maybe-fontify-keywords)
+
(defun context-coloring-colorize ()
"Color the current buffer by function context."
(interactive)
@@ -381,12 +421,8 @@ permissible.")
(defun context-coloring-ignore-unavailable-message-p ()
"Determine if the unavailable message should be silenced."
- (let ((predicates context-coloring-ignore-unavailable-predicates)
- (ignore-p nil))
- (while (and predicates
- (not ignore-p))
- (setq ignore-p (funcall (pop predicates))))
- ignore-p))
+ (context-coloring-check-predicates
+ context-coloring-ignore-unavailable-predicates))
(defvar context-coloring-interruptable-p t
"When non-nil, coloring may be interrupted by user input.")