summaryrefslogtreecommitdiffstats
path: root/runtime
diff options
context:
space:
mode:
authorBram Moolenaar <Bram@vim.org>2018-05-13 00:02:36 +0200
committerBram Moolenaar <Bram@vim.org>2018-05-13 00:02:36 +0200
commit7db25fed5de1be922b8cbb0328149469606a0424 (patch)
treead7a588d2f32740df2fb5d23ae41e06eac36be16 /runtime
parent52ecaaa63d8d4c6d2ae9072e944a45d8d4e2ac76 (diff)
Update runtime files.
Diffstat (limited to 'runtime')
-rw-r--r--runtime/autoload/xmlformat.vim112
-rw-r--r--runtime/doc/change.txt51
-rw-r--r--runtime/doc/cmdline.txt11
-rw-r--r--runtime/doc/tags1
-rw-r--r--runtime/doc/terminal.txt4
-rw-r--r--runtime/doc/todo.txt30
-rw-r--r--runtime/doc/version8.txt4
-rw-r--r--runtime/ftplugin/xml.vim33
-rw-r--r--runtime/indent/sh.vim79
-rw-r--r--runtime/indent/tex.vim199
-rw-r--r--runtime/syntax/zsh.vim12
11 files changed, 349 insertions, 187 deletions
diff --git a/runtime/autoload/xmlformat.vim b/runtime/autoload/xmlformat.vim
new file mode 100644
index 0000000000..b21eccd8e3
--- /dev/null
+++ b/runtime/autoload/xmlformat.vim
@@ -0,0 +1,112 @@
+" Vim plugin for formatting XML
+" Last Change: Thu, 15 Jan 2015 21:26:55 +0100
+" Version: 0.1
+" Author: Christian Brabandt <cb@256bit.org>
+" Script: http://www.vim.org/scripts/script.php?script_id=
+" License: VIM License
+" GetLatestVimScripts: ???? 18 :AutoInstall: xmlformat.vim
+" Documentation: see :h xmlformat.txt (TODO!)
+" ---------------------------------------------------------------------
+" Load Once: {{{1
+if exists("g:loaded_xmlformat") || &cp
+ finish
+endif
+let g:loaded_xmlformat = 1
+let s:keepcpo = &cpo
+set cpo&vim
+
+" Main function: Format the input {{{1
+func! xmlformat#Format()
+ " only allow reformatting through the gq command
+ " (e.g. Vim is in normal mode)
+ if mode() != 'n'
+ " do not fall back to internal formatting
+ return 0
+ endif
+ let sw = shiftwidth()
+ let prev = prevnonblank(v:lnum-1)
+ let s:indent = indent(prev)/sw
+ let result = []
+ let lastitem = prev ? getline(prev) : ''
+ let is_xml_decl = 0
+ " split on `<`, but don't split on very first opening <
+ for item in split(getline(v:lnum), '.\@<=[>]\zs')
+ if s:EndTag(item)
+ let s:indent = s:DecreaseIndent()
+ call add(result, s:Indent(item))
+ elseif s:EmptyTag(lastitem)
+ call add(result, s:Indent(item))
+ elseif s:StartTag(lastitem) && s:IsTag(item)
+ let s:indent += 1
+ call add(result, s:Indent(item))
+ else
+ if !s:IsTag(item)
+ " Simply split on '<'
+ let t=split(item, '.<\@=\zs')
+ let s:indent+=1
+ call add(result, s:Indent(t[0]))
+ let s:indent = s:DecreaseIndent()
+ call add(result, s:Indent(t[1]))
+ else
+ call add(result, s:Indent(item))
+ endif
+ endif
+ let lastitem = item
+ endfor
+
+ if !empty(result)
+ exe v:lnum. ",". (v:lnum + v:count - 1). 'd'
+ call append(v:lnum - 1, result)
+ " Might need to remove the last line, if it became empty because of the
+ " append() call
+ let last = v:lnum + len(result)
+ if getline(last) is ''
+ exe last. 'd'
+ endif
+ endif
+
+ " do not run internal formatter!
+ return 0
+endfunc
+" Check if given tag is XML Declaration header {{{1
+func! s:IsXMLDecl(tag)
+ return a:tag =~? '^\s*<?xml\s\?\%(version="[^"]*"\)\?\s\?\%(encoding="[^"]*"\)\? ?>\s*$'
+endfunc
+" Return tag indented by current level {{{1
+func! s:Indent(item)
+ return repeat(' ', shiftwidth()*s:indent). s:Trim(a:item)
+endfu
+" Return item trimmed from leading whitespace {{{1
+func! s:Trim(item)
+ if exists('*trim')
+ return trim(a:item)
+ else
+ return matchstr(a:item, '\S\+.*')
+ endif
+endfunc
+" Check if tag is a new opening tag <tag> {{{1
+func! s:StartTag(tag)
+ return a:tag =~? '^\s*<[^/?]'
+endfunc
+" Remove one level of indentation {{{1
+func! s:DecreaseIndent()
+ return (s:indent > 0 ? s:indent - 1 : 0)
+endfunc
+" Check if tag is a closing tag </tag> {{{1
+func! s:EndTag(tag)
+ return a:tag =~? '^\s*</'
+endfunc
+" Check that the tag is actually a tag and not {{{1
+" something like "foobar</foobar>"
+func! s:IsTag(tag)
+ return s:Trim(a:tag)[0] == '<'
+endfunc
+" Check if tag is empty <tag/> {{{1
+func! s:EmptyTag(tag)
+ return a:tag =~ '/>\s*$'
+endfunc
+" Restoration And Modelines: {{{1
+let &cpo= s:keepcpo
+unlet s:keepcpo
+" Modeline {{{1
+" vim: fdm=marker fdl=0 ts=2 et sw=0 sts=-1
diff --git a/runtime/doc/change.txt b/runtime/doc/change.txt
index ab820b0662..ffc5abde77 100644
--- a/runtime/doc/change.txt
+++ b/runtime/doc/change.txt
@@ -1,4 +1,4 @@
-*change.txt* For Vim version 8.0. Last change: 2018 May 06
+*change.txt* For Vim version 8.0. Last change: 2018 May 12
VIM REFERENCE MANUAL by Bram Moolenaar
@@ -1445,6 +1445,55 @@ to the name of an external program for Vim to use for text formatting. The
'textwidth' and other options have no effect on formatting by an external
program.
+ *format-formatexpr*
+The 'formatexpr' option can be set to a Vim Script function that performs
+reformatting of the buffer. This should usually happen in an |ftplugin|,
+since formatting is highly dependent on the type of file. It makes
+sense to use an |autoload| script, so the corresponding script is only loaded
+when actually needed and the script should be called <filetype>format.vim.
+
+For example, the XML filetype plugin distributed with Vim in the $VIMRUNTIME
+directory, sets the 'formatexpr' option to: >
+
+ setlocal formatexpr=xmlformat#Format()
+
+That means, you will find the corresponding script, defining the
+xmlformat#Format() function, in the directory:
+`$VIMRUNTIME/autoload/xmlformat.vim`
+
+Here is an example script that removes trailing whitespace from the selected
+text. Put it in your autoload directory, e.g. ~/.vim/autoload/format.vim: >
+
+ func! format#Format()
+ " only reformat on explicit gq command
+ if mode() != 'n'
+ " fall back to Vims internal reformatting
+ return 1
+ endif
+ let lines = getline(v:lnum, v:lnum + v:count - 1)
+ call map(lines, {key, val -> substitute(val, '\s\+$', '', 'g')})
+ call setline('.', lines)
+
+ " do not run internal formatter!
+ return 0
+ endfunc
+
+You can then enable the formatting by executing: >
+ setlocal formatexpr=format#Format()
+>
+Note: this function explicitly returns non-zero when called from insert mode
+(which basically means, text is inserted beyond the 'textwidth' limit). This
+causes Vim to fall back to reformat the text by using the internal formatter.
+
+However, if the |gq| command is used to reformat the text, the function
+will receive the selected lines, trim trailing whitespace from those lines and
+put them back in place. If you are going to split single lines into multiple
+lines, be careful not to overwrite anything.
+
+If you want to allow reformatting of text from insert or replace mode, one has
+to be very careful, because the function might be called recursively. For
+debugging it helps to set the 'debug' option.
+
*right-justify*
There is no command in Vim to right justify text. You can do it with
an external command, like "par" (e.g.: "!}par" to format until the end of the
diff --git a/runtime/doc/cmdline.txt b/runtime/doc/cmdline.txt
index 25577a2b6a..d7a026143a 100644
--- a/runtime/doc/cmdline.txt
+++ b/runtime/doc/cmdline.txt
@@ -1,4 +1,4 @@
-*cmdline.txt* For Vim version 8.0. Last change: 2017 Oct 19
+*cmdline.txt* For Vim version 8.0. Last change: 2018 May 10
VIM REFERENCE MANUAL by Bram Moolenaar
@@ -412,14 +412,17 @@ CTRL-D List names that match the pattern in front of the cursor.
match is inserted. After the last match, the first is used
again (wrap around).
The behavior can be changed with the 'wildmode' option.
+ *c_<S-Tab>*
+<S-Tab> Like 'wildchar' or <Tab>, but begin with the last match and
+ then go to the previous match.
+ <S-Tab> does not work everywhere.
*c_CTRL-N*
CTRL-N After using 'wildchar' which got multiple matches, go to next
match. Otherwise recall more recent command-line from history.
-<S-Tab> *c_CTRL-P* *c_<S-Tab>*
+ *c_CTRL-P*
CTRL-P After using 'wildchar' which got multiple matches, go to
previous match. Otherwise recall older command-line from
- history. <S-Tab> only works with the GUI, on the Amiga and
- with MS-DOS.
+ history.
*c_CTRL-A*
CTRL-A All names that match the pattern in front of the cursor are
inserted.
diff --git a/runtime/doc/tags b/runtime/doc/tags
index e6424da647..3dd035438b 100644
--- a/runtime/doc/tags
+++ b/runtime/doc/tags
@@ -6137,6 +6137,7 @@ fork os_unix.txt /*fork*
form.vim syntax.txt /*form.vim*
format-bullet-list tips.txt /*format-bullet-list*
format-comments change.txt /*format-comments*
+format-formatexpr change.txt /*format-formatexpr*
formatting change.txt /*formatting*
formfeed intro.txt /*formfeed*
fortran.vim syntax.txt /*fortran.vim*
diff --git a/runtime/doc/terminal.txt b/runtime/doc/terminal.txt
index 2da6904362..5283ead59b 100644
--- a/runtime/doc/terminal.txt
+++ b/runtime/doc/terminal.txt
@@ -1,4 +1,4 @@
-*terminal.txt* For Vim version 8.0. Last change: 2018 May 04
+*terminal.txt* For Vim version 8.0. Last change: 2018 May 11
VIM REFERENCE MANUAL by Bram Moolenaar
@@ -317,7 +317,7 @@ the job ends while in Terminal-Normal mode this changes to
When the job outputs lines in the terminal, such that the contents scrolls off
the top, those lines are remembered and can be seen in Terminal-Normal mode.
The number of lines is limited by the 'termwinscroll' option. When going over
-this limit, the first 10% of the scrolled lins are deleted and are lost.
+this limit, the first 10% of the scrolled lines are deleted and are lost.
Cursor style ~
diff --git a/runtime/doc/todo.txt b/runtime/doc/todo.txt
index e5e699ea7f..9247a7013e 100644
--- a/runtime/doc/todo.txt
+++ b/runtime/doc/todo.txt
@@ -1,4 +1,4 @@
-*todo.txt* For Vim version 8.0. Last change: 2018 May 05
+*todo.txt* For Vim version 8.0. Last change: 2018 May 12
VIM REFERENCE MANUAL by Bram Moolenaar
@@ -38,16 +38,8 @@ entered there will not be repeated below, unless there is extra information.
Terminal emulator window:
- Still some stuff to implement and bugs to fix, see src/terminal.c
-Problem with sudo. #2758
-
-Looks like an error for inserting register makes ":file other" not work.
-(Tom M, 2018 Mar 28) Reset did_emsg after inserting a register.
-Or at the top of the loop? (Apr 4)
-
-Make assert_functions return non-zero on failure. Make sure they add one
-entry to v:errors then.
-Use WaitForAssert() in tests: give error when failed.
-Remove asserts after WaitFor().
+On Win32 when not in the console and t_Co >= 256, allow using 'tgc'.
+(Nobuhiro Takasaki, #2833) Also check t_Co.
balloon_show() does not work properly in the terminal. (Ben Jackson, 2017 Dec
20, #2481)
@@ -163,6 +155,9 @@ ch_sendraw() with long string does not try to read inbetween, which may cause
a deadlock if the reading side is waiting for the write to finish. (Nate
Bosch, 2018 Jan 13, #2548)
+Patch to include a cfilter plugin to filter quickfix/location lists.
+(Yegappan Lakshmanan, 2018 May 12)
+
Add Makefiles to the runtime/spell directory tree, since nobody uses Aap.
Will have to explain the manual steps (downloading the .aff and .dic files,
applying the diff, etc.
@@ -181,6 +176,8 @@ With foldmethod=syntax and nofoldenable comment highlighting isn't removed.
Using 'wildignore' also applies to literally entered file name. Also with
:drop (remote commands).
+Patch to support ":tag <tagkind> <tagname". (emmrk, 2018 May 7, #2871)
+
Patch to use the xdiff library instead of external diff. (Christian Brabandt,
2018 Mar 20, #2732)
@@ -296,6 +293,13 @@ Ask whether to use Windows or Vim key behavior?
Patch for improving detecting Ruby on Mac in configure. (Ilya Mikhaltsou, 2017
Nov 21)
+When t_Co is changed from termresponse, the OptionSet autocmmand event isn't
+triggered. Use the code from the end of set_num_option() in
+set_color_count().
+
+Add another autocommand like TermResponse that is fired for the other terminal
+responses, such as bg and fg. Use "bg", "fg", "blink", etc. for the name.
+
When using command line window, CmdlineLeave is triggered without
CmdlineEnter. (xtal8, 2017 Oct 30, #2263)
Add some way to get the nested state. Although CmdwinEnter is obviously
@@ -1000,10 +1004,6 @@ github with a URL like this:
https://github.com/vim/vim/compare/v7.4.920%5E...v7.4.920.diff
Diff for version.c contains more context, can't skip a patch.
-When t_Co is changed from termresponse, the OptionSet autocmmand event isn't
-triggered. Use the code from the end of set_num_option() in
-set_color_count().
-
Python: ":py raw_input('prompt')" doesn't work. (Manu Hack)
Comparing nested structures with "==" uses a different comparator than when
diff --git a/runtime/doc/version8.txt b/runtime/doc/version8.txt
index c8df5cdf05..db22c6d999 100644
--- a/runtime/doc/version8.txt
+++ b/runtime/doc/version8.txt
@@ -1,4 +1,4 @@
-*version8.txt* For Vim version 8.0. Last change: 2017 Nov 24
+*version8.txt* For Vim version 8.0. Last change: 2018 May 10
VIM REFERENCE MANUAL by Bram Moolenaar
@@ -1799,7 +1799,7 @@ Solution: Always use the stubs. (Danek Duvall, Yukihiro Nakadaira)
Files: src/if_ruby.c
Patch 7.4.226 (after 7.4.219)
-Problem: Cursurline highlighting not redrawn when scrolling. (John
+Problem: Cursorline highlighting not redrawn when scrolling. (John
Marriott)
Solution: Check for required redraw in two places.
Files: src/move.c
diff --git a/runtime/ftplugin/xml.vim b/runtime/ftplugin/xml.vim
index 236e870537..573a6ba441 100644
--- a/runtime/ftplugin/xml.vim
+++ b/runtime/ftplugin/xml.vim
@@ -1,8 +1,10 @@
" Vim filetype plugin file
" Language: xml
-" Maintainer: Dan Sharp <dwsharp at users dot sourceforge dot net>
-" Last Changed: 20 Jan 2009
-" URL: http://dwsharp.users.sourceforge.net/vim/ftplugin
+" Maintainer: Christian Brabandt <cb@256bit.org>
+" Last Changed: May 08th, 2018
+" Repository: https://github.com/chrisbra/vim-xml-ftplugin
+" Previous Maintainer: Dan Sharp <dwsharp at users dot sourceforge dot net>
+" URL: http://dwsharp.users.sourceforge.net/vim/ftplugin
if exists("b:did_ftplugin") | finish | endif
let b:did_ftplugin = 1
@@ -10,16 +12,16 @@ let b:did_ftplugin = 1
" Make sure the continuation lines below do not cause problems in
" compatibility mode.
let s:save_cpo = &cpo
-set cpo-=C
+set cpo&vim
setlocal commentstring=<!--%s-->
-setlocal comments=s:<!--,m:\ \ \ \ \ ,e:-->
+" Remove the middlepart from the comments section, as this causes problems:
+" https://groups.google.com/d/msg/vim_dev/x4GT-nqa0Kg/jvtRnEbtAnMJ
+setlocal comments=s:<!--,e:-->
setlocal formatoptions-=t
-if !exists("g:ft_xml_autocomment") || (g:ft_xml_autocomment == 1)
- setlocal formatoptions+=croql
-endif
-
+setlocal formatoptions+=croql
+setlocal formatexpr=xmlformat#Format()
" XML: thanks to Johannes Zellner and Akbar Ibrahim
" - case sensitive
@@ -39,7 +41,6 @@ if exists("loaded_matchit")
\ '<\@<=\%([^ \t>/]\+\)\%(\s\+[^/>]*\|$\):/>'
endif
-"
" For Omni completion, by Mikolaj Machowski.
if exists('&ofu')
setlocal ofu=xmlcomplete#CompleteTags
@@ -47,17 +48,17 @@ endif
command! -nargs=+ XMLns call xmlcomplete#CreateConnection(<f-args>)
command! -nargs=? XMLent call xmlcomplete#CreateEntConnection(<f-args>)
-
" Change the :browse e filter to primarily show xml-related files.
-if has("gui_win32")
+if (has("gui_win32") || has("gui_gtk")) && !exists("b:browsefilter")
let b:browsefilter="XML Files (*.xml)\t*.xml\n" .
- \ "DTD Files (*.dtd)\t*.dtd\n" .
- \ "All Files (*.*)\t*.*\n"
+ \ "DTD Files (*.dtd)\t*.dtd\n" .
+ \ "XSD Files (*.xsd)\t*.xsd\n" .
+ \ "All Files (*.*)\t*.*\n"
endif
" Undo the stuff we changed.
-let b:undo_ftplugin = "setlocal commentstring< comments< formatoptions<" .
- \ " | unlet! b:match_ignorecase b:match_words b:browsefilter"
+let b:undo_ftplugin = "setlocal commentstring< comments< formatoptions< formatexpr< " .
+ \ " | unlet! b:match_ignorecase b:match_words b:browsefilter"
" Restore the saved compatibility options.
let &cpo = s:save_cpo
diff --git a/runtime/indent/sh.vim b/runtime/indent/sh.vim
index fd9a6a9c92..2a9688a4d7 100644
--- a/runtime/indent/sh.vim
+++ b/runtime/indent/sh.vim
@@ -3,7 +3,7 @@
" Maintainer: Christian Brabandt <cb@256bit.org>
" Previous Maintainer: Peter Aronoff <telemachus@arpinum.org>
" Original Author: Nikolai Weibull <now@bitwi.se>
-" Latest Revision: 2017-08-08
+" Latest Revision: 2018-05-12
" License: Vim (see :h license)
" Repository: https://github.com/chrisbra/vim-sh-indent
" Changelog:
@@ -59,12 +59,15 @@ function! GetShIndent()
if lnum == 0
return 0
endif
+ let line = getline(lnum)
let pnum = prevnonblank(lnum - 1)
-
+ let pline = getline(pnum)
let ind = indent(lnum)
- let line = getline(lnum)
- if line =~ '^\s*\%(if\|then\|do\|else\|elif\|case\|while\|until\|for\|select\|foreach\)\>'
+
+ " Check contents of previous lines
+ if line =~ '^\s*\%(if\|then\|do\|else\|elif\|case\|while\|until\|for\|select\|foreach\)\>' ||
+ \ (&ft is# 'zsh' && line =~ '\%(if\|then\|do\|else\|elif\|case\|while\|until\|for\|select\|foreach\)\>')
if line !~ '\<\%(fi\|esac\|done\|end\)\>\s*\%(#.*\)\=$'
let ind += s:indent_value('default')
endif
@@ -72,21 +75,35 @@ function! GetShIndent()
if !s:is_case_ended(line)
let ind += s:indent_value('case-statements')
endif
- elseif line =~ '^\s*\<\k\+\>\s*()\s*{' || line =~ '^\s*{' || line =~ '^\s*function\s*\w\S\+\s*\%(()\)\?\s*{'
+ " function definition
+ elseif s:is_function_definition(line)
if line !~ '}\s*\%(#.*\)\=$'
let ind += s:indent_value('default')
endif
elseif s:is_continuation_line(line)
- if pnum == 0 || !s:is_continuation_line(getline(pnum))
+ if pnum == 0 || !s:is_continuation_line(pline)
let ind += s:indent_value('continuation-line')
endif
- elseif pnum != 0 && s:is_continuation_line(getline(pnum))
- let ind = indent(s:find_continued_lnum(pnum))
+ elseif s:end_block(line) && !s:start_block(line)
+ let ind -= s:indent_value('default')
+ elseif pnum != 0 && s:is_continuation_line(pline) && !s:end_block(getline(v:lnum))
+ " only add indent, if line and pline is in the same block
+ let i = v:lnum
+ let ind2 = indent(s:find_continued_lnum(pnum))
+ while !s:is_empty(getline(i)) && i > pnum
+ let i -= 1
+ endw
+ if i == pnum
+ let ind += ind2
+ else
+ let ind = ind2
+ endif
endif
let pine = line
+ " Check content of current line
let line = getline(v:lnum)
- if line =~ '^\s*\%(then\|do\|else\|elif\|fi\|done\|end\)\>' || line =~ '^\s*}'
+ if line =~ '^\s*\%(then\|do\|else\|elif\|fi\|done\|end\)\>' || s:end_block(line)
let ind -= s:indent_value('default')
elseif line =~ '^\s*esac\>' && s:is_case_empty(getline(v:lnum - 1))
let ind -= s:indent_value('default')
@@ -112,14 +129,24 @@ function! GetShIndent()
" statements, executed within a here document. Keep the current indent
elseif match(map(synstack(v:lnum, 1), 'synIDattr(v:val, "name")'), '\c\mheredoc') > -1
return indent(v:lnum)
+ elseif s:is_comment(line) && s:is_empty(getline(v:lnum-1))
+ return indent(v:lnum)
endif
- return ind
+ return ind > 0 ? ind : 0
endfunction
function! s:is_continuation_line(line)
- return a:line =~ '\%(\%(^\|[^\\]\)\\\|&&\|||\||\)' .
+ " Comment, cannot be a line continuation
+ if a:line =~ '^\s*#'
+ return 0
+ else
+ " start-of-line
+ " \\ or && or || or |
+ " followed optionally by { or #
+ return a:line =~ '\%(\%(^\|[^\\]\)\\\|&&\|||\||\)' .
\ '\s*\({\s*\)\=\(#.*\)\=$'
+ endif
endfunction
function! s:find_continued_lnum(lnum)
@@ -130,6 +157,12 @@ function! s:find_continued_lnum(lnum)
return i
endfunction
+function! s:is_function_definition(line)
+ return a:line =~ '^\s*\<\k\+\>\s*()\s*{' ||
+ \ a:line =~ '^\s*{' ||
+ \ a:line =~ '^\s*function\s*\w\S\+\s*\%(()\)\?\s*{'
+endfunction
+
function! s:is_case_label(line, pnum)
if a:line !~ '^\s*(\=.*)'
return 0
@@ -195,5 +228,29 @@ function! s:escape(pattern)
return '\V'. escape(a:pattern, '\\')
endfunction
+function! s:is_empty(line)
+ return a:line =~ '^\s*$'
+endfunction
+
+function! s:end_block(line)
+ return a:line =~ '^\s*}'
+endfunction
+
+function! s:start_block(line)
+ return a:line =~ '{\s*\(#.*\)\?$'
+endfunction
+
+function! s:find_start_block(lnum)
+ let i = a:lnum
+ while i > 1 && !s:start_block(getline(i))
+ let i -= 1
+ endwhile
+ return i
+endfunction
+
+function! s:is_comment(line)
+ return a:line =~ '^\s*#'
+endfunction
+
let &cpo = s:cpo_save
unlet s:cpo_save
diff --git a/runtime/indent/tex.vim b/runtime/indent/tex.vim
index a748cfbb40..119a66c1b8 100644
--- a/runtime/indent/tex.vim
+++ b/runtime/indent/tex.vim
@@ -1,12 +1,16 @@
-" Vim indent file
-" Language: LaTeX
-" Maintainer: Yichao Zhou <broken.zhou AT gmail.com>
-" Created: Sat, 16 Feb 2002 16:50:19 +0100
-" Version: 1.0.0
+" Vim indent file for TeX
+" Language: TeX
+" Maintainer: Christian Brabandt <cb@256bit.org>
+" Previous Maintainer: YiChao Zhou <broken.zhou AT gmail.com>
+" Latest Revision: 2017-05-03
+" Version: 0.9.3
+" Repository: https://github.com/chrisbra/vim-tex-indent
+" Documention: :h ft-tex-indent
+" Created: Sat, 16 Feb 2002 16:50:19 +0100
" Please email me if you found something I can do. Comments, bug report and
" feature request are welcome.
-" Last Update: {{{
+" Last Update: {{{1
" 25th Sep 2002, by LH :
" (*) better support for the option
" (*) use some regex instead of several '||'.
@@ -15,122 +19,64 @@
" 2005/06/15, Moshe Kaminsky <kaminsky AT math.huji.ac.il>
" (*) New variables:
" g:tex_items, g:tex_itemize_env, g:tex_noindent_env
-" 2011/3/6, by Yichao Zhou <broken.zhou AT gmail.com>
+" 2011/3/6, by Zhou YiChao <broken.zhou AT gmail.com>
" (*) Don't change indentation of lines starting with '%'
" I don't see any code with '%' and it doesn't work properly
" so I add some code.
" (*) New features: Add smartindent-like indent for "{}" and "[]".
" (*) New variables: g:tex_indent_brace
-" 2011/9/25, by Yichao Zhou <broken.zhou AT gmail.com>
+" 2011/9/25, by Zhou Yichao <broken.zhou AT gmail.com>
" (*) Bug fix: smartindent-like indent for "[]"
" (*) New features: Align with "&".
" (*) New variable: g:tex_indent_and.
-" 2011/10/23 by Yichao Zhou <broken.zhou AT gmail.com>
+" 2011/10/23 by Zhou Yichao <broken.zhou AT gmail.com>
" (*) Bug fix: improve the smartindent-like indent for "{}" and
" "[]".
-" 2012/02/27 by Yichao Zhou <broken.zhou AT gmail.com>
+" 2012/02/27 by Zhou Yichao <broken.zhou AT gmail.com>
" (*) Bug fix: support default folding marker.
" (*) Indent with "&" is not very handy. Make it not enable by
" default.
-" 2012/03/06 by Yichao Zhou <broken.zhou AT gmail.com>
+" 2012/03/06 by Zhou Yichao <broken.zhou AT gmail.com>
" (*) Modify "&" behavior and make it default again. Now "&"
" won't align when there are more then one "&" in the previous
" line.
" (*) Add indent "\left(" and "\right)"
" (*) Trust user when in "verbatim" and "lstlisting"
-" 2012/03/11 by Yichao Zhou <broken.zhou AT gmail.com>
+" 2012/03/11 by Zhou Yichao <broken.zhou AT gmail.com>
" (*) Modify "&" so that only indent when current line start with
" "&".
-" 2012/03/12 by Yichao Zhou <broken.zhou AT gmail.com>
+" 2012/03/12 by Zhou Yichao <broken.zhou AT gmail.com>
" (*) Modify indentkeys.
-" 2012/03/18 by Yichao Zhou <broken.zhou AT gmail.com>
+" 2012/03/18 by Zhou Yichao <broken.zhou AT gmail.com>
" (*) Add &cpo
-" 2013/05/02 by Yichao Zhou <broken.zhou AT gmail.com>
+" 2013/05/02 by Zhou Yichao <broken.zhou AT gmail.com>
" (*) Fix problem about GetTeXIndent checker. Thank Albert Netymk
" for reporting this.
-" 2014/06/23 by Yichao Zhou <broken.zhou AT gmail.com>
+" 2014/06/23 by Zhou Yichao <broken.zhou AT gmail.com>
" (*) Remove the feature g:tex_indent_and because it is buggy.
" (*) If there is not any obvious indentation hints, we do not
" alert our user's current indentation.
" (*) g:tex_indent_brace now only works if the open brace is the
" last character of that line.
-" 2014/08/03 by Yichao Zhou <broken.zhou AT gmail.com>
+" 2014/08/03 by Zhou Yichao <broken.zhou AT gmail.com>
" (*) Indent current line if last line has larger indentation
-" 2016/11/08 by Yichao Zhou <broken.zhou AT gmail.com>
-" (*) Fix problems for \[ and \]. Thanks Bruno for reporting.
-" 2017/04/30 by Yichao Zhou <broken.zhou AT gmail.com>
-" (*) Fix a bug between g:tex_noindent_env and g:tex_indent_items
-" Now g:tex_noindent_env='document\|verbatim\|itemize' (Emacs
-" style) is supported. Thanks Miles Wheeler for reporting.
-" 2018/02/07 by Yichao Zhou <broken.zhou AT gmail.com>
-" (*) Make indentation more smart in the normal mode
+" 2014/08/09 by Zhou Yichao <broken.zhou AT gmail.com>
+" (*) Add missing return value for s:GetEndIndentation(...)
+" 2017/05/02: new maintainer Christian Brabandt
+" 2017/05/02: use shiftwidth() function
+" 2017/05/02: do not add indent when environment starts and ends
+" at previous line
+" 2017/05/03: release 0.9.3 submitted for inclusion with Vim
"
" }}}
-
-" Document: {{{
-"
-" To set the following options (ok, currently it's just one), add a line like
-" let g:tex_indent_items = 1
-" to your ~/.vimrc.
-"
-" * g:tex_indent_brace
-"
-" If this variable is unset or non-zero, it will use smartindent-like style
-" for "{}" and "[]". Now this only works if the open brace is the last
-" character of that line.
-"
-" % Example 1
-" \usetikzlibrary{
-" external
-" }
-"
-" % Example 2
-" \tikzexternalize[
-" prefix=tikz]
-"
-" * g:tex_indent_items
-"
-" If this variable is set, item-environments are indented like Emacs does
-" it, i.e., continuation lines are indented with a shiftwidth.
-"
-" set unset
-" ------------------------------------------------------
-" \begin{itemize} \begin{itemize}
-" \item blablabla \item blablabla
-" bla bla bla bla bla bla
-" \item blablabla \item blablabla
-" bla bla bla bla bla bla
-" \end{itemize} \end{itemize}
-"
-"
-" * g:tex_items
-"
-" A list of tokens to be considered as commands for the beginning of an item
-" command. The tokens should be separated with '\|'. The initial '\' should
-" be escaped. The default is '\\bibitem\|\\item'.
-"
-" * g:tex_itemize_env
-"
-" A list of environment names, separated with '\|', where the items (item
-" commands matching g:tex_items) may appear. The default is
-" 'itemize\|description\|enumerate\|thebibliography'.
-"
-" * g:tex_noindent_env
-"
-" A list of environment names. separated with '\|', where no indentation is
-" required. The default is 'document\|verbatim'.
-" }}}
-
-" Only define the function once
+" Only define the function once {{{1
if exists("b:did_indent")
finish
endif
let s:cpo_save = &cpo
set cpo&vim
-
-" Define global variable {{{
-
+" Define global variable {{{1
let b:did_indent = 1
if !exists("g:tex_indent_items")
@@ -147,7 +93,7 @@ if g:tex_indent_items
let g:tex_itemize_env = 'itemize\|description\|enumerate\|thebibliography'
endif
if !exists('g:tex_items')
- let g:tex_items = '\\bibitem\|\\item'
+ let g:tex_items = '\\bibitem\|\\item'
endif
else
let g:tex_items = ''
@@ -156,17 +102,17 @@ endif
if !exists("g:tex_noindent_env")
let g:tex_noindent_env = 'document\|verbatim\|lstlisting'
endif "}}}
-
-" VIM Setting " {{{
+" VIM Setting " {{{1
setlocal autoindent
setlocal nosmartindent
setlocal indentexpr=GetTeXIndent()
setlocal indentkeys&
exec 'setlocal indentkeys+=[,(,{,),},],\&' . substitute(g:tex_items, '^\|\(\\|\)', ',=', 'g')
let g:tex_items = '^\s*' . substitute(g:tex_items, '^\(\^\\s\*\)*', '', '')
-" }}}
-function! GetTeXIndent() " {{{
+let b:undo_indent = 'setlocal indentexpr< indentkeys< smartindent< autoindent<'
+" }}}
+function! GetTeXIndent() " {{{1
" Find a non-blank line above the current line.
let lnum = prevnonblank(v:lnum - 1)
let cnum = v:lnum
@@ -178,7 +124,7 @@ function! GetTeXIndent() " {{{
" At the start of the file use zero indent.
if lnum == 0
- return 0
+ return 0
endif
let line = substitute(getline(lnum), '\s*%.*', '','g') " last line
@@ -192,9 +138,9 @@ function! GetTeXIndent() " {{{
return indent(v:lnum)
end
endif
-
+
if lnum == 0
- return 0
+ return 0
endif
let ind = indent(lnum)
@@ -205,16 +151,12 @@ function! GetTeXIndent() " {{{
return indent(v:lnum)
endif
- " Add a 'shiftwidth' after beginning of environments.
- " Don't add it for \begin{document} and \begin{verbatim}
- " if line =~ '^\s*\\begin{\(.*\)}' && line !~ 'verbatim'
- " LH modification : \begin does not always start a line
- " ZYC modification : \end after \begin won't cause wrong indent anymore
- if line =~ '\\begin{.*}'
- if line !~ g:tex_noindent_env
- let ind = ind + shiftwidth()
- let stay = 0
- endif
+ " Add a 'shiftwidth' after beginning of environments
+ " But don't do it for g:tex_noindent_env or when it also ends at the
+ " previous line.
+ if line =~ '\\begin{.*}' && line !~ '\\end{.*}' && line !~ g:tex_noindent_env
+ let ind = ind + shiftwidth()
+ let stay = 0
if g:tex_indent_items
" Add another sw for item-environments
@@ -248,27 +190,29 @@ function! GetTeXIndent() " {{{
endif
if g:tex_indent_brace
- if line =~ '[[{]$'
+ let char = line[strlen(line)-1]
+ if char == '[' || char == '{'
let ind += shiftwidth()
let stay = 0
endif
- if cline =~ '^\s*\\\?[\]}]' && s:CheckPairedIsLastCharacter(v:lnum, indent(v:lnum))
+ let cind = indent(v:lnum)
+ let char = cline[cind]
+ if (char == ']' || char == '}') &&
+ \ s:CheckPairedIsLastCharacter(v:lnum, cind)
let ind -= shiftwidth()
let stay = 0
endif
- if line !~ '^\s*\\\?[\]}]'
- for i in range(indent(lnum)+1, strlen(line)-1)
- let char = line[i]
- if char == ']' || char == '}'
- if s:CheckPairedIsLastCharacter(lnum, i)
- let ind -= shiftwidth()
- let stay = 0
- endif
+ for i in range(indent(lnum)+1, strlen(line)-1)
+ let char = line[i]
+ if char == ']' || char == '}'
+ if s:CheckPairedIsLastCharacter(lnum, i)
+ let ind -= shiftwidth()
+ let stay = 0
endif
- endfor
- endif
+ endif
+ endfor
endif
" Special treatment for 'item'
@@ -287,9 +231,8 @@ function! GetTeXIndent() " {{{
endif
endif
- if stay && mode() == 'i'
- " If there is no obvious indentation hint, and indentation is triggered
- " in insert mode, we trust our user.
+ if stay
+ " If there is no obvious indentation hint, we trust our user.
if empty(cline)
return ind
else
@@ -299,8 +242,7 @@ function! GetTeXIndent() " {{{
return ind
endif
endfunction "}}}
-
-function! s:GetLastBeginIndentation(lnum) " {{{
+function! s:GetLastBeginIndentation(lnum) " {{{1
let matchend = 1
for lnum in range(a:lnum-1, max([a:lnum - g:tex_max_scan_line, 1]), -1)
let line = getline(lnum)
@@ -311,19 +253,19 @@ function! s:GetLastBeginIndentation(lnum) " {{{
let matchend -= 1
endif
if matchend == 0
- if line =~ g:tex_noindent_env
- return indent(lnum)
- endif
if line =~ g:tex_itemize_env
return indent(lnum) + 2 * shiftwidth()
endif
+ if line =~ g:tex_noindent_env
+ return indent(lnum)
+ endif
return indent(lnum) + shiftwidth()
endif
endfor
return -1
endfunction
-function! s:GetEndIndentation(lnum) " {{{
+function! s:GetEndIndentation(lnum) " {{{1
if getline(a:lnum) =~ '\\begin{.*}.*\\end{.*}'
return -1
endif
@@ -350,1