From c6b9e722fcb37d225c82aa04132958ca05df49e5 Mon Sep 17 00:00:00 2001 From: Evan Moses Date: Sat, 10 Mar 2018 19:11:12 -0800 Subject: [PATCH] [Fix #471] Added support for tagged maps --- CHANGELOG.md | 1 + clojure-mode.el | 10 +++++++--- test/clojure-mode-syntax-test.el | 14 ++++++++++++++ 3 files changed, 22 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index cc98680d..f782e356 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 diff --git a/clojure-mode.el b/clojure-mode.el index 39362d11..45423c5c 100644 --- a/clojure-mode.el +++ b/clojure-mode.el @@ -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? @@ -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." @@ -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))))))))) diff --git a/test/clojure-mode-syntax-test.el b/test/clojure-mode-syntax-test.el index 2ea590c6..829dfba1 100644 --- a/test/clojure-mode-syntax-test.el +++ b/test/clojure-mode-syntax-test.el @@ -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