Skip to content
Open
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
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
28 changes: 28 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
(<kbd>M-x</kbd> `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
Expand Down
7 changes: 6 additions & 1 deletion clojure-mode.el
Original file line number Diff line number Diff line change
Expand Up @@ -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."
Expand Down Expand Up @@ -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)))) "`")
Expand Down
10 changes: 5 additions & 5 deletions test/clojure-mode-font-lock-test.el
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand All @@ -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)"
Expand Down