Skip to content

Gray out ignored variables #296

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

Merged
merged 1 commit into from
Nov 26, 2015
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
18 changes: 18 additions & 0 deletions elixir-mode.el
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,16 @@
"For use with atoms & map keys."
:group 'font-lock-faces)

(defvar elixir-ignored-var-face 'elixir-ignored-var-face)
(defface elixir-ignored-var-face
'((((class color) (min-colors 88) (background light))
:foreground "#424242")
(((class color) (background dark))
(:foreground "#616161"))
(t nil))
"For use with ignored variables (starting with underscore)."
:group 'font-lock-faces)

(eval-when-compile
(defconst elixir-rx-constituents
`(
Expand Down Expand Up @@ -405,6 +415,14 @@ is used to limit the scan."
(one-or-more "\n")))
1 font-lock-variable-name-face)

;; Gray out variables starting with "_"
(,(elixir-rx symbol-start
(group (and "_"
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I thought about extracting the contents of this group to a variable like it is done with sigils and identifiers, but I couldn't find a descriptive name, so I've left the definition inlined.

What do you guys think?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it's fine to leave for now.

(any "A-Z" "a-z" "0-9"))
(zero-or-more (any "A-Z" "a-z" "0-9" "_"))
(optional (or "?" "!"))))
1 elixir-ignored-var-face)

;; Map keys
(,(elixir-rx (group (and (one-or-more identifiers) ":")))
1 elixir-atom-face)
Expand Down
27 changes: 27 additions & 0 deletions test/elixir-mode-font-test.el
Original file line number Diff line number Diff line change
Expand Up @@ -426,6 +426,33 @@ end
"
(should (eq (elixir-test-face-at 33) 'font-lock-string-face))))

(ert-deftest elixir-mode-syntax-table/gray-out-ignored-var ()
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have little experience writing these kind of tests.

Is this acceptable ?

"https://github.com/elixir-lang/emacs-elixir/issues/292"
:tags '(fontification syntax-table)
(elixir-test-with-temp-buffer
"variable
_var
_x
_x!
_x?
_
__MODULE__
"
(should (eq (elixir-test-face-at 4) nil))
(should (eq (elixir-test-face-at 14) 'elixir-ignored-var-face))
(should (eq (elixir-test-face-at 15) 'elixir-ignored-var-face))
(should (eq (elixir-test-face-at 23) 'elixir-ignored-var-face))
(should (eq (elixir-test-face-at 24) 'elixir-ignored-var-face))
(should (eq (elixir-test-face-at 30) 'elixir-ignored-var-face))
(should (eq (elixir-test-face-at 32) 'elixir-ignored-var-face))
(should (eq (elixir-test-face-at 38) 'elixir-ignored-var-face))
(should (eq (elixir-test-face-at 40) 'elixir-ignored-var-face))
(should (eq (elixir-test-face-at 46) 'font-lock-constant-face))
(should (eq (elixir-test-face-at 46) 'font-lock-constant-face))
(should (eq (elixir-test-face-at 52) 'font-lock-constant-face))
(should (eq (elixir-test-face-at 53) 'font-lock-constant-face))
(should (eq (elixir-test-face-at 55) 'font-lock-constant-face))))

(provide 'elixir-mode-font-test)

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