[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
+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.")
- [elpa] master 26f48c5 06/21: Improve Font Lock integration., (continued)
- [elpa] master 26f48c5 06/21: Improve Font Lock integration., Jackson Ray Hamilton, 2016/12/23
- [elpa] master c847b0f 01/21: Mention tern-context-coloring in README., Jackson Ray Hamilton, 2016/12/23
- [elpa] master 54593e5 11/21: Add Emacs 25.1 to the build matrix., Jackson Ray Hamilton, 2016/12/23
- [elpa] master abded5f 14/21: Check for compositions on old Emacsen., Jackson Ray Hamilton, 2016/12/23
- [elpa] master 269a382 15/21: Ensure coloring still works after prettification., Jackson Ray Hamilton, 2016/12/23
- [elpa] master b3ea138 19/21: Remove no-byte-compile from development files., Jackson Ray Hamilton, 2016/12/23
- [elpa] master ce29abd 17/21: Don't color before or beyond the buffer., Jackson Ray Hamilton, 2016/12/23
- [elpa] master 45b5ad0 16/21: Merge pull request #5 from jacksonrayhamilton/prettify-symbols, Jackson Ray Hamilton, 2016/12/23
- [elpa] master 5fe3695 07/21: Revert "Clean up local variable.", Jackson Ray Hamilton, 2016/12/23
- [elpa] master 550e61b 08/21: Merge branch 'master' into prettify-symbols, Jackson Ray Hamilton, 2016/12/23
- [elpa] master a1a6256 05/21: Set up post-colorize hooks.,
Jackson Ray Hamilton <=
- [elpa] master 4836dd0 10/21: Add tests for prettifying symbols., Jackson Ray Hamilton, 2016/12/23
- [elpa] master edbb191 13/21: Feature-detect prettify-symbols-mode for Emacs 24.3 compat., Jackson Ray Hamilton, 2016/12/23
- [elpa] master 3985437 09/21: Use a mode hook for detecting entering Prettify Symbols mode., Jackson Ray Hamilton, 2016/12/23
- [elpa] master 1b30a28 20/21: Version 8.1.0., Jackson Ray Hamilton, 2016/12/23
- [elpa] master 5402f35 21/21: Merge commit '1b30a28857727202d1f6a027f83ad66151fb1e92' from context-coloring, Jackson Ray Hamilton, 2016/12/23