From 48f229d40c30544182d73b06b05aa4e2e7b799f4 Mon Sep 17 00:00:00 2001 From: Evan Moses Date: Sat, 10 Mar 2018 19:11:12 -0800 Subject: [PATCH] Added support for tagged maps, see #471 --- CHANGELOG.md | 1 + clojure-mode.el | 13 ++++++++----- test/clojure-mode-syntax-test.el | 14 ++++++++++++++ 3 files changed, 23 insertions(+), 5 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index cc98680d..18dc1e5d 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/pull/471): Support tagged maps, new in Clojure 1.9 * Consider `deps.edn` a project root. ### Changes diff --git a/clojure-mode.el b/clojure-mode.el index 39362d11..6895fddf 100644 --- a/clojure-mode.el +++ b/clojure-mode.el @@ -443,8 +443,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 +454,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))))))))) @@ -521,7 +521,8 @@ replacement for `cljr-expand-let`." (setq-local clojure-expected-ns-function #'clojure-expected-ns) (setq-local parse-sexp-ignore-comments t) (setq-local prettify-symbols-alist clojure--prettify-symbols-alist) - (setq-local open-paren-in-column-0-is-defun-start nil)) + (setq-local open-paren-in-column-0-is-defun-start nil) + ) (defsubst clojure-in-docstring-p () "Check whether point is in a docstring." @@ -733,7 +734,9 @@ definition of 'macros': URL `http://git.io/vRGLD'.") (concat "[^" clojure--sym-forbidden-1st-chars "][^" clojure--sym-forbidden-rest-chars "]*") "A regexp matching a Clojure symbol or namespace alias. Matches the rule `clojure--sym-forbidden-1st-chars' followed by -any number of matches of `clojure--sym-forbidden-rest-chars'.")) +any number of matches of `clojure--sym-forbidden-rest-chars'.") + (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.")) (defconst clojure-font-lock-keywords (eval-when-compile 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