@@ -327,7 +327,49 @@ If JUSTIFY is non-nil, justify as well as fill the paragraph."
327
327
(do-auto-fill )))))
328
328
329
329
330
+ ; ;; #_ comments font-locking
331
+ ; ; Code heavily borrowed from Slime.
332
+ ; ; https://github.com/slime/slime/blob/master/contrib/slime-fontifying-fu.el#L186
333
+ (defvar clojure--comment-macro-regexp
334
+ (rx " #_" (* " " ) (group-n 1 (not (any " " ))))
335
+ " Regexp matching the start of a comment sexp.
336
+ The beginning of match-group 1 should be before the sexp to be
337
+ marked as a comment. The end of sexp is found with
338
+ `clojure-forward-logical-sexp' .
339
+
340
+ By default, this only applies to code after the `#_' reader
341
+ macro. In order to also font-lock the `(comment ...)' macro as a
342
+ comment, you can set the value to:
343
+ \" #_ *\\\\ (?1:[^ ]\\\\ )\\\\ |\\\\ (?1:(comment\\\\ _>\\\\ )\" " )
344
+
345
+ (defun clojure--search-comment-macro-internal (limit )
346
+ (when (search-forward-regexp clojure--comment-macro-regexp limit t )
347
+ (let* ((md (match-data ))
348
+ (start (match-beginning 1 ))
349
+ (state (syntax-ppss start)))
350
+ ; ; inside string or comment?
351
+ (if (or (nth 3 state)
352
+ (nth 4 state))
353
+ (clojure--search-comment-macro-internal limit)
354
+ (goto-char start)
355
+ (clojure-forward-logical-sexp 1 )
356
+ ; ; Data for (match-end 1).
357
+ (setf (elt md 3 ) (point ))
358
+ (set-match-data md)
359
+ t ))))
360
+
361
+ (defun clojure--search-comment-macro (limit )
362
+ " Find comment macros and set the match data."
363
+ (let ((result 'retry ))
364
+ (while (and (eq result 'retry ) (<= (point ) limit))
365
+ (condition-case nil
366
+ (setq result (clojure--search-comment-macro-internal limit))
367
+ (end-of-file (setq result nil ))
368
+ (scan-error (setq result 'retry ))))
369
+ result))
330
370
371
+
372
+ ; ;; General font-locking
331
373
(defun clojure-match-next-def ()
332
374
" Scans the buffer backwards for the next \" top-level\" definition.
333
375
Called by `imenu--generic-function' ."
@@ -499,6 +541,8 @@ any number of matches of `clojure--sym-forbidden-rest-chars'."))
499
541
(1 font-lock-type-face nil t ))
500
542
; ; fooBar
501
543
(" \\ (?:\\ <\\ |/\\ )\\ ([a-z]+[A-Z]+[a-zA-Z0-9$]*\\ >\\ )" 1 'clojure-interop-method-face )
544
+ ; ; #_ and (comment ...) macros.
545
+ (clojure--search-comment-macro 1 font-lock-comment-face t )
502
546
; ; Highlight `code` marks, just like `elisp' .
503
547
(,(rx " `" (group-n 1 (optional " #'" )
504
548
(+ (or (syntax symbol) (syntax word)))) " `" )
0 commit comments