1
0
mirror of https://github.com/SpaceVim/SpaceVim.git synced 2025-04-14 15:19:12 +08:00

Improve lang#asciidoc layer (#3775)

This commit is contained in:
Wang Shidong 2020-09-06 21:56:12 +08:00 committed by GitHub
parent 5ff1277666
commit 79facb9a64
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
36 changed files with 2144 additions and 11 deletions

View File

@ -19,15 +19,31 @@
func! SpaceVim#layers#lang#asciidoc#plugins() abort
return [
\ ['wsdjeg/vim-asciidoc', {'merged' : 0}],
\ ['Raimondi/VimRegStyle', {'merged' : 0}],
\ [g:_spacevim_root_dir . 'bundle/vim-asciidoc', {'merged' : 0}],
\ [g:_spacevim_root_dir . 'bundle/VimRegStyle', {'merged' : 0}],
\ ]
endf
function! SpaceVim#layers#lang#asciidoc#config() abort
" tagbar configuration
"
let g:tagbar_type_asciidoc = {
\ 'ctagstype' : 'asciidoc',
\ 'kinds' : [
\ 'h:table of contents',
\ 'a:anchors:1',
\ 't:titles:1',
\ 'n:includes:1',
\ 'i:images:1',
\ 'I:inline images:1'
\ ],
\ 'deffile': g:_spacevim_root_dir . 'bundle/vim-asciidoc/ctags/asciidoc.conf' ,
\ 'sort' : 0
\ }
endfunction
" https://asciidoctor.org/docs/editing-asciidoc-with-live-preview/
" VimRegStyle based on https://github.com/Raimondi/VimRegStyle/commit/771e32e659b345cf29993d517e08b6b3f741f9c6
" vim-asciidoc is based on https://github.com/wsdjeg/vim-asciidoc/

2
bundle/VimRegStyle/.gitignore vendored Normal file
View File

@ -0,0 +1,2 @@
test/*.msgout
test/*.tap

View File

@ -0,0 +1,7 @@
VimRegStyle
-----------
__Ohhh, Sexy Regex!__
VimRegStyle is a Regular Expression Pattern Library and suite of utilities for
operating on matches within text.

1
bundle/VimRegStyle/TODO Normal file
View File

@ -0,0 +1 @@
* Allow user patterns in ~/.vim/patterns/

View File

@ -0,0 +1,106 @@
" Vim library for short description
" Maintainer: Barry Arthur <barry.arthur@gmail.com>
" Israel Chauca F. <israelchauca@gmail.com>
" Version: 0.1
" Description: Long description.
" Last Change: 2013-02-03
" License: Vim License (see :help license)
" Location: autoload/extended_regex.vim
" Website: https://github.com/Raimondi/extended_regex
"
" See extended_regex.txt for help. This can be accessed by doing:
"
" :helptags ~/.vim/doc
" :help extended_regex
" Vimscript Setup: {{{1
" Allow use of line continuation.
let s:save_cpo = &cpo
set cpo&vim
" load guard
" uncomment after plugin development
" Remove the conditions you do not need, they are there just as an example.
"if exists("g:loaded_lib_extended_regex")
" \ || v:version < 700
" \ || v:version == 703 && !has('patch338')
" \ || &compatible
" let &cpo = s:save_cpo
" finish
"endif
"let g:loaded_lib_extended_regex = 1
" Private Functions: {{{1
" Library Interface: {{{1
function! extended_regex#ExtendedRegex(...)
let erex = {}
let erex.lookup_function = ''
let erex.lookup_dict = {}
func erex.default_lookup(name) dict
return eval(a:name)
endfunc
"TODO: revisit this with eval() solution
func erex.lookup(name) dict
if empty(self.lookup_function)
return call(self.default_lookup, [a:name], self)
else
"TODO: this 'self' dict arg needs to be the object's self...
return call(self.lookup_function, [a:name], self.lookup_dict)
endif
endfunc
func erex.expand_composition_atom(ext_reg) dict
let ext_reg = a:ext_reg
let composition_atom = '\\%{\s*\([^,} \t]\+\)\%(\s*,\s*\(\d\+\)\%(\s*,\s*\(.\{-}\)\)\?\)\?\s*}'
let remaining = match(ext_reg, composition_atom)
while remaining != -1
let [_, name, cnt, sep ;__] = matchlist(ext_reg, composition_atom)
let cnt = cnt ? cnt : 1
let sep = escape(escape(sep, '.*[]$^'), '\\')
let pattern = escape(self.lookup(name), '\\' )
let ext_reg = substitute(ext_reg, composition_atom, join(repeat([pattern], cnt), sep), '')
let remaining = match(ext_reg, composition_atom)
endwhile
return ext_reg
endfunc
func erex.expand(ext_reg) dict
return self.expand_composition_atom(a:ext_reg)
endfunc
func erex.parse_multiline_regex(ext_reg) dict
return substitute(substitute(substitute(a:ext_reg, '#\s\+\S\+', '', 'g'), '\\\@<! ', '', 'g'), '\(\\\\\)\@<=\zs\s\+', '', 'g')
endfunc
" common public API
func erex.register_lookup(callback) dict
let self.lookup_function = a:callback
endfunc
func erex.register_lookup_dict(dict) dict
let self.lookup_dict = a:dict
endfunc
func erex.parse(ext_reg) dict
return self.expand(self.parse_multiline_regex(a:ext_reg))
endfunc
if a:0
call erex.register_lookup(a:1)
if a:0 > 1
call erex.register_lookup_dict(a:2)
endif
endif
return erex
endfunction
" Teardown:{{{1
"reset &cpo back to users setting
let &cpo = s:save_cpo
" vim: set sw=2 sts=2 et fdm=marker:

View File

@ -0,0 +1,196 @@
" Vim library for short description
" Maintainer: Barry Arthur <barry.arthur@gmail.com>
" Israel Chauca F. <israelchauca@gmail.com>
" Version: 0.1
" Description: Long description.
" Last Change: 2013-02-03
" License: Vim License (see :help license)
" Location: autoload/vrs.vim
" Website: https://github.com/Raimondi/vrs
"
" See vrs.txt for help. This can be accessed by doing:
"
" :helptags ~/.vim/doc
" :help vrs
" Vimscript Setup: {{{1
" Allow use of line continuation.
let s:save_cpo = &cpo
set cpo&vim
" load guard
" uncomment after plugin development
" Remove the conditions you do not need, they are there just as an example.
"if exists("g:loaded_lib_vrs")
" \ || v:version < 700
" \ || v:version == 703 && !has('patch338')
" \ || &compatible
" let &cpo = s:save_cpo
" finish
"endif
"let g:loaded_lib_vrs = 1
" Private Functions: {{{1
" Library Interface: {{{1
let s:vrs_patterns = {}
let s:erex = ExtendedRegexObject('vrs#get')
let g:vrs_collection = []
let g:vrs_collection_stack = []
function! vrs#set(name, flavour, pattern)
if !has_key(s:vrs_patterns, a:name)
let s:vrs_patterns[a:name] = {}
endif
if has_key(s:vrs_patterns[a:name], a:flavour)
echohl ErrorMsg
echom 'VRS: A pattern of that flavour ('.a:flavour.') already exists under "'.a:name.'".'
echohl None
return 0
endif
" let s:vrs_patterns[a:name][a:flavour] = (a:flavour == 'vim' ? s:erex.parse(a:pattern) : s:erex.parse_multiline_regex(a:pattern))
let s:vrs_patterns[a:name][a:flavour] = (a:flavour == 'vim' ? s:erex.parse(a:pattern) : a:pattern)
return 1
endfunction
function! vrs#get(name, ...)
let flavor = a:0 ? a:1 : 'vim'
" Allow using a list of names as well.
return type(a:name) == type("")
\ ? get(get(s:vrs_patterns, a:name, {}), flavor, '')
\ : map(a:name, 's:vrs_patterns[v:val].' . flavor)
endfunction
function! vrs#match(string, pattern, ...)
let args = extend([a:string, vrs#get(a:pattern)], a:000)
return call('match', args)
endfunction
function! vrs#matchend(string, pattern, ...)
let args = extend([a:string, vrs#get(a:pattern)], a:000)
return call('matchend', args)
endfunction
function! vrs#matches(string, pattern, ...)
return call('vrs#match', extend([a:string, a:pattern], a:000)) != -1
endfunction
function! vrs#exactly(string, pattern, ...)
return (call('vrs#match', extend([a:string, a:pattern], a:000)) == 0) && (call('vrs#matchend', extend([a:string, a:pattern], a:000)) == (len(a:string)))
endfunction
" XXX Should these two return the filtered dict or just a list of keys?
function! vrs#from_partial(partial)
return keys(filter(copy(s:vrs_patterns), 'stridx(v:key, a:partial) > -1'))
endfunction
function! vrs#from_sample(sample)
return keys(filter(copy(s:vrs_patterns), 'a:sample =~# v:val.vim'))
endfunction
" operate on each match within a string
" TODO: allow this to work over a range
" perhaps make the default callback be a new collection
" example: :call vrs#each(getline(1, '$'), 'ip4', 'vrs#collect')
function! vrs#each(source, pattern, callback)
let pattern = vrs#get(a:pattern)
let remaining = match(a:source, pattern)
while remaining != -1
call call(a:callback, [matchlist(a:source, vrs#get(a:pattern), remaining)])
let remaining = match(a:source, pattern, 1 + remaining)
endwhile
endfunction
" callback for adding to the current collection
function! vrs#collect(item)
call add(g:vrs_collection, a:item)
endfunction
" reset the current collection
function! vrs#delete_collection()
let g:vrs_collection = []
endfunction
" extract a common submatch from the collection (defaults to 0 - the whole match)
function! vrs#slice_collection(...)
let submatch = a:0 ? a:1 : 0
return map(copy(g:vrs_collection), 'v:val[' . submatch . ']')
endfunction
" dump the collection submatch (default 0) at cursor point
function! vrs#append_collection(...)
call append('.', call('vrs#slice_collection', a:000))
endfunction
" save this collection on the stack
function! vrs#push_collection()
call add(g:vrs_collection_stack, g:vrs_collection)
endfunction
" save this collection and clear it ready for new collection
function! vrs#new_collection()
call vrs#push_collection()
call vrs#delete_collection()
endfunction
" restore a saved collection
function! vrs#pop_collection()
if len(g:vrs_collection_stack) > 0
let g:vrs_collection = remove(g:vrs_collection_stack, 0)
else
let g:vrs_collection = []
endif
endfunction
" TODO: Add commands for the collection functions to make them simpler to use
" load VRS patterns
let erex = ExtendedRegexObject('vrs#get')
for pfile in split(glob(expand('<sfile>:p:h:h') . '/patterns/*.vrs'), "\n")
" skip syntax test file
if fnamemodify(pfile, ':t') == 'test.vrs'
continue
endif
" echo fnamemodify(pfile, ':t')
let [name, flavour, pattern] = ['', '', '']
for line in readfile(pfile)
" skip blank and comment only lines
if line =~ '^\s*\(#\|$\)'
continue
endif
" name lines must be flush to first column (no leading spaces)
if line =~ '^\S'
" strip trailing comments
let line = substitute(line, '\s*#.*', '', '')
if !empty(name)
" finalise & add prior multiline pattern
" echo 'call vrs#set(' . name . ' ' . flavour . ' ' . erex.parse(pattern) . ')'
call vrs#set(name, flavour, pattern)
let [name, flavour, pattern] = ['', '', '']
endif
if line =~ '\s\+\S\+\s\+\S'
let [all, name, flavour, pattern ;rest] = matchlist(line, '^\(\S\+\)\s\+\(\S\+\)\s\+\(.*\)')
" echo 'call vrs#set(' . name . ' ' . flavour . ' ' . erex.parse(pattern) . ')'
call vrs#set(name, flavour, pattern)
let [name, flavour, pattern] = ['', '', '']
else
let [all, name, flavour ;rest] = matchlist(line, '^\s*\(\S\+\)\s\+\(\S\+\)')
let pattern = ''
endif
else
" collect multiline pattern - each line must be preceded by spaces
let pattern .= line
endif
endfor
if !empty(name)
" echo 'call vrs#set(' . name . ' ' . flavour . ' ' . erex.parse(pattern) . ')'
call vrs#set(name, flavour, pattern)
endif
endfor
" Teardown:{{{1
"reset &cpo back to users setting
let &cpo = s:save_cpo
" vim: set sw=2 sts=2 et fdm=marker:

View File

@ -0,0 +1,129 @@
*vimregstyle.txt* Extended regular expressions & pattern library
VIM REFERENCE MANUAL by Barry Arthur
Help on using vimregstyle *vimregstyle*
1. Introduction |vimregstyle-intro|
2. Functions |vimregstyle-functions|
3. Patterns |vimregstyle-patterns|
4. External Resources |vimregstyle-resources|
==============================================================================
1. INTRODUCTION *vimregstyle-intro*
VimRegStyle is a Regular Expression Pattern Library and suite of
utilities for operating on matches within text.
==============================================================================
2. FUNCTIONS *vimregstyle-functions*
VimRegStyle maintains an internal library of named patterns. This section
details the public interface for that library.
*vimregstyle-set*
vrs#set({name}, {flavour}, {pattern})
Used to add new patterns to the library. {flavour} should be either 'vim' or
'pcre'. There is a single namespace per {flavour} for all VimRegStyle patterns
and attempting to add a pattern with a name that already exists in the library
will generate an error message like:
*Error* VRS: A pattern of that flavour (vim) already exists under "ip4".
NOTE: Casual users will almost never use the |vrs#set()| function. The better
way to add patterns is through additions to the |vrs-files|. See
|vimregstyle-contribute| for contributing patterns back to the library.
*vimregstyle-get*
vrs#get({name}[, {flavour}='vim')
Get the pattern for the given {name} and {flavour} (defaulting to 'vim').
*vimregstyle-match*
vrs#match({string}, {named-pattern} [, {start}[, {count}]])
Replica of builtin |match()| function.
*vimregstyle-matchend*
vrs#matchend({string}, {named-pattern} [, {start}[, {count}]])
Replica of builtin |matchend()| function.
*vimregstyle-matches*
vrs#matches({string}, {named-pattern} [, {start}[, {count}]])
Predicate returning true if {string} contains {named-pattern} anywhere within
it. Anchoring to the start and end of the {string} will only occur if the
{named-pattern} specifically includes the associated anchors. Use
|vrs#exactly()| to force an anchored match.
*vimregstyle-exactly*
vrs#exactly({string}, {named-pattern} [, {start}[, {count}]])
Predicate returning true if {string} exactly matches {named-pattern}. Use
|vrs#matches()| to check if the {string} contains the {named-pattern} anywhere
within the {string}.
==============================================================================
*vrs-files*
3. PATTERNS *vimregstyle-patterns*
The patterns are stored in {*.vrs} files within the plugin's
{/patterns/} directory. The {.vrs} files have the following format:
name flavour pattern ~
Where:~
* {name} contains no whitespace and must not be preceded by whitespace
* {flavour} can be {vim} or {pcre}
* {pattern} is not delimiteduse a bare regex
The patterns are further enhanced in that they:
* Accept PCRE style multiline, whitespace insensitive syntax. All multiline
patterns must commence on the line below the named entry and must be
indented with whitespace.
* Accept a new regex atom: \%{name,count,separator} providing pattern
composition by inline-expanding the {name}d pattern at the current point in
the regex optionally {count} times, each one separated by {separator} (which
is a multicharacter string literal, not using regular syntax).
Example:~
Assuming the VRS library had a pattern called <_ip4_segment>
that represented a single 0-255 chunk, an <ip4> regex could then be written
using this composition atom as:
>
ip4 vim \<\%{_ip4_segment,4,.}>
<
Which would concatenate four copies of the <_ip4_segment> partial pattern,
each separated by the literal string '.'.
------------------------------------------------------------------------------
*vimregstyle-contribute*
Pattern contributors can submit additional patterns to VimRegStyle through
pull requests on the main Github repository:
https://github.com/Raimondi/VimRegStyle
Please ensure that all patterns are accompanied with tests. VimRegStyle uses
the runVimTests (https://github.com/vim-scripts/runVimTests) unit testing
framework.
*TODO* Allow user-crafted patterns in a nominal directory (defaulting
to ~/.vim/patterns/ ?)
==============================================================================
4. EXTERNAL RESOURCES *vimregstyle-resources*
* http://www.regexlib.com/
* http://www.programmersheaven.com/2/Regex
* http://www.asiteaboutnothing.net/regex/
vim:tw=78:ts=8:ft=help:norl:

View File

@ -0,0 +1,16 @@
" Vim filetype detect plugin for filetype name.
" Maintainer: Barry Arthur <barry.arthur@gmail.com>
" Israel Chauca F. <israelchauca@gmail.com>
" Version: 0.1
" Description: Long description.
" Last Change: 2013-02-03
" License: Vim License (see :help license)
" Location: ftdetect/vrs.vim
" Website: https://github.com/Raimondi/vrs
"
" See vrs.txt for help. This can be accessed by doing:
"
" :helptags ~/.vim/doc
" :help vrs
au BufRead,BufNewFile */patterns/*.vrs set filetype=vrs

View File

@ -0,0 +1,2 @@
seconds vim \<[0-5]\?[0-9]\>
minutes vim \%{seconds}

View File

@ -0,0 +1,47 @@
natural vim +\?\d\+
integer vim [-+]\?\d\+
hundredths vim \<\%(\d\|[1-9]\d\)\>
z_hundredths vim \<\d\{2}\>
thousandths vim \<\%(\%{hundredths}\|[1-9]\d\d\)\>
z_thousandths vim \<\d\{3}\>
z_thousandths pcre \b[0-9]{3}\b
_ip4_segment vim \%(25[0-5]\|2[0-4]\d\|[01]\?\d\d\?\)
_ip4_segment pcre (25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)
ip4 vim \<\%{_ip4_segment,4,.}\>
ip4 pcre \b(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\b
floating pcre /[-+]?[0-9]*\.?[0-9]+([eE][-+]?[0-9]+)?/
floating vim [-+]\?[0-9]*\.\?[0-9]\+\([eE][-+]\?[0-9]\+\)\?
phone_number vim # multiline
^
\%(
\(\d\) # prefix_digit
[\ \-\.]\? # optional_separator
\)\?
\%(
(\?\(\d\{3}\))\? # area_code
[\ \-\.] # separator
\)\?
\(\d\{3}\) # trunk
[\ \-\.] # separator
\(\d\{4}\) # line
\%(:\ \?x\? # optional_space_or_x
\(\d\+\) # extension
\)\?
$
phone_number pcre # multiline
/^
(?:
(?<prefix>\d) # prefix digit
[ \-\.]? # optional separator
)?
(?:
\(?(?<areacode>\d{3})\)? # area code
[ \-\.] # separator
)?
(?<trunk>\d{3}) # trunk
[ \-\.] # separator
(?<line>\d{4}) # line
(?:\ ?x? # optional space or 'x'
(?<extension>\d+) # extension
)?
$/x

View File

@ -0,0 +1,5 @@
abc vim \w\+\%{abc,3,.} # a comment here
[a-z]\%\# # more comments
# a whole line of comments
abc¡ vi&m \w\+\%{abc,3,.} # some errors
<wrong line start jdh # with a comment

View File

@ -0,0 +1,27 @@
vim_function vim ^[\ :]*fu\%[nction]!\?\s*\(.\{-}\)(
function
function!
:function
:function!
function
function!
:function
:function!
: function
: function!
: :function
: :function!
::function
::function!
:::function
:::function!
: function
: function!
: :function
: :function!

View File

@ -0,0 +1,6 @@
function! ExtendedRegexObject(...)
return call('extended_regex#ExtendedRegex', a:000)
endfunction
" ERex is a global object with access to Vim's vars:
let ERex = ExtendedRegexObject()

View File

@ -0,0 +1,135 @@
" Vim global plugin for short description
" Maintainer: Barry Arthur <barry.arthur@gmail.com>
" Israel Chauca F. <israelchauca@gmail.com>
" Version: 0.1
" Description: Long description.
" Last Change: 2013-02-03
" License: Vim License (see :help license)
" Location: plugin/vrs.vim
" Website: https://github.com/Raimondi/vrs
"
" See vrs.txt for help. This can be accessed by doing:
"
" :helptags ~/.vim/doc
" :help vrs
" Vimscript Setup: {{{1
" Allow use of line continuation.
let s:save_cpo = &cpo
set cpo&vim
" load guard
" uncomment after plugin development.
" XXX The conditions are only as examples of how to use them. Change them as
" needed. XXX
"if exists("g:loaded_vrs")
" \ || v:version < 700
" \ || v:version == 703 && !has('patch338')
" \ || &compatible
" let &cpo = s:save_cpo
" finish
"endif
"let g:loaded_vrs = 1
" Options: {{{1
" Private Functions: {{{1
function! s:ex(key, ...) "{{{1
let pattern = vrs#get(a:key)
if empty(pattern)
return ''
endif
let dest = a:0 ? a:1 : '@/'
return 'let ' . dest . ' = ' . string(pattern)
endfunction
function! s:get_re(...)
let re = vrs#get(input('Pattern name: ', '',
\ 'customlist,'.s:SID().'get_names'))
if empty(re)
return ''
endif
if !a:0 || a:1 == 0
return re
elseif a:1 == 1
return string(re)
else
return '"' . escape(re, '"\') . '"'
endif
endfunction
function! s:get_names(a, c, p)
return vrs#from_partial(a:a)
endfunction
function! s:SID()
return matchstr(expand('<sfile>'), '<SNR>\d\+_\zeSID$')
endfun
" Public Interface: {{{1
function! ExtendedRegexObject(...)
return call('extended_regex#ExtendedRegex', a:000)
endfunction
" Commands: {{{1
" first arg is the name of the pattern, second is the destination of the
" pattern found (defaults to @/.
" TODO add completion support.
command! -nargs=+ VRS exec s:ex(<f-args>)
" Maps: {{{1
inoremap <Plug>VRSPlain <C-R>=<SID>get_re(0)<CR>
inoremap <Plug>VRSSingle <C-R>=<SID>get_re(1)<CR>
inoremap <Plug>VRSDouble <C-R>=<SID>get_re(2)<CR>
cnoremap <Plug>VRSPlain <C-R>=<SID>get_re(0)<CR>
cnoremap <Plug>VRSSingle <C-R>=<SID>get_re(1)<CR>
cnoremap <Plug>VRSDouble <C-R>=<SID>get_re(2)<CR>
nnoremap <Plug>VRSPlain "=<SID>get_re(0)<CR>p
nnoremap <Plug>VRSSingle "=<SID>get_re(1)<CR>p
nnoremap <Plug>VRSDouble "=<SID>get_re(2)<CR>p
nnoremap <Plug>VRS/ /<C-R>=<SID>get_re()<CR>
nnoremap <Plug>VRS? ?<C-R>=<SID>get_re()<CR>
if !hasmapto('<Plug>VRSPlain', 'i')
imap <unique> <C-B>rep <Plug>VRSPlain
endif
if !hasmapto('<Plug>VRSSingle', 'i')
imap <unique> <C-B>re' <Plug>VRSSingle
endif
if !hasmapto('<Plug>VRSDouble', 'i')
imap <unique> <C-B>re" <Plug>VRSDouble
endif
if !hasmapto('<Plug>VRSPlain', 'c')
cmap <unique> <C-G>rep <Plug>VRSPlain
endif
if !hasmapto('<Plug>VRSSingle', 'c')
cmap <unique> <C-G>re' <Plug>VRSSingle
endif
if !hasmapto('<Plug>VRSDouble', 'c')
cmap <unique> <C-G>re" <Plug>VRSDouble
endif
if !hasmapto('<Plug>VRSPlain', 'n')
nmap <unique> <Leader>rep <Plug>VRSPlain
endif
if !hasmapto('<Plug>VRSSingle', 'n')
nmap <unique> <Leader>re' <Plug>VRSSingle
endif
if !hasmapto('<Plug>VRSDouble', 'n')
nmap <unique> <Leader>re" <Plug>VRSDouble
endif
if !hasmapto('<Plug>VRS/', 'n')
nmap <unique> <Leader>re/ <Plug>VRS/
endif
if !hasmapto('<Plug>VRS?', 'n')
nmap <unique> <Leader>re? <Plug>VRS?
endif
" Teardown:{{{1
"reset &cpo back to users setting
let &cpo = s:save_cpo
" vim: set sw=2 sts=2 et fdm=marker:

View File

@ -0,0 +1,57 @@
" Vim syntax plugin for filetype name.
" Maintainer: Barry Arthur <barry.arthur@gmail.com>
" Israel Chauca F. <israelchauca@gmail.com>
" Version: 0.1
" Description: Long description.
" Last Change: 2013-02-01
" License: Vim License (see :help license)
" Location: syntax/vrs.vim
" Website: https://github.com/Raimondi/vrs
"
" See vrs.txt for help. This can be accessed by doing:
"
" :helptags ~/.vim/doc
" :help vrs
" Quit when a (custom) syntax file was already loaded
if exists('b:current_syntax')
finish
endif
" Allow use of line continuation.
let s:save_cpo = &cpo
set cpo&vim
syn match vrsNameErr /^\S\+\s\+/ contained
syn match vrsName /^\w\+\s\+/ contained
syn match vrsFlavorErr /\%(^\S\+\s\+\)\@<=\S\+\s\+/ contained
syn match vrsFlavor /\%(^\S\+\s\+\)\@<=\w\+\s\+/ contained
syn match vrsCompItem /\w\+\|\d\+\|,\@<=\%(\\}\|[^}]\)\+/ contained
syn match vrsCompose /\\%{\S\+,\d\+,\%(\\}\|[^}]\)*}/ contained contains=vrsCompItem
syn match vrsRegExp /\%(^\S\+\s\+\S\+\s\+\)\@<=.*/ contains=vrsCompose contained
syn match vrsCommand /^\S\+\s\+\S\+\s\+\S.*/ contains=vrsName,vrsFlavor,vrsNameErr,vrsFlavorErr,vrsRegExp,vrsComment
syn match vrsContinued /^\s\+\S.*/ contains=vrsComment
syn match vrsComment /\%(\%(\\\\\)*\\\)\@<!#.*$/ containedin=ALL contains=vrsTODO
syn keyword vrsTodo TODO FIXME XXX
syn match vrsError /^[^a-zA-Z0-9_# ].*/
" Define the default highlighting.
" Only used when an item doesn't have highlighting yet
hi def link vrsTodo Todo
hi def link vrsComment Comment
hi def link vrsName Identifier
hi def link vrsFlavor Type
hi def link vrsRegExp String
hi def link vrsContinued String
hi def link vrsCompose PreProc
hi def link vrsCompItem Normal
hi def link vrsError Error
hi def link vrsFlavorErr Error
hi def link vrsNameErr Error
let b:current_syntax = 'vrs'
let &cpo = s:save_cpo
unlet s:save_cpo
" vim: set sw=2 sts=2 et fdm=marker:

View File

@ -0,0 +1,37 @@
let match_list = [
\ '1000',
\ '1',
\ '01.',
\ '1.0',
\ '.1',
\ '+1',
\ '-1.234',
\ '3.14e2',
\ '3.14e+14',
\ '3.14E+14',
\ '3.14e-14'
\]
let no_match_list = [
\ '1.00.0',
\ '1,0',
\ '-1. 234',
\ '3.14 e2',
\ '3.14 e+14',
\ '3.14 E+14',
\ '3.14 e-14'
\]
call vimtest#StartTap()
call vimtap#Plan(len(match_list) + (2 * len(no_match_list)))
for v in no_match_list
call vimtap#Is(vrs#matches(v, 'floating'), 1, v)
call vimtap#Is(vrs#exactly(v, 'floating'), 0, v)
endfor
for v in match_list
call vimtap#Is(vrs#matches(v, 'floating'), 1, v)
endfor
call vimtest#Quit()

View File

@ -0,0 +1,64 @@
call vimtest#StartTap()
call vimtap#Plan(8 + 13 + 7 + 7 + 7 + 7) " <== XXX Keep plan number updated. XXX
" hundredths vim \<\%(\d\|[1-9]\d\)\>
" z_hundredths vim \<\d\{2}\>
" thousandths vim \<\%(\%{hundredths}\|[1-9]\d\d\)\>
" z_thousandths vim \<\d\{3}\>
call vimtap#Is(vrs#exactly('0', 'natural'), 1, 'natural - int')
call vimtap#Is(vrs#exactly('1', 'natural'), 1, 'natural - int')
call vimtap#Is(vrs#exactly('99', 'natural'), 1, 'natural - int')
call vimtap#Is(vrs#exactly('123', 'natural'), 1, 'natural - int')
call vimtap#Is(vrs#exactly('+1', 'natural'), 1, 'natural + posint')
call vimtap#Is(vrs#exactly('-1', 'natural'), 0, 'natural - negint')
call vimtap#Is(vrs#exactly('', 'natural'), 0, 'natural - empty')
call vimtap#Is(vrs#exactly('a', 'natural'), 0, 'natural - char')
call vimtap#Is(vrs#exactly('0', 'integer'), 1, 'integer + int')
call vimtap#Is(vrs#exactly('1', 'integer'), 1, 'integer + int')
call vimtap#Is(vrs#exactly('99', 'integer'), 1, 'integer + int')
call vimtap#Is(vrs#exactly('123', 'integer'), 1, 'integer + int')
call vimtap#Is(vrs#exactly('-1', 'integer'), 1, 'integer + negint')
call vimtap#Is(vrs#exactly('-99', 'integer'), 1, 'integer + negint')
call vimtap#Is(vrs#exactly('-123', 'integer'), 1, 'integer + negint')
call vimtap#Is(vrs#exactly('+1', 'integer'), 1, 'integer + posint')
call vimtap#Is(vrs#exactly('+99', 'integer'), 1, 'integer + posint')
call vimtap#Is(vrs#exactly('+123', 'integer'), 1, 'integer + posint')
call vimtap#Is(vrs#exactly('', 'integer'), 0, 'integer - empty')
call vimtap#Is(vrs#exactly('a', 'integer'), 0, 'integer - char')
call vimtap#Is(vrs#exactly('1.0', 'integer'), 0, 'integer - float')
call vimtap#Is(vrs#exactly('0', 'hundredths'), 1, 'hundredths - int 0')
call vimtap#Is(vrs#exactly('1', 'hundredths'), 1, 'hundredths - int 1')
call vimtap#Is(vrs#exactly('22', 'hundredths'), 1, 'hundredths - int 22')
call vimtap#Is(vrs#exactly('99', 'hundredths'), 1, 'hundredths - upperbound int 99')
call vimtap#Is(vrs#exactly('100', 'hundredths'), 0, 'hundredths - overbounds')
call vimtap#Is(vrs#exactly('', 'hundredths'), 0, 'hundredths - empty')
call vimtap#Is(vrs#exactly('a', 'hundredths'), 0, 'hundredths - char')
call vimtap#Is(vrs#exactly('00', 'z_hundredths'), 1, 'z_hundredths - int 00')
call vimtap#Is(vrs#exactly('01', 'z_hundredths'), 1, 'z_hundredths - int 01')
call vimtap#Is(vrs#exactly('22', 'z_hundredths'), 1, 'z_hundredths - int 22')
call vimtap#Is(vrs#exactly('99', 'z_hundredths'), 1, 'z_hundredths - upperbound int 99')
call vimtap#Is(vrs#exactly('100', 'z_hundredths'), 0, 'z_hundredths - overbounds')
call vimtap#Is(vrs#exactly('', 'z_hundredths'), 0, 'z_hundredths - empty')
call vimtap#Is(vrs#exactly('a', 'z_hundredths'), 0, 'z_hundredths - char')
call vimtap#Is(vrs#exactly('0', 'thousandths'), 1, 'thousandths - int 0')
call vimtap#Is(vrs#exactly('333', 'thousandths'), 1, 'thousandths - int 333')
call vimtap#Is(vrs#exactly('999', 'thousandths'), 1, 'thousandths - upperbound int 999')
call vimtap#Is(vrs#exactly('1', 'thousandths'), 1, 'thousandths - int 1')
call vimtap#Is(vrs#exactly('1000', 'thousandths'), 0, 'thousandths - overbounds')
call vimtap#Is(vrs#exactly('', 'thousandths'), 0, 'thousandths - empty')
call vimtap#Is(vrs#exactly('a', 'thousandths'), 0, 'thousandths - char')
call vimtap#Is(vrs#exactly('000', 'z_thousandths'), 1, 'z_thousandths - int 000')
call vimtap#Is(vrs#exactly('333', 'z_thousandths'), 1, 'z_thousandths - int 333')
call vimtap#Is(vrs#exactly('999', 'z_thousandths'), 1, 'z_thousandths - upperbound int 999')
call vimtap#Is(vrs#exactly('001', 'z_thousandths'), 1, 'z_thousandths - int 001')
call vimtap#Is(vrs#exactly('1000', 'z_thousandths'), 0, 'z_thousandths - overbounds')
call vimtap#Is(vrs#exactly('', 'z_thousandths'), 0, 'z_thousandths - empty')
call vimtap#Is(vrs#exactly('a', 'z_thousandths'), 0, 'z_thousandths - char')
call vimtest#Quit()

View File

@ -0,0 +1,10 @@
call vimtest#StartTap()
call vimtap#Plan(2) " <== XXX Keep plan number updated. XXX
let an_ip4 = '192.168.1.1'
let not_an_ip4 = '999.168.1.1'
call vimtap#Is(vrs#matches(an_ip4 , 'ip4' ), 1, 'ip4')
call vimtap#Is(vrs#matches(not_an_ip4 , 'ip4' ), 0, 'not an ip4')
call vimtest#Quit()

View File

@ -0,0 +1,24 @@
call vimtest#StartTap()
call vimtap#Plan(1) " <== XXX Keep plan number updated. XXX
let pcre_regex = '
\ /^
\ (?:
\ (?<prefix>\d) # prefix digit
\ [ \-\.]? # optional separator
\ )?
\ (?:
\ \(?(?<areacode>\d{3})\)? # area code
\ [ \-\.] # separator
\ )?
\ (?<trunk>\d{3}) # trunk
\ [ \-\.] # separator
\ (?<line>\d{4}) # line
\ (?:\ ?x? # optional space or ''x''
\ (?<extension>\d+) # extension
\ )?
\ $/x'
call vimtap#Is(vrs#get('phone_number', 'pcre'), pcre_regex, 'retrieve pcre regex')
call vimtest#Quit()

View File

@ -0,0 +1,14 @@
call vimtest#StartTap()
call vimtap#Plan(4) " <== XXX Keep plan number updated. XXX
let a_phone_number = '1-234-567-0987:1234'
let not_a_phone_number_1 = ''
let not_a_phone_number_2 = 'x'
let not_a_phone_number_3 = '1234'
call vimtap#Is(vrs#matches(a_phone_number, 'phone_number'), 1, 'valid telephone matches')
call vimtap#Is(vrs#matches(not_a_phone_number_1, 'phone_number'), 0, 'invalid telephone 1 does not match')
call vimtap#Is(vrs#matches(not_a_phone_number_2, 'phone_number'), 0, 'invalid telephone 2 does not match')
call vimtap#Is(vrs#matches(not_a_phone_number_3, 'phone_number'), 0, 'invalid telephone 3 does not match')
call vimtest#Quit()

View File

@ -0,0 +1,39 @@
call vimtest#StartTap()
call vimtap#Plan(8 + 8 + 7) " <== XXX Keep plan number updated. XXX
let erex = ExtendedRegexObject('vrs#get')
let t = '\<\%{_ip4_segment,4,.}\>'
let t_expanded = '\<\%(25[0-5]\|2[0-4]\d\|[01]\?\d\d\?\)\.\%(25[0-5]\|2[0-4]\d\|[01]\?\d\d\?\)\.\%(25[0-5]\|2[0-4]\d\|[01]\?\d\d\?\)\.\%(25[0-5]\|2[0-4]\d\|[01]\?\d\d\?\)\>'
let vim_func_pat = '^[\ :]*fu\%[nction]!\?\s*\(.\{-}\)('
call vimtap#Is(erex.expand_composition_atom(t), t_expanded, 'expand _ip4_segment')
call vimtap#Is(erex.expand_composition_atom('\%{_ip4_segment,2,.}'), '\%(25[0-5]\|2[0-4]\d\|[01]\?\d\d\?\)\.\%(25[0-5]\|2[0-4]\d\|[01]\?\d\d\?\)', 'explicit count of 2 and explicit sep of dot')
call vimtap#Is(erex.expand_composition_atom('\%{vim_function,1,}'), vim_func_pat, 'explicit count of 1 and explicitly empty sep')
call vimtap#Is(erex.expand_composition_atom('\%{vim_function,1}'), vim_func_pat, 'explicit count of 1 and implicit sep')
call vimtap#Is(erex.expand_composition_atom('\%{vim_function}'), vim_func_pat, 'implicitly expand name only')
call vimtap#Is(erex.expand_composition_atom('\%{vim_function,2,}'), vim_func_pat . vim_func_pat, 'explicit count and explicitly empty sep')
call vimtap#Is(erex.expand_composition_atom('\%{vim_function,2}'), vim_func_pat . vim_func_pat, 'explicit count, implicit sep')
call vimtap#Is(erex.expand_composition_atom('\%{vim_function,3,\n}'), join(repeat(vim_func_pat, 3), "\n"), 'explicit literal sep')
call vimtap#Is(erex.parse(t), t_expanded, 'expand _ip4_segment')
call vimtap#Is(erex.parse('\%{_ip4_segment,2,.}'), '\%(25[0-5]\|2[0-4]\d\|[01]\?\d\d\?\)\.\%(25[0-5]\|2[0-4]\d\|[01]\?\d\d\?\)', 'explicit count of 2 and explicit sep of dot')
call vimtap#Is(erex.parse('\%{vim_function,1,}'), vim_func_pat, 'explicit count of 1 and explicitly empty sep')
call vimtap#Is(erex.parse('\%{vim_function,1}'), vim_func_pat, 'explicit count of 1 and implicit sep')
call vimtap#Is(erex.parse('\%{vim_function}'), vim_func_pat, 'expand name only')
call vimtap#Is(erex.parse('\%{vim_function,2,}'), vim_func_pat . vim_func_pat, 'explicit count and explicitly empty sep')
call vimtap#Is(erex.parse('\%{vim_function,2}'), vim_func_pat . vim_func_pat, 'explicit count, implicit sep')
call vimtap#Is(erex.parse('\%{vim_function,3,\n}'), join(repeat(vim_func_pat, 3), "\n"), 'explicit literal sep')
" with spaces
let t = '\<\%{_ip4_segment, 4, .}\>'
call vimtap#Is( erex.parse(t), t_expanded, 'expand _ip4_segment with spaces')
call vimtap#Is( erex.parse('\%{vim_function , 1 , }'), vim_func_pat, 'expand explicitly empty sep with spaces')
call vimtap#Is( erex.parse('\%{vim_function ,1}'), vim_func_pat, 'expand implicit sep with spaces')
call vimtap#Is( erex.parse('\%{vim_function }'), vim_func_pat, 'expand name only with space')
call vimtap#Is( erex.parse('\%{vim_function, 2, }'), vim_func_pat . vim_func_pat, 'expand count of 2 and explicitly empty sep with spaces')
call vimtap#Is( erex.parse('\%{vim_function , 2}'), vim_func_pat . vim_func_pat, 'expand count of 2 and implicit sep with spaces')
call vimtap#Is( erex.parse('\%{ vim_function , 3 , \n }'), join(repeat(vim_func_pat, 3), "\n"), 'expand count of 3 and explicit of \\n sep with spaces')
call vimtest#Quit()

View File

@ -0,0 +1,14 @@
call vimtest#StartTap()
call vimtap#Plan(2) " <== XXX Keep plan number updated. XXX
" use default lookup function (which simply accesses vim variables)
let erex = ExtendedRegexObject()
let x = 'a'
let t = '\<\%{g:x,4,.}\>'
let t_expanded = '\<a\.a\.a\.a\>'
call vimtap#Is(erex.expand_composition_atom(t), t_expanded, 'expand vim global variable (expand_composition_atom)')
call vimtap#Is(erex.parse(t), t_expanded, 'expand vim global variable (parse)')
call vimtest#Quit()

View File

@ -0,0 +1,9 @@
call vimtest#StartTap()
call vimtap#Plan(1) " <== XXX Keep plan number updated. XXX
call vrs#set('vrs#test', 'test', 'abc')
call vimtap#Ok(!vrs#set('vrs#test', 'test', 'cde'), 'Prevent duplicated entries.')
call vimtest#Quit()

View File

@ -0,0 +1,13 @@
The plugins runVimTests (http://www.vim.org/scripts/script.php?script_id=2565)
and VimTAP (http://www.vim.org/scripts/script.php?script_id=2213) are needed to
run these tests.
Besides the _setup.vim configuration file present in this repo you need to
create a global one and place it in the same dir where the runVimTests
executable is located. Assuming the executable is at '~/bin/runVimTests' this
global configuration file should be '~/bin/runVimTestsSetup.vim' and should
have something like the following lines inside of it:
" Prepend tests repos to &rtp
let &runtimepath = '/path/to/runVimTests_dir,' . &rtp
let &runtimepath = '/path/to/vimTAP_dir,' . &rtp

View File

@ -0,0 +1,3 @@
let &rtp = expand('<sfile>:p:h:h') . ',' . &rtp . ',' . expand('<sfile>:p:h:h') . '/after'
exe "so " . expand('<sfile>:p:h:h') . '/plugin/vrs.vim'

View File

@ -0,0 +1,135 @@
== vim-asciidoc
__Enhanced editing support for http://asciidoc.org[Asciidoc] files in Vim__
=== Dependencies
* https://github.com/dahu/vimple[]
* https://github.com/dahu/Asif[]
* https://github.com/Raimondi/VimRegStyle[]
* (optional) https://github.com/vim-scripts/SyntaxRange[]
=== Compilers
vim-asciidoc provides:
[style="horizontal"]
`:compiler asciidoc` :: To use the original Python Asciidoc
`:compiler asciidoctor` :: To use the newer Ruby Asciidoctor
Each compiler provides a `:Theme` command for changing the style-sheet.
.Asciidoc
[style="horizontal"]
`g:asciidoc_themes` :: The list of installed themes, defaulting to the
two themes that come with standard asciidoc, _flask_ and _volnitsky_.
`g:asciidoc_theme` :: The name of your preferred default theme,
defaulting to the asciidoc default blue stylesheet.
.Asciidoctor
`g:asciidoctor_themes_dir` :: The location of your CSS stylesheets
`g:asciidoctor_theme` :: The name of your preferred default theme,
defaulting to the asciidoctor default red stylesheet.
==== Live Reload
- The https://wiki.gnome.org/Apps/Web[Epiphany browser] automatically
refreshes when it detects that the source has been updated. This makes
for a wonderful previewer when editing asciidoc files. Just run
`:make` and switch to Epiphany and watch it auto-refresh.
- Firefox has the plugin
(https://addons.mozilla.org/fr/firefox/addon/auto-reload[AutoReload]), and
- Chrome has the plugins
(https://chrome.google.com/webstore/detail/livepage/pilnojpmdoofaelbinaeodfpjheijkbh[LivePage]
and
https://chrome.google.com/webstore/detail/livereload/jnihajbhpnppcggbcgedagnkighmdlei[LiveReload])
to the same effect.
=== Headings
The key sequence `<leader>1` will turn the current line into a level 1
heading using the current heading style as defined in
`g:asciidoc_title_style` (_setext_, or the default, _atx_). Similar
mappings exist for heading levels 2-5.
The Vim _section keys_ (`[[ ]] [] ][`) will move you between headings.
==== Heading Styles
By default, vim-asciidoc uses asymmetric _atx_ style headings, like:
....
== Level 2 Heading
....
You can force symmetric _atx_ style headings with `let
g:asciidoc_title_style_atx = "symmetric"` which will result in
headings like:
....
== Level 2 Heading ==
....
_Setext_ style headings are also supported with `let
g:asciidoc_title_style = "setext"` which results in headings like:
....
Level 2 Heading
---------------
....
=== Lists
.Nested bullet and number lists are supported using the following syntax:
....
* item
** sub-item
*** sub-sub-item
....
.And numbered lists:
....
. item
.. sub-item
... sub-sub-item
....
==== List Building Commands
Use the following visual mode list building commands:
[style="horizontal"]
`lu` :: Create unordered lists
`lo` :: Create ordered lists
`l>` :: Increase list depth
`l<` :: Decrease list depth
=== Reformatting
By default, Vim does the wrong thing by reformatting Asciidoc's block
delimiters as part of the paragraph. This plugin fixes that problem,
correctly formatting blocks, lists and normal paragraphs.
Use the `Q` key to reformat the current _block_.
=== Syntax Highlighting
vim-asciidoc merely bundles Stuart Rackham's original asciidoc syntax
file.
If you have the
https://github.com/vim-scripts/SyntaxRange[SyntaxRange] plugin
installed, source blocks within ++[=+-]++ blocks will be highlighted
according to the named language. Currently only C, Python and VimL are
highlighted by default. Submit a PR if you want to extend this set, or just
add your own to ++~/.vim/after/syntax/asciidoc.vim++
=== Snippets
vim-asciidoc provides several convenient snippets in the
https://github.com/SirVer/ultisnips[UltiSnips] format.

View File

@ -0,0 +1,129 @@
priority -50
snippet version "Document header version string"
v1.0, `!v strftime('%Y-%m-%d', localtime())`:${1: Revision remark}
endsnippet
snippet author "Document header author string"
`!v g:username` <`!v g:email`>
endsnippet
snippet header "Document Blockheader"
${1:`!v expand('%:t:r')`}
`!p snip.rv="=" * len(t[1])`
`!v g:username` <`!v g:email`>
v1.0, `!v strftime('%Y-%m-%d', localtime())`:${2: Revision remark}
endsnippet
snippet quote "Quote Block" b
[quote,${1:author},${2:source}]
____
$0
____
endsnippet
snippet verse "Verse Block" b
[verse,${1:author},${2:source}]
____
$0
____
endsnippet
snippet comment "Comment Block" b
////
$0
////
endsnippet
snippet passthrough "Passthrough Block" b
++++
$0
++++
endsnippet
snippet listing "Listing Block" b
----
$0
----
endsnippet
snippet literal "Literal Block" b
....
$0
....
endsnippet
snippet sidebar "Sidebar Block" b
****
$0
****
endsnippet
snippet quote "Quote Block" b
____
$0
____
endsnippet
snippet example "Example Block" b
====
$0
====
endsnippet
snippet note "Note admonition" b
[NOTE]
.${1:Title}
====
$0
====
endsnippet
snippet footnote "Footnote"
footnote:[${1:text}]
endsnippet
snippet anchor "Hypertext link target"
anchor:${1:id}[${2:label}]
endsnippet
snippet xref "Link to hypertext anchor"
xref:${1:id}[${2:caption}]
endsnippet
snippet image "Image"
image:${1:target}[${2:alt="$3"}]
endsnippet
snippet table "Table" b
.${1:Title}
[${2:width="50%",cols=">s,^m,e",frame="topbot",options="header,footer"}]
|====
|$0
|====
endsnippet
# Two line headers
snippet l1 "Level 1 Section" b
${1:Level 1 Section}
`!p snip.rv="-" * len(t[1])`
$0
endsnippet
snippet l2 "Level 2 Section" b
${1:Level 2 Section}
`!p snip.rv="~" * len(t[1])`
$0
endsnippet
snippet l3 "Level 3 Section" b
${1:Level 3 Section}
`!p snip.rv="^" * len(t[1])`
$0
endsnippet
snippet l4 "Level 4 Section" b
${1:Level 4 Section}
`!p snip.rv="+" * len(t[1])`
$0
endsnippet

View File

@ -0,0 +1,122 @@
" TODO: create T title text-object
" TODO: make section jumps [[ ]] etc work
let s:atx_title = '\_^=*\s\+\(\S\%(.\%(\s\+=\+\s*\_$\)\@!\)*.\)\(\s\+=\+\)\?\s*$'
let s:setext_title_underline = '[-=~^+]\+\s*$'
let s:setext_title = '\_^\(\S.\+\)\s*\n' . s:setext_title_underline
let s:setext_levels = ['=','-', '~', '^', '+']
function! asciidoc#find_prior_section_title()
let old_pos = getpos('.')
let pos = old_pos
let pos[2] = 0
call setpos('.', pos)
let prior_atx = search(s:atx_title, 'Wbn')
let prior_setext = search(s:setext_title, 'Wbn')
call setpos('.', old_pos)
let prior = max([prior_atx, prior_setext])
if prior == 0
return
endif
return prior . 'G'
endfunction
function! asciidoc#find_next_section_title()
let next_atx = search(s:atx_title, 'Wn')
let next_setext = search(s:setext_title, 'Wn')
let next = min(filter([next_atx, next_setext], 'v:val != 0'))
if next == 0
return
endif
return next . 'G'
endfunction
function! asciidoc#get_atx_section_title(line_number)
let line = getline(a:line_number)
let match = matchlist(line, s:atx_title)
if !empty(match)
let title = match[1]
let symmetric = len(match[2]) != 0
let level = len(matchstr(line, '^=*'))
return {'line' : a:line_number, 'type' : 'atx', 'symmetric' : symmetric, 'level' : level, 'title' : title}
else
return {}
endif
endfunction
function! asciidoc#get_setext_section_title(line_number)
let line = getline(a:line_number)
if line =~ '^' . s:setext_title_underline
let underline = line
let line_number = a:line_number - 1
let line = getline(line_number)
else
let line_number = a:line_number
let underline = getline(line_number + 1)
endif
let level = 1 + index(s:setext_levels, underline[0])
if (line . "\n" . underline) =~ s:setext_title
return {'line' : line_number, 'type' : 'setext', 'level' : level, 'title' : line}
else
return {}
endif
endfunction
function! asciidoc#get_section_title(line_number)
let atx = asciidoc#get_atx_section_title(a:line_number)
if !empty(atx)
return atx
else
return asciidoc#get_setext_section_title(a:line_number)
endif
endfunction
function! asciidoc#set_atx_section_title(line_number, level, title, symmetric)
let level_marks = repeat('=', a:level)
call setline(a:line_number, level_marks . ' ' . a:title . (a:symmetric ? (' ' . level_marks) : ''))
endfunction
function! asciidoc#set_setext_section_title(line_number, level, title)
let line_number = a:line_number + 1
let level_marks = repeat(s:setext_levels[a:level - 1], len(a:title))
if getline(line_number) =~ '^$'
call append(line_number - 1, level_marks)
else
call setline(line_number, level_marks)
endif
endfunction
function! asciidoc#set_section_title_level(level)
let line = line('.')
let section_title = asciidoc#get_section_title(line)
if !empty(section_title)
if section_title.type == 'atx'
call asciidoc#set_atx_section_title(section_title.line, a:level, section_title.title, section_title.symmetric)
else
call asciidoc#set_setext_section_title(section_title.line, a:level, section_title.title)
endif
else
let title = getline('.')
if g:asciidoc_title_style == 'atx'
call asciidoc#set_atx_section_title(line, a:level, title, g:asciidoc_title_style_atx != 'asymmetric')
else
call asciidoc#set_setext_section_title(line, a:level, title)
endif
endif
endfunction
function! asciidoc#make_list(type) range
let old_search = @/
exe a:firstline . ',' . a:lastline . 's/^\s*\([*.]*\)\s*/\=repeat("' . a:type . '", max([1, len(submatch(1))]))." "/'
let @/ = old_search
endfunction
function! asciidoc#dent_list(in_out) range
let old_search = @/
if a:in_out == 'in'
silent! exe a:firstline . ',' . a:lastline . 's/^[*.]//'
else
silent! exe a:firstline . ',' . a:lastline . 's/^\([*.]\)/&&/'
endif
let @/ = old_search
endfunction

View File

@ -0,0 +1,62 @@
" Asciidoc compiler settings for Vim
if exists('b:current_compiler')
finish
endif
let b:current_compiler = 'asciidoc'
if exists(':CompilerSet') != 2
command! -nargs=* CompilerSet setlocal <args>
endif
" errorformat stolen from syntastic
let &l:errorformat = ''
\. '%Easciidoc: %tRROR: %f: line %l: %m,'
\. '%Easciidoc: %tRROR: %f: %m,'
\. '%Easciidoc: FAILED: %f: line %l: %m,'
\. '%Easciidoc: FAILED: %f: %m,'
\. '%Wasciidoc: %tARNING: %f: line %l: %m,'
\. '%Wasciidoc: %tARNING: %f: %m,'
\. '%Wasciidoc: DEPRECATED: %f: line %l: %m,'
\. '%Wasciidoc: DEPRECATED: %f: %m'
function! s:set_makeprg()
let &l:makeprg = ''
\. 'asciidoc'
\. ' -a urldata'
\. ' -a icons'
\. ' ' . get(b:, 'asciidoc_theme', '')
\. ' ' . get(b:, 'asciidoc_icons_dir', '-a iconsdir=./images/icons/')
\. ' ' . get(b:, 'asciidoc_backend', '')
\. ' %'
endfunction
let s:asciidoc_default_themes = ['default', 'flask', 'volnitsky']
if ! exists('g:asciidoc_themes')
let g:asciidoc_themes = s:asciidoc_default_themes
endif
if ! exists('g:asciidoc_theme')
let g:asciidoc_theme = 'default'
endif
function! s:available_themes_completer(ArgLead, CmdLine, CursorPos)
return filter(copy(g:asciidoc_themes), 'v:val =~ a:ArgLead')
endfunction
function! s:update_theme(theme)
if a:theme ==# 'default'
let b:asciidoc_theme = ''
else
let b:asciidoc_theme = '-a theme=' . a:theme
endif
call s:set_makeprg()
endfunction
command! -nargs=1 -complete=customlist,s:available_themes_completer Theme call <SID>update_theme(<q-args>)
call s:set_makeprg()
call s:update_theme(g:asciidoc_theme)

View File

@ -0,0 +1,72 @@
" Asciidoc compiler settings for Vim
if exists("b:current_compiler")
finish
endif
let b:current_compiler = "asciidoc"
if exists(":CompilerSet") != 2
command! -nargs=* CompilerSet setlocal <args>
endif
" errorformat stolen from syntastic
let &l:errorformat = ''
\. '%Easciidoc: %tRROR: %f: line %l: %m,'
\. '%Easciidoc: %tRROR: %f: %m,'
\. '%Easciidoc: FAILED: %f: line %l: %m,'
\. '%Easciidoc: FAILED: %f: %m,'
\. '%Wasciidoc: %tARNING: %f: line %l: %m,'
\. '%Wasciidoc: %tARNING: %f: %m,'
\. '%Wasciidoc: DEPRECATED: %f: line %l: %m,'
\. '%Wasciidoc: DEPRECATED: %f: %m'
function! s:set_makeprg()
let &l:makeprg = ''
\. 'asciidoctor'
\. ' -a urldata'
\. ' -a icons'
\. ' ' . get(b:, 'asciidoctor_theme', '')
\. ' ' . get(b:, 'asciidoctor_icons_dir', '-a iconsdir=./images/icons/')
\. ' ' . get(b:, 'asciidoctor_backend', '')
\. ' %'
endfunction
if ! exists('g:asciidoctor_themes_dir')
echohl Warning
echom 'Set g:asciidoctor_themes_dir for theme support.'
echohl None
endif
if ! exists('g:asciidoctor_theme')
let g:asciidoctor_theme = 'default'
endif
function! s:asciidoctor_themes()
if ! exists('g:asciidoctor_themes_dir')
echohl Warning
echom 'Set g:asciidoctor_themes_dir for theme support.'
echohl None
return ['default']
endif
return map(glob(g:asciidoctor_themes_dir . '/*.css', 0, 1)
\, 'fnamemodify(v:val, ":p:t")')
endfunction
function! s:available_themes_completer(ArgLead, CmdLine, CursorPos)
return filter(s:asciidoctor_themes(), 'v:val =~ a:ArgLead')
endfunction
function! s:update_theme(theme)
if a:theme == 'default'
let b:asciidoctor_theme = ''
else
let b:asciidoctor_theme = '-a stylesheet=' . a:theme . ' -a stylesdir=' . g:asciidoctor_themes_dir
endif
call s:set_makeprg()
endfunction
command! -nargs=1 -complete=customlist,s:available_themes_completer Theme call <SID>update_theme(<q-args>)
call s:set_makeprg()
call s:update_theme(g:asciidoctor_theme)

View File

@ -0,0 +1,14 @@
--langdef=asciidoc
--langmap=asciidoc:.ad.adoc.asciidoc
--regex-asciidoc=/^=[ \t]+(.*)/# \1/h/
--regex-asciidoc=/^==[ \t]+(.*)/. \1/h/
--regex-asciidoc=/^===[ \t]+(.*)/. . \1/h/
--regex-asciidoc=/^====[ \t]+(.*)/. . . \1/h/
--regex-asciidoc=/^=====[ \t]+(.*)/. . . . \1/h/
--regex-asciidoc=/^======[ \t]+(.*)/. . . . \1/h/
--regex-asciidoc=/^=======[ \t]+(.*)/. . . . \1/h/
--regex-asciidoc=/\[\[([^]]+)\]\]/\1/a/
--regex-asciidoc=/^\.([^ \t].+)/\1/t/
--regex-asciidoc=/image::([^\[]+)/\1/i/
--regex-asciidoc=/image:([^:][^\[]+)/\1/I/
--regex-asciidoc=/include::([^\[]+)/\1/n/

View File

@ -0,0 +1,12 @@
" Vim filetype detection file
" Language: AsciiDoc
" Maintainer: Barry Arthur <barry.arthur@gmail.com>
" URL: http://asciidoc.org/
" https://github.com/wsdjeg/vim-asciidoc
" Licence: Licensed under the same terms as Vim itself
" Remarks: Vim 6 or greater
augroup asciidoc
au!
au BufRead,BufNewFile *.asciidoc,*.adoc,*.asc set filetype=asciidoc
augroup END

View File

@ -0,0 +1,405 @@
" Asciidoc
" Barry Arthur
" 1.1, 2014-08-26
" 'atx' or 'setext'
if !exists('g:asciidoc_title_style')
let g:asciidoc_title_style = 'atx'
endif
" 'asymmetric' or 'symmetric'
if !exists('g:asciidoc_title_style_atx')
let g:asciidoc_title_style_atx = 'asymmetric'
endif
compiler asciidoc
setlocal foldmethod=marker
if &spelllang == ''
setlocal spelllang=en
endif
setlocal autoindent expandtab softtabstop=2 shiftwidth=2 wrap
if &textwidth == 0
setlocal textwidth=70
endif
setlocal comments=://
setlocal commentstring=//\ %s
setlocal formatoptions+=tcroqln2
setlocal indentkeys=!^F,o,O
setlocal nosmartindent nocindent
setlocal isk-=_
" headings
" nnoremap <buffer> <leader>0 :call asciidoc#set_section_title_level(1)<cr>
" nnoremap <buffer> <leader>1 :call asciidoc#set_section_title_level(2)<cr>
" nnoremap <buffer> <leader>2 :call asciidoc#set_section_title_level(3)<cr>
" nnoremap <buffer> <leader>3 :call asciidoc#set_section_title_level(4)<cr>
" nnoremap <buffer> <leader>4 :call asciidoc#set_section_title_level(5)<cr>
" TODO: Make simple 'j/k' offsets honour setext style sections
nnoremap <buffer> <expr><silent> [[ asciidoc#find_prior_section_title()
nnoremap <buffer> <expr><silent> [] asciidoc#find_prior_section_title() . 'j'
nnoremap <buffer> <expr><silent> ]] asciidoc#find_next_section_title()
nnoremap <buffer> <expr><silent> ][ asciidoc#find_next_section_title() . 'k'
xnoremap <buffer> <expr><silent> [[ asciidoc#find_prior_section_title()
xnoremap <buffer> <expr><silent> [] asciidoc#find_prior_section_title() . 'j'
xnoremap <buffer> <expr><silent> ]] asciidoc#find_next_section_title()
xnoremap <buffer> <expr><silent> ][ asciidoc#find_next_section_title() . 'k'
" xnoremap <buffer> <silent> lu :call asciidoc#make_list('*')<cr>gv
" xnoremap <buffer> <silent> lo :call asciidoc#make_list('.')<cr>gv
" xnoremap <buffer> <silent> l< :call asciidoc#dent_list('in')<cr>gv
" xnoremap <buffer> <silent> l> :call asciidoc#dent_list('out')<cr>gv
" nmap <buffer> <leader>lu viplu<c-\><c-n>``
" nmap <buffer> <leader>lo viplo<c-\><c-n>``
let s:asciidoc = {}
let s:asciidoc.delimited_block_pattern = '^[-.~_+^=*\/]\{4,}\s*$'
let s:asciidoc.heading_pattern = '^[-=~^+]\{4,}\s*$'
let s:asciidoc.list_pattern = ERex.parse('
\ \%(\_^\|\n\) # explicitly_numbered
\ \s*
\ \d\+
\ \.
\ \s\+
\ \|
\ \%(\_^\|\n\) # explicitly_alpha
\ \s*
\ [a-zA-Z]
\ \.
\ \s\+
\ \|
\ \%(\_^\|\n\) # explicitly_roman
\ \s*
\ [ivxIVX]\+ # (must_end_in_")"
\ )
\ \s\+
\ \|
\ \%(\_^\|\n\) # definition_list
\ \%(\_^\|\n\)
\ \%(\S\+\s\+\)\+
\ ::\+
\ \s\+
\ \%(\S\+\)\@=
\ \|
\ \%(\_^\|\n\) # implicit
\ \s*
\ [-*+.]\+
\ \s\+
\ \%(\S\+\)\@=
\')
" DEPRECATED after accurate list_pattern definition above
" let s:asciidoc.itemization_pattern = '^\s*[-*+.]\+\s'
" allow multi-depth list chars (--, ---, ----, .., ..., ...., etc)
exe 'syn match asciidocListBullet /' . s:asciidoc.list_pattern . '/'
let &l:formatlistpat=s:asciidoc.list_pattern
"Typing "" in insert mode inserts a pair of smart quotes and places the
"cursor between them. Depends on asciidoc/asciidoctor flavour. Off by default.
if ! exists('g:asciidoc_smartquotes')
let g:asciidoc_smartquotes = 0
endif
if ! exists('g:asciidoctor_smartquotes')
let g:asciidoctor_smartquotes = 0
endif
" indent
" ------
setlocal indentexpr=GetAsciidocIndent()
" stolen from the RST equivalent
function! GetAsciidocIndent()
let lnum = prevnonblank(v:lnum - 1)
if lnum == 0
return 0
endif
let [lnum, line] = s:asciidoc.skip_back_until_white_line(lnum)
let ind = indent(lnum)
" echom 'lnum=' . lnum
" echom 'ind=' . ind
" echom 'line=' . line
" Don't auto-indent within lists
if line =~ s:asciidoc.itemization_pattern
let ind = 0
endif
let line = getline(v:lnum - 1)
return ind
endfunction
" format
" ------
" The following object and its functions is modified from Yukihiro Nakadaira's
" autofmt example.
" Easily reflow text
" the Q form (badly) tries to keep cursor position
" the gQ form subsequently jumps over the reformatted block
nnoremap <silent> <buffer> Q :call <SID>Q(0)<cr>
nnoremap <silent> <buffer> gQ :call <SID>Q(1)<cr>
function! s:Q(skip_block_after_format)
if ! a:skip_block_after_format
let save_clip = @*
let save_reg = @@
let tos = line('w0')
let pos = getpos('.')
norm! v{y
call setpos('.', pos)
let word_count = len(split(@@, '\_s\+'))
endif
norm! gqap
if a:skip_block_after_format
normal! }
else
let scrolloff = &scrolloff
set scrolloff=0
call setpos('.', pos)
exe 'norm! {' . word_count . 'W'
let pos = getpos('.')
call cursor(tos, 1)
norm! zt
call setpos('.', pos)
let &scrolloff = scrolloff
let @* = save_clip
let @@ = save_reg
endif
endfunction
setlocal formatexpr=AsciidocFormatexpr()
function! AsciidocFormatexpr()
return s:asciidoc.formatexpr()
endfunction
function s:asciidoc.formatexpr()
" echom 'formatter called'
if mode() =~# '[iR]' && &formatoptions =~# 'a'
return 1
elseif mode() !~# '[niR]' || (mode() =~# '[iR]' && v:count != 1) || v:char =~# '\s'
echohl ErrorMsg
echomsg "Assert(formatexpr): Unknown State: " mode() v:lnum v:count string(v:char)
echohl None
return 1
endif
if mode() == 'n'
return self.format_normal_mode(v:lnum, v:count - 1)
else
" We don't actually do anything in insert mode yet
" return self.format_insert_mode(v:char)
endif
endfunction
function s:asciidoc.format_normal_mode(lnum, count)
" echom "normal formatexpr(lnum,count): " . a:lnum . ", " . a:count
let lnum = a:lnum
let last_line = lnum + a:count
let lnum = self.skip_white_lines(lnum)
let [lnum, line] = self.skip_fixed_lines(lnum)
let last_line = max([last_line, lnum])
let last_line = self.find_last_line(last_line)
" echom "normal formatexpr(first,last): " . lnum . ", " . last_line
" echom 'line = ' . line
" echom 'lnum = ' . lnum
" echom 'last_line = ' . last_line
call self.reformat_text(lnum, last_line)
return 0
endfunction
function s:asciidoc.reformat_chunk(chunk)
" echom 'reformat_chunk: ' . a:chunk[0]
return Asif(a:chunk, 'asciidoc', ['setlocal textwidth=' . &tw, 'setlocal indentexpr=', 'setlocal formatexpr=', 'normal! gqap'])
endfunction
function s:asciidoc.replace_chunk(chunk, lnum, last_line)
exe a:lnum . ',' . a:last_line . 'd'
undojoin
call append(a:lnum - 1, a:chunk)
endfunction
function s:asciidoc.reformat_text(lnum, last_line)
" echom 'reformat_text: ' . a:lnum . ', ' . a:last_line
let lnum = a:lnum
let last_line = a:last_line
let lines = getline(lnum, a:last_line)
let block = s:asciidoc.identify_block(lines[0])
echom 'block=' . block
if block == 'literal'
" nothing to do
elseif block == 'para'
let formatted = s:asciidoc.reformat_chunk(lines)
if formatted != lines
call s:asciidoc.replace_chunk(formatted, lnum, last_line)
endif
elseif block == 'list'
let formatted = []
let elems = list#partition(
\ string#scanner(lines).split(
\ '\n\?\zs\(\(+\n\)\|\(' . s:asciidoc.list_pattern . '\)\)'
\ , 1)[1:], 2)
let elems = (type(elems[0]) == type([]) ? elems : [elems])
for chunk in map(elems
\ , 'v:val[0] . string#trim(substitute(v:val[1], "\\n\\s\\+", " ", "g"))')
if chunk =~ "^+\n"
call extend(formatted, ['+'])
call extend(formatted, s:asciidoc.reformat_chunk(matchstr(chunk, "^+\n\\zs.*")))
else
call extend(formatted, s:asciidoc.reformat_chunk(chunk))
endif
endfor
if formatted != lines
call s:asciidoc.replace_chunk(formatted, lnum, last_line)
endif
else
echohl Comment
echom 'vim-asciidoc: unknown block on ' . lnum . ": don't know how to format: " . strpart(lines[0], 0, 20) . '...'
echohl None
endif
endfunction
function s:asciidoc.identify_block(line)
let line = a:line
if line =~ self.list_pattern
return 'list'
elseif line =~ '^[*_`+]\{0,2}\S'
return 'para'
elseif line =~ '^\s\+'
return 'literal'
else
return 'unknown'
endif
endfunction
function s:asciidoc.get_line(lnum)
return [a:lnum, getline(a:lnum)]
endfunction
function s:asciidoc.get_next_line(lnum)
return s:asciidoc.get_line(a:lnum + 1)
endfunction
function s:asciidoc.get_prev_line(lnum)
return s:asciidoc.get_line(a:lnum - 1)
endfunction
function s:asciidoc.skip_fixed_lines(lnum)
let [lnum, line] = s:asciidoc.get_line(a:lnum)
let done = 0
while done == 0
let done = 1
" skip optional block title
if line =~ '^\.\a'
let [lnum, line] = self.get_next_line(lnum)
let done = 0
endif
" " skip list joiner
" if line =~ '^+$'
" let [lnum, line] = self.get_next_line(lnum)
" let done = 0
" endif
" skip optional attribute or blockid
if line =~ '^\['
let [lnum, line] = self.get_next_line(lnum)
let done = 0
endif
" skip possible one-line heading
if line =~ '^=\+\s\+\a'
let [lnum, line] = self.get_next_line(lnum)
let done = 0
endif
" skip possible table
if line =~ '^|'
let [lnum, line] = self.get_next_line(lnum)
let done = 0
endif
" skip possible start of delimited block
if line =~ self.delimited_block_pattern
let [lnum, line] = self.get_next_line(lnum)
let done = 0
endif
" skip possible two-line heading
let [next_lnum, next_line] = self.get_next_line(lnum)
if (line =~ '^\a') && (next_line =~ self.heading_pattern)
let [lnum, line] = self.get_next_line(next_lnum)
let done = 0
endif
endwhile
return [lnum, line]
endfunction
function s:asciidoc.find_last_line(lnum)
let [lnum, line] = s:asciidoc.get_line(a:lnum)
let done = 0
while done == 0
let done = 1
" skip until blank line
if line !~ '^\s*$'
let [lnum, line] = self.get_next_line(lnum)
let done = 0
endif
endwhile
let done = 0
while done == 0
let done = 1
" skip possible blank lines
if line =~ '^\s*$'
let [lnum, line] = self.get_prev_line(lnum)
let done = 0
endif
" skip possible one-line heading
if line =~ self.delimited_block_pattern
let [lnum, line] = self.get_prev_line(lnum)
let done = 0
endif
endwhile
return lnum
endfunction
function s:asciidoc.format_insert_mode(char)
endfunction
function s:asciidoc.skip_white_lines(lnum)
let [lnum, line] = s:asciidoc.get_line(a:lnum)
while line =~ '^\s*$'
let [lnum, line] = self.get_next_line(lnum)
endwhile
return lnum
endfunction
function s:asciidoc.skip_back_until_white_line(lnum)
let [lnum, line] = s:asciidoc.get_line(a:lnum)
while line !~ '^\s*$'
let [pn, pl] = [lnum, line]
let [lnum, line] = self.get_prev_line(lnum)
endwhile
return [pn, pl]
endfunction

View File

@ -0,0 +1,188 @@
" Vim syntax file
" Language: AsciiDoc
" Author: Stuart Rackham <srackham@gmail.com> (inspired by Felix
" Obenhuber's original asciidoc.vim script).
" URL: http://www.methods.co.nz/asciidoc/
" https://github.com/dahu/vim-asciidoc
" Licence: GPL (http://www.gnu.org)
" Remarks: Vim 6 or greater
" Limitations: See 'Appendix E: Vim Syntax Highlighter' in the AsciiDoc 'User
" Guide'.
if exists("b:current_syntax")
finish
endif
syn clear
syn sync fromstart
syn sync linebreaks=1
function! AsciidocEnableSyntaxRanges()
" source block syntax highlighting
if exists('g:loaded_SyntaxRange')
for lang in ['c', 'python', 'vim']
call SyntaxRange#Include(
\ '^\c\[source\s*,\s*' . lang . '.*\]\s*$'
\, '\(\]\s*\n\)\@<![=-]\{4,\}'
\, lang)
endfor
endif
endfunction
" Run :help syn-priority to review syntax matching priority.
syn keyword asciidocToDo TODO FIXME CHECK TEST XXX ZZZ DEPRECATED
syn match asciidocBackslash /\\/
syn region asciidocIdMarker start=/^\$Id:\s/ end=/\s\$$/
syn match asciidocCallout /\\\@<!<\d\{1,2}>/
syn match asciidocListBlockDelimiter /^--$/
syn match asciidocLineBreak /[ \t]+$/
syn match asciidocRuler /^'\{3,}$/
syn match asciidocPagebreak /^<\{3,}$/
syn match asciidocEntityRef /\\\@<!&[#a-zA-Z]\S\{-};/
syn region asciidocLiteralParagraph start=/\(\%^\|\_^\n\)\@<=\s\+\S\+/ end=/\(^\(+\|--\)\?\s*$\)\@=/ contains=asciidocToDo
syn match asciidocURL /\\\@<!\<\(http\|https\|ftp\|file\|irc\):\/\/[^| \t]*\(\w\|\/\)/
syn match asciidocEmail /[\\.:]\@<!\(\<\|<\)\w\(\w\|[.-]\)*@\(\w\|[.-]\)*\w>\?[0-9A-Za-z_]\@!/
syn match asciidocAttributeRef /\\\@<!{\w\(\w\|[-,+]\)*\([=!@#$%?:].*\)\?}/
" As a damage control measure quoted patterns always terminate at a blank
" line (see 'Limitations' above).
syn match asciidocQuotedAttributeList /\\\@<!\[[a-zA-Z0-9_-][a-zA-Z0-9 _-]*\][+_'`#*]\@=/
syn match asciidocQuotedSubscript /\\\@<!\~\S\_.\{-}\(\~\|\n\s*\n\)/ contains=asciidocEntityRef
syn match asciidocQuotedSuperscript /\\\@<!\^\S\_.\{-}\(\^\|\n\s*\n\)/ contains=asciidocEntityRef
syn match asciidocQuotedMonospaced /\(^\|[| \t([.,=\]]\)\@<=+\([ )\n\t]\)\@!\(.\|\n\(\s*\n\)\@!\)\{-}\S\(+\([| \t)[\],.?!;:=]\|$\)\@=\)/ contains=asciidocEntityRef
syn match asciidocQuotedMonospaced2 /\(^\|[| \t([.,=\]]\)\@<=`\([ )\n\t]\)\@!\(.\|\n\(\s*\n\)\@!\)\{-}\S\(`\([| \t)[\],.?!;:=]\|$\)\@=\)/
syn match asciidocQuotedUnconstrainedMonospaced /[\\+]\@<!++\S\_.\{-}\(++\|\n\s*\n\)/ contains=asciidocEntityRef
syn match asciidocQuotedEmphasized /\(^\|[| \t([.,=\]]\)\@<=_\([ )\n\t]\)\@!\(.\|\n\(\s*\n\)\@!\)\{-}\S\(_\([| \t)[\],.?!;:=]\|$\)\@=\)/ contains=asciidocEntityRef
syn match asciidocQuotedEmphasized2 /\(^\|[| \t([.,=\]]\)\@<='\([ )\n\t]\)\@!\(.\|\n\(\s*\n\)\@!\)\{-}\S\('\([| \t)[\],.?!;:=]\|$\)\@=\)/ contains=asciidocEntityRef
syn match asciidocQuotedUnconstrainedEmphasized /\\\@<!__\S\_.\{-}\(__\|\n\s*\n\)/ contains=asciidocEntityRef
syn match asciidocQuotedBold /\(^\|[| \t([.,=\]]\)\@<=\*\([ )\n\t]\)\@!\(.\|\n\(\s*\n\)\@!\)\{-}\S\(\*\([| \t)[\],.?!;:=]\|$\)\@=\)/ contains=asciidocEntityRef
syn match asciidocQuotedUnconstrainedBold /\\\@<!\*\*\S\_.\{-}\(\*\*\|\n\s*\n\)/ contains=asciidocEntityRef
" Don't allow ` in single quoted (a kludge to stop confusion with `monospaced`).
syn match asciidocQuotedSingleQuoted /\(^\|[| \t([.,=\]]\)\@<=`\([ )\n\t]\)\@!\([^`]\|\n\(\s*\n\)\@!\)\{-}[^` \t]\('\([| \t)[\],.?!;:=]\|$\)\@=\)/ contains=asciidocEntityRef
syn match asciidocQuotedDoubleQuoted /\(^\|[| \t([.,=\]]\)\@<=``\([ )\n\t]\)\@!\(.\|\n\(\s*\n\)\@!\)\{-}\S\(''\([| \t)[\],.?!;:=]\|$\)\@=\)/ contains=asciidocEntityRef
syn match asciidocDoubleDollarPassthrough /\\\@<!\(^\|[^0-9a-zA-Z$]\)\@<=\$\$..\{-}\(\$\$\([^0-9a-zA-Z$]\|$\)\@=\|^$\)/
syn match asciidocTriplePlusPassthrough /\\\@<!\(^\|[^0-9a-zA-Z$]\)\@<=+++..\{-}\(+++\([^0-9a-zA-Z$]\|$\)\@=\|^$\)/
syn match asciidocAdmonition /^\u\{3,15}:\(\s\+.*\)\@=/
syn region asciidocTable_OLD start=/^\([`.']\d*[-~_]*\)\+[-~_]\+\d*$/ end=/^$/
syn match asciidocBlockTitle /^\.[^. \t].*[^-~_]$/ contains=asciidocQuoted.*,asciidocAttributeRef
syn match asciidocTitleUnderline /[-=~^+]\{2,}$/ transparent contained contains=NONE
syn match asciidocOneLineTitle /^=\{1,5}\s\+\S.*$/ contains=asciidocQuoted.*,asciidocMacroAttributes,asciidocAttributeRef,asciidocEntityRef,asciidocEmail,asciidocURL,asciidocBackslash
syn match asciidocTwoLineTitle /^[^. +/].*[^.]\n[-=~^+]\{2,}$/ contains=asciidocQuoted.*,asciidocMacroAttributes,asciidocAttributeRef,asciidocEntityRef,asciidocEmail,asciidocURL,asciidocBackslash,asciidocTitleUnderline
syn match asciidocAttributeList /^\[[^[ \t].*\]$/
syn match asciidocQuoteBlockDelimiter /^_\{4,}$/
syn match asciidocExampleBlockDelimiter /^=\{4,}$/
syn match asciidocSidebarDelimiter /^*\{4,}$/
" See http://vimdoc.sourceforge.net/htmldoc/usr_44.html for excluding region
" contents from highlighting.
syn match asciidocTablePrefix /\(\S\@<!\(\([0-9.]\+\)\([*+]\)\)\?\([<\^>.]\{,3}\)\?\([a-z]\)\?\)\?|/ containedin=asciidocTableBlock contained
syn region asciidocTableBlock matchgroup=asciidocTableDelimiter start=/^|=\{3,}$/ end=/^|=\{3,}$/ keepend contains=ALL
syn match asciidocTablePrefix /\(\S\@<!\(\([0-9.]\+\)\([*+]\)\)\?\([<\^>.]\{,3}\)\?\([a-z]\)\?\)\?!/ containedin=asciidocTableBlock contained
syn region asciidocTableBlock2 matchgroup=asciidocTableDelimiter2 start=/^!=\{3,}$/ end=/^!=\{3,}$/ keepend contains=ALL
syn match asciidocListContinuation /^+$/
syn region asciidocExampleBlock start=/^=\{4,}$/ end=/^=\{4,}$/ contains=asciidocCallout,asciidocToDo keepend
syn region asciidocLiteralBlock start=/^\.\{4,}$/ end=/^\.\{4,}$/ contains=asciidocCallout,asciidocToDo keepend
syn region asciidocListingBlock start=/^-\{4,}$/ end=/^-\{4,}$/ contains=asciidocCallout,asciidocToDo keepend
syn region asciidocCommentBlock start="^/\{4,}$" end="^/\{4,}$" contains=asciidocToDo
syn region asciidocPassthroughBlock start="^+\{4,}$" end="^+\{4,}$"
" Allowing leading \w characters in the filter delimiter is to accomodate
" the pre version 8.2.7 syntax and may be removed in future releases.
syn region asciidocFilterBlock start=/^\w*\~\{4,}$/ end=/^\w*\~\{4,}$/
syn region asciidocMacroAttributes matchgroup=asciidocRefMacro start=/\\\@<!<<"\{-}\(\w\|-\|_\|:\|\.\)\+"\?,\?/ end=/\(>>\)\|^$/ contains=asciidocQuoted.* keepend
syn region asciidocMacroAttributes matchgroup=asciidocAnchorMacro start=/\\\@<!\[\{2}\(\w\|-\|_\|:\|\.\)\+,\?/ end=/\]\{2}/ keepend
syn region asciidocMacroAttributes matchgroup=asciidocAnchorMacro start=/\\\@<!\[\{3}\(\w\|-\|_\|:\|\.\)\+/ end=/\]\{3}/ keepend
syn region asciidocMacroAttributes matchgroup=asciidocMacro start=/[\\0-9a-zA-Z]\@<!\w\(\w\|-\)*:\S\{-}\[/ skip=/\\\]/ end=/\]\|^$/ contains=asciidocQuoted.*,asciidocAttributeRef,asciidocEntityRef keepend
" Highlight macro that starts with an attribute reference (a common idiom).
syn region asciidocMacroAttributes matchgroup=asciidocMacro start=/\(\\\@<!{\w\(\w\|[-,+]\)*\([=!@#$%?:].*\)\?}\)\@<=\S\{-}\[/ skip=/\\\]/ end=/\]\|^$/ contains=asciidocQuoted.*,asciidocAttributeRef keepend
syn region asciidocMacroAttributes matchgroup=asciidocIndexTerm start=/\\\@<!(\{2,3}/ end=/)\{2,3}/ contains=asciidocQuoted.*,asciidocAttributeRef keepend
syn match asciidocCommentLine "^//\([^/].*\|\)$" contains=asciidocToDo
syn region asciidocAttributeEntry start=/^:\w/ end=/:\(\s\|$\)/ oneline
" Lists.
syn match asciidocListBullet /^\s*\zs\(-\|\*\{1,5}\)\ze\s/
syn match asciidocListNumber /^\s*\zs\(\(\d\+\.\)\|\.\{1,5}\|\(\a\.\)\|\([ivxIVX]\+)\)\)\ze\s\+/
syn region asciidocListLabel start=/^\s*/ end=/\(:\{2,4}\|;;\)$/ oneline contains=asciidocQuoted.*,asciidocMacroAttributes,asciidocAttributeRef,asciidocEntityRef,asciidocEmail,asciidocURL,asciidocBackslash,asciidocToDo keepend
" DEPRECATED: Horizontal label.
syn region asciidocHLabel start=/^\s*/ end=/\(::\|;;\)\(\s\+\|\\$\)/ oneline contains=asciidocQuoted.*,asciidocMacroAttributes keepend
" Starts with any of the above.
syn region asciidocList start=/^\s*\(-\|\*\{1,5}\)\s/ start=/^\s*\(\(\d\+\.\)\|\.\{1,5}\|\(\a\.\)\|\([ivxIVX]\+)\)\)\s\+/ start=/.\+\(:\{2,4}\|;;\)$/ end=/\(^[=*]\{4,}$\)\@=/ end=/\(^+\?\s*$\)\@=/ contains=asciidocList.\+,asciidocQuoted.*,asciidocMacroAttributes,asciidocAttributeRef,asciidocEntityRef,asciidocEmail,asciidocURL,asciidocBackslash,asciidocCommentLine,asciidocAttributeList,asciidocToDo
highlight link asciidocAdmonition Special
highlight link asciidocAnchorMacro Macro
highlight link asciidocAttributeEntry Special
highlight link asciidocAttributeList Special
highlight link asciidocAttributeMacro Macro
highlight link asciidocAttributeRef Special
highlight link asciidocBackslash Special
highlight link asciidocBlockTitle Title
highlight link asciidocCallout Label
highlight link asciidocCommentBlock Comment
highlight link asciidocCommentLine Comment
highlight link asciidocDoubleDollarPassthrough Special
highlight link asciidocEmail Macro
highlight link asciidocEntityRef Special
highlight link asciidocExampleBlockDelimiter Type
highlight link asciidocFilterBlock Type
highlight link asciidocHLabel Label
highlight link asciidocIdMarker Special
highlight link asciidocIndexTerm Macro
highlight link asciidocLineBreak Special
highlight link asciidocListBlockDelimiter Label
highlight link asciidocListBullet Label
highlight link asciidocListContinuation Label
highlight link asciidocListingBlock Identifier
highlight link asciidocListLabel Label
highlight link asciidocListNumber Label
highlight link asciidocLiteralBlock Identifier
highlight link asciidocLiteralParagraph Identifier
highlight link asciidocMacroAttributes Label
highlight link asciidocMacro Macro
highlight link asciidocOneLineTitle Title
highlight link asciidocPagebreak Type
highlight link asciidocPassthroughBlock Identifier
highlight link asciidocQuoteBlockDelimiter Type
highlight link asciidocQuotedAttributeList Special
highlight link asciidocQuotedBold Special
highlight link asciidocQuotedDoubleQuoted Label
highlight link asciidocQuotedEmphasized2 Type
highlight link asciidocQuotedEmphasized Type
highlight link asciidocQuotedMonospaced2 Identifier
highlight link asciidocQuotedMonospaced Identifier
highlight link asciidocQuotedSingleQuoted Label
highlight link asciidocQuotedSubscript Type
highlight link asciidocQuotedSuperscript Type
highlight link asciidocQuotedUnconstrainedBold Special
highlight link asciidocQuotedUnconstrainedEmphasized Type
highlight link asciidocQuotedUnconstrainedMonospaced Identifier
highlight link asciidocRefMacro Macro
highlight link asciidocRuler Type
highlight link asciidocSidebarDelimiter Type
highlight link asciidocTableBlock2 NONE
highlight link asciidocTableBlock NONE
highlight link asciidocTableDelimiter2 Label
highlight link asciidocTableDelimiter Label
highlight link asciidocTable_OLD Type
highlight link asciidocTablePrefix2 Label
highlight link asciidocTablePrefix Label
highlight link asciidocToDo Todo
highlight link asciidocTriplePlusPassthrough Special
highlight link asciidocTwoLineTitle Title
highlight link asciidocURL Macro
let b:current_syntax = "asciidoc"
" vim: wrap et sw=2 sts=2:

View File

@ -6,19 +6,19 @@ lang: zh
# [Available Layers](../../) >> lang#asciidoc
![asciidoc](https://user-images.githubusercontent.com/13142418/92319337-7554ec00-f049-11ea-90fb-ad663dceea12.png)
<!-- vim-markdown-toc GFM -->
- [模块简介](#模块简介)
- [启用模块](#启用模块)
- [快捷键](#快捷键)
<!-- vim-markdown-toc -->
## 模块简介
这一模块为 SpaceVim 提供了 AsciiDoc 的编辑支持,包括格式化、自动生成文章目录、代码块等特性。该模块包括以下插件:
- `wsdjeg/vim-asciidoc`
- `Raimondi/VimRegStyle`
这一模块为 SpaceVim 提供了 AsciiDoc 的编辑支持,包括格式化、自动生成文章目录、代码块等特性。
## 启用模块
@ -29,3 +29,10 @@ lang: zh
name = "lang#asciidoc"
```
若需要查看 asciidoc 侧栏标题目录,则需要安装 `ctags`
## 快捷键
| 快捷键 | 功能描述 |
| ------ | -------------- |
| `F2` | 打开侧边语法树 |

View File

@ -5,19 +5,19 @@ description: "Edit AsciiDoc within vim, autopreview AsciiDoc in the default brow
# [Available Layers](../../) >> lang#asciidoc
![asciidoc](https://user-images.githubusercontent.com/13142418/92319337-7554ec00-f049-11ea-90fb-ad663dceea12.png)
<!-- vim-markdown-toc GFM -->
- [Description](#description)
- [Install](#install)
- [Key bindings](#key-bindings)
<!-- vim-markdown-toc -->
## Description
This layer is for editing AsciiDoc file. Following plugins are included in this layer:
- `wsdjeg/vim-asciidoc`
- `Raimondi/VimRegStyle`
This layer is for editing AsciiDoc file. Including syntax highlighting, indent and syntax lint.
## Install
@ -27,3 +27,11 @@ To use this configuration layer, update custom configuration file with:
[[layers]]
name = "lang#asciidoc"
```
`ctags` is required, if users want to view the syntax outline.
## Key bindings
| Key bindings | Description |
| ------------ | ------------------------------------- |
| `F2` | Open outline of current asciidoc file |