smartparens
smartparens copied to clipboard
C++ template angle brackets not supported <>
So obviously C++ has syntactic ambiguities that means support will be imperfect, but it would be nice to be able to at least highlight a region and press < to enclose it in angle brackets.
For determining if <> should be considered a comparsion, shift, or an opener/closer I think this is a decent heuristic based on common style:
- If there isn't a space on either side, assume it's a template opener, so "a<b" "a <b" and "a< b" have an opener but "a < b" does not. Same for "a<<b" "a<< b" and "a <<b", etc. In modern C++ code usually spaces on both sides indicates a comparison but on one side probably means templates.
- Any instance of multiple space separated "<" or ">" s is a template opener/closer. When space separated it can't be bit shift, and with no non-space characters between it can't be a comparison.
- Every "<" or ">"on a line only containing only instances of that character is an opener/closer. Comparators usually appear on the same line as at least one of their arguments.
Additionally can infer closers/openers based on the following being invalid syntax otherwise (optionally may have spaces between parts):
-
::
-
,
-
;
- <>
- <typename
- <class
- template<
Well, this should all be possible and some code could probably be recycled from the ruby setup.
(Aditionally I'm currently working on a simple parser library that could be used to determine these situations, I plan to integrate it into SP somehow.)
That being said, I'm not going to implement this myself. I don't use C++ and so I would (rather selfishly) concentrate on things that bring benefit to me :)
If you come up with something I'm happy to merge and give you push rights so you can maintain the C++ support.
@jgarvin if you're still interested on working this, I've recently had to solve essentially the same problem in rust-mode. Take a look at smartparens-rust.el and test/smartparens-rust-test.el for examples.