Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

#355, highlight @doc fixed #383

Merged
merged 1 commit into from
Jan 2, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 20 additions & 1 deletion elixir-mode.el
Original file line number Diff line number Diff line change
Expand Up @@ -493,6 +493,22 @@ just return nil."
(when (looking-back "^\\s-*\\_<end" (line-beginning-position))
(forward-line 1)))))

(defun elixir--docstring-p (&optional pos)
"Check to see if there is a docstring at pos."
(let ((pos (or pos (nth 8 (parse-partial-sexp (point-min) (point))))))
(when pos
(save-excursion
(goto-char pos)
(and (looking-at "\"\"\"")(looking-back "@moduledoc[ \]+\\|@doc[ \]+"
(line-beginning-position)))))))

(defun elixir-font-lock-syntactic-face-function (state)
(if (nth 3 state)
(if (elixir--docstring-p (nth 8 state))
font-lock-doc-face
font-lock-string-face)
font-lock-comment-face))

(easy-menu-define elixir-mode-menu elixir-mode-map
"Elixir mode menu."
'("Elixir"
Expand All @@ -508,7 +524,10 @@ just return nil."

\\{elixir-mode-map}"
(set (make-local-variable 'font-lock-defaults)
'(elixir-font-lock-keywords))
'(elixir-font-lock-keywords
nil nil nil nil
(font-lock-syntactic-face-function
. elixir-font-lock-syntactic-face-function)))
(set (make-local-variable 'comment-start) "# ")
(set (make-local-variable 'comment-end) "")
(set (make-local-variable 'comment-start-skip) "#+ *")
Expand Down
44 changes: 42 additions & 2 deletions test/elixir-mode-font-test.el
Original file line number Diff line number Diff line change
Expand Up @@ -167,15 +167,15 @@ end"
"@doc \"\"\""
(should (eq (elixir-test-face-at 1) 'elixir-attribute-face))
(should (eq (elixir-test-face-at 2) 'elixir-attribute-face))
(should (eq (elixir-test-face-at 6) 'font-lock-string-face))))
(should (eq (elixir-test-face-at 6) 'font-lock-doc-face))))

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

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

(ert-deftest elixir-mode-in-docstring ()
"https://github.com/elixir-lang/emacs-elixir/issues/355"
:tags 'fontification
(elixir-test-with-temp-buffer
"# https://github.com/elixir-lang/emacs-elixir/issues/355

@moduledoc \"\"\"
Everything in here should be gray, including the @moduledoc and triple-quotes
\"\"\"

@doc \"\"\"
Everything in here should be gray, including the @doc and triple-quotes
\"\"\""
;; (switch-to-buffer (current-buffer))
(search-forward "Everything")
(should (elixir--docstring-p))
(search-forward "Everything")
(should (elixir--docstring-p))))

(ert-deftest elixir-mode-docstring-face ()
"https://github.com/elixir-lang/emacs-elixir/issues/355"
:tags 'fontification
(elixir-test-with-temp-buffer
"# https://github.com/elixir-lang/emacs-elixir/issues/355

@moduledoc \"\"\"
Everything in here should be gray, including the @moduledoc and triple-quotes
\"\"\"

@doc \"\"\"
Everything in here should be gray, including the @doc and triple-quotes
\"\"\""
(switch-to-buffer (current-buffer))
(search-forward "Everything")
(should (eq 'font-lock-doc-face (get-char-property (point) 'face)))
(search-forward "Everything")
(should (eq 'font-lock-doc-face (get-char-property (point) 'face)))))



(provide 'elixir-mode-font-test)

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