Skip to content

No special font-locking for mixedCase, CamelCase #462

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

Merged
merged 2 commits into from
Mar 13, 2018
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
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,9 @@
* [#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`.
* Stop distinctive font-locking of java interop methods & constants: There is no semantic distinction between interop methods, constants and global vars in clojure.
* Fix namespace font-locking: namespaces may also contain non alphanumeric chars.


## 5.6.1 (2016-12-21)

Expand Down
59 changes: 35 additions & 24 deletions clojure-mode.el
Original file line number Diff line number Diff line change
Expand Up @@ -92,11 +92,6 @@
"Face used to font-lock Clojure character literals."
:package-version '(clojure-mode . "3.0.0"))

(defface clojure-interop-method-face
'((t (:inherit font-lock-preprocessor-face)))
"Face used to font-lock interop method names (camelCase)."
:package-version '(clojure-mode . "3.0.0"))

(defcustom clojure-indent-style :always-align
"Indentation style to use for function forms and macro forms.
There are two cases of interest configured by this variable.
Expand Down Expand Up @@ -848,29 +843,45 @@ any number of matches of `clojure--sym-forbidden-rest-chars'."))
0 font-lock-constant-face)
;; Character literals - \1, \a, \newline, \u0000
("\\\\\\([[:punct:]]\\|[a-z0-9]+\\>\\)" 0 'clojure-character-face)
;; foo/ Foo/ @Foo/ /FooBar
(,(concat "\\(?:\\<:?\\|\\.\\)@?\\(" clojure--sym-regexp "\\)\\(/\\)")
(1 font-lock-type-face) (2 'default))
;; Constant values (keywords), including as metadata e.g. ^:static
("\\<^?\\(:\\(\\sw\\|\\s_\\)+\\(\\>\\|\\_>\\)\\)" 1 'clojure-keyword-face append)
;; Java interop highlighting
;; CONST SOME_CONST (optionally prefixed by /)
("\\(?:\\<\\|/\\)\\([A-Z]+\\|\\([A-Z]+_[A-Z1-9_]+\\)\\)\\>" 1 font-lock-constant-face)
Copy link
Member

Choose a reason for hiding this comment

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

And I guess no special font-locking for SCREAMING_UPPER_CASE.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Right, no special font-locking for SCREAMING_UPPER_CASE at the moment. But feel free to change or propose something else.

Copy link
Member

Choose a reason for hiding this comment

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

I'm just mentioning it. I don't feel strongly about this.

;; .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

;; namespace definitions: (ns foo.bar)
(,(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)
"\\(" clojure--sym-regexp "\\)")
(1 font-lock-type-face))

;; TODO dedupe the code for matching of keywords, type-hints and unmatched symbols

;; keywords: {:oneword/veryCom|pLex.stu-ff 0}
(,(concat "\\(:\\)\\(" clojure--sym-regexp "\\)\\(/\\)\\(" clojure--sym-regexp "\\)")
(1 'clojure-keyword-face)
(2 font-lock-type-face)
(3 'default)
(4 'clojure-keyword-face))
(,(concat "\\(:\\)\\(" clojure--sym-regexp "\\)")
(1 'clojure-keyword-face)
(2 'clojure-keyword-face))

;; type-hints: #^oneword
(,(concat "\\(#^\\)\\(" clojure--sym-regexp "\\)\\(/\\)\\(" clojure--sym-regexp "\\)")
(1 'default)
(2 font-lock-type-face)
(3 'default)
(4 'default))
(,(concat "\\(#^\\)\\(" clojure--sym-regexp "\\)")
(1 'default)
(2 font-lock-type-face))

;; clojure symbols not matched by the previous regexps
(,(concat "\\(" clojure--sym-regexp "\\)\\(/\\)\\(" clojure--sym-regexp "\\)")
(1 font-lock-type-face)
(2 'default)
(3 'default))
(,(concat "\\(" clojure--sym-regexp "\\)")
(1 'default))

;; #_ and (comment ...) macros.
(clojure--search-comment-macro 1 font-lock-comment-face t)
;; Highlight `code` marks, just like `elisp'.
Expand Down
174 changes: 167 additions & 7 deletions test.clj
Original file line number Diff line number Diff line change
@@ -1,9 +1,43 @@
;;; font locking
(ns clojure-mode.demo
(:require [clojure.something]
[something.s]))
(:require
[oneword]
[seg.mnt]
[mxdCase]
[CmlCase]
[veryCom|pLex.stu-ff]))

(defn foo [x] x)
;; try to byte-recompile the clojure-mode.el when the face of 'fn' is 't'
(fn foo [x] x)

#_
;; the myfn sexp should have a comment face
(mysfn 101
foo

0 0i)

;; 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
'some/symbol

(with-hi heya
somebuddy)

Expand All @@ -19,11 +53,137 @@
;; character literals
[\a \newline \u0032 \/ \+ \,, \;]

;; namespaced/static calls/references
(core.foo-baz/bar)
@foo-bar/bar
(FooBar/bar)
(some.package.FooBar/baz)
;; TODO change font-face for sexps starting with @,#
(comment ;; examples

SCREAMING_UPPER_CASE
veryCom|pLex.stu-ff/.SCREAMING_UPPER_CASE

oneword
@oneword
#oneword
#^oneword ;; type-hint
.oneword
(oneword)
(oneword/oneword)
(oneword/seg.mnt)
(oneword/CmlCase)
(oneword/mxdCase)
(oneword/veryCom|pLex.stu-ff)
(oneword/.veryCom|pLex.stu-ff)

seg.mnt
@seg.mnt
#seg.mnt
#^seg.mnt ;; type-hint
.seg.mnt
(seg.mnt)
(seg.mnt/oneword)
(seg.mnt/seg.mnt)
(seg.mnt/CmlCase)
(seg.mnt/mxdCase)
(seg.mnt/veryCom|pLex.stu-ff)
(seg.mnt/.veryCom|pLex.stu-ff)

CmlCase
@CmlCase
#CmlCase
#^CmlCase ;; type-hint
.CmlCase
(CmlCase)
(CmlCase/oneword)
(CmlCase/seg.mnt)
(CmlCase/CmlCase)
(CmlCase/mxdCase)
(CmlCase/veryCom|pLex.stu-ff)
(CmlCase/.veryCom|pLex.stu-ff)

mxdCase
@mxdCase
#mxdCase
#^mxdCase ;; type-hint
.mxdCase
(mxdCase)
(mxdCase/oneword)
(mxdCase/seg.mnt)
(mxdCase/CmlCase)
(mxdCase/mxdCase)
(mxdCase/veryCom|pLex.stu-ff)
(mxdCase/.veryCom|pLex.stu-ff)

veryCom|pLex.stu-ff
@veryCom|pLex.stu-ff
#veryCom|pLex.stu-ff
#^veryCom|pLex.stu-ff ;; type-hint
.veryCom|pLex.stu-ff
(veryCom|pLex.stu-ff)
(veryCom|pLex.stu-ff/oneword)
(veryCom|pLex.stu-ff/seg.mnt)
(veryCom|pLex.stu-ff/CmlCase)
(veryCom|pLex.stu-ff/mxdCase)
(veryCom|pLex.stu-ff/veryCom|pLex.stu-ff)
(veryCom|pLex.stu-ff/.veryCom|pLex.stu-ff)

:oneword
{:oneword 0}
;; {:@oneword 0} ; not allowed
{:#oneword 0}
{:.oneword 0}
{:oneword/oneword 0}
{:oneword/seg.mnt 0}
{:oneword/CmlCase 0}
{:oneword/mxdCase 0}
{:oneword/veryCom|pLex.stu-ff 0}
{:oneword/.veryCom|pLex.stu-ff 0}

{:seg.mnt 0}
;; {:@seg.mnt 0} ; not allowed
{:#seg.mnt 0}
{:.seg.mnt 0}
{:seg.mnt/oneword 0}
{:seg.mnt/seg.mnt 0}
{:seg.mnt/CmlCase 0}
{:seg.mnt/mxdCase 0}
{:seg.mnt/veryCom|pLex.stu-ff 0}
{:seg.mnt/.veryCom|pLex.stu-ff 0}

:CmlCase
{:CmlCase 0}
;; {:@CmlCase 0} ; not allowed
{:#CmlCase 0}
{:.CmlCase 0}
{:CmlCase/oneword 0}
{:CmlCase/seg.mnt 0}
{:CmlCase/CmlCase 0}
{:CmlCase/mxdCase 0}
{:CmlCase/veryCom|pLex.stu-ff 0}
{:CmlCase/.veryCom|pLex.stu-ff 0}

:mxdCase
{:mxdCase 0}
;; {:@mxdCase 0} ; not allowed
{:#mxdCase 0}
{:.mxdCase 0}
{:mxdCase/oneword 0}
{:mxdCase/seg.mnt 0}
{:mxdCase/CmlCase 0}
{:mxdCase/mxdCase 0}
{:mxdCase/veryCom|pLex.stu-ff 0}
{:mxdCase/.veryCom|pLex.stu-ff 0}

:veryCom|pLex.stu-ff
{:veryCom|pLex.stu-ff 0}
;; {:@veryCom|pLex.stu-ff 0} ; not allowed
{:#veryCom|pLex.stu-ff 0}
{:.veryCom|pLex.stu-ff 0}
{:veryCom|pLex.stu-ff 0}
{:veryCom|pLex.stu-ff/oneword 0}
{:veryCom|pLex.stu-ff/seg.mnt 0}
{:veryCom|pLex.stu-ff/CmlCase 0}
{:veryCom|pLex.stu-ff/mxdCase 0}
{:veryCom|pLex.stu-ff/veryCom|pLex.stu-ff 0}
{:veryCom|pLex.stu-ff/.veryCom|pLex.stu-ff 0}
)

;; metadata doesn't break docstrings
(defn max
Expand Down
Loading