[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
bug#25858: 25.1.91; js.el should use font-lock-doc-face
From: |
Tom Tromey |
Subject: |
bug#25858: 25.1.91; js.el should use font-lock-doc-face |
Date: |
Sat, 25 Feb 2017 10:28:28 -0700 |
User-agent: |
Gnus/5.13 (Gnus v5.13) Emacs/25.1.91 (gnu/linux) |
>>>>> "Dmitry" == Dmitry Gutov <dgutov@yandex.ru> writes:
Dmitry> Agreed. An implementation like Python's should work well, I think.
How's this?
Tom
commit d825891eaf1480fe82d4f5c51b2a921dda6e9cf7
Author: Tom Tromey <tom@tromey.com>
Date: Sat Feb 25 10:27:48 2017 -0700
Use font-lock-doc-face in js-mode
Bug#25858:
* lisp/progmodes/js.el (js-font-lock-syntactic-face-function): New
defun.
(js-mode): Use it.
* test/lisp/progmodes/js-tests.el (js-mode-doc-comment-face): New
test.
diff --git a/lisp/progmodes/js.el b/lisp/progmodes/js.el
index 65325a8..aed42a8 100644
--- a/lisp/progmodes/js.el
+++ b/lisp/progmodes/js.el
@@ -1687,6 +1687,16 @@ js--font-lock-keywords
js--font-lock-keywords-3)
"Font lock keywords for `js-mode'. See `font-lock-keywords'.")
+(defun js-font-lock-syntactic-face-function (state)
+ "Return syntactic face given STATE."
+ (if (nth 3 state)
+ font-lock-string-face
+ (if (save-excursion
+ (goto-char (nth 8 state))
+ (looking-at "/\\*\\*"))
+ font-lock-doc-face
+ font-lock-comment-face)))
+
(defconst js--syntax-propertize-regexp-regexp
(rx
;; Start of regexp.
@@ -3828,7 +3838,10 @@ js-mode
(setq-local beginning-of-defun-function #'js-beginning-of-defun)
(setq-local end-of-defun-function #'js-end-of-defun)
(setq-local open-paren-in-column-0-is-defun-start nil)
- (setq-local font-lock-defaults (list js--font-lock-keywords))
+ (setq-local font-lock-defaults
+ (list js--font-lock-keywords nil nil nil nil
+ '(font-lock-syntactic-face-function
+ . js-font-lock-syntactic-face-function)))
(setq-local syntax-propertize-function #'js-syntax-propertize)
(setq-local prettify-symbols-alist js--prettify-symbols-alist)
diff --git a/test/lisp/progmodes/js-tests.el b/test/lisp/progmodes/js-tests.el
index 07e659a..e030675 100644
--- a/test/lisp/progmodes/js-tests.el
+++ b/test/lisp/progmodes/js-tests.el
@@ -128,6 +128,18 @@
;; Any success is ok here.
(should t)))
+(ert-deftest js-mode-doc-comment-face ()
+ (dolist (test '(("/*" "*/" font-lock-comment-face)
+ ("//" "\n" font-lock-comment-face)
+ ("/**" "*/" font-lock-doc-face)
+ ("\"" "\"" font-lock-string-face)))
+ (with-temp-buffer
+ (js-mode)
+ (insert (car test) " he")
+ (save-excursion (insert "llo " (cadr test)))
+ (font-lock-ensure)
+ (should (eq (get-text-property (point) 'face) (caddr test))))))
+
(provide 'js-tests)
;;; js-tests.el ends here