From 87c70a0657ced2323aa768ae17037d10ec9f2d52 Mon Sep 17 00:00:00 2001 From: Rostislav Svoboda Date: Mon, 2 Oct 2017 16:03:28 +0200 Subject: [PATCH 1/4] Namespace definition examples --- test.clj | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/test.clj b/test.clj index 06b519fe..a8c8a97f 100644 --- a/test.clj +++ b/test.clj @@ -1,7 +1,22 @@ ;;; 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 foo.bar)) (comment ;; for indentation (with-hi heya From 7680ba0ca73446719d03ad51898604a8e9bab444 Mon Sep 17 00:00:00 2001 From: Rostislav Svoboda Date: Tue, 17 Oct 2017 17:28:40 +0200 Subject: [PATCH 2/4] Fix namespace font-locking --- CHANGELOG.md | 1 + clojure-mode.el | 14 +++++++------- 2 files changed, 8 insertions(+), 7 deletions(-) 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. From 81a090e89051150a6c0f8e267c15e2f18d4b9877 Mon Sep 17 00:00:00 2001 From: Rostislav Svoboda Date: Mon, 6 Nov 2017 15:39:42 +0100 Subject: [PATCH 3/4] Fix: symbols containing '.' aren't necessarily namespaces --- test/clojure-mode-font-lock-test.el | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/clojure-mode-font-lock-test.el b/test/clojure-mode-font-lock-test.el index 8e5d0bda..0334ec0b 100644 --- a/test/clojure-mode-font-lock-test.el +++ b/test/clojure-mode-font-lock-test.el @@ -161,7 +161,7 @@ POS." (should (eq (clojure-test-face-at 2 3) 'font-lock-type-face)) (should (eq (clojure-test-face-at 5 14) 'font-lock-type-face)))) -(ert-deftest clojure-mode-syntax-table/namespace () +(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)) From 0178d419e517bd7bb4f30177192422ec4b3d6b66 Mon Sep 17 00:00:00 2001 From: Rostislav Svoboda Date: Mon, 6 Nov 2017 15:41:14 +0100 Subject: [PATCH 4/4] Namespace definition examples with unit tests --- test.clj | 9 ++++++++- test/clojure-mode-font-lock-test.el | 17 +++++++++++++++++ 2 files changed, 25 insertions(+), 1 deletion(-) diff --git a/test.clj b/test.clj index a8c8a97f..f1e2db1a 100644 --- a/test.clj +++ b/test.clj @@ -16,7 +16,14 @@ (ns ValidNs<>?+|?*.b*ar.ba*z) (ns other.valid.ns) (ns oneword) - (ns foo.bar)) + (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 0334ec0b..50493915 100644 --- a/test/clojure-mode-font-lock-test.el +++ b/test/clojure-mode-font-lock-test.el @@ -161,6 +161,23 @@ POS." (should (eq (clojure-test-face-at 2 3) 'font-lock-type-face)) (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))