diff --git a/CHANGELOG.md b/CHANGELOG.md index 98210219..0724787d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,7 @@ ### Bugs fixed * Dynamic vars whose names contain non-alphanumeric characters are now font-locked correctly. +* [#445](https://github.com/clojure-emacs/clojure-mode/issues/445), [#405](https://github.com/clojure-emacs/clojure-mode/issues/405), [#469](https://github.com/clojure-emacs/clojure-mode/issues/469): Correct font-lock on string definitions with docstrings, e.g: `(def foo "doc" "value")`. Correct indentation as well. ## 5.10.0 (2019-01-05) diff --git a/clojure-mode.el b/clojure-mode.el index a9ea8e2c..e98b46f5 100644 --- a/clojure-mode.el +++ b/clojure-mode.el @@ -955,7 +955,13 @@ highlighted region)." (setq docelt (1- docelt))))) (and (zerop docelt) (<= (point) startpos) (progn (forward-comment (point-max)) t) - (= (point) (nth 8 state))))) + (= (point) (nth 8 state)))) + ;; In a def, at last position is not a docstring + (not (and (string= "def" firstsym) + (save-excursion + (goto-char startpos) + (goto-char (+ startpos (length (sexp-at-point)) 2)) + (looking-at "[ \r\n\t]*\)"))))) font-lock-doc-face font-lock-string-face)))) font-lock-comment-face)) diff --git a/test/clojure-mode-font-lock-test.el b/test/clojure-mode-font-lock-test.el index 2eb1fa15..ac202b4d 100644 --- a/test/clojure-mode-font-lock-test.el +++ b/test/clojure-mode-font-lock-test.el @@ -718,6 +718,34 @@ POS." (should (eq (clojure-test-face-at 6 8 "(def foo 10)") 'font-lock-variable-name-face))) +(ert-deftest clojure-mode-syntax-table/variable-def-string () + :tags '(fontification syntax-table) + (should (eq (clojure-test-face-at 10 16 "(def foo \"hello\")") + 'font-lock-string-face)) + (should (eq (clojure-test-face-at 10 16 "(def foo \"hello\" )") + 'font-lock-string-face)) + (should (eq (clojure-test-face-at 13 19 "(def foo \n \"hello\")") + 'font-lock-string-face)) + (should (eq (clojure-test-face-at 13 19 "(def foo \n \"hello\"\n)") + 'font-lock-string-face))) + +(ert-deftest clojure-mode-syntax-table/variable-def-string-with-docstring () + :tags '(fontification syntax-table) + (should (eq (clojure-test-face-at 10 16 "(def foo \"usage\" \"hello\")") + 'font-lock-doc-face)) + (should (eq (clojure-test-face-at 18 24 "(def foo \"usage\" \"hello\")") + 'font-lock-string-face)) + (should (eq (clojure-test-face-at 18 24 "(def foo \"usage\" \"hello\" )") + 'font-lock-string-face)) + (should (eq (clojure-test-face-at 21 27 "(def foo \"usage\" \n \"hello\")") + 'font-lock-string-face)) + (should (eq (clojure-test-face-at 13 19 "(def foo \n \"usage\" \"hello\")") + 'font-lock-doc-face)) + (should (eq (clojure-test-face-at 13 19 "(def foo \n \"usage\" \n \"hello\")") + 'font-lock-doc-face)) + (should (eq (clojure-test-face-at 24 30 "(def foo \n \"usage\" \n \"hello\")") + 'font-lock-string-face))) + (ert-deftest clojure-mode-syntax-table/type-def () :tags '(fontification syntax-table) (clojure-test-with-temp-buffer "(deftype Foo)" diff --git a/test/clojure-mode-indentation-test.el b/test/clojure-mode-indentation-test.el index 7c71f11c..7afa3ffd 100644 --- a/test/clojure-mode-indentation-test.el +++ b/test/clojure-mode-indentation-test.el @@ -68,6 +68,7 @@ values of customisable variables." (search-forward "|") (delete-char -1) (clojure-mode) + (font-lock-ensure) (indent-according-to-mode) (should (equal expected-state (buffer-string))) @@ -118,6 +119,10 @@ values of customisable variables." (->> |expr)") +(check-indentation no-indent-for-def-string + "(def foo \"hello|\")" + "(def foo \"hello|\")") + (check-indentation doc-strings-without-indent-specified " (defn some-fn