Skip to content

Commit

Permalink
[Fix clojure-emacs#471] Added support for tagged maps
Browse files Browse the repository at this point in the history
  • Loading branch information
emosesSfdc committed Mar 12, 2018
1 parent 633331f commit c6b9e72
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 3 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
* New interactive command `clojure-cycle-not`.
* New defcustom `clojure-comment-regexp` for font-locking `#_` or `#_` AND `(comment)` sexps.
* [#459](https://github.com/clojure-emacs/clojure-mode/issues/459): Add font-locking for new built-ins added in Clojure 1.9.
* [#471](https://github.com/clojure-emacs/clojure-mode/issues/471): Support tagged maps (new in Clojure 1.9) in paredit integration.
* Consider `deps.edn` a project root.

### Changes
Expand Down
10 changes: 7 additions & 3 deletions clojure-mode.el
Original file line number Diff line number Diff line change
Expand Up @@ -435,6 +435,10 @@ ENDP and DELIM."
nil)
(t)))))

(defconst clojure--collection-tag-regexp "#\\(::[a-zA-Z0-9._-]*\\|:?\\([a-zA-Z0-9._-]+/\\)?[a-zA-Z0-9._-]+\\)"
"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.")

(defun clojure-no-space-after-tag (endp delimiter)
"Prevent inserting a space after a reader-literal tag?
Expand All @@ -443,8 +447,8 @@ listed in `clojure-omit-space-between-tag-and-delimiters', this
function returns t.
This allows you to write things like #db/id[:db.part/user]
without inserting a space between the tag and the opening
bracket.
and #::my-ns{:some \"map\"} without inserting a space between
the tag and the opening bracket.
See `paredit-space-for-delimiter-predicates' for the meaning of
ENDP and DELIMITER."
Expand All @@ -454,7 +458,7 @@ ENDP and DELIMITER."
(save-excursion
(let ((orig-point (point)))
(not (and (re-search-backward
"#\\([a-zA-Z0-9._-]+/\\)?[a-zA-Z0-9._-]+"
clojure--collection-tag-regexp
(line-beginning-position)
t)
(= orig-point (match-end 0)))))))))
Expand Down
14 changes: 14 additions & 0 deletions test/clojure-mode-syntax-test.el
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,20 @@
(backward-prefix-chars)
(should (bobp)))))


(ert-deftest clojure-allowed-collection-tags ()
(dolist (tag '("#::ns" "#:ns" "#ns" "#:f.q/ns" "#f.q/ns" "#::"))
(with-temp-buffer
(clojure-mode)
(insert tag)
(should-not (clojure-no-space-after-tag nil ?{))))
(dolist (tag '("#$:" "#/f" "#:/f" "#::f.q/ns" "::ns" "::" "#f:ns"))
(with-temp-buffer
(clojure-mode)
(insert tag)
(should (clojure-no-space-after-tag nil ?{)))))


(def-refactor-test test-paragraph-fill-within-comments
"
;; Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt
Expand Down

0 comments on commit c6b9e72

Please sign in to comment.