-
-
Notifications
You must be signed in to change notification settings - Fork 247
Font locking (syntax highlighting) doesn't work with keywords starting with a number #581
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
Comments
Probably the regexp for font-locking keywords needs to be tweaked. |
I don't think this is a bug, such keywords are not syntactically correct even though the reader currently accepts them. https://stackoverflow.com/a/39193032 |
Yeah, that's technically true, but on the other hand I also know this is never going to be fixed, as it will break backwards compatibility. That's why probably it makes sense to acknowlege this weird case as valid. |
Maybe the bug is in the clojuredocs.org description as the official doc doesn't mention this constraint Keywords are symbolic tokens that express a concept/value by themselves like: I know that there are other ways to express such values, but the point is that the language should allow you to express it like this is you wish so. The same consideration could be valid for the symbols themselves. The only reason why symbols have to start with a non-numerical character is to avoid ambiguity with the various numerical qualifiers, such as: I had a look at the source, and the keyword pattern reuses the definition of the symbol, which makes the fix slightly more complicated. |
This happens because Line 977 in ad322e9
It can be fixed by introducing a separate regexp specifically for Clojure keyword symbol Lines 779 to 782 in ad322e9
Matches the rule `clojure--sym-forbidden-1st-chars' followed by
+any number of matches of `clojure--sym-forbidden-rest-chars'.")
+ (defconst clojure--keyword-sym-forbidden-1st-chars
+ (concat clojure--sym-forbidden-rest-chars ":'")
+ "A list of chars that a Clojure keyword symbol cannot start with.")
+ (defconst clojure--keyword-sym-regexp
+ (concat "[^" clojure--keyword-sym-forbidden-1st-chars "]"
+ "[^" clojure--sym-forbidden-rest-chars "]*")
+ "A regexp matching a Clojure keyword name or keyword namespace.
+Matches the rule `clojure--keyword-sym-forbidden-1st-chars' followed by
any number of matches of `clojure--sym-forbidden-rest-chars'.")) I tried to copy the way the symbol regexp is written (save the formatting), though it looks a little too verbose to me. If it looks okay, I'll send a PR |
Looks reasonable to me. |
Expected behavior
The following are both valid keywords, however, the font locking doesn't work on the second one
Actual behavior
Keywords starting with a number are not colorised as keywords
Steps to reproduce the problem
see example above
Environment & Version information
clojure-mode version
Include here the version string displayed by
M-x clojure-mode-display-version
. Here's an example:Emacs version
GNU Emacs 27.1
Operating system
Mac OS 11.1
The text was updated successfully, but these errors were encountered: