Skip to content

Match angle brackets syntactically #79

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 4 commits into from
Jul 6, 2015

Conversation

MicahChalmer
Copy link
Contributor

Remove the angle bracket blinking feature, and make it actually match < and > characters as parens in the syntax table instead. This matching is suppressed as needed, so that less-than and greater-than operators, arrow operators, etc don't throw off the matches.

This has the following effects:

Macros have arbitrary syntax and therefore it's not possible to know whether a < or > character is an angle bracket or not. So the matching is always suppressed inside macro definitions and uses.

There are a few disadvantages: besides the fact that the code is rather hairy, it also has to detect the non-angle-brackets perfectly, or else it throws off the indentation for the whole rest of the file. For that reason there is still a custom variable available to disable it (though with a different name than the previous one.)

Having said that, I don't know of any cases where it gets it wrong. I tested it with this program, which compares what emacs thinks are the non-bracket </> characters with what the rust compiler thinks. It passed for all of the rust compiler code base, as well as all the rust code in servo and as many of servo's dependencies as still compile with the latest nightly.

Also included are some bug fixes for some edge case issues in the handling of raw strings and character literals. I found these while running the test script. Even if the angle bracket matching itself is deemed to be too risky or hairy to be merged (and I would understand it if that turns out to be the case), you may want to merge the other commits for the bug fixes. I've put them first to make this easy.

If this PR is accepted, close #66 (because the variable that it renames has been removed entirely) and close #74 (because post-self-insert-hook is no longer used at all.) Both of these pertain to the old angle bracket blinking code that this PR removes entirely.

And if the PR is not accepted - hey, I still had fun writing it.

@rust-highfive
Copy link

r? @pnkfelix

(rust_highfive has picked a reviewer for you, use r? to override)

@pnkfelix
Copy link
Member

pnkfelix commented Jul 5, 2015

I think I do want to accept this. At the very least, I've noticed that the current bracket-blinking code totally messes up multiple-cursors mode.

cc @nikomatsakis any thoughts here?

Factor out the method of looking for a match for a regexp, but filtering
out some of the matches with a filtering function.  This will be used
again for angle bracket filtering.

This also fixes an issue with raw string handling.
Add angle brackets to the list of emacs matching characters.  Use
syntactic fontification to suppress this where it is not appropriate (in
less than operators, arrows, etc.)  Remove the non-syntactic version
that was there previously.

For electric-pair-mode, suppress the pairing for < and > characters that
are not angle brackets.

Because syntax is used for indentation, this fixes some problems with
it, particularly when attempting to stretch type parameter lists over
multiple lines.
@MicahChalmer MicahChalmer force-pushed the angle-bracket-madness branch from 2fd4641 to 07943f0 Compare July 6, 2015 01:39
@MicahChalmer
Copy link
Contributor Author

Thanks @pnkfelix.

I just rebased after the latest other commits to master. (Nothing else was changed.)

@nikomatsakis
Copy link
Contributor

I have no objections -- it sounds strictly better than the hack I did. I don't quite understand how it works (but I haven't tried reading it).

nikomatsakis added a commit that referenced this pull request Jul 6, 2015
@nikomatsakis nikomatsakis merged commit c9c7871 into rust-lang:master Jul 6, 2015
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.

Angle bracket matching doesn't handle -> Adding a line break after a Trait in a template argument list breaks emacs-mode indentation
4 participants