Skip to content

Commit 1d03f00

Browse files
committed
[Fix #471] Added support for tagged maps
1 parent 633331f commit 1d03f00

File tree

3 files changed

+23
-5
lines changed

3 files changed

+23
-5
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/pull/471): Support tagged maps, new in Clojure 1.9
1314
* Consider `deps.edn` a project root.
1415

1516
### Changes

clojure-mode.el

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -443,8 +443,8 @@ listed in `clojure-omit-space-between-tag-and-delimiters', this
443443
function returns t.
444444
445445
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.
446+
and #::my-ns{:some \"map\"} without inserting a space between
447+
the tag and the opening bracket.
448448
449449
See `paredit-space-for-delimiter-predicates' for the meaning of
450450
ENDP and DELIMITER."
@@ -454,7 +454,7 @@ ENDP and DELIMITER."
454454
(save-excursion
455455
(let ((orig-point (point)))
456456
(not (and (re-search-backward
457-
"#\\([a-zA-Z0-9._-]+/\\)?[a-zA-Z0-9._-]+"
457+
clojure--collection-tag-regexp
458458
(line-beginning-position)
459459
t)
460460
(= orig-point (match-end 0)))))))))
@@ -521,7 +521,8 @@ replacement for `cljr-expand-let`."
521521
(setq-local clojure-expected-ns-function #'clojure-expected-ns)
522522
(setq-local parse-sexp-ignore-comments t)
523523
(setq-local prettify-symbols-alist clojure--prettify-symbols-alist)
524-
(setq-local open-paren-in-column-0-is-defun-start nil))
524+
(setq-local open-paren-in-column-0-is-defun-start nil)
525+
)
525526

526527
(defsubst clojure-in-docstring-p ()
527528
"Check whether point is in a docstring."
@@ -733,7 +734,9 @@ definition of 'macros': URL `http://git.io/vRGLD'.")
733734
(concat "[^" clojure--sym-forbidden-1st-chars "][^" clojure--sym-forbidden-rest-chars "]*")
734735
"A regexp matching a Clojure symbol or namespace alias.
735736
Matches the rule `clojure--sym-forbidden-1st-chars' followed by
736-
any number of matches of `clojure--sym-forbidden-rest-chars'."))
737+
any number of matches of `clojure--sym-forbidden-rest-chars'.")
738+
(defconst clojure--collection-tag-regexp "#\\(::[a-zA-Z0-9._-]*\\|:?\\([a-zA-Z0-9._-]+/\\)?[a-zA-Z0-9._-]+\\)"
739+
"Allowed strings that can come before a collection literal (e.g. '[]' or '{}'), as reader macro tags. This includes #fully.qualified/my-ns[:kw val] and #::my-ns{:kw val} as of Clojure 1.9."))
737740

738741
(defconst clojure-font-lock-keywords
739742
(eval-when-compile

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)