Skip to content

Commit 197298e

Browse files
arichiardibbatsov
authored andcommitted
Add defcustom for comment font-locking
The patch adds a `clojure-comment-regexp` defcustom that enable the user to consider comments also the ones defined in a `(comment)` form. The default behavior is not changed, the comment reader macro is the only one considered a comment.
1 parent eacd330 commit 197298e

File tree

2 files changed

+19
-6
lines changed

2 files changed

+19
-6
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
* Make imenu recognize indented def-forms
1515
* New interactive command `clojure-cycle-when`.
1616
* New interactive command `clojure-cycle-not`.
17+
* New defcustom `clojure-comment-regexp` for font-locking `#_` or `#_` AND `(comment)` sexps.
1718

1819
## 5.6.1 (2016-12-21)
1920

clojure-mode.el

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -614,15 +614,27 @@ If JUSTIFY is non-nil, justify as well as fill the paragraph."
614614
"Regexp matching the start of a comment sexp.
615615
The beginning of match-group 1 should be before the sexp to be
616616
marked as a comment. The end of sexp is found with
617-
`clojure-forward-logical-sexp'.
617+
`clojure-forward-logical-sexp'.")
618618

619-
By default, this only applies to code after the `#_' reader
620-
macro. In order to also font-lock the `(comment ...)' macro as a
621-
comment, you can set the value to:
622-
\"#_ *\\\\(?1:[^ ]\\\\)\\\\|\\\\(?1:(comment\\\\_>\\\\)\"")
619+
(defvar clojure--reader-and-comment-regexp
620+
"#_ *\\(?1:[^ ]\\)\\|\\(?1:(comment\\_>\\)"
621+
"Regexp matching both `#_' macro and a comment sexp." )
622+
623+
(defcustom clojure-comment-regexp clojure--comment-macro-regexp
624+
"Comment mode.
625+
626+
The possible values for this variable are keywords indicating
627+
what is considered a comment (affecting font locking).
628+
629+
- Reader macro `#_' only - the default
630+
- Reader macro `#_' and `(comment)'"
631+
:type '(choice (const :tag "Reader macro `#_' and `(comment)'" clojure--reader-and-comment-regexp)
632+
(other :tag "Reader macro `#_' only" clojure--comment-macro-regexp))
633+
:package-version '(clojure-mode . "5.7.0"))
623634

624635
(defun clojure--search-comment-macro-internal (limit)
625-
(when (search-forward-regexp clojure--comment-macro-regexp limit t)
636+
"Search for a comment forward stopping at LIMIT."
637+
(when (search-forward-regexp clojure-comment-regexp limit t)
626638
(let* ((md (match-data))
627639
(start (match-beginning 1))
628640
(state (syntax-ppss start)))

0 commit comments

Comments
 (0)