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
Latex ac #1011
base: master
Are you sure you want to change the base?
Latex ac #1011
Conversation
LaTeX macros start with a \, but constructions like \def\macroone\macrotwo are allowed and should not be understood as a single word. The character @ is sometimes allowed as part of a macro. The character : can be used as part of a label.
Things like \newcommand{macro} no longer produce a new tag. Also, constructions like \def\somemacro\alpha are treated correctly.
Have you submitted the changes to ctags/latex.c to the upstream ctags project? What was the response? In general it is better not to hardcode language specific features in Geany (I'm talking about the editor.c changes). Instead a more generic functionality controlled by settings in the filetype file should be used so that other languages that are not C can also benefit. |
I was not aware of the ctags project. But their tex file does not seem to have anything for macros, and is considerably different from the ctags/latex.c file here. So I don't see how I could submit theses changes there, and I also don't see how it would help Geany. One way of making this functionality more generic would be to use the lexer to filter which symbols can be used for autocompletion. So if the lexer can tell whether the current word is a macro or not, and if the known symbols are properly typed, the LaTeX specific code could go away. But I don't know if this could break autocompletion for other languages. |
Sigh, looks like in the past "somebody" made significant changes without getting them upstream which will make sharing improvements hard in future. That was why I asked had you tried first. Ok, guess it will have to be local only.
Just a note on Geany terminology, lexers are the things inside Scintilla that do purely syntax identification for highlighting, the ctags things are parsers since they understand semantics (at least of declarations). Being purely semantics the lexers don't know what a syntactic element (like a name) represents. But they can compare syntactic elements that are names with a list of known names and identify them differently if they are in the list. This list is usually provided by the parsers from the declarations. But be warned, occurrence of a name will allways be identified that way irrespective of its context, so depending on how latex treats names YMMV (works fairly ok in C, but often quite badly in C++). What sorts of names does latex have? What sorts are identified by the parser? The autocomplete operation is currently really elementary, and only (sort of) works for C/C++ and look alike languages that use . or -> (which is why you will see an occasional "not all languages are C" rant in Geany discussions :). So a more general mechanism for having autocomplete handle context when offering names would be good. Or possibly you could look at re-mapping the symbol kinds used in latex so they can be filtered by the C like mechanism already available an so only need a setting for the separator (instead of . and ->). |
LaTeX has plain text (natural language), macros (always preceded by a The lexer is capable of identifying a |
Yeah, I guess the programming language model of symbol types is being somewhat stretched here, but hey programming languages don't have free text in them either :)
Sounds like a plan.
|
Now `\def\alpha` is interpreted as `alpha`. Special treatment for this case is no longer necessary.
Now plain text is treated as string, so there is no longer any need for LaTeX-specific treatment in editor.c (other than defining wordchar). I had to slightly change the lexer so that The main problem now is that there is no autocomplete for labels, since they are treated as plain text by the lexer. Without changing scintilla, I'm afraid it would be complicated to fix this. However, it is common practice in LaTeX to name labels like |
I don't plan on changing anything else. I have been testing my changes for the past month and it is working quite well. I never received an answer for the changes on scintilla. Is there any chance of this getting merged? |
Can you provide a link to the Scintilla report? |
The merge request is here. |
Ok, looking at the date it was submitted I think you probably missed getting it before the Scintilla maintainer went away for some months (and still is away). As for the rest, just needs someone who is confident it works to have time to test and commit it. Latex users are welcome to try the PR and comment. |
# Conflicts: # ctags/parsers/latex.c # src/editor.c
No point in making changes to Also updates to ctags should be made upstream to universal ctags, although they are not updated so often. |
I never got a reply to my merge request to the Scintilla project. I'll try to make a request to universal ctags, let's see if I have more luck there. |
You might try pinging your PR to Scintilla in a few weeks when the maintainer is back from holidays. |
I extended Tex parser of u-ctags agressively. Commands in \newcommand are captured. If you think u-ctags captures more things, please, consider to open an issue at u-ctags repo. |
Fixes issue #1000 . Geany now correctly autocompletes LaTeX macros.
The difference in behaviour can be illustrated with the following document:
The tests were updated to accept this behaviour (since macro tags now start with
\
).This also identifies macros defined with
\let
,\newlength
and environments defined with\renewenvironment
.Finally,
@
can be used sometimes in a macro name and mostly any character can be used in a label. I added:@
to wordchars so that they can be used in autocomplete.