]> git.eshelyaron.com Git - emacs.git/commitdiff
Use font-lock-doc-face in js-mode
authorTom Tromey <tom@tromey.com>
Sat, 25 Feb 2017 17:27:48 +0000 (10:27 -0700)
committerTom Tromey <tom@tromey.com>
Sat, 25 Feb 2017 21:02:37 +0000 (14:02 -0700)
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.

lisp/progmodes/js.el
test/lisp/progmodes/js-tests.el

index 65325a8ffad896b037f2c957cc825b2b0fe19e1c..aed42a8507624e2b7490ee7cfe0ad3bd2d8fb861 100644 (file)
@@ -1687,6 +1687,16 @@ This performs fontification according to `js--class-styles'."
                                    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 @@ If one hasn't been set, or if it's stale, prompt for a new one."
   (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)
 
index 07e659af605d594a429955e83233483ea37a12c1..e030675e07c91b182281eb89707f4881890fb940 100644 (file)
@@ -128,6 +128,18 @@ if (!/[ (:,='\"]/.test(value)) {
     ;; 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