Skip to content

Purpose of completion files and customizing completion #2757

@rhelder

Description

@rhelder

Thanks again for your help with my issue the other day - sorry to be back again so soon! This time I have a question about what I think is expected behavior - TL;DR, based on what I understand from the documentation and from my testing, it is VimTeX's parsing of .fls files and/or of \usepackage statements that does the heavy lifting when it comes to determining what commands to suggest during completion. If that's true, my question is what role the completion files in autoload/vimtex/complete are playing, and whether or not it is possible to customize what commands are suggested during completion.

Ok, now for the long-winded part. What I'm asking about is expected behavior (as far as I know), and there's no difference in behavior between my full configuration and a minimal configuration - but just to hold everything constant, I used the following minimal.vim:

set nocompatible
set runtimepath^=~/.config/nvim/vim-plug/vimtex
set runtimepath+=~/.config/nvim/vim-plug/vimtex/after
filetype plugin indent on
syntax enable

And here's a minimal tex file (minimal1.tex):

\documentclass{article}

\usepackage{biblatex}

\setlength{\bibitemsep}{0pt} \DeclareLanguageMapping{latin}{american}

\begin{document}
Hello, world
\end{document}

While typing (after having typed \usepackage{biblatex} and used :VimtexReloadState), \bibitemsep was suggested during completion, and \DeclareLanguageMapping was not. This is what I expected, since \bibitemsep is in biblatex's completion file in autoload/vimtex/complete, and \DelareLanguageMapping is not.

However, suppose I really wanted \DeclareLanguageMapping to be suggested during completion. I expected (in my ignorance) that appending DeclareLanguageMapping to biblatex's completion file in autoload/vimtex/complete would cause \DeclareLanguageMapping to appear in the list of possible commands. As it is (even after :VimtexReloadState or compilation), adding \DeclareLanguageMapping to the biblatex completion file causes no change in what is suggested during completion.

I also tried this out with the following minimal.sty file:

\ProvidesPackage{minimal}
\NewDocumentCommand{\texttitle}{m}{\emph{#1}}
\NewCommandCopy{\define}{\emph}
\endinput

and the following minimal2.tex file:

\documentclass{article}

\usepackage{minimal}

\begin{document}

My favorite book by Kant is the \texttitle{Groundwork of the Metaphysics of Morals}.
He begins the first section by discussing the \define{good will},
which he says is the only thing in the world that is unconditionally good.

\end{document}

Without any completion file at all, VimTeX was able to recognize \texttitle and suggest it during completion, but not \define. This is not what I expected, but I realized that it made sense, since VimTeX looks for new commands either after compilation or upon initialization (or after :VimtexReloadState) - even without a completion file - and since there are good reasons for not wanting to include copies of commands among the commands that are suggested during completion. What I did expect (in my ignorance) is that if I drafted the following completion file

texttitle
define

and added it to autoload/vimtex/complete, that not only \texttitle but also \define would be suggested during completion. As it is, drafting and placing the completion file made no difference. (This is the same behavior as I observed with my actual, non-minimal .sty files).

So what it looks like on my end (and also from what I can tell from going back over the documentation) is that it's really VimTeX's parsing of .fls files and/or \usepackage statements that does (all?) the work when determining what commands to suggest during completion.

Hence my initial question: what role do the completion files in autoload/vimtex/complete play, since they don't have any visible effect on the behavior described above? And if one can't customize completion by modifying the completion files, do you have any suggestions for how completion could be customized?

(I did try to see for myself by having a look at complete.vim, but I'm very much a novice at vimscript, and I'm not confident that I followed completely. I also had a look at #650 and #770, which were illuminating but still left me wondering).

I hope that I didn't miss anything either in the documentation or online - I looked very hard and couldn't find what I was looking for. Thanks for your help, and for your work on this excellent plugin.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions