Skip to content

Support multiple consecutive reader comments (#_#_a b) #545

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Nov 12, 2019
Merged
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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

* [#520](https://github.com/clojure-emacs/clojure-mode/issues/508): Fix allow `clojure-align-cond-forms` to recognize qualified forms.
* Enhance add arity refactoring to support a defn inside a reader conditional.
* [#404](https://github.com/clojure-emacs/clojure-mode/issues/404)/[#528]((https://github.com/clojure-emacs/clojure-mode/issues/528)) Fix syntax highlighting for multiple consecutive comment reader macros (`#_#_`)

### Changes

Expand Down
12 changes: 9 additions & 3 deletions clojure-mode.el
Original file line number Diff line number Diff line change
Expand Up @@ -654,14 +654,16 @@ If JUSTIFY is non-nil, justify as well as fill the paragraph."
;; Code heavily borrowed from Slime.
;; https://github.com/slime/slime/blob/master/contrib/slime-fontifying-fu.el#L186
(defvar clojure--comment-macro-regexp
(rx "#_" (* " ") (group-n 1 (not (any " "))))
(rx (seq (+ (seq "#_" (* " ")))) (group-n 1 (not (any " "))))
"Regexp matching the start of a comment sexp.
The beginning of match-group 1 should be before the sexp to be
marked as a comment. The end of sexp is found with
`clojure-forward-logical-sexp'.")

(defvar clojure--reader-and-comment-regexp
"#_ *\\(?1:[^ ]\\)\\|\\(?1:(comment\\_>\\)"
(rx (or (seq (+ (seq "#_" (* " ")))
(group-n 1 (not (any " "))))
(seq (group-n 1 "(comment" symbol-end))))
"Regexp matching both `#_' macro and a comment sexp." )

(defcustom clojure-comment-regexp clojure--comment-macro-regexp
Expand All @@ -687,7 +689,11 @@ what is considered a comment (affecting font locking).
(nth 4 state))
(clojure--search-comment-macro-internal limit)
(goto-char start)
(clojure-forward-logical-sexp 1)
;; Count how many #_ we got and step by that many sexps
;; For (comment ...), step at least 1 sexp
(clojure-forward-logical-sexp
(max (count-matches (rx "#_") (elt md 0) (elt md 1))
1))
;; Data for (match-end 1).
(setf (elt md 3) (point))
(set-match-data md)
Expand Down
26 changes: 25 additions & 1 deletion test/clojure-mode-font-lock-test.el
Original file line number Diff line number Diff line change
Expand Up @@ -133,11 +133,35 @@ DESCRIPTION is the description of the spec."
("#_"
(1 2 nil))

("#_#_"
(1 2 nil))

("#_#_"
(3 2 font-lock-comment-face))

("#_ #_"
(1 3 nil))

("#_ #_"
(4 2 font-lock-comment-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 font-lock-comment-face))

("#_#_ \n;; some crap\n (lala 0101\n lao\n\n 0 0i)\n;; more crap\n (foobar tnseriao)"
(1 4 nil))

("#_ #_ \n;; some crap\n (lala 0101\n lao\n\n 0 0i)\n;; more crap\n (foobar tnseriao)"
(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))

("#_ #_ \n;; some crap\n (lala 0101\n lao\n\n 0 0i)\n;; more crap\n (foobar tnseriao)"
(8 75 font-lock-comment-face)))

(when-fontifying-it "should handle namespace declarations"
("(ns .validns)"
Expand Down