Skip to content

Commit 1fdb3cd

Browse files
emosesbbatsov
authored andcommittedMar 12, 2018
[Fix #471] Add support for tagged maps (#472)
1 parent b031cb1 commit 1fdb3cd

File tree

3 files changed

+22
-3
lines changed

3 files changed

+22
-3
lines changed
 

‎CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
* New interactive command `clojure-cycle-not`.
1111
* New defcustom `clojure-comment-regexp` for font-locking `#_` or `#_` AND `(comment)` sexps.
1212
* [#459](https://github.com/clojure-emacs/clojure-mode/issues/459): Add font-locking for new built-ins added in Clojure 1.9.
13+
* [#471](https://github.com/clojure-emacs/clojure-mode/issues/471): Support tagged maps (new in Clojure 1.9) in paredit integration.
1314
* Consider `deps.edn` a project root.
1415

1516
### Changes

‎clojure-mode.el

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -435,6 +435,10 @@ ENDP and DELIM."
435435
nil)
436436
(t)))))
437437

438+
(defconst clojure--collection-tag-regexp "#\\(::[a-zA-Z0-9._-]*\\|:?\\([a-zA-Z0-9._-]+/\\)?[a-zA-Z0-9._-]+\\)"
439+
"Allowed strings that can come before a collection literal (e.g. '[]' or '{}'), as reader macro tags.
440+
This includes #fully.qualified/my-ns[:kw val] and #::my-ns{:kw val} as of Clojure 1.9.")
441+
438442
(defun clojure-no-space-after-tag (endp delimiter)
439443
"Prevent inserting a space after a reader-literal tag?
440444
@@ -443,8 +447,8 @@ listed in `clojure-omit-space-between-tag-and-delimiters', this
443447
function returns t.
444448
445449
This allows you to write things like #db/id[:db.part/user]
446-
without inserting a space between the tag and the opening
447-
bracket.
450+
and #::my-ns{:some \"map\"} without inserting a space between
451+
the tag and the opening bracket.
448452
449453
See `paredit-space-for-delimiter-predicates' for the meaning of
450454
ENDP and DELIMITER."
@@ -454,7 +458,7 @@ ENDP and DELIMITER."
454458
(save-excursion
455459
(let ((orig-point (point)))
456460
(not (and (re-search-backward
457-
"#\\([a-zA-Z0-9._-]+/\\)?[a-zA-Z0-9._-]+"
461+
clojure--collection-tag-regexp
458462
(line-beginning-position)
459463
t)
460464
(= orig-point (match-end 0)))))))))

‎test/clojure-mode-syntax-test.el

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,20 @@
7878
(backward-prefix-chars)
7979
(should (bobp)))))
8080

81+
82+
(ert-deftest clojure-allowed-collection-tags ()
83+
(dolist (tag '("#::ns" "#:ns" "#ns" "#:f.q/ns" "#f.q/ns" "#::"))
84+
(with-temp-buffer
85+
(clojure-mode)
86+
(insert tag)
87+
(should-not (clojure-no-space-after-tag nil ?{))))
88+
(dolist (tag '("#$:" "#/f" "#:/f" "#::f.q/ns" "::ns" "::" "#f:ns"))
89+
(with-temp-buffer
90+
(clojure-mode)
91+
(insert tag)
92+
(should (clojure-no-space-after-tag nil ?{)))))
93+
94+
8195
(def-refactor-test test-paragraph-fill-within-comments
8296
"
8397
;; Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt

0 commit comments

Comments
 (0)
Please sign in to comment.