diff --git a/CHANGELOG.md b/CHANGELOG.md index a0b2f7d4..e685f348 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -21,6 +21,7 @@ * [#429](https://github.com/clojure-emacs/clojure-mode/issues/429): Fix a bug causing last occurrence of expression sometimes is not replaced when using `move-to-let`. * [#423](https://github.com/clojure-emacs/clojure-mode/issues/423): Make `clojure-match-next-def` more robust against zero-arity def-like forms. * [#451](https://github.com/clojure-emacs/clojure-mode/issues/451): Make project root directory calculation customized by `clojure-project-root-function`. +* Fix namespace font-locking. ## 5.6.1 (2016-12-21) diff --git a/clojure-mode.el b/clojure-mode.el index f1421f0a..ab69a039 100644 --- a/clojure-mode.el +++ b/clojure-mode.el @@ -855,19 +855,19 @@ any number of matches of `clojure--sym-forbidden-rest-chars'.")) ;; Java interop highlighting ;; CONST SOME_CONST (optionally prefixed by /) ("\\(?:\\<\\|/\\)\\([A-Z]+\\|\\([A-Z]+_[A-Z1-9_]+\\)\\)\\>" 1 font-lock-constant-face) + ;; special handling for foo.bar.baz in the namespace definition + (,(concat "(\\[ \r\n\t]*" + ;; Possibly metadata + "\\(?:\\^?{[^}]+}[ \r\n\t]*\\)*" + ;; namespace + "\\(" clojure--sym-regexp "\\)") + (1 font-lock-type-face nil t)) ;; .foo .barBaz .qux01 .-flibble .-flibbleWobble ("\\<\\.-?[a-z][a-zA-Z0-9]*\\>" 0 'clojure-interop-method-face) ;; Foo Bar$Baz Qux_ World_OpenUDP Foo. Babylon15. ("\\(?:\\<\\|\\.\\|/\\|#?^\\)\\([A-Z][a-zA-Z0-9_]*[a-zA-Z0-9$_]+\\.?\\>\\)" 1 font-lock-type-face) ;; foo.bar.baz ("\\<^?\\([a-z][a-z0-9_-]+\\.\\([a-z][a-z0-9_-]*\\.?\\)+\\)" 1 font-lock-type-face) - ;; (ns namespace) - special handling for single segment namespaces - (,(concat "(\\[ \r\n\t]*" - ;; Possibly metadata - "\\(?:\\^?{[^}]+}[ \r\n\t]*\\)*" - ;; namespace - "\\([a-z0-9-]+\\)") - (1 font-lock-type-face nil t)) ;; fooBar ("\\(?:\\<\\|/\\)\\([a-z]+[A-Z]+[a-zA-Z0-9$]*\\>\\)" 1 'clojure-interop-method-face) ;; #_ and (comment ...) macros. diff --git a/test.clj b/test.clj index 06b519fe..f1e2db1a 100644 --- a/test.clj +++ b/test.clj @@ -1,7 +1,29 @@ ;;; font locking (ns clojure-mode.demo - (:require [clojure.something] - [something.s])) + (:require + [clojure.something] + [something.s] + [oneword] + ;; TODO mixedCase shouldn't be font-locked to clojure-interop-method-face + [mixedCase] + [CamelCase])) + +;; examples of valid namespace definitions +(comment + (ns .validns) + (ns =validns) + (ns .ValidNs=<>?+|?*.) + (ns ValidNs<>?+|?*.b*ar.ba*z) + (ns other.valid.ns) + (ns oneword) + (ns one.X) + (ns foo.bar) + (ns Foo.bar) + (ns Foo.Bar) + (ns foo.Bar) + (ns Foo-bar) + (ns Foo-Bar) + (ns foo-Bar)) (comment ;; for indentation (with-hi heya diff --git a/test/clojure-mode-font-lock-test.el b/test/clojure-mode-font-lock-test.el index 8e5d0bda..50493915 100644 --- a/test/clojure-mode-font-lock-test.el +++ b/test/clojure-mode-font-lock-test.el @@ -162,6 +162,23 @@ POS." (should (eq (clojure-test-face-at 5 14) 'font-lock-type-face)))) (ert-deftest clojure-mode-syntax-table/namespace () + :tags '(fontification syntax-table) + (should (eq (clojure-test-face-at 5 12 "(ns .validns)") 'font-lock-type-face)) + (should (eq (clojure-test-face-at 5 12 "(ns =validns)") 'font-lock-type-face)) + (should (eq (clojure-test-face-at 5 21 "(ns .ValidNs=<>?+|?*.)") 'font-lock-type-face)) + (should (eq (clojure-test-face-at 5 28 "(ns ValidNs<>?+|?*.b*ar.ba*z)") 'font-lock-type-face)) + (should (eq (clojure-test-face-at 5 18 "(ns other.valid.ns)") 'font-lock-type-face)) + (should (eq (clojure-test-face-at 5 11 "(ns oneword)") 'font-lock-type-face)) + (should (eq (clojure-test-face-at 5 11 "(ns foo.bar)") 'font-lock-type-face)) + (should (eq (clojure-test-face-at 5 11 "(ns Foo.bar)") 'font-lock-type-face)) + (should (eq (clojure-test-face-at 5 11 "(ns Foo.Bar)") 'font-lock-type-face)) + (should (eq (clojure-test-face-at 5 11 "(ns foo.Bar)") 'font-lock-type-face)) + (should (eq (clojure-test-face-at 5 11 "(ns Foo-bar)") 'font-lock-type-face)) + (should (eq (clojure-test-face-at 5 11 "(ns Foo-Bar)") 'font-lock-type-face)) + (should (eq (clojure-test-face-at 5 11 "(ns foo-Bar)") 'font-lock-type-face)) + (should (eq (clojure-test-face-at 5 9 "(ns one.X)") 'font-lock-type-face))) + +(ert-deftest clojure-mode-syntax-table/segmented-symbol () :tags '(fontification syntax-table) (should (eq (clojure-test-face-at 1 5 "one.p") 'font-lock-type-face)) (should (eq (clojure-test-face-at 1 11 "one.p.top13") 'font-lock-type-face))