Skip to content
Merged
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
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,14 @@

## master (unreleased)

### New features

* Indent and font-lock forms that start with `let-`, `while-` or `when-` like their counterparts.

### Bugs fixed

* Namespaces can now use the full palette of legal symbol characters.

## 5.0.1 (15/11/2015)

### Bugs fixed
Expand Down
28 changes: 2 additions & 26 deletions clojure-mode.el
Original file line number Diff line number Diff line change
Expand Up @@ -1016,32 +1016,8 @@ nil."
(zero-or-more "^:"
(one-or-more (not (any whitespace)))))
(one-or-more (any whitespace "\n")))
;; why is this here? oh (in-ns 'foo) or (ns+ :user)
(zero-or-one (any ":'"))
(group (one-or-more (not (any "()\"" whitespace))) word-end)))

;; for testing clojure-namespace-name-regex, you can evaluate this code and make
;; sure foo (or whatever the namespace name is) shows up in results. some of
;; these currently fail.
;; (mapcar (lambda (s) (let ((n (string-match clojure-namespace-name-regex s)))
;; (if n (match-string 4 s))))
;; '("(ns foo)"
;; "(ns
;; foo)"
;; "(ns foo.baz)"
;; "(ns ^:bar foo)"
;; "(ns ^:bar ^:baz foo)"
;; "(ns ^{:bar true} foo)"
;; "(ns #^{:bar true} foo)"
;; "(ns #^{:fail {}} foo)"
;; "(ns ^{:fail2 {}} foo.baz)"
;; "(ns ^{} foo)"
;; "(ns ^{:skip-wiki true}
;; aleph.netty
;; "
;; "(ns
;; foo)"
;; "foo"))
(zero-or-one (any ":'")) ;; (in-ns 'foo) or (ns+ :user)
(group (one-or-more (not (any "()\"" whitespace))) symbol-end)))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure how correct our symbol definition is. If memory serves - not very correct. This change definitely requires unit tests illustrating it actually solves something.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Our symbol definition is inherited from elisp so it's at least better than using the word definition. I can't think of any notable differences in clojure's and elisp's notion of what a symbol is.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The problem is that I tried using symbol instead of word semantics when I inherited the mode and everything broke, therefore my reservations... Using symbol semantics is the reasonable thing to do for pretty much everything, but I really think something was fucked up regarding them (don't remember what). I recall lisp-mode's code was full of word references itself, which was odd.

At any rate - a few unit tests won't hurt.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

AFAICT, that regexp should be just (1+ (any symbol word)). But you're the voice of experience here @bbatsov.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That sounds reasonable. But on a general note @expez is right that there should be fewer word checks and symbols checks, as we're talking about symbols here.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes. I agree too.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Btw, most of this word stuff predates me becoming the maintainer of clojure-mode. I always wanted to redo it (and unify the regex syntax used in clojure-mode), but never had the time to do.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

AFAICT, that regexp should be just (1+ (any symbol word)).

Correction, what I wrote is not valid rx. It would have to be (1+ (or (syntax word) (syntax symbol)))




Expand Down
42 changes: 42 additions & 0 deletions test/clojure-mode-util-test.el
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,48 @@
(clojure-expected-ns))
clj-file-ns)))))

(ert-deftest clojure-namespace-name-regex-test ()
:tags '(regexp)
(let ((ns "(ns foo)"))
(should (string-match clojure-namespace-name-regex ns))
(match-string 4 ns))
(let ((ns "(ns
foo)"))
(should (string-match clojure-namespace-name-regex ns))
(should (equal "foo" (match-string 4 ns))))
(let ((ns "(ns foo.baz)"))
(should (string-match clojure-namespace-name-regex ns))
(should (equal "foo.baz" (match-string 4 ns))))
(let ((ns "(ns ^:bar foo)"))
(should (string-match clojure-namespace-name-regex ns))
(should (equal "foo" (match-string 4 ns))))
(let ((ns "(ns ^:bar ^:baz foo)"))
(should (string-match clojure-namespace-name-regex ns))
(should (equal "foo" (match-string 4 ns))))
(let ((ns "(ns ^{:bar true} foo)"))
(should (string-match clojure-namespace-name-regex ns))
(should (equal "foo" (match-string 4 ns))))
(let ((ns "(ns #^{:bar true} foo)"))
(should (string-match clojure-namespace-name-regex ns))
(should (equal "foo" (match-string 4 ns))))
;; TODO
;; (let ((ns "(ns #^{:fail {}} foo)"))
;; (should (string-match clojure-namespace-name-regex ns))
;; (match-string 4 ns))
;; (let ((ns "(ns ^{:fail2 {}} foo.baz)"))
;; (should (string-match clojure-namespace-name-regex ns))
;; (should (equal "foo.baz" (match-string 4 ns))))
(let ((ns "(ns ^{} foo)"))
(should (string-match clojure-namespace-name-regex ns))
(should (equal "foo" (match-string 4 ns))))
(let ((ns "(ns ^{:skip-wiki true}
aleph.netty"))
(should (string-match clojure-namespace-name-regex ns))
(should (equal "aleph.netty" (match-string 4 ns))))
(let ((ns "(ns foo+)"))
(should (string-match clojure-namespace-name-regex ns))
(should (equal "foo+" (match-string 4 ns)))))

(provide 'clojure-mode-util-test)

;; Local Variables:
Expand Down