diff --git a/CHANGELOG.md b/CHANGELOG.md index 51077f9e..98bf8565 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,8 @@ ## master (unreleased) +* [#688](https://github.com/clojure-emacs/clojure-mode/issues/688): Add `clojure-discard-face` to allow for font-locking expressions discarded with the #_ form differently than comments. Maintains default by inheriting from `font-lock-comment-face`. + ## 5.20.0 (2025-05-27) ### New features diff --git a/README.md b/README.md index 4845bbd3..6636bd82 100644 --- a/README.md +++ b/README.md @@ -388,6 +388,34 @@ instructed how to handle the docstrings and highlighting. Here's an example: > > The `clojure-doc-string-elt` attribute is processed by the function `clojure-font-lock-syntactic-face-function`. +### Custom Faces + +`clojure-mode` defines several custom faces that you can customize to adjust the +appearance of Clojure-specific syntax elements: + +- `clojure-keyword-face` - Used to highlight Clojure keywords (e.g., + `:something`, `:keyword-name`). By default, this face inherits from + `font-lock-constant-face`. + +- `clojure-character-face` - Used to highlight Clojure character literals (e.g., + `\a`, `\newline`, `\u00ff`). By default, this face inherits from + `font-lock-string-face`. + +- `clojure-discard-face` - Used to highlight forms that are discarded by + Clojure's `#_` reader macro. By default, this face inherits from + `font-lock-comment-face`, which visually indicates that the discarded form is + ignored by the reader. + +You can customize these faces using Emacs's customization interface +(M-x `customize-face`) or by setting face attributes directly in your +configuration. For example, to make keywords stand out with a bold blue color: + +```el +(set-face-attribute 'clojure-keyword-face nil + :foreground "blue" + :weight 'bold) +``` + ## Refactoring support The available refactorings were originally created and maintained by the diff --git a/clojure-mode.el b/clojure-mode.el index c3d950ce..0ba2098b 100644 --- a/clojure-mode.el +++ b/clojure-mode.el @@ -93,6 +93,11 @@ "Face used to font-lock Clojure keywords (:something)." :package-version '(clojure-mode . "3.0.0")) +(defface clojure-discard-face + '((t (:inherit font-lock-comment-face))) + "Face used to font-lock forms discarded by Clojure's #_ reader macro." + :package-version '(clojure-mode . "5.21.0")) + (defface clojure-character-face '((t (:inherit font-lock-string-face))) "Face used to font-lock Clojure character literals." @@ -1145,7 +1150,7 @@ any number of matches of `clojure--sym-forbidden-rest-chars'.")) (1 nil)) ;; #_ and (comment ...) macros. - (clojure--search-comment-macro 1 font-lock-comment-face t) + (clojure--search-comment-macro 1 'clojure-discard-face t) ;; Highlight `code` marks, just like `elisp'. (,(rx "`" (group-n 1 (optional "#'") (+ (or (syntax symbol) (syntax word)))) "`") diff --git a/test/clojure-mode-font-lock-test.el b/test/clojure-mode-font-lock-test.el index 34771905..2ee9f6d3 100644 --- a/test/clojure-mode-font-lock-test.el +++ b/test/clojure-mode-font-lock-test.el @@ -138,19 +138,19 @@ DESCRIPTION is the description of the spec." (1 2 nil)) ("#_#_" - (3 2 font-lock-comment-face)) + (3 2 clojure-discard-face)) ("#_ #_" (1 3 nil)) ("#_ #_" - (4 2 font-lock-comment-face)) + (4 2 clojure-discard-face)) ("#_ \n;; some crap\n (lala 0101\n lao\n\n 0 0i)" (1 2 nil)) ("#_ \n;; some crap\n (lala 0101\n lao\n\n 0 0i)" - (5 41 font-lock-comment-face)) + (5 41 clojure-discard-face)) ("#_#_ \n;; some crap\n (lala 0101\n lao\n\n 0 0i)\n;; more crap\n (foobar tnseriao)" (1 4 nil)) @@ -159,10 +159,10 @@ DESCRIPTION is the description of the spec." (1 5 nil)) ("#_#_ \n;; some crap\n (lala 0101\n lao\n\n 0 0i)\n;; more crap\n (foobar tnseriao)" - (7 75 font-lock-comment-face)) + (7 75 clojure-discard-face)) ("#_ #_ \n;; some crap\n (lala 0101\n lao\n\n 0 0i)\n;; more crap\n (foobar tnseriao)" - (8 75 font-lock-comment-face))) + (8 75 clojure-discard-face))) (when-fontifying-it "should handle namespace declarations" ("(ns .validns)"