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

More specific functions for vimtex API #2212

Closed
L1szt opened this issue Oct 18, 2021 · 12 comments
Closed

More specific functions for vimtex API #2212

L1szt opened this issue Oct 18, 2021 · 12 comments

Comments

@L1szt
Copy link

L1szt commented Oct 18, 2021

The vimtex api is great so far but I would like to have the possibility to find out whether my cursor is currently in a x section where x is just a placeholder for any possible section, e.g.

\begin{x}
...
\end{x}

and I would like to be able to call some API function to tell me whether my cursor currently is in an x-block.

@lervag
Copy link
Owner

lervag commented Oct 18, 2021

E.g. something like vimtex#syntax#in?

@lervag
Copy link
Owner

lervag commented Oct 18, 2021

I.e., if you have the following source

\begin{x}
  cursor here
\end{x}

with the cursor where indicated, then vimtex#syntax#in('x') should return a true value.

@clason
Copy link
Contributor

clason commented Oct 18, 2021

Wouldn't it be easier to have in() return 'x' and let the caller do the checking?

@lervag
Copy link
Owner

lervag commented Oct 18, 2021

Sorry, I was wrong. ...#in(...) does not check specifically for environment x. It checks for syntax item x, which is generally not the same.

Wouldn't it be easier to have in() return 'x' and let the caller do the checking?

No, not quite - it would have to return the syntax stack.


However, we have vimtex#env#is_inside(env), which I think should work as expected. And your question is the same - it could be relevant to add a function like vimtex#env#get_current which returns the current outermost innermost environment. Or perhaps the full stack of surrounding environments?

@clason
Copy link
Contributor

clason commented Oct 18, 2021

I think a concrete use case would go a long way here...

which returns the current outermost environment

I'd expect the _inner_most environment to be more useful in most cases? (The outermost environment tends to be document ;P)

So I guess you'd either need two functions (get_inner and get_outer), or indeed the full stack (so get_env()[0] can be a shortcut for the former).

@lervag
Copy link
Owner

lervag commented Oct 18, 2021

I'd expect the _inner_most environment to be more useful in most cases? (The outermost environment tends to be document ;P)

hah, my mistake... in any case, I'll add the functions more or less as described here:

vimtex#env#get_inner()
  Get innermost environment name.
vimtex#env#get_outer()
  Get outermost environment name (ignore "document").
vimtex#env#get_all()
  Get list of all surrounding environments ([innermost, ..., outermost]).

@clason
Copy link
Contributor

clason commented Oct 18, 2021

I don't see how anybody could complain about that :)

@L1szt
Copy link
Author

L1szt commented Oct 19, 2021

@lervag thanks a lot for the quick response! Apparently the documentation I read contained only a subset of the commands.

@L1szt L1szt closed this as completed Oct 19, 2021
@L1szt
Copy link
Author

L1szt commented Oct 19, 2021

@lervag An of topic question: Whenever I start the continuous compile mode the preview application on my OS opens and shows the rendered pdf. How can I disable this (that vimtex automatically causes this application to open)/change the application?

lervag added a commit that referenced this issue Oct 19, 2021
@lervag
Copy link
Owner

lervag commented Oct 19, 2021

I don't see how anybody could complain about that :)

Right? :) I've pushed the first version of this. A "simple" and straightforward implementation, but I believe it should do the trick. Let me know what you think.

thanks a lot for the quick response! Apparently the documentation I read contained only a subset of the commands.

Yes, I assume you refer to :help vimtex-code-api? It is a work-in-progress that I am not really devoting much time to. I'll try to improve it with time, but it is not a priority.

An of topic question: Whenever I start the continuous compile mode the preview application on my OS opens and shows the rendered pdf. How can I disable this (that vimtex automatically causes this application to open)/change the application?

First, it is not really VimTeX that does this; it is the standard behaviour of latexmk. But VimTeX does configure latexmk to use the same viewer as specified in VimTeX. And yes, VimTeX does have an option to prevent the automatic viewer. Just add let g:vimtex_view_automatic = 0 to your vimrc.

@L1szt
Copy link
Author

L1szt commented Oct 21, 2021

@lervag again, thanks a lot for your help (it's very rare that the creator of an extension is so quick in helping its users).

@lervag
Copy link
Owner

lervag commented Oct 21, 2021

Glad to help, and thanks for the kind words :)

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