Skip to content
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

autocompletion of expl3 commands #3896

Closed
mbertucci47 opened this issue Dec 3, 2024 · 13 comments
Closed

autocompletion of expl3 commands #3896

mbertucci47 opened this issue Dec 3, 2024 · 13 comments

Comments

@mbertucci47
Copy link
Contributor

mbertucci47 commented Dec 3, 2024

Describe the feature and the current behavior/state

Correct highlighting for expl3 code was somewhat recently added to TXS, but there is currently no autocompletion for expl3 commands. Generating an appropriate cwl would be easy since LaTeX Workshop has a script for making a json file of expl3 commands: https://github.com/James-Yu/LaTeX-Workshop/blob/master/data/packages/expl3.json

A quick test shows that commands in cwls can contain underscores and colons, so that part is fine. The only thing that would need extra code is making the autocompletion active only inside \ExplSyntaxOn...\ExplSyntaxOff or in a file that declares \ProvidesExplPackage, etc.

Who will benefit with this feature?

Anyone who writes expl3 code in TXS.

@muzimuzhi
Copy link
Contributor

Generating an appropriate cwl would be easy since LaTeX Workshop has a script for making a json file of expl3 commands: https://github.com/James-Yu/LaTeX-Workshop/blob/master/data/packages/expl3.json

It even uses .cwl (generated by latex3command.py) as an intermediate representation, though currently only the function or variable name is extracted (or, can be reliably extracted?).

@sunderme
Copy link
Member

sunderme commented Dec 7, 2024

it is not strictly necessary that txs restricts the completion wintin \ExplSyntaxOn...\ExplSyntaxOff
So, we can just add the commands first, the user can activate them generally and one can add the extra restriction into txs later.

@muzimuzhi
Copy link
Contributor

@sunderme Ah yes! Why I didn't realize it earlier?

Tried with cwl entries

\tl_new:N %<tl var%>
\tl_const:Nn %<tl const%> {%<content%>}

and they do work (currently not necessarily in between \ExplSyntaxOn ... \ExplSyntaxOff).
image

@sunderme
Copy link
Member

sunderme commented Dec 8, 2024

so, we can close this for now ?

@mbertucci47
Copy link
Contributor Author

I think having automatic activation inside expl3 environments is important to this issue as outside such environments, they just pollute the autocompleter. So I’d vote not to close

@mbertucci47
Copy link
Contributor Author

Just a note for the future, the completion file should be called expl3-commands.cwl or something else not named expl3.cwl since some people still load expl3.sty manually (which has been unnecessary for several years) and calling it expl3.cwl would make the expl3 commands always active instead of only in expl3 environments.

@mbertucci47
Copy link
Contributor Author

Also useful would be a way of marking commands as expl3-only, so only show in the autocompleter in an expl3 environment. Something like

# somecwl.cwl
\normalcommandone
\normalcommandtwo
#beginexplcmds
\some_expl_cmd:nn
\some_other_explcmd:Nn
#endexplcmds

That way packages that provide an expl3 programming layer like fontspec or l3draw could have proper autocompletion in addition to the kernel expl3 commands.

@muzimuzhi
Copy link
Contributor

@mbertucci47 With 19f3aea (generalize start/stop env per command, 2024-12-18) and cd2d61d (avoid potential naming collision, 2024-12-18), maybe it's possible to use something like

# somecwl.cwl
\normalcommandone
\normalcommandtwo
# only available in generalized env "%expl3"
\some_expl_cmd:nn#/%expl3
\some_other_explcmd:Nn/%expl3

But I didn't test it.

@sunderme
Copy link
Member

Something like /%expl3 will probably be the solution. But currently the completer does not filter for valid commands.

@sunderme
Copy link
Member

this is basically implemented (completer list with expl3 commands and limited completion based on context).

@muzimuzhi
Copy link
Contributor

Wondering if texstudio wants to also recognize deprecated (but not removed) l3kernel functions and variables. They are not documented in interface3.pdf and are only listed in l3obsolete.txt, but may appear in existing codes.

@mbertucci47
Copy link
Contributor Author

@muzimuzhi As far as I can tell there is no syntax checking done in expl3 environments, only command completion. So wouldn't it be better to not show the obsolete commands in the completer?

@muzimuzhi
Copy link
Contributor

@muzimuzhi As far as I can tell there is no syntax checking done in expl3 environments, only command completion.

@mbertucci47 If so then yes, current support is enough.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants