branch: master
commit dc2f9a6e3b43e7559b9d2325031bdd79542e9cf1
Author: Jackson Ray Hamilton <[email protected]>
Commit: Jackson Ray Hamilton <[email protected]>
Refactor maybe-colorize-comments-and-strings.
---
context-coloring.el | 30 +++++++++++++-----------------
1 files changed, 13 insertions(+), 17 deletions(-)
diff --git a/context-coloring.el b/context-coloring.el
index 940b90d..22097a5 100644
--- a/context-coloring.el
+++ b/context-coloring.el
@@ -172,29 +172,25 @@ the END point (exclusive) with the face corresponding to
LEVEL."
"Tell `font-lock' to color a string but not a comment."
(if (nth 3 state) font-lock-string-face nil))
-(defsubst context-coloring-maybe-colorize-comments-and-strings ()
+(defsubst context-coloring-maybe-colorize-comments-and-strings (&optional min
max)
"Color the current buffer's comments and strings if
`context-coloring-comments-and-strings' is non-nil."
(when (or context-coloring-comments-and-strings
context-coloring-syntactic-comments
context-coloring-syntactic-strings)
- (let ((old-function font-lock-syntactic-face-function)
- saved-function-p)
- (cond
- ((and context-coloring-syntactic-comments
- (not context-coloring-syntactic-strings))
- (setq font-lock-syntactic-face-function
- 'context-coloring-font-lock-syntactic-comment-function)
- (setq saved-function-p t))
- ((and context-coloring-syntactic-strings
- (not context-coloring-syntactic-comments))
- (setq font-lock-syntactic-face-function
- 'context-coloring-font-lock-syntactic-string-function)
- (setq saved-function-p t)))
+ (let ((font-lock-syntactic-face-function
+ (cond
+ ((and context-coloring-syntactic-comments
+ (not context-coloring-syntactic-strings))
+ 'context-coloring-font-lock-syntactic-comment-function)
+ ((and context-coloring-syntactic-strings
+ (not context-coloring-syntactic-comments))
+ 'context-coloring-font-lock-syntactic-string-function)
+ (t
+ font-lock-syntactic-face-function))))
(save-excursion
- (font-lock-fontify-syntactically-region (point-min) (point-max)))
- (when saved-function-p
- (setq font-lock-syntactic-face-function old-function)))))
+ (font-lock-fontify-syntactically-region (or min (point-min))
+ (or max (point-max)))))))
;;; js2-mode colorization