SublimeText / LaTeXTools

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

Autocomplete enhancement w/ support for glossaries-extra commands #1554

Open heavystrain opened 2 years ago

heavystrain commented 2 years ago

Problem description

The glossaries package has been somewhat overhauled with the advent of the glossaries-extra package. The biggest problem, for me, was missing autocompletions for entries created using the new glossaries-extra syntax.

Below, I suggest some modifications to enhance the autocompletion feature of LatexTools in ST.

Preferred solution

I personally have added

to line 25 of latex_glossary_completions.py https://github.com/SublimeText/LaTeXTools/blob/b27fc391b2e0c7298d7e2be2472f3642e25ed3d2/latex_glossary_completions.py#L24-L25 which does the trick (almost) perfectly:

glo_commands = ana.filter_commands(
    ["newglossaryentry", "longnewglossaryentry", "newacronym", "newabbreviation",
    "glsxtrnewsymbol", "glsxtrnewnumber", "newentry", "newsym", "newnum"])

also I modified the regular expression GLO_LINE_RE in line 9 of latex_glossary_completions.py https://github.com/SublimeText/LaTeXTools/blob/b27fc391b2e0c7298d7e2be2472f3642e25ed3d2/latex_glossary_completions.py#L8-L10 to include triggering for the standard "glsentry" commands (very important for headings, captions etc.) as well as multiglossary commands:

GLO_LINE_RE = re.compile(
    r"([^{}\[\]]*)\{*?(?:lp|(?:lobmys|eman|csed)(yrtne)?)?sl(?:G|g)(?:P|p)?(?:M|m)?\\"
)

Minor problems arise with the extraction of the entry labels for some special cases (glossary entries with a footnote and citation) , such that there are some faux labels in my completion drop-down list in ST. Sadly, I could not locate the code where the labels are extracted so I don't know why this happens. Nevertheless, this enhancement has been of great benefit to myself as I juggle many glossaries.

Maybe it would also be helpful if the user could integrate his own keys. I've added an operation (op) and unit (unit) field into my glossaries and therefore simply modified the regex to include these field names (keys):

GLO_LINE_RE = re.compile(
    r"([^{}\[\]]*)\{*?(?:lp|(?:lobmys|eman|csed|po|tinu)(yrtne)?)?sl(?:G|g)(?:P|p)?(?:M|m)?\\"
)

Alternatives

None.

Additional Information

Thanks in advance and of course for this great tool!