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

Prevent Emacs fontification failure with lots of classes - Fixes #248 #2508

Merged
merged 2 commits into from
Jun 5, 2017

Conversation

defaultxr
Copy link
Contributor

Hi,

These changes should prevent Emacs from failing to fontify class names when lots of classes exist in sclang (i.e. when many quarks are installed). I've elaborated in the commit messages, but the general idea of these changes is this:

  • instead of generating a huge regexp containing every class name in SuperCollider, just use a general class regexp, which is: any word starting with a capital letter. Before SuperCollider is started, all words starting with a capital letter will be highlighted as class names. After SC is started, only words starting with a capital letter that are actually class names will be highlighted.
  • when sclang starts, we generate a list of classes and store it in sclang-class-list so we can refer back to it later during fontification (lines 223-226 in sclang-language.el).
  • when fontification happens after SC is started, we check all words that start with a capital letter. if they're in the sclang-class-list then we know that they're an actual class and we color them as such. if they're not in sclang-class-list then it's not a class, so we don't color it.

I've been using these changes locally on my own machine for about a year now and have not had any problems with them so I figured it was time to submit a pull request so everyone can benefit from them. I've tested these changes myself and have not had any issues. I've made other changes to the elisp but I made sure to only stage the relevant ones to #248. I also included one minor change to line 268 in sclang-mode.el which is to just add a space between the function name and the argument, because that was bothering me.

…ollider#248

What I've done to fix this:

- add a sclang-class-list variable in sclang-language.el, which is a
  list of all the classes known to sclang. this is populated when
  sclang starts.
- update sclang-font-lock-class-keyword-matcher in
  sclang-mode.el. since the sclang-class-name-regexp now will match
  all words that start with a capital letter (see next bullet point
  for that change), this function had to be updated to check to make
  sure that the word starting with a capital letter is in the list of
  classes. if it is, then we know it's a class and it gets
  highlighted. if it's not, then it's just something the user typed
  with a capital letter, so we don't highlight it.
- update sclang-update-font-lock in sclang-mode.el. instead of
  generating a huge regexp from a list of all the classes in
  SuperCollider, just run the normal fontification from that
  function. this avoids making the regexp too big and thus prevents
  fontification from failing.
@vivid-synth
Copy link
Member

I haven't thoroughly read the elisp but the overview of this PR looks like a definite improvement!

@nhthn nhthn added this to the 3.9 milestone Nov 22, 2016
@timblechmann
Copy link
Contributor

i'd recommend to get rid of the regex: when i was still using scel, i often ran into issues that the compiled regex exceeded the maximum size and highlighting classes broke completely. so highlighting symbols starting with capital letters might be the best approach in general (the highlighter in the IDE works similar)

@nhthn
Copy link
Contributor

nhthn commented Dec 2, 2016

@defaultxr Unless you disagree, I think it's best if we incorporate Tim's advice as a requirement for merge.

@defaultxr
Copy link
Contributor Author

I'm not sure I understand - the only regex for classes I have is the one that matches all capitalized words. That regex will never grow long enough to break because it isn't made of the list of class names. The fontification function first tests against the capitalized word regex (which should be relatively fast), and then if it matches and slang has started (and thus we have a list of classes) it checks if the capitalized word is in the list of classes. No regex is ever generated from the class list, so it's not possible for it to break if too many are installed.

I think if we have the list of classes and can highlight ones that actually exist and don't highlight the ones that don't, it provides better feedback to the user since they can see if they've made a spelling mistake or don't have a quark installed, etc. Let me know if I'm misunderstanding anything.

@nhthn
Copy link
Contributor

nhthn commented Dec 3, 2016

Ah ok, I misunderstood the status of this PR. I shouldn't have tried to contribute to discussion without knowing anything about scel or emacs!

@vivid-synth
Copy link
Member

I'm happy to merge this if noone has thoughts!

@mossheim mossheim self-assigned this Jan 14, 2017
@mossheim mossheim removed their assignment Jan 31, 2017
Copy link
Contributor

@mossheim mossheim left a comment

Choose a reason for hiding this comment

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

I think we should merge this! I was looking it over to consider moving to backlog but it seems 100% ready.

@telephon telephon merged commit d3fdb4a into supercollider:master Jun 5, 2017
@mossheim
Copy link
Contributor

mossheim commented Jun 5, 2017

Thanks for the contribution @defaultxr , sorry it took so long to merge!

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.

6 participants