SublimeText / LaTeXTools

LaTeX plugin for Sublime Text
https://latextools.readthedocs.io/
2k stars 364 forks source link

Customize \ref completion #1463

Open JakobScholbach opened 4 years ago

JakobScholbach commented 4 years ago

I love a feature of LatexTools: if I type \ref{, it automatically scans for all occurrences of \label{…} and offers these for some auto-completion.

How do I customize this? I want to achieve the same behavior with \thref{ and \thlabel{…} instead.

Thanks!

r-stein commented 4 years ago

The behavior of ref and label is hard coded and not configurable. You may however adapt the source code. Select View > Browse Packages... then open the LaTeXTools folder and the file latex_ref_completions.py.

Then add "th" to the array in this line (i.e. "title", "headname", "tocname", "th") to open the completion for \thref.

Then adapt this line to

for command in doc.filter_commands(['label', 'thlabel']):

and this line to

view.find_all(r'\\(?:th)?label\{([^\{\}]+)\}', 0, '\\1', completions)

to also scan the \thlabel commands

JakobScholbach commented 4 years ago

Thank you, r-stein, this works!