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

Closing latex environments #41

Open
maxfl opened this issue Nov 13, 2013 · 9 comments
Open

Closing latex environments #41

maxfl opened this issue Nov 13, 2013 · 9 comments

Comments

@maxfl
Copy link

maxfl commented Nov 13, 2013

I was trying to add latex environment to endwise by adding the following code:

let b:endwise_addition = '\\end{\=submatch(1)}'
let b:endwise_addition = 'end'
let b:endwise_words = 'begin'
let b:endwise_pattern = '^\s*\\begin{\(.\+\)}.*$' 
let b:endwise_syngroups = 'texBeginEndName'

to ftplugin/tex.vim and it fails.

I guess I completely do not understand how configuration is supposed to be done. The idea is to close the following block:

\begin{env}[optional]{parameters}

\end{env}

The block may be indented. Is it possible to add the latex support to the endwise?

Thanks!

@maxfl
Copy link
Author

maxfl commented Nov 17, 2013

So far after some playing I was able to figure out that the following sequence does the job:

let b:endwise_words = '\\begin{\zs[a-zA-Z0-9*]*\ze}' " ignored
let b:endwise_pattern = '\\begin{\zs[a-zA-Z0-9*]*\ze}'
let b:endwise_addition = '\\end{&}'
let b:endwise_syngroups = 'texBeginEndName'

But it doesn't prevent endwise to add the ending even if it already exists. For now I don't know how it works and how it can be fixed.

@ghost
Copy link

ghost commented Mar 27, 2014

Nevertheless, this could for better or worse be included in the standard plugin.

@tpope
Copy link
Owner

tpope commented Mar 27, 2014

Where did texBeginEndName come from? I see texSection (though this might be version dependent).

@maxfl
Copy link
Author

maxfl commented Mar 27, 2014

It's from vim's tex syntax file.
vim 7.3.1287

" Vim syntax file
" Language: TeX
" Maintainer: Charles E. Campbell [email protected]
" Last Change: Mar 11, 2013
" Version: 78
" URL: http://www.drchip.org/astronaut/vim/index.html#SYNTAX_TEX

@tpope
Copy link
Owner

tpope commented Mar 27, 2014

That's a curious inconsistency with both 7.3.000 and 7.4.000 but doesn't appear to be relevant. b:endwise_words needs to be a comma delimited list of words. You might have better luck if you start by trying to target a few specific environments. I doubt a general solution is possible without tweaking the rest of the implementation.

@michaelmior
Copy link

The example given by @maxfl doesn't seem to work for me. This would be very cool to have working somehow in any case.

@gelguy
Copy link

gelguy commented Feb 28, 2015

I can confirm @maxfl example works and the problem with preventing extra endings exists. There's two factors affecting this.

Firstly, b:endwise_addition is not escaped when endpat is generated so the double-slashes in \\end becomes \end when doing searchpair.

Secondly, in Latex's syntax highlighting, \begin{foo} has two different syntax groups, \begin having texBeginEnd and foo with texBeginEndName. My current method is to introduce a new variable b:endwise_endsyngroups which when defined, overrides b:endwise_syngroups in mysearchpair.

Another minor issue is that the \begin has a lot of environments, so a new tag may match an already existing, but different tag. I believe it is possible to generate the exact end pattern from word when doing searchpos.

@elliotpatros
Copy link

elliotpatros commented Oct 25, 2018

This has been working for me:

  autocmd FileType tex
        \ let b:endwise_addition = '\="\\end" . matchstr(submatch(0), "{.\\{-}}")' |
        \ let b:endwise_words = 'begin' |
        \ let b:endwise_pattern = '\\begin{.\{-}}' |
        \ let b:endwise_syngroups = 'texSection,texBeginEnd,texBeginEndName,texStatement'

Edit: you can do \begin{env*} now too.

@michaelmior
Copy link

Thanks @elliotpatros! That works for me :)

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

No branches or pull requests

5 participants