Skip to content

Commit c08e2dd

Browse files
rrudakovbbatsov
authored andcommitted
Properly highlight function name in letfn form
1 parent c8286e2 commit c08e2dd

File tree

4 files changed

+77
-9
lines changed

4 files changed

+77
-9
lines changed

CHANGELOG.md

+8-7
Original file line numberDiff line numberDiff line change
@@ -3,19 +3,20 @@
33
## main (unreleased)
44

55
- [#62](https://github.com/clojure-emacs/clojure-ts-mode/issues/62): Define `list` "thing" to improve navigation in Emacs 31.
6-
- [#64]: Add defcustom `clojure-ts-auto-remap` to control remapping of `clojure-mode` buffers.
7-
- Improve syntax highlighting:
6+
- [#64](https://github.com/clojure-emacs/clojure-ts-mode/pull/64): Add defcustom `clojure-ts-auto-remap` to control remapping of `clojure-mode` buffers.
7+
- [#66](https://github.com/clojure-emacs/clojure-ts-mode/pull/66): Improve syntax highlighting:
88
- Highlight metadata with single keyword with `clojure-ts-keyword-face`.
99
- Only highlight built-ins from `clojure.core` namespace.
1010
- Highlight named lambda functions properly.
1111
- Fix syntax highlighting for functions and vars with metadata on the previous
1212
line.
13-
- Improve semantic indentation rules to be more consistent with cljfmt.
14-
- Introduce `clojure-ts-semantic-indent-rules` customization option.
13+
- [#67](https://github.com/clojure-emacs/clojure-ts-mode/pull/67): Improve semantic indentation rules to be more consistent with cljfmt.
14+
- [#67](https://github.com/clojure-emacs/clojure-ts-mode/pull/67): Introduce `clojure-ts-semantic-indent-rules` customization option.
1515
- [#61](https://github.com/clojure-emacs/clojure-ts-mode/issues/61): Fix issue with indentation of collection items with metadata.
16-
- Proper syntax highlighting for expressions with metadata.
17-
- Add basic support for dynamic indentation via `clojure-ts-get-indent-function`.
18-
- Add support for nested indentation rules.
16+
- [#68](https://github.com/clojure-emacs/clojure-ts-mode/pull/68): Proper syntax highlighting for expressions with metadata.
17+
- [#69](https://github.com/clojure-emacs/clojure-ts-mode/pull/69): Add basic support for dynamic indentation via `clojure-ts-get-indent-function`.
18+
- [#70](https://github.com/clojure-emacs/clojure-ts-mode/pull/70): Add support for nested indentation rules.
19+
- [#71](https://github.com/clojure-emacs/clojure-ts-mode/pull/71): Properly highlight function name in `letfn` form.
1920

2021
## 0.2.3 (2025-03-04)
2122

clojure-ts-mode.el

+8-1
Original file line numberDiff line numberDiff line change
@@ -473,7 +473,14 @@ with the markdown_inline grammar."
473473
((sym_lit name: (sym_name) @def)
474474
((:equal "reify" @def)))
475475
(list_lit
476-
(sym_lit name: (sym_name) @font-lock-function-name-face)))))
476+
(sym_lit name: (sym_name) @font-lock-function-name-face))))
477+
;; letfn
478+
((list_lit
479+
((sym_lit name: (sym_name) @symbol)
480+
((:equal "letfn" @symbol)))
481+
(vec_lit
482+
(list_lit
483+
(sym_lit name: (sym_name) @font-lock-function-name-face))))))
477484

478485
:feature 'variable ;; def, defonce
479486
:language 'clojure

test/clojure-ts-mode-font-lock-test.el

+53-1
Original file line numberDiff line numberDiff line change
@@ -167,4 +167,56 @@ DESCRIPTION is the description of the spec."
167167
(when-fontifying-it "special-forms-with-metadata"
168168
("^long (if true 1 2)"
169169
(2 5 font-lock-type-face)
170-
(8 9 font-lock-keyword-face))))
170+
(8 9 font-lock-keyword-face)))
171+
172+
(when-fontifying-it "should highlight function name in all known forms"
173+
("(letfn [(add [x y]
174+
(+ x y))
175+
(hello [user]
176+
(println \"Hello\" user))]
177+
(dotimes [_ (add 6 8)]
178+
(hello \"John Doe\")))"
179+
(2 6 font-lock-keyword-face)
180+
(10 12 font-lock-function-name-face)
181+
(48 52 font-lock-function-name-face))
182+
183+
("(reify
184+
AutoCloseable
185+
(close [this] (.close this)))"
186+
(2 6 font-lock-keyword-face)
187+
(27 31 font-lock-function-name-face))
188+
189+
("(defrecord TestRecord [field]
190+
AutoCloseable
191+
(close [this]
192+
(.close this)))"
193+
(2 10 font-lock-keyword-face)
194+
(12 21 font-lock-type-face)
195+
(50 54 font-lock-function-name-face))
196+
197+
("(definterface MyInterface
198+
(^String name [])
199+
(^double mass []))"
200+
(2 13 font-lock-keyword-face)
201+
(15 25 font-lock-type-face)
202+
(31 36 font-lock-type-face)
203+
(38 41 font-lock-function-name-face)
204+
(51 56 font-lock-type-face)
205+
(58 61 font-lock-function-name-face))
206+
207+
("(deftype ImageSelection [data]
208+
Transferable
209+
(getTransferDataFlavors
210+
[this]
211+
(into-array DataFlavor [DataFlavor/imageFlavor])))"
212+
(2 8 font-lock-keyword-face)
213+
(10 23 font-lock-type-face)
214+
(50 71 font-lock-function-name-face))
215+
216+
("(defprotocol P
217+
(foo [this])
218+
(bar-me [this] [this y]))"
219+
(2 12 font-lock-keyword-face)
220+
(14 14 font-lock-type-face)
221+
(19 21 font-lock-function-name-face)
222+
(34 39 font-lock-function-name-face))))

test/samples/test.clj

+8
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,14 @@
2727
(clojure.core/for [])
2828
(honey.sql/for {})
2929

30+
;; the "add" and "hello" should both have a function name face
31+
(letfn [(add [x y]
32+
(+ x y))
33+
(hello [user]
34+
(println "Hello" user))]
35+
(dotimes [_ (add 6 8)]
36+
(hello "John Doe")))
37+
3038
;; the myfn sexp should have a comment face
3139
(mysfn 101
3240
foo

0 commit comments

Comments
 (0)