-
Notifications
You must be signed in to change notification settings - Fork 253
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
Syntax highlighting #677
Comments
There are I think possibly two problems:
In short, I think it's doable and I can try to put together something that It's currently possible to use: (rtags-symbol-info-internal) to get an assoc list with all the necessary I'm not sure I'm entirely the right person to write the mode that does Anders On Mon, May 9, 2016 at 2:43 PM, quicknir notifications@github.com wrote:
|
Those are both good points, sounds though like there are solutions for both. Possibly also for 2), the last symbol type could be kept from the last successful compile. In a typical workflow you will have a successful compile at some point, change something, then it fails, and 99% of the symbols would have the same type. Truthfully, I am not yet an emacs user, nor have I ever written a line of elisp, so I'm probably not the right person. Where else in the ecosystem do you think I could bring this up? Emacs core, CEDET? I realized it's a bit of a long shot to bring this up when I'm unlikely to implement it myself, but I figure if nothing else it's a datapoint. |
There is an attempt to bring a similar feature to ycmd. |
It's definitely interesting. I certainly wouldn't mind doing the c++ part On Tue, May 10, 2016 at 7:12 AM, dvzubarev notifications@github.com wrote:
|
This is a nice idea. It would solve issues where cc-mode is not handling C++11 syntax correctly. There are several outstanding issues and not much activity on cc-mode (I think). If using the rtags to syntax highlight, it would also be great to hook this up with clang-tidy to get indentation correct when the tab key is hit or you do M-x indent-region. The current cc-mode indentation and highlighting are coupled. One concern with doing this is that running clang (rdm/rp) on large files takes many seconds. The processing of clang looks at all headers, so if you've include a lot of STL/Boost, the size of the preprocessor output is in the millions of lines (ignoring blank lines). Whereas the current regex cc-mode approach is fast on similar files. If there were a way to incrementally analyze a source file or analyze code regions in a file without diving into the headers, this approach would be very viable and not too difficult to implement. |
Yeah. It's a bit problematic. I don't believe clang has a mode to only I think any successful mode would have to asynchronously wait for RTags' Anders On Wed, May 11, 2016 at 8:59 AM, JohnC32 notifications@github.com wrote:
|
So I've made a bit of progress research wise. First off, it seems like one can can populate a variable called font-lock-keywords. This is a list of elements, each element can take several forms but one form of particular interest is a pair, with the first element being a function and the second function being a face. One calls the function which returns some description of the matched area, then the face in the second element is applied to the matched area. Font-lock works through this list of elements one by one. (http://www.gnu.org/software/emacs/manual/html_node/elisp/Search_002dbased-Fontification.html#Search_002dbased-Fontification) In our case, these functions could basically have references to some array that's populated by querying the backend. One function per face; each function does a single scan over the array and sees which points in the text match the syntactic element its looking to highlight. A second useful piece of information is that Steve Yegge actually wrote a proper AST emacs syntax highlighter for JS. He apparently did not use font lock at all, and did not fall back to regex parsing. His code is long as he actually wrote the entire js parser, but somewhere in that code, there is the part that actually sets the colors, which we can use. |
Yeah. I do use js2-mode which is quite the engineering achievement. I agree I have started exposing the token information to elisp already a little bit Anders On Thu, May 12, 2016 at 8:22 AM, quicknir notifications@github.com wrote:
|
I'm interested in this effort. Perhaps a good start would be handling nothing but raw string literals. It seems like that might simplify things and would solve an important problem area for me. I don't think it's fair to say there is work on cc-mode (Alan Mackenzie has been quite responsive in my experience), but so far it doesn't support raw string literals. Hopefully that will change soon, but I think it's non-trivial. In my estimation, as long as it uses clang instead of gcc it won't get into Emacs core--RMS will veto it. There are several threads about this that you can read if you're interested. |
Yeah, that's a given. I recently emailed the emacs mailing list. Here was RMS' reply: We develop GCC as well as Emacs. To adopt a competitor to GCC A proper solution is to extend GCC so that it does the necessary job. Shrug. Other people were more helpful and pointed me to font lock. But I don't think there's any appetite to do it themselves. gvol, how's your elisp? ;-) |
My elisp is decent (I have a few MELPA packages) . My time is less so. :-( But I'll try to make some time since it would help me immensely. What I don't have a good handle on is calling rtags to get the information. But I'll see what I can get going. |
Hi Ivan Currently one would call (rtags-tokens) to get the info. This is currently Anders On Fri, May 13, 2016 at 7:46 PM, Ivan Andrus notifications@github.com
|
I'll point out that https://github.com/jeaye/color_coded handles this quite nicely, in vim. Ideally, YCMD will provide an API which color_coded can use so that both projects don't end up compiling the source, and I encourage each of you to follow up with that request here ycm-core/ycmd#291. As I'm currently in the middle of switching from vim to spacemacs, I'd really like to port color_coded over to a spacemacs layer; being able to ride on YCMD's tokens would make that easier, but it's not necessary. If someone is looking into implementing semantic highlighting for emacs, I recommend doing so as a port of color_coded; its native code should be able to remain unchanged. |
We're certainly not opposed to having rtags output the tokens in some Anders On Tue, May 17, 2016 at 5:11 PM, jeaye notifications@github.com wrote:
|
Here's a very rough first attempt. I'm sure I haven't covered everything, I only tried it on a few cpp files. To test it out, evaluate the function below, open an rtags-enabled cpp file, and do
You can also set it to be the default fontification function with in a cpp file with
However, it currently requires that the file be saved and indexed, or all the offsets will be off (and hence fontification will be off), so it doesn't really work to edit. There are probably other issues that I haven't noticed.
|
Thanks. I am not sure what one can do about the requirement for it being Wanna file a pull request to get it into rtags.el? Anders On Tue, May 24, 2016 at 10:53 AM, Ivan Andrus notifications@github.com
|
Having tried it a bit, I don't think I would use it and it would take a bit of work to get around being saved/indexed. If we just fall back to cc-mode whenever someone edits the file, then it seems there's not much point. I really wouldn't want my font-lock to "flicker". I also found https://github.com/terranpro/clang-faces today, which likely gives a better start then what I have. It probably makes more sense to improve rdm so that it can output color_coded and clang-faces output. Or change them to use rtags formatted output. |
Hello, I found this discussion via reddit. I recently started Font Lock for "Modern C++". I discovered this weekend As a developer, I expect the font locking of an editor to be simple and quick - I expect it to work out of the box (no need for extra third party, such as Clang in this context) and I don't want to wait 1 second (or more) to see a keyword highlighted. Also, I expect it to work wherever the source file is (on local or distant machine). These are my main specifications, which seem to be reasonable? If the font lock relies on the Clang AST, most (maybe all) of my previous specifications are not satisfied:
Anyway, I had a look at Clang AST to give me a better idea and I notice some limitations (or maybe I am missing some flags in the command line): it provides processed data. Let's consider this snippet: Maybe a better solution is to code an elisp C++ lexer and provide it when your package is installed from Melpa. However, parsing C++ is not an easy task. I started Font Lock for "Modern C++", with these specifications in mind. It aims to font lock only the C++ language (which is well defined so no need to build an AST). The downside is that user defined functions, types, etc. Are not recognized. This is were I disable only The user wants less font lock from I could help you to provide font locking for symbols recognized by Please, tell me what you think about this approach? |
I think this approach is pretty sensible. Would you be interested in adding some support for using rtags when You can currently asynchronously query info about the source file in If there's any API or piece of information you'd need I'd definitely be Anders On Mon, May 30, 2016 at 3:08 AM, Ludwig PACIFICI notifications@github.com
|
I was thinking to add the font lock for symbols that can be lookup via rtags. For example:
Does it seems logical? |
I will close this since I think all the machinery that RTags needs to provide already is there. @ludwigpacifici Sorry about the long delay. I think that approach is sensible. |
Is it completely insane to ask whether it would be possible to write a major mode for C++ that uses rtags to query the type of token for syntax highlighting, instead of doing it regex based?
I found myself contemplating a switch to spacemacs + rtags this weekend. There's a handful of places where it falls short of Eclipse (and of course places where it's stronger as well). One of these is that in Eclipse, syntax highlighting is based on the AST. Not only is this going to be accurate whenever your index is, but it also lets you make a lot more interesting distinctions. For example, static variables can be italicized (not just at declaration, but also whenever used), member functions can be a different color from functions (inside another member function of the same class they can't be distinguished by ege or regex), etc.
Given that rtatgs has all this information available, it seems like this should be possible in principle. So a major mode could try querying rtags for the information by calling appropriate functions, and then fall back to the regex when necessary.
The text was updated successfully, but these errors were encountered: