all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: Tom Tromey <tom@tromey.com>
To: Dmitry Gutov <dgutov@yandex.ru>
Cc: Tom Tromey <tom@tromey.com>, 25858@debbugs.gnu.org
Subject: bug#25858: 25.1.91; js.el should use font-lock-doc-face
Date: Sat, 25 Feb 2017 10:28:28 -0700	[thread overview]
Message-ID: <878touuqmb.fsf@tromey.com> (raw)
In-Reply-To: <eec15421-11aa-66ad-09d3-856cd12324cb@yandex.ru> (Dmitry Gutov's message of "Fri, 24 Feb 2017 12:58:09 +0200")

[-- Attachment #1: Type: text/plain, Size: 153 bytes --]

>>>>> "Dmitry" == Dmitry Gutov <dgutov@yandex.ru> writes:

Dmitry> Agreed. An implementation like Python's should work well, I think.

How's this?

Tom


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: patch --]
[-- Type: text/x-patch, Size: 2483 bytes --]

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

  reply	other threads:[~2017-02-25 17:28 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-02-24  7:40 bug#25858: 25.1.91; js.el should use font-lock-doc-face Tom Tromey
2017-02-24 10:58 ` Dmitry Gutov
2017-02-25 17:28   ` Tom Tromey [this message]
2017-02-25 19:54     ` Dmitry Gutov
2017-02-25 21:04 ` bug#25858: done Tom Tromey

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=878touuqmb.fsf@tromey.com \
    --to=tom@tromey.com \
    --cc=25858@debbugs.gnu.org \
    --cc=dgutov@yandex.ru \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/emacs.git
	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.