Skip to content

Commit 5ca0665

Browse files
#355, highlight @doc fixed
1 parent b71145e commit 5ca0665

File tree

2 files changed

+62
-3
lines changed

2 files changed

+62
-3
lines changed

elixir-mode.el

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -493,6 +493,22 @@ just return nil."
493493
(when (looking-back "^\\s-*\\_<end" (line-beginning-position))
494494
(forward-line 1)))))
495495

496+
(defun elixir--docstring-p (&optional pos)
497+
"Check to see if there is a docstring at pos."
498+
(let ((pos (or pos (nth 8 (parse-partial-sexp (point-min) (point))))))
499+
(when pos
500+
(save-excursion
501+
(goto-char pos)
502+
(and (looking-at "\"\"\"")(looking-back "@moduledoc[ \]+\\|@doc[ \]+"
503+
(line-beginning-position)))))))
504+
505+
(defun elixir-font-lock-syntactic-face-function (state)
506+
(if (nth 3 state)
507+
(if (elixir--docstring-p (nth 8 state))
508+
font-lock-doc-face
509+
font-lock-string-face)
510+
font-lock-comment-face))
511+
496512
(easy-menu-define elixir-mode-menu elixir-mode-map
497513
"Elixir mode menu."
498514
'("Elixir"
@@ -508,7 +524,10 @@ just return nil."
508524
509525
\\{elixir-mode-map}"
510526
(set (make-local-variable 'font-lock-defaults)
511-
'(elixir-font-lock-keywords))
527+
'(elixir-font-lock-keywords
528+
nil nil nil nil
529+
(font-lock-syntactic-face-function
530+
. elixir-font-lock-syntactic-face-function)))
512531
(set (make-local-variable 'comment-start) "# ")
513532
(set (make-local-variable 'comment-end) "")
514533
(set (make-local-variable 'comment-start-skip) "#+ *")

test/elixir-mode-font-test.el

Lines changed: 42 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -167,15 +167,15 @@ end"
167167
"@doc \"\"\""
168168
(should (eq (elixir-test-face-at 1) 'elixir-attribute-face))
169169
(should (eq (elixir-test-face-at 2) 'elixir-attribute-face))
170-
(should (eq (elixir-test-face-at 6) 'font-lock-string-face))))
170+
(should (eq (elixir-test-face-at 6) 'font-lock-doc-face))))
171171

172172
(ert-deftest elixir-mode-syntax-table/fontify-heredoc/2 ()
173173
:tags '(fontification heredoc syntax-table)
174174
(elixir-test-with-temp-buffer
175175
"@moduledoc \"\"\""
176176
(should (eq (elixir-test-face-at 1) 'elixir-attribute-face))
177177
(should (eq (elixir-test-face-at 2) 'elixir-attribute-face))
178-
(should (eq (elixir-test-face-at 12) 'font-lock-string-face))))
178+
(should (eq (elixir-test-face-at 12) 'font-lock-doc-face))))
179179

180180
(ert-deftest elixir-mode-syntax-table/fontify-heredoc/3 ()
181181
:tags '(fontification heredoc syntax-table)
@@ -545,6 +545,46 @@ _1_day"
545545
(should (eq (elixir-test-face-at 2) 'font-lock-comment-face))
546546
(should (eq (elixir-test-face-at 19) 'font-lock-comment-face))))
547547

548+
(ert-deftest elixir-mode-in-docstring ()
549+
"https://github.com/elixir-lang/emacs-elixir/issues/355"
550+
:tags 'fontification
551+
(elixir-test-with-temp-buffer
552+
"# https://github.com/elixir-lang/emacs-elixir/issues/355
553+
554+
@moduledoc \"\"\"
555+
Everything in here should be gray, including the @moduledoc and triple-quotes
556+
\"\"\"
557+
558+
@doc \"\"\"
559+
Everything in here should be gray, including the @doc and triple-quotes
560+
\"\"\""
561+
;; (switch-to-buffer (current-buffer))
562+
(search-forward "Everything")
563+
(should (elixir--docstring-p))
564+
(search-forward "Everything")
565+
(should (elixir--docstring-p))))
566+
567+
(ert-deftest elixir-mode-docstring-face ()
568+
"https://github.com/elixir-lang/emacs-elixir/issues/355"
569+
:tags 'fontification
570+
(elixir-test-with-temp-buffer
571+
"# https://github.com/elixir-lang/emacs-elixir/issues/355
572+
573+
@moduledoc \"\"\"
574+
Everything in here should be gray, including the @moduledoc and triple-quotes
575+
\"\"\"
576+
577+
@doc \"\"\"
578+
Everything in here should be gray, including the @doc and triple-quotes
579+
\"\"\""
580+
(switch-to-buffer (current-buffer))
581+
(search-forward "Everything")
582+
(should (eq 'font-lock-doc-face (get-char-property (point) 'face)))
583+
(search-forward "Everything")
584+
(should (eq 'font-lock-doc-face (get-char-property (point) 'face)))))
585+
586+
587+
548588
(provide 'elixir-mode-font-test)
549589

550590
;;; elixir-mode-font-test.el ends here

0 commit comments

Comments
 (0)