Skip to content

Commit b0b8231

Browse files
committed
Merge pull request #505 from carlosgeos/fix-445
[Fix #445] def form with strings and docstrings
2 parents 2d6ccab + a9a0276 commit b0b8231

File tree

4 files changed

+41
-1
lines changed

4 files changed

+41
-1
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
* [#445 (comment)](https://github.com/clojure-emacs/clojure-mode/issues/445#issuecomment-340460753): Proper font lock for namespaced keywords like for example `(s/def ::keyword)`
99
* [#508](https://github.com/clojure-emacs/clojure-mode/issues/508): Fix font lock for namespaces with metadata
1010
* [#506](https://github.com/clojure-emacs/clojure-mode/issues/506): `clojure-mode-display-version` correctly displays the package's version
11+
* [#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.
1112

1213
## 5.10.0 (2019-01-05)
1314

clojure-mode.el

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -958,7 +958,13 @@ highlighted region)."
958958
(setq docelt (1- docelt)))))
959959
(and (zerop docelt) (<= (point) startpos)
960960
(progn (forward-comment (point-max)) t)
961-
(= (point) (nth 8 state)))))
961+
(= (point) (nth 8 state))))
962+
;; In a def, at last position is not a docstring
963+
(not (and (string= "def" firstsym)
964+
(save-excursion
965+
(goto-char startpos)
966+
(goto-char (+ startpos (length (sexp-at-point)) 2))
967+
(looking-at "[ \r\n\t]*\)")))))
962968
font-lock-doc-face
963969
font-lock-string-face))))
964970
font-lock-comment-face))

test/clojure-mode-font-lock-test.el

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -731,6 +731,34 @@ POS."
731731
(should (eq (clojure-test-face-at 6 8 "(def foo 10)")
732732
'font-lock-variable-name-face)))
733733

734+
(ert-deftest clojure-mode-syntax-table/variable-def-string ()
735+
:tags '(fontification syntax-table)
736+
(should (eq (clojure-test-face-at 10 16 "(def foo \"hello\")")
737+
'font-lock-string-face))
738+
(should (eq (clojure-test-face-at 10 16 "(def foo \"hello\" )")
739+
'font-lock-string-face))
740+
(should (eq (clojure-test-face-at 13 19 "(def foo \n \"hello\")")
741+
'font-lock-string-face))
742+
(should (eq (clojure-test-face-at 13 19 "(def foo \n \"hello\"\n)")
743+
'font-lock-string-face)))
744+
745+
(ert-deftest clojure-mode-syntax-table/variable-def-string-with-docstring ()
746+
:tags '(fontification syntax-table)
747+
(should (eq (clojure-test-face-at 10 16 "(def foo \"usage\" \"hello\")")
748+
'font-lock-doc-face))
749+
(should (eq (clojure-test-face-at 18 24 "(def foo \"usage\" \"hello\")")
750+
'font-lock-string-face))
751+
(should (eq (clojure-test-face-at 18 24 "(def foo \"usage\" \"hello\" )")
752+
'font-lock-string-face))
753+
(should (eq (clojure-test-face-at 21 27 "(def foo \"usage\" \n \"hello\")")
754+
'font-lock-string-face))
755+
(should (eq (clojure-test-face-at 13 19 "(def foo \n \"usage\" \"hello\")")
756+
'font-lock-doc-face))
757+
(should (eq (clojure-test-face-at 13 19 "(def foo \n \"usage\" \n \"hello\")")
758+
'font-lock-doc-face))
759+
(should (eq (clojure-test-face-at 24 30 "(def foo \n \"usage\" \n \"hello\")")
760+
'font-lock-string-face)))
761+
734762
(ert-deftest clojure-mode-syntax-table/type-def ()
735763
:tags '(fontification syntax-table)
736764
(clojure-test-with-temp-buffer "(deftype Foo)"

test/clojure-mode-indentation-test.el

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@ values of customisable variables."
6868
(search-forward "|")
6969
(delete-char -1)
7070
(clojure-mode)
71+
(font-lock-ensure)
7172
(indent-according-to-mode)
7273

7374
(should (equal expected-state (buffer-string)))
@@ -118,6 +119,10 @@ values of customisable variables."
118119
(->>
119120
|expr)")
120121

122+
(check-indentation no-indent-for-def-string
123+
"(def foo \"hello|\")"
124+
"(def foo \"hello|\")")
125+
121126
(check-indentation doc-strings-without-indent-specified
122127
"
123128
(defn some-fn

0 commit comments

Comments
 (0)