[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[elpa] master a1a6256 05/21: Set up post-colorize hooks.

From: Jackson Ray Hamilton
Subject: [elpa] master a1a6256 05/21: Set up post-colorize hooks.
Date: Fri, 23 Dec 2016 20:27:51 +0000 (UTC)

branch: master
commit a1a62560ac27bd4eefe50de1e0a5df691f646fef
Author: Jackson Ray Hamilton <address@hidden>
Commit: Jackson Ray Hamilton <address@hidden>

    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
 (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."
+(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)))
     (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."
@@ -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.")

reply via email to

[Prev in Thread] Current Thread [Next in Thread]