Skip to content

Commit 3ff38f4

Browse files
Abdussalam Abdurrahmanmarijnh
Abdussalam Abdurrahman
authored andcommitted
[clojure mode] Highlight forms wrapped by (comment ...) as comment.
This commit partially resolves issues codemirror#1896 and codemirror#2314 .
1 parent c53b342 commit 3ff38f4

File tree

2 files changed

+26
-5
lines changed

2 files changed

+26
-5
lines changed

mode/clojure/clojure.js

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -175,6 +175,8 @@ CodeMirror.defineMode("clojure", function (options) {
175175
var name = readSymbol(stream);
176176
tokenType = "symbol";
177177

178+
if (is(name, "comment") && is(state.lastToken, "("))
179+
return (state.tokenize = inComment)(stream, state);
178180
if (is(name, atom) || is(name.charAt(0), ":")) return "atom";
179181
if (is(name, specialForm) || is(name, coreSymbol)) return "keyword";
180182
if (is(state.lastToken, "(")) return "builtin"; // other head symbol
@@ -193,6 +195,25 @@ CodeMirror.defineMode("clojure", function (options) {
193195
return "string";
194196
}
195197

198+
function inComment(stream, state) {
199+
var parenthesisCount = 1;
200+
var next;
201+
202+
while (next = stream.next()) {
203+
if (is(next, ")")) parenthesisCount--;
204+
if (is(next, "(")) parenthesisCount++;
205+
if (is(parenthesisCount, 0)) {
206+
stream.backUp(1);
207+
state.tokenize = base;
208+
break;
209+
}
210+
}
211+
212+
tokenType = "ws";
213+
214+
return "comment";
215+
}
216+
196217
function readSymbol(stream) {
197218
var ch;
198219

mode/clojure/test.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -75,9 +75,9 @@
7575

7676
MT("comments",
7777
"[comment ; this is an in-line comment.]",
78-
"[comment ;; this is a line comment.]"
79-
// FIXME
80-
// "[bracket (][comment comment] [comment (][comment foo] [comment 1] [comment 2] [comment 3][comment )][bracket )]"
78+
"[comment ;; this is a line comment.]",
79+
"[keyword comment]",
80+
"[bracket (][comment comment (foo 1 2 3)][bracket )]"
8181
);
8282

8383
MT("reader macro characters",
@@ -309,8 +309,8 @@
309309
);
310310

311311
MT("should indent comment",
312-
"[bracket (][keyword comment] [bracket (][builtin foo][bracket )]",
313-
" [bracket (][builtin bar] [number 1] [number 2] [number 3][bracket ))]"
312+
"[bracket (][comment comment (foo)]",
313+
"[comment (bar 1 2 3)][bracket )]"
314314
);
315315

316316
MT("should indent cond",

0 commit comments

Comments
 (0)