Skip to content

Fix namespace font locking #461

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 4 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
14 changes: 7 additions & 7 deletions clojure-mode.el
Original file line number Diff line number Diff line change
Expand Up @@ -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 "(\\<ns\\>[ \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 "(\\<ns\\>[ \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.
Expand Down
26 changes: 24 additions & 2 deletions test.clj
Original file line number Diff line number Diff line change
@@ -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
Expand Down
17 changes: 17 additions & 0 deletions test/clojure-mode-font-lock-test.el
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down