Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Syntax highlight comment reader macro as a comment #15

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
axvr merged 2 commits into master from comment-reader-macro
Mar 7, 2021

Conversation

Copy link
Member

@axvr axvr commented Mar 4, 2021
edited
Loading

Before After
image image

@axvr axvr changed the title (削除) Syntax highlight use of the comment reader macro as comments (削除ここまで) (追記) Syntax highlight comment reader macro as a comment (追記ここまで) Mar 4, 2021
@axvr axvr merged commit 2382c8b into master Mar 7, 2021
@axvr axvr deleted the comment-reader-macro branch March 7, 2021 13:22
Copy link
Member

Deraen commented Mar 9, 2021
edited
Loading

Did you compare if this affects the performance?

Quickly comparing one file with and without this, the syntax time doesn't seem to be affected, but this added lots of additional checks. Probably the regex checks are fast anyway as it will just stop when the string doesn't start with #_. Maybe check count increases a lot as this has 5 different regexes checking for #_ and the different parenthesis, so it has to do a bit of duplicated work to check for #_ again for each case.

Also, this doesn't support case with multiple #_ combined to ignore map key value pairs, like #_#_:foo "bar". Probably unfeasible to support that using regexes.

Copy link
Member Author

axvr commented Mar 9, 2021
edited
Loading

I did test it but didn't add the results here, I'll make sure to do that next time.

When #_ is used, this PR improved performance as it can stop processing the commented region upon a #_ match. When #_ isn't used there is negligible performance difference.

With #_ usages

Test file: https://gist.github.com/axvr/9bb2665336bb3ec351d5b11d55b1555e#file-with_usage_test-clj

Before (s) After (s)
0.056664 0.042818

Without #_ usages

Test file: https://gist.github.com/axvr/9bb2665336bb3ec351d5b11d55b1555e#file-without_usage_test-clj

Before (s) After (s)
0.054265 0.055136

I intentionally didn't try to implement stacking #_#_:foo "bar" for the reason you mentioned, that would be almost impossible to do that with regular expressions.

Deraen reacted with thumbs up emoji

Copy link
Member

Deraen commented Mar 9, 2021
edited
Loading

One side effect of changing the style for code forms after #_ is that it breaks the indentation. Indentation uses the syntax rules to find forms etc.

 (defn foo [bar]
 #_
 (let [a 1]
 (+ 1
 2
 3)))
;; =>
(defn foo [bar]
 #_
 (let [a 1]
 (+ 1
 2
 3)))

Another is that motions that deal with elements, like ae used to work inside commented out forms. Maybe also cpp or such commands from fireplace or others? Like (+ ...) in the example, now these select the whole commented out form.

Do you know if we could still parse the commented out forms like previously, but only change the color?

axvr reacted with thumbs up emoji

Copy link
Member Author

axvr commented Mar 9, 2021
edited
Loading

One side effect of changing the style for code forms after #_ is that it breaks the indentation. Indentation uses the syntax rules to find forms etc.

I've pushed a small fix for this.

Another is that motions that deal with elements, like ae used to work inside commented out forms. Maybe also cpp or such commands from fireplace or others? Like (+ ...) in the example, now these select the whole commented out form.

Would you mind trying them again with the patch I just pushed? If they still don't work I might make the highlighting of this optional (disabled by default) or even revert the change entirely until I find a way to make this work without breaking keybindings.

Do you know if we could still parse the commented out forms like previously, but only change the color?

As far as I know, this isn't possible using the syntax file, but "text properties" might be able to.

Copy link
Member

Deraen commented Mar 9, 2021

Indent works now.

Text objects (confused with motions in previous comment) still don't work.

Copy link
Member

Deraen commented Mar 9, 2021

For context:
https://github.com/guns/vim-sexp/blob/master/plugin/sexp.vim#L269
https://github.com/guns/vim-sexp/blob/master/autoload/sexp.vim#L1434

There are some notes about "contained" syntax rules also here:
https://github.com/guns/vim-sexp/blob/master/autoload/sexp.vim#L458-L474

Looking at clojureCommentReaderMacroForm, it is still parsing every form inside the comment, as that is needed anyway to count the parenthesis to find the end of macro form. There is just some small difference in this syntax rule compared to others.

axvr reacted with thumbs up emoji

Copy link
Member Author

axvr commented Mar 9, 2021

I've found the source of the problem. Vim-sexp will ignore syntax regions containing "comment". The way to fix this is to rename clojureCommentReaderMacro and clojureCommentReaderMacroForm to not contain the word "comment".

Now I'm not sure whether I should:

  1. rename it,
  2. make it optional, or
  3. remove the feature entirely.

The fact that it isn't possible to correctly syntax highlight stacked #_s is making me lean more towards removing this change.

axvr added a commit that referenced this pull request Mar 9, 2021
This commit intentionally misspells "clojureCommentReaderMacro" so that
Vim-sexp will treat it as if it weren't a comment.
See: <#15>
Copy link
Member Author

axvr commented Mar 9, 2021

I've pushed a commit to rename it for now although I'm still considering making it optional or removing it.

Copy link
Member

Deraen commented Mar 9, 2021
edited
Loading

I thought I tested that myself, but yeah, works now. Strange that they check for partial matches of syntax names, but maybe that is a feature.

Not quite sure yet what's best solution here. I'm used to #_ not affecting syntax coloring, but it would also be nice to have. Though would be indeed even better if we could support stacked macros.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Reviewers
No reviews
Assignees
No one assigned
Labels
highlighting Affects syntax highlighting
Projects
None yet
Milestone
No milestone
Development

Successfully merging this pull request may close these issues.

2 participants

AltStyle によって変換されたページ (->オリジナル) /