[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[elpa] master ba015ce 04/11: Add option to only colorize comments specia
From: |
Jackson Ray Hamilton |
Subject: |
[elpa] master ba015ce 04/11: Add option to only colorize comments specially. |
Date: |
Sat, 14 Mar 2015 20:21:42 +0000 |
branch: master
commit ba015cea148300fb10f19acfcbebf046d52e9258
Author: Jackson Ray Hamilton <address@hidden>
Commit: Jackson Ray Hamilton <address@hidden>
Add option to only colorize comments specially.
---
context-coloring.el | 24 +++++++++++++++++++++---
test/context-coloring-test.el | 27 +++++++++++++++++++++++++++
2 files changed, 48 insertions(+), 3 deletions(-)
diff --git a/context-coloring.el b/context-coloring.el
index 849d392..4755ca0 100644
--- a/context-coloring.el
+++ b/context-coloring.el
@@ -136,12 +136,27 @@ the END point (exclusive) with the face corresponding to
LEVEL."
"If non-nil, also color comments and strings using `font-lock'."
:group 'context-coloring)
+(defcustom context-coloring-syntactic-comments nil
+ "If non-nil, also color comments using `font-lock'."
+ :group 'context-coloring)
+
+(defun context-coloring-font-lock-syntactic-comment-function (state)
+ "Tell `font-lock' to color a comment but not a string."
+ (if (nth 3 state) nil font-lock-comment-face))
+
(defsubst context-coloring-maybe-colorize-comments-and-strings ()
"Color the current buffer's comments and strings if
`context-coloring-comments-and-strings' is non-nil."
- (when context-coloring-comments-and-strings
- (save-excursion
- (font-lock-fontify-syntactically-region (point-min) (point-max)))))
+ (when (or context-coloring-comments-and-strings
+ context-coloring-syntactic-comments)
+ (let ((old-function font-lock-syntactic-face-function))
+ (when context-coloring-syntactic-comments
+ (setq font-lock-syntactic-face-function
+ 'context-coloring-font-lock-syntactic-comment-function))
+ (save-excursion
+ (font-lock-fontify-syntactically-region (point-min) (point-max)))
+ (when context-coloring-syntactic-comments
+ (setq font-lock-syntactic-face-function old-function)))))
;;; js2-mode colorization
@@ -835,6 +850,9 @@ Supported modes: `js-mode', `js3-mode'"
(font-lock-mode 0)
(jit-lock-mode nil)
+ ;; Safely change the valye of this function as necessary.
+ (make-local-variable 'font-lock-syntactic-face-function)
+
(let ((dispatch (gethash major-mode context-coloring-mode-hash-table)))
(when dispatch
(let ((command (plist-get dispatch :command))
diff --git a/test/context-coloring-test.el b/test/context-coloring-test.el
index 8e26991..e8d6474 100644
--- a/test/context-coloring-test.el
+++ b/test/context-coloring-test.el
@@ -52,6 +52,7 @@
(defun context-coloring-test-cleanup ()
"Cleanup after all tests."
(setq context-coloring-comments-and-strings t)
+ (setq context-coloring-syntactic-comments nil)
(setq context-coloring-js-block-scopes nil))
(defmacro context-coloring-test-with-fixture (fixture &rest body)
@@ -717,6 +718,32 @@ see that function."
(context-coloring-colorize)
(context-coloring-test-js-comments-and-strings)))
+(defun context-coloring-test-js-syntactic-comments ()
+ "Test fixtures/comments-and-strings.js."
+ (context-coloring-test-assert-region-comment-delimiter 1 4)
+ (context-coloring-test-assert-region-comment 4 8)
+ (context-coloring-test-assert-region-comment-delimiter 9 12)
+ (context-coloring-test-assert-region-comment 12 19)
+ (context-coloring-test-assert-region-level 20 33 0))
+
+(ert-deftest-async context-coloring-test-js-mode-syntactic-comments (done)
+ (context-coloring-test-js-mode
+ "./fixtures/comments-and-strings.js"
+ (lambda (teardown)
+ (unwind-protect
+ (context-coloring-test-js-syntactic-comments)
+ (funcall teardown))
+ (funcall done))
+ (lambda ()
+ (setq context-coloring-syntactic-comments t))))
+
+(ert-deftest context-coloring-test-js2-mode-syntactic-comments ()
+ (context-coloring-test-js2-mode
+ "./fixtures/comments-and-strings.js"
+ (setq context-coloring-syntactic-comments t)
+ (context-coloring-colorize)
+ (context-coloring-test-js-syntactic-comments)))
+
(provide 'context-coloring-test)
;;; context-coloring-test.el ends here
- [elpa] master updated (b36c4b4 -> 1d1af16), Jackson Ray Hamilton, 2015/03/14
- [elpa] master 5dff74a 01/11: Cleanup., Jackson Ray Hamilton, 2015/03/14
- [elpa] master 6d0ed0e 03/11: Cleanup dependency management., Jackson Ray Hamilton, 2015/03/14
- [elpa] master 32f67a7 02/11: Cleanup., Jackson Ray Hamilton, 2015/03/14
- [elpa] master ba015ce 04/11: Add option to only colorize comments specially.,
Jackson Ray Hamilton <=
- [elpa] master 5ef598f 05/11: Refactor tests for setups and reused fixtures., Jackson Ray Hamilton, 2015/03/14
- [elpa] master 7e208ed 08/11: Use the better zenburn red., Jackson Ray Hamilton, 2015/03/14
- [elpa] master bde8c44 06/11: Add syntactic strings option., Jackson Ray Hamilton, 2015/03/14
- [elpa] master b83709f 07/11: Deprecate `comments-and-strings'., Jackson Ray Hamilton, 2015/03/14
- [elpa] master f062d5a 10/11: Version 6.1.0., Jackson Ray Hamilton, 2015/03/14
- [elpa] master 4849fd4 09/11: Update options documentation., Jackson Ray Hamilton, 2015/03/14
- [elpa] master 1d1af16 11/11: Merge commit 'f062d5a55496e22cf89f2ef9778a24a840a5a68e' from context-coloring, Jackson Ray Hamilton, 2015/03/14