Skip to content

Commit

Permalink
[Fix #1371] Font-lock deprecated vars with a background color
Browse files Browse the repository at this point in the history
  • Loading branch information
Malabarba committed Oct 19, 2015
1 parent cb47d71 commit c8fb695
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 2 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

### New features

* [#1371](https://github.com/clojure-emacs/cider/issues/1371): Font-lock deprecated vars with a background color.
* [#1232](https://github.com/clojure-emacs/cider/pull/1232): Add `cider-load-buffer-and-switch-to-repl-buffer`.
* [#1325](https://github.com/clojure-emacs/cider/issues/1325): Jump to error location when clicking on the error message in the stack-trace pop-up.
* [#1301](https://github.com/clojure-emacs/cider/issues/1301): CIDER can do dynamic font-locking of defined variables, functions, and macros. This is controlled by the `cider-font-lock-dynamically` custom option.
Expand Down
24 changes: 22 additions & 2 deletions cider-mode.el
Original file line number Diff line number Diff line change
Expand Up @@ -314,7 +314,7 @@ Returns to the buffer in which the command was invoked."
(cider--deep-vector-to-list (read indent))))))

;;; Dynamic font locking
(defcustom cider-font-lock-dynamically '(macro core)
(defcustom cider-font-lock-dynamically '(macro core deprecated)
"Specifies how much dynamic font-locking CIDER should use.
Dynamic font-locking this refers to applying syntax highlighting to vars
defined in the currently active nREPL connection. This is done in addition
Expand All @@ -326,30 +326,45 @@ that should be font-locked:
`macro' (default): Any defined macro gets the `font-lock-builtin-face'.
`function': Any defined function gets the `font-lock-function-face'.
`var': Any non-local var gets the `font-lock-variable-face'.
`deprecated' (default): Any deprecated var gets the `cider-deprecated' face.
`core' (default): Any symbol from clojure.core (face depends on type).
The value can also be t, which means to font-lock as much as possible."
:type '(choice (set :tag "Fine-tune font-locking"
(const :tag "Any defined macro" macro)
(const :tag "Any defined function" function)
(const :tag "Any defined var" var)
(const :tag "Any defined deprecated" deprecated)
(const :tag "Any symbol from clojure.core" core))
(const :tag "Font-lock as much as possible" t))
:group 'cider
:package-version '(cider . "0.10.0"))

(defface cider-deprecated
'((((background light)) :background "light goldenrod")
(((background dark)) :background "#432"))

This comment has been minimized.

Copy link
@expez

expez Oct 19, 2015

Member

Can't we re-use an existing face here? This is unlikely to look good in every possible theme out there.

This comment has been minimized.

Copy link
@Malabarba

Malabarba Oct 19, 2015

Author Member

I tried looking for a face with a mild background and no foreground, but I couldn't find any.
It would indeed be nice if we found one.

This comment has been minimized.

Copy link
@bbatsov

bbatsov Oct 19, 2015

Member

No existing face would be a good fit for this. People sometimes use an error or a warning face for deprecations, but I'm not fond of the idea. From time to time I think that the built-in faces have be extended a bit, as they definitely don't cover many common situations.

"Faced used on depreacted vars"
:group 'cider)

(defconst cider-deprecated-properties
'(face cider-deprecated
help-echo "This var is deprecated. \\[cider-doc] for version information."))

(defun cider--compile-font-lock-keywords (symbols-plist core-plist)
"Return a list of font-lock rules for the symbols in SYMBOLS-PLIST."
(let ((cider-font-lock-dynamically (if (eq cider-font-lock-dynamically t)
'(function var macro core)
'(function var macro core deprecated)
cider-font-lock-dynamically))
deprecated
macros functions vars instrumented)
(when (memq 'core cider-font-lock-dynamically)
(while core-plist
(let ((sym (pop core-plist))
(meta (pop core-plist)))
(when (nrepl-dict-get meta "cider-instrumented")
(push sym instrumented))
(when (nrepl-dict-get meta "deprecated")
(push sym deprecated))
(cond
((nrepl-dict-get meta "macro")
(push sym macros))
Expand All @@ -362,6 +377,9 @@ The value can also be t, which means to font-lock as much as possible."
(meta (pop symbols-plist)))
(when (nrepl-dict-get meta "cider-instrumented")
(push sym instrumented))
(when (and (nrepl-dict-get meta "deprecated")
(memq 'deprecated cider-font-lock-dynamically))
(push sym deprecated))
(cond
((and (memq 'macro cider-font-lock-dynamically)
(nrepl-dict-get meta "macro"))
Expand All @@ -380,6 +398,8 @@ The value can also be t, which means to font-lock as much as possible."
`((,(regexp-opt functions 'symbols) 0 font-lock-function-name-face append)))
,@(when vars
`((,(regexp-opt vars 'symbols) 0 font-lock-variable-name-face append)))
,@(when deprecated
`((,(regexp-opt deprecated 'symbols) 0 cider-deprecated-properties append)))
,@(when instrumented
`((,(regexp-opt instrumented 'symbols) 0 'cider-instrumented-face append))))))

Expand Down

1 comment on commit c8fb695

@Malabarba
Copy link
Member Author

Choose a reason for hiding this comment

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

Just so everyone knows, I had to rewrite a few minutes of history on this commit.

Please sign in to comment.