Skip to content

Commit 30bd0e1

Browse files
committed
Merge remote-tracking branch 'vim/master'
2 parents 3214b9e + 9cfc7d8 commit 30bd0e1

51 files changed

Lines changed: 8634 additions & 274 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

runtime/autoload/xmlformat.vim

Lines changed: 112 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,112 @@
1+
" Vim plugin for formatting XML
2+
" Last Change: Thu, 15 Jan 2015 21:26:55 +0100
3+
" Version: 0.1
4+
" Author: Christian Brabandt <[email protected]>
5+
" Script: http://www.vim.org/scripts/script.php?script_id=
6+
" License: VIM License
7+
" GetLatestVimScripts: ???? 18 :AutoInstall: xmlformat.vim
8+
" Documentation: see :h xmlformat.txt (TODO!)
9+
" ---------------------------------------------------------------------
10+
" Load Once: {{{1
11+
if exists("g:loaded_xmlformat") || &cp
12+
finish
13+
endif
14+
let g:loaded_xmlformat = 1
15+
let s:keepcpo = &cpo
16+
set cpo&vim
17+
18+
" Main function: Format the input {{{1
19+
func! xmlformat#Format()
20+
" only allow reformatting through the gq command
21+
" (e.g. Vim is in normal mode)
22+
if mode() != 'n'
23+
" do not fall back to internal formatting
24+
return 0
25+
endif
26+
let sw = shiftwidth()
27+
let prev = prevnonblank(v:lnum-1)
28+
let s:indent = indent(prev)/sw
29+
let result = []
30+
let lastitem = prev ? getline(prev) : ''
31+
let is_xml_decl = 0
32+
" split on `<`, but don't split on very first opening <
33+
for item in split(getline(v:lnum), '.\@<=[>]\zs')
34+
if s:EndTag(item)
35+
let s:indent = s:DecreaseIndent()
36+
call add(result, s:Indent(item))
37+
elseif s:EmptyTag(lastitem)
38+
call add(result, s:Indent(item))
39+
elseif s:StartTag(lastitem) && s:IsTag(item)
40+
let s:indent += 1
41+
call add(result, s:Indent(item))
42+
else
43+
if !s:IsTag(item)
44+
" Simply split on '<'
45+
let t=split(item, '.<\@=\zs')
46+
let s:indent+=1
47+
call add(result, s:Indent(t[0]))
48+
let s:indent = s:DecreaseIndent()
49+
call add(result, s:Indent(t[1]))
50+
else
51+
call add(result, s:Indent(item))
52+
endif
53+
endif
54+
let lastitem = item
55+
endfor
56+
57+
if !empty(result)
58+
exe v:lnum. ",". (v:lnum + v:count - 1). 'd'
59+
call append(v:lnum - 1, result)
60+
" Might need to remove the last line, if it became empty because of the
61+
" append() call
62+
let last = v:lnum + len(result)
63+
if getline(last) is ''
64+
exe last. 'd'
65+
endif
66+
endif
67+
68+
" do not run internal formatter!
69+
return 0
70+
endfunc
71+
" Check if given tag is XML Declaration header {{{1
72+
func! s:IsXMLDecl(tag)
73+
return a:tag =~? '^\s*<?xml\s\?\%(version="[^"]*"\)\?\s\?\%(encoding="[^"]*"\)\? ?>\s*$'
74+
endfunc
75+
" Return tag indented by current level {{{1
76+
func! s:Indent(item)
77+
return repeat(' ', shiftwidth()*s:indent). s:Trim(a:item)
78+
endfu
79+
" Return item trimmed from leading whitespace {{{1
80+
func! s:Trim(item)
81+
if exists('*trim')
82+
return trim(a:item)
83+
else
84+
return matchstr(a:item, '\S\+.*')
85+
endif
86+
endfunc
87+
" Check if tag is a new opening tag <tag> {{{1
88+
func! s:StartTag(tag)
89+
return a:tag =~? '^\s*<[^/?]'
90+
endfunc
91+
" Remove one level of indentation {{{1
92+
func! s:DecreaseIndent()
93+
return (s:indent > 0 ? s:indent - 1 : 0)
94+
endfunc
95+
" Check if tag is a closing tag </tag> {{{1
96+
func! s:EndTag(tag)
97+
return a:tag =~? '^\s*</'
98+
endfunc
99+
" Check that the tag is actually a tag and not {{{1
100+
" something like "foobar</foobar>"
101+
func! s:IsTag(tag)
102+
return s:Trim(a:tag)[0] == '<'
103+
endfunc
104+
" Check if tag is empty <tag/> {{{1
105+
func! s:EmptyTag(tag)
106+
return a:tag =~ '/>\s*$'
107+
endfunc
108+
" Restoration And Modelines: {{{1
109+
let &cpo= s:keepcpo
110+
unlet s:keepcpo
111+
" Modeline {{{1
112+
" vim: fdm=marker fdl=0 ts=2 et sw=0 sts=-1

runtime/doc/change.txt

Lines changed: 50 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
*change.txt* For Vim version 8.0. Last change: 2018 May 06
1+
*change.txt* For Vim version 8.0. Last change: 2018 May 12
22

33

44
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
14451445
'textwidth' and other options have no effect on formatting by an external
14461446
program.
14471447

1448+
*format-formatexpr*
1449+
The 'formatexpr' option can be set to a Vim Script function that performs
1450+
reformatting of the buffer. This should usually happen in an |ftplugin|,
1451+
since formatting is highly dependent on the type of file. It makes
1452+
sense to use an |autoload| script, so the corresponding script is only loaded
1453+
when actually needed and the script should be called <filetype>format.vim.
1454+
1455+
For example, the XML filetype plugin distributed with Vim in the $VIMRUNTIME
1456+
directory, sets the 'formatexpr' option to: >
1457+
1458+
setlocal formatexpr=xmlformat#Format()
1459+
1460+
That means, you will find the corresponding script, defining the
1461+
xmlformat#Format() function, in the directory:
1462+
`$VIMRUNTIME/autoload/xmlformat.vim`
1463+
1464+
Here is an example script that removes trailing whitespace from the selected
1465+
text. Put it in your autoload directory, e.g. ~/.vim/autoload/format.vim: >
1466+
1467+
func! format#Format()
1468+
" only reformat on explicit gq command
1469+
if mode() != 'n'
1470+
" fall back to Vims internal reformatting
1471+
return 1
1472+
endif
1473+
let lines = getline(v:lnum, v:lnum + v:count - 1)
1474+
call map(lines, {key, val -> substitute(val, '\s\+$', '', 'g')})
1475+
call setline('.', lines)
1476+
1477+
" do not run internal formatter!
1478+
return 0
1479+
endfunc
1480+
1481+
You can then enable the formatting by executing: >
1482+
setlocal formatexpr=format#Format()
1483+
>
1484+
Note: this function explicitly returns non-zero when called from insert mode
1485+
(which basically means, text is inserted beyond the 'textwidth' limit). This
1486+
causes Vim to fall back to reformat the text by using the internal formatter.
1487+
1488+
However, if the |gq| command is used to reformat the text, the function
1489+
will receive the selected lines, trim trailing whitespace from those lines and
1490+
put them back in place. If you are going to split single lines into multiple
1491+
lines, be careful not to overwrite anything.
1492+
1493+
If you want to allow reformatting of text from insert or replace mode, one has
1494+
to be very careful, because the function might be called recursively. For
1495+
debugging it helps to set the 'debug' option.
1496+
14481497
*right-justify*
14491498
There is no command in Vim to right justify text. You can do it with
14501499
an external command, like "par" (e.g.: "!}par" to format until the end of the

runtime/doc/cmdline.txt

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
*cmdline.txt* For Vim version 8.0. Last change: 2017 Oct 19
1+
*cmdline.txt* For Vim version 8.0. Last change: 2018 May 10
22

33

44
VIM REFERENCE MANUAL by Bram Moolenaar
@@ -412,14 +412,17 @@ CTRL-D List names that match the pattern in front of the cursor.
412412
match is inserted. After the last match, the first is used
413413
again (wrap around).
414414
The behavior can be changed with the 'wildmode' option.
415+
*c_<S-Tab>*
416+
<S-Tab> Like 'wildchar' or <Tab>, but begin with the last match and
417+
then go to the previous match.
418+
<S-Tab> does not work everywhere.
415419
*c_CTRL-N*
416420
CTRL-N After using 'wildchar' which got multiple matches, go to next
417421
match. Otherwise recall more recent command-line from history.
418-
<S-Tab> *c_CTRL-P* *c_<S-Tab>*
422+
*c_CTRL-P*
419423
CTRL-P After using 'wildchar' which got multiple matches, go to
420424
previous match. Otherwise recall older command-line from
421-
history. <S-Tab> only works with the GUI, on the Amiga and
422-
with MS-DOS.
425+
history.
423426
*c_CTRL-A*
424427
CTRL-A All names that match the pattern in front of the cursor are
425428
inserted.

runtime/doc/eval.txt

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
*eval.txt* For Vim version 8.0. Last change: 2018 Apr 28
1+
*eval.txt* For Vim version 8.0. Last change: 2018 May 13
22

33

44
VIM REFERENCE MANUAL by Bram Moolenaar
@@ -9943,6 +9943,14 @@ This does NOT work: >
99439943
variables are automatically deleted when the function
99449944
ends.
99459945

9946+
:unl[et] ${env-name} ... *:unlet-environment* *:unlet-$*
9947+
Remove environment variable {env-name}.
9948+
Can mix {name} and ${env-name} in one :unlet command.
9949+
No error message is given for a non-existing
9950+
variable, also without !.
9951+
If the system does not support deleting an environment
9952+
variable, it is made emtpy.
9953+
99469954
:lockv[ar][!] [depth] {name} ... *:lockvar* *:lockv*
99479955
Lock the internal variable {name}. Locking means that
99489956
it can no longer be changed (until it is unlocked).

runtime/doc/map.txt

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
*map.txt* For Vim version 8.0. Last change: 2018 May 06
1+
*map.txt* For Vim version 8.0. Last change: 2018 May 13
22

33

44
VIM REFERENCE MANUAL by Bram Moolenaar
@@ -917,7 +917,9 @@ an additional rule:
917917
full-id In front of the match is a non-keyword character, or this is where
918918
the line or insertion starts. Exception: When the abbreviation is
919919
only one character, it is not recognized if there is a non-keyword
920-
character in front of it, other than a space or a tab.
920+
character in front of it, other than a space or a tab. However, for
921+
the command line "'<,'>" (or any other marks) is ignored, as if the
922+
command line starts after it.
921923

922924
end-id In front of the match is a keyword character, or a space or a tab,
923925
or this is where the line or insertion starts.

runtime/doc/tags

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3228,6 +3228,8 @@ $VIM_POSIX vi_diff.txt /*$VIM_POSIX*
32283228
:unhide windows.txt /*:unhide*
32293229
:unl eval.txt /*:unl*
32303230
:unlet eval.txt /*:unlet*
3231+
:unlet-$ eval.txt /*:unlet-$*
3232+
:unlet-environment eval.txt /*:unlet-environment*
32313233
:unlo eval.txt /*:unlo*
32323234
:unlockvar eval.txt /*:unlockvar*
32333235
:unm map.txt /*:unm*
@@ -6197,6 +6199,7 @@ fork os_unix.txt /*fork*
61976199
form.vim syntax.txt /*form.vim*
61986200
format-bullet-list tips.txt /*format-bullet-list*
61996201
format-comments change.txt /*format-comments*
6202+
format-formatexpr change.txt /*format-formatexpr*
62006203
formatting change.txt /*formatting*
62016204
formfeed intro.txt /*formfeed*
62026205
fortran.vim syntax.txt /*fortran.vim*

runtime/doc/terminal.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
*terminal.txt* For Vim version 8.0. Last change: 2018 May 04
1+
*terminal.txt* For Vim version 8.0. Last change: 2018 May 11
22

33

44
VIM REFERENCE MANUAL by Bram Moolenaar
@@ -317,7 +317,7 @@ the job ends while in Terminal-Normal mode this changes to
317317
When the job outputs lines in the terminal, such that the contents scrolls off
318318
the top, those lines are remembered and can be seen in Terminal-Normal mode.
319319
The number of lines is limited by the 'termwinscroll' option. When going over
320-
this limit, the first 10% of the scrolled lins are deleted and are lost.
320+
this limit, the first 10% of the scrolled lines are deleted and are lost.
321321

322322

323323
Cursor style ~

0 commit comments

Comments
 (0)