clojure-mode icon indicating copy to clipboard operation
clojure-mode copied to clipboard

Symbols with ' in them are not font-locked correctly

Open oskarkv opened this issue 7 years ago • 7 comments

A symbol with ' in it should be font-locked so that the whole symbol has the same color. I'm no expert on font-locking, nor on clojure-mode, but I quickly browsed the code, and this seems wrong: (defconst clojure--sym-forbidden-rest-chars "][\";\'@\\^`~\(\)\{\}\\,\s\t\n\r" since https://clojure.org/reference/reader says that ' is allowed in a symbol. I tried to change that but it didn't solve the problem below.

Steps to reproduce the problem

Type (defn test'fn []) in clojure-mode and note the colors.

Expected behavior

All characters of test'fn should be of the same color.

Actual behavior

The characters after and including ' are not of the expected color (they are white, my default text color).

clojure-mode version information

5.7.0-snapshot

oskarkv avatar Jun 07 '17 22:06 oskarkv

I think the ' character is defined as a prefix character in the syntax table, so it goes beyond just font locking. So fixing it would probably take quite a bit of work, and there would probably be other broken behaviours (like forward-sexp or Isearch-symbol).

Malabarba avatar Jun 08 '17 00:06 Malabarba

Wow that's surprising and odd at the same time.

arichiardi avatar Jun 14 '17 03:06 arichiardi

Basically the problem stems for quoting symbols 'symbol. It's rather hard to support this and allow quotes to appear anywhere in the symbol's name. I think allowing this was a major mistake in Clojure. Funny enough - officially this is not a valid symbol name, but it works and people use it. :-)

bbatsov avatar Jun 14 '17 06:06 bbatsov

officially this is not a valid symbol name

This has changed, it has been blessed now. Reader docs

expez avatar Jun 14 '17 07:06 expez

I think there is no harm in allowing ' to be a symbol for font-lock purpose. #290 is essentially un-fixable given current syntax table toolset in emacs, but this particular issue is easy.

Of course one would end up being surprised to see the doc completion for test when point is on test'fn but, well, at least it's highlighted properly.

vspinu avatar Aug 11 '17 22:08 vspinu

@vspinu Yeah, you make a good point. Maybe we should just fix the font-locking. After all it's just tweaking a regular expression.

bbatsov avatar Oct 31 '17 08:10 bbatsov

autogenerated with https://github.com/MalloZup/doghub: issue inactive since 450 days. Please update the issue or close it

MalloZup avatar Aug 05 '19 21:08 MalloZup