Skip to content
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

Symbols with colon in the middle get wrong syntax highlighting #653

Closed
daveliepmann opened this issue Jul 7, 2023 · 1 comment · Fixed by #670
Closed

Symbols with colon in the middle get wrong syntax highlighting #653

daveliepmann opened this issue Jul 7, 2023 · 1 comment · Fixed by #670

Comments

@daveliepmann
Copy link
Contributor

Symbols with colons in the middle (like a:b) get separate font faces before and after the colon.

Expected behavior

Symbols or bindings with a single colon : not at beginning or end should be recognized as a single symbol unit for the purpose of syntax highlighting. Specifically, it seems they should get font-lock-variable-name-face.

Per the Clojure reader reference docs for symbols:

Symbols beginning or ending with ':' are reserved by Clojure. A symbol can contain one or more non-repeating ':'s.

Actual behavior

A symbol with a colon (not at beginning or end) in the name-defining position gets the correct font-face (apparently font-lock-variable-name-face), but other instances get default for the pre-colon portion and clojure-keyword-face thereafter.

This makes every usage of the symbol or binding to get styled like a half-keyword, half-symbol.

Screenshot 2023-07-07 at 01 44 43

Steps to reproduce the problem

(ns repl.clojure-mode-font-bug-colon)

(let [foo:bar 1]
  foo:bar)

(def baz:qux 2)

baz:qux

(defn qqq:zzz [] 5)

qqq:zzz

Environment & Version information

clojure-mode version

clojure-mode (version nil)

However, jumping to a clojure font-face definition gives me clojure-mode-20230626.715. (The clojure-mode invocation was broken in my previous spring 2022 version, too. I installed with package-list-packages from melpa.)

Emacs version

GNU Emacs 28.2 (build 1, aarch64-apple-darwin22.1.0, Carbon Version 169 AppKit 2299) of 2022-12-10

Operating system

macOS Ventura 13.4

@daveliepmann
Copy link
Contributor Author

daveliepmann commented Aug 28, 2023

the issue seems to be this snippet in clojure-font-lock-keywords:

(,(concat "\\(:\\{1,2\\}\\)\\(" clojure--keyword-sym-regexp "\\)")
       (1 'clojure-keyword-face)
       (2 'clojure-keyword-face))

https://github.com/clojure-emacs/clojure-mode/blob/master/clojure-mode.el#L1065

daveliepmann added a commit to daveliepmann/clojure-mode that referenced this issue Nov 21, 2023
Changes syntax highlighting regexp for keywords to match a colon/double-colon
only at the beginning of a word, not in the middle. This allows local vars like
`foo:bar` to be highlighted correctly instead of like an unknown symbol for the
part before the colon and a keyword for the rest.

Fixes clojure-emacs#653
@vemv vemv closed this as completed in #670 Nov 24, 2023
vemv pushed a commit that referenced this issue Nov 24, 2023
Changes syntax highlighting regexp for keywords to match a colon/double-colon
only at the beginning of a word, not in the middle. This allows local vars like
`foo:bar` to be highlighted correctly instead of like an unknown symbol for the
part before the colon and a keyword for the rest.

Fixes #653
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants