Skip to content

Namespace font-locking according to clojure.lang.LispReader #353

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
Dec 7, 2015
Merged

Namespace font-locking according to clojure.lang.LispReader #353

merged 2 commits into from
Dec 7, 2015

Conversation

Bost
Copy link
Contributor

@Bost Bost commented Dec 2, 2015

Fix namespace alias font-locking for aliases containing non-letter
charactes like $, 0-9, _, etc.

@@ -352,6 +352,13 @@ Called by `imenu--generic-function'."
(set-match-data (list def-beg def-end)))))
(goto-char start)))))

(eval-when-compile
;; See clojure.lang.LispReader definition and getMacro invocation(s)
Copy link
Member

Choose a reason for hiding this comment

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

Could you add a url link to the LispReader source here?

Copy link
Member

Choose a reason for hiding this comment

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

If we're going to link I think we should link to a line in a specific revision, e.g. the tag for clojure 1.7. If just put a link to a line number in a file on master we might get in a situation where there's something else on that line or that the file itself has been moved/deleted.

@Bost
Copy link
Contributor Author

Bost commented Dec 3, 2015

Please see my improvements in cb62888.

(defconst clojure-sym-1st-chars (concat clojure-sym-rest-chars "0-9")
"A black list of chars a clojure symbol must not start with. See
getMacro invocation:
https://github.com/clojure/clojure/blob/master/src/jvm/clojure/lang/LispReader.java#L260
Copy link
Member

Choose a reason for hiding this comment

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

This links to a function invocation, at least to me this line:

IFn macroFn = getMacro(ch);

doesn't shed much light on anything discussed in this PR.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Well, basically I took a look at the for-loop https://github.com/clojure/clojure/blob/master/src/jvm/clojure/lang/LispReader.java#L232 consuming the input string in order to see which chars can be a part of a clojure symbol and which chars delimit string boundaries, lists, vectors, special forms etc. From this point of view the line 260 (together with line 254) is the key point of the for-loop.

@Bost
Copy link
Contributor Author

Bost commented Dec 3, 2015

@expez your note about linking to a specific clojure version (1.7) was right. I'm gonna fix that too.

Bost added 2 commits December 3, 2015 18:18
Fix namespace alias font-locking for aliases containing non-letter
charactes like $, 0-9, _, etc.
@Bost
Copy link
Contributor Author

Bost commented Dec 3, 2015

I amended the cb62888 to fc5e092. Please review it.

@Malabarba
Copy link
Member

Looks good to me.

Malabarba added a commit that referenced this pull request Dec 7, 2015
Namespace font-locking according to clojure.lang.LispReader
@Malabarba Malabarba merged commit 2670ae1 into clojure-emacs:master Dec 7, 2015
@Malabarba
Copy link
Member

Merged. Thanks again!

@Bost Bost deleted the font-locking branch December 8, 2015 01:50
@bbatsov
Copy link
Member

bbatsov commented Dec 8, 2015

Just for the protocol - the second commit had a commit message, that doesn't match our standards and should have been simply squashed into the first one. Anyways, didn't have time to take a look at this until just now.

@bbatsov
Copy link
Member

bbatsov commented Dec 8, 2015

And a bit more feedback - I strongly prefer the usage of whitelists over blacklists as they tend to leave less probability for mistakes. The naming of the 3 constants is not exactly ideal either - one would hardly imagine those are blacklists.

@Malabarba
Copy link
Member

Sorry. The thing with the commits escaped me indeed.
I merged with the intention of fixing some formatting anyway, so I'll make your changes too.

@bbatsov
Copy link
Member

bbatsov commented Dec 8, 2015

Sounds good.

@Malabarba
Copy link
Member

I strongly prefer the usage of whitelists over blacklists as they tend to leave less probability for mistakes

Agreed, but in this case a whitelist is rather impractical. Clojure symbols are like elisp symbols in the sense that almost anything is a valid symbol char (e.g., (def ação😇✈ 10)). So it's easier to define the exclusions than the inclusions (even if we do miss a couple, as we did :).

@bbatsov
Copy link
Member

bbatsov commented Dec 8, 2015

Fair enough.

@Bost
Copy link
Contributor Author

Bost commented Dec 8, 2015

whitelist is rather impractical.

Yes I noticed that white vs. black list dissent too. Here I made a conscious decision "correctness before practicality". If authors of clojure.lang.LispReader decided for blacklist, so be it! I should follow their decision. An Emacs plugin is not the right place to question it.
Besides, if the attempts to write a whitelist regexps failed, then one should not repeat the same mistakes again and should write them the same way as they come over from the model (= LispReader).

The naming of the 3 constants is not exactly ideal either - one would hardly imagine those are blacklists.

???
I wrote "... blacklist... " to the docstrings! Moreover it's just an implementation detail if a regexp is a type-of blacklist or a type-of whitelist. A regexp matches or not a pattern in a string. How it is done should be abstracted away.
I see Artur already added "forbidden" to the names of the constants in questions. Uhm, I have a feeling a type-information leaks into the variable names. Don't you think we're complecting things here?
Except that:

  1. I agree the variable names are not well chosen. I'm getting the impression I could better describe what they are good for.
  2. Where can I find the commit message standards? (Sorry I missed them somehow.)

@Bost
Copy link
Contributor Author

Bost commented Dec 8, 2015

@Malabarba thanx for the "Add whitespace to clojure--sym-forbidden-rest-chars" commit. That was a mistake! I realized that only a day ago.

@bbatsov
Copy link
Member

bbatsov commented Dec 8, 2015

I'm quite fine with the naming changes Artur made. Variable names should convey meaning and the original names conveyed less meaning.

  1. Where can I find the commit message standards? (Sorry I missed them somehow.)

CONTRIBUTING.md

@Malabarba
Copy link
Member

Moreover it's just an implementation detail if a regexp is a type-of blacklist or a type-of whitelist. A regexp matches or not a pattern in a string. How it is done should be abstracted away.

Except the first two variables are not regexps (they lack the surrounding []). Technically they weren't blacklists either (they started with a ^ for use in a regexp).
I've changed the variables to be actual blacklists now, and that's why I changed the name to include the word forbidden.

Anyway, let's not bikeshed this too much. I believe we are all happy with the current state, right?

@Bost
Copy link
Contributor Author

Bost commented Dec 8, 2015

we are all happy with the current state

Yea. Sort of. Either way I started to work more on this regexp thing. I hope I'll sent you a PR withing next 2 or 3 weeks.

@Bost
Copy link
Contributor Author

Bost commented Dec 8, 2015

Technically they weren't blacklists either (they started with a ^ for use in a regexp).

That's a nit-picky remark... or(!) a fine demonstration of a sharp, bug-catching eye. I like that! I'll incorporate that in my PR. Thx Artur.

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

Successfully merging this pull request may close these issues.

4 participants