2016-12-21 17:09:25 +01:00
|
|
|
" vim:tabstop=2:shiftwidth=2:expandtab:textwidth=99
|
|
|
|
" Vimwiki autoload plugin file
|
|
|
|
" Home: https://github.com/vimwiki/vimwiki/
|
|
|
|
|
2018-04-20 07:03:53 +02:00
|
|
|
|
|
|
|
|
2018-02-15 18:38:39 +01:00
|
|
|
" ------------------------------------------------------------------------------------------------
|
|
|
|
" This file provides functions to manage the various state variables which are needed during a
|
|
|
|
" Vimwiki session.
|
|
|
|
" They consist of:
|
|
|
|
"
|
|
|
|
" - global variables. These are stored in the dict g:vimwiki_global_vars. They consist mainly of
|
|
|
|
" global user variables and syntax stuff which is the same for every syntax.
|
|
|
|
"
|
|
|
|
" - wiki-local variables. They are stored in g:vimwiki_wikilocal_vars which is a list of
|
2019-01-19 21:05:27 +01:00
|
|
|
" dictionaries, one dict for every registered wiki. The last dictionary contains default values
|
2018-02-15 18:38:39 +01:00
|
|
|
" (used for temporary wikis).
|
|
|
|
"
|
|
|
|
" - syntax variables. Stored in the dict g:vimwiki_syntax_variables which holds all the regexes and
|
|
|
|
" other stuff which is needed for highlighting.
|
|
|
|
"
|
|
|
|
" - buffer-local variables. They are stored as buffer variables directly (b:foo)
|
|
|
|
|
|
|
|
" As a developer, you should, if possible, only use the get_ and set_ functions for these types of
|
|
|
|
" variables, not the underlying dicts!
|
|
|
|
" ------------------------------------------------------------------------------------------------
|
|
|
|
|
2016-12-21 17:09:25 +01:00
|
|
|
|
|
|
|
function! s:populate_global_variables()
|
2018-02-15 18:38:39 +01:00
|
|
|
|
2019-01-19 21:05:27 +01:00
|
|
|
let g:vimwiki_global_vars = {}
|
2016-12-21 17:09:25 +01:00
|
|
|
|
2019-01-19 21:05:27 +01:00
|
|
|
call s:read_global_settings_from_user()
|
|
|
|
call s:normalize_global_settings()
|
2016-12-21 22:11:44 +01:00
|
|
|
|
2018-02-15 18:38:39 +01:00
|
|
|
" non-configurable global variables:
|
2016-12-21 22:11:44 +01:00
|
|
|
|
2018-02-15 18:38:39 +01:00
|
|
|
" Scheme regexes must be defined even if syntax file is not loaded yet cause users should be
|
2016-12-21 22:11:44 +01:00
|
|
|
" able to <leader>w<leader>w without opening any vimwiki file first
|
2018-05-20 15:18:05 +02:00
|
|
|
let g:vimwiki_global_vars.schemes = join(['wiki\d\+', 'diary', 'local'], '\|')
|
|
|
|
let g:vimwiki_global_vars.web_schemes1 = join(['http', 'https', 'file', 'ftp', 'gopher',
|
|
|
|
\ 'telnet', 'nntp', 'ldap', 'rsync', 'imap', 'pop', 'irc', 'ircs', 'cvs', 'svn', 'svn+ssh',
|
|
|
|
\ 'git', 'ssh', 'fish', 'sftp'], '\|')
|
|
|
|
let web_schemes2 =
|
|
|
|
\ join(['mailto', 'news', 'xmpp', 'sip', 'sips', 'doi', 'urn', 'tel', 'data'], '\|')
|
|
|
|
|
|
|
|
let g:vimwiki_global_vars.rxSchemes = '\%('.
|
|
|
|
\ g:vimwiki_global_vars.schemes . '\|'.
|
|
|
|
\ g:vimwiki_global_vars.web_schemes1 . '\|'.
|
|
|
|
\ web_schemes2 .
|
2016-12-21 22:11:44 +01:00
|
|
|
\ '\)'
|
|
|
|
|
|
|
|
" match URL for common protocols; see http://en.wikipedia.org/wiki/URI_scheme
|
|
|
|
" http://tools.ietf.org/html/rfc3986
|
|
|
|
let rxWebProtocols =
|
|
|
|
\ '\%('.
|
|
|
|
\ '\%('.
|
2018-05-20 15:18:05 +02:00
|
|
|
\ '\%('.g:vimwiki_global_vars.web_schemes1 . '\):'.
|
2016-12-21 22:11:44 +01:00
|
|
|
\ '\%(//\)'.
|
|
|
|
\ '\)'.
|
|
|
|
\ '\|'.
|
2018-05-20 15:18:05 +02:00
|
|
|
\ '\%('.web_schemes2.'\):'.
|
2016-12-21 22:11:44 +01:00
|
|
|
\ '\)'
|
|
|
|
|
2017-01-12 21:45:09 +01:00
|
|
|
let g:vimwiki_global_vars.rxWeblinkUrl = rxWebProtocols . '\S\{-1,}'. '\%(([^ \t()]*)\)\='
|
2016-12-28 22:17:08 +01:00
|
|
|
|
|
|
|
let wikilink_prefix = '[['
|
|
|
|
let wikilink_suffix = ']]'
|
|
|
|
let wikilink_separator = '|'
|
|
|
|
let g:vimwiki_global_vars.rx_wikilink_prefix = vimwiki#u#escape(wikilink_prefix)
|
|
|
|
let g:vimwiki_global_vars.rx_wikilink_suffix = vimwiki#u#escape(wikilink_suffix)
|
|
|
|
let g:vimwiki_global_vars.rx_wikilink_separator = vimwiki#u#escape(wikilink_separator)
|
|
|
|
|
|
|
|
" templates for the creation of wiki links
|
|
|
|
" [[URL]]
|
|
|
|
let g:vimwiki_global_vars.WikiLinkTemplate1 = wikilink_prefix . '__LinkUrl__'. wikilink_suffix
|
|
|
|
" [[URL|DESCRIPTION]]
|
|
|
|
let g:vimwiki_global_vars.WikiLinkTemplate2 = wikilink_prefix . '__LinkUrl__'. wikilink_separator
|
|
|
|
\ . '__LinkDescription__' . wikilink_suffix
|
|
|
|
|
|
|
|
let valid_chars = '[^\\\]]'
|
|
|
|
let g:vimwiki_global_vars.rxWikiLinkUrl = valid_chars.'\{-}'
|
|
|
|
let g:vimwiki_global_vars.rxWikiLinkDescr = valid_chars.'\{-}'
|
|
|
|
|
|
|
|
" this regexp defines what can form a link when the user presses <CR> in the
|
|
|
|
" buffer (and not on a link) to create a link
|
|
|
|
" basically, it's Ascii alphanumeric characters plus #|./@-_~ plus all
|
2018-09-17 11:21:07 +02:00
|
|
|
" non-Ascii characters, except that . is not accepted as the last character
|
|
|
|
let g:vimwiki_global_vars.rxWord = '[^[:blank:]!"$%&''()*+,:;<=>?\[\]\\^`{}]*[^[:blank:]!"$%&''()*+.,:;<=>?\[\]\\^`{}]'
|
2016-12-28 22:17:08 +01:00
|
|
|
|
2018-02-15 18:38:39 +01:00
|
|
|
let g:vimwiki_global_vars.rx_wikilink_prefix1 = g:vimwiki_global_vars.rx_wikilink_prefix .
|
|
|
|
\ g:vimwiki_global_vars.rxWikiLinkUrl . g:vimwiki_global_vars.rx_wikilink_separator
|
2017-01-04 21:53:03 +01:00
|
|
|
let g:vimwiki_global_vars.rx_wikilink_suffix1 = g:vimwiki_global_vars.rx_wikilink_suffix
|
2016-12-28 22:17:08 +01:00
|
|
|
|
|
|
|
let g:vimwiki_global_vars.rxWikiInclPrefix = '{{'
|
|
|
|
let g:vimwiki_global_vars.rxWikiInclSuffix = '}}'
|
|
|
|
let g:vimwiki_global_vars.rxWikiInclSeparator = '|'
|
|
|
|
" '{{__LinkUrl__}}'
|
2018-02-15 18:38:39 +01:00
|
|
|
let g:vimwiki_global_vars.WikiInclTemplate1 = g:vimwiki_global_vars.rxWikiInclPrefix
|
|
|
|
\ .'__LinkUrl__'. g:vimwiki_global_vars.rxWikiInclSuffix
|
2016-12-28 22:17:08 +01:00
|
|
|
" '{{__LinkUrl____LinkDescription__}}'
|
2018-02-15 18:38:39 +01:00
|
|
|
let g:vimwiki_global_vars.WikiInclTemplate2 = g:vimwiki_global_vars.rxWikiInclPrefix
|
|
|
|
\ . '__LinkUrl__' . g:vimwiki_global_vars.rxWikiInclSeparator . '__LinkDescription__'
|
|
|
|
\ . g:vimwiki_global_vars.rxWikiInclSuffix
|
2016-12-28 22:17:08 +01:00
|
|
|
|
|
|
|
let valid_chars = '[^\\\}]'
|
|
|
|
let g:vimwiki_global_vars.rxWikiInclUrl = valid_chars.'\{-}'
|
|
|
|
let g:vimwiki_global_vars.rxWikiInclArg = valid_chars.'\{-}'
|
|
|
|
let g:vimwiki_global_vars.rxWikiInclArgs = '\%('. g:vimwiki_global_vars.rxWikiInclSeparator.
|
|
|
|
\ g:vimwiki_global_vars.rxWikiInclArg. '\)'.'\{-}'
|
|
|
|
|
|
|
|
" *. {{URL}[{...}]} - i.e. {{URL}}, {{URL|ARG1}}, {{URL|ARG1|ARG2}}, etc.
|
|
|
|
" *a) match {{URL}[{...}]}
|
|
|
|
let g:vimwiki_global_vars.rxWikiIncl = g:vimwiki_global_vars.rxWikiInclPrefix.
|
|
|
|
\ g:vimwiki_global_vars.rxWikiInclUrl.
|
|
|
|
\ g:vimwiki_global_vars.rxWikiInclArgs. g:vimwiki_global_vars.rxWikiInclSuffix
|
|
|
|
" *b) match URL within {{URL}[{...}]}
|
|
|
|
let g:vimwiki_global_vars.rxWikiInclMatchUrl = g:vimwiki_global_vars.rxWikiInclPrefix.
|
|
|
|
\ '\zs'. g:vimwiki_global_vars.rxWikiInclUrl . '\ze'.
|
|
|
|
\ g:vimwiki_global_vars.rxWikiInclArgs . g:vimwiki_global_vars.rxWikiInclSuffix
|
|
|
|
|
|
|
|
let g:vimwiki_global_vars.rxWikiInclPrefix1 = g:vimwiki_global_vars.rxWikiInclPrefix.
|
|
|
|
\ g:vimwiki_global_vars.rxWikiInclUrl . g:vimwiki_global_vars.rxWikiInclSeparator
|
|
|
|
let g:vimwiki_global_vars.rxWikiInclSuffix1 = g:vimwiki_global_vars.rxWikiInclArgs.
|
|
|
|
\ g:vimwiki_global_vars.rxWikiInclSuffix
|
|
|
|
|
2018-04-01 21:45:15 +02:00
|
|
|
let g:vimwiki_global_vars.rxTodo = '\C\<\%(TODO\|DONE\|STARTED\|FIXME\|FIXED\|XXX\)\>'
|
2017-01-04 21:53:03 +01:00
|
|
|
|
|
|
|
" default colors when headers of different levels are highlighted differently
|
|
|
|
" not making it yet another option; needed by ColorScheme autocommand
|
2018-02-15 18:38:39 +01:00
|
|
|
let g:vimwiki_global_vars.hcolor_guifg_light = ['#aa5858', '#507030', '#1030a0', '#103040'
|
|
|
|
\ , '#505050', '#636363']
|
|
|
|
let g:vimwiki_global_vars.hcolor_ctermfg_light = ['DarkRed', 'DarkGreen', 'DarkBlue', 'Black'
|
|
|
|
\ , 'Black', 'Black']
|
|
|
|
let g:vimwiki_global_vars.hcolor_guifg_dark = ['#e08090', '#80e090', '#6090e0', '#c0c0f0'
|
|
|
|
\ , '#e0e0f0', '#f0f0f0']
|
|
|
|
let g:vimwiki_global_vars.hcolor_ctermfg_dark = ['Red', 'Green', 'Blue', 'White', 'White'
|
|
|
|
\ , 'White']
|
2016-12-21 17:09:25 +01:00
|
|
|
endfunction
|
|
|
|
|
|
|
|
|
2019-01-19 21:05:27 +01:00
|
|
|
function! s:read_global_settings_from_user()
|
|
|
|
let global_settings = {
|
|
|
|
\ 'CJK_length': {'type': type(0), 'default': 0, 'min': 0, 'max': 1},
|
|
|
|
\ 'auto_chdir': {'type': type(0), 'default': 0, 'min': 0, 'max': 1},
|
2019-04-13 15:00:06 +02:00
|
|
|
\ 'auto_header': {'type': type(0), 'default': 0, 'min': 0, 'max': 1},
|
2019-01-19 21:05:27 +01:00
|
|
|
\ 'autowriteall': {'type': type(0), 'default': 1, 'min': 0, 'max': 1},
|
|
|
|
\ 'conceallevel': {'type': type(0), 'default': 2, 'min': 0, 'max': 3},
|
2019-04-09 07:34:34 +02:00
|
|
|
\ 'conceal_onechar_markers': {'type': type(0), 'default': 1, 'min': 0, 'max': 1},
|
2019-03-28 22:49:42 +01:00
|
|
|
\ 'conceal_pre': {'type': type(0), 'default': 0, 'min': 0, 'max': 1},
|
2019-03-18 22:35:28 +01:00
|
|
|
\ 'create_link': {'type': type(0), 'default': 1, 'min':0, 'max': 1},
|
2019-01-19 21:05:27 +01:00
|
|
|
\ 'diary_months': {'type': type({}), 'default':
|
|
|
|
\ {
|
|
|
|
\ 1: 'January', 2: 'February', 3: 'March',
|
|
|
|
\ 4: 'April', 5: 'May', 6: 'June',
|
|
|
|
\ 7: 'July', 8: 'August', 9: 'September',
|
|
|
|
\ 10: 'October', 11: 'November', 12: 'December'
|
|
|
|
\ }},
|
|
|
|
\ 'dir_link': {'type': type(''), 'default': ''},
|
|
|
|
\ 'ext2syntax': {'type': type({}), 'default': {}},
|
|
|
|
\ 'folding': {'type': type(''), 'default': '', 'possible_values': ['', 'expr', 'syntax',
|
|
|
|
\ 'list', 'custom', ':quick', 'expr:quick', 'syntax:quick', 'list:quick',
|
|
|
|
\ 'custom:quick']},
|
|
|
|
\ 'global_ext': {'type': type(0), 'default': 1, 'min': 0, 'max': 1},
|
|
|
|
\ 'hl_cb_checked': {'type': type(0), 'default': 0, 'min': 0, 'max': 2},
|
|
|
|
\ 'hl_headers': {'type': type(0), 'default': 0, 'min': 0, 'max': 1},
|
|
|
|
\ 'html_header_numbering': {'type': type(0), 'default': 0, 'min': 0, 'max': 6},
|
|
|
|
\ 'html_header_numbering_sym': {'type': type(''), 'default': ''},
|
2019-04-27 05:17:35 +02:00
|
|
|
\ 'key_mappings': {'type': type({}), 'default':
|
|
|
|
\ {
|
|
|
|
\ 'all_maps': 1, 'global': 1, 'headers': 1, 'text_objs': 1,
|
|
|
|
\ 'table_format': 1, 'table_mappings': 1, 'lists': 1, 'links': 1,
|
|
|
|
\ 'html': 1, 'mouse': 0,
|
|
|
|
\ }},
|
2019-01-19 21:05:27 +01:00
|
|
|
\ 'list_ignore_newline': {'type': type(0), 'default': 1, 'min': 0, 'max': 1},
|
|
|
|
\ 'text_ignore_newline': {'type': type(0), 'default': 1, 'min': 0, 'max': 1},
|
2019-03-21 20:31:04 +01:00
|
|
|
\ 'links_header': {'type': type(''), 'default': 'Generated Links', 'min_length': 1},
|
|
|
|
\ 'links_header_level': {'type': type(0), 'default': 1, 'min': 1, 'max': 6},
|
2019-01-19 21:05:27 +01:00
|
|
|
\ 'listsyms': {'type': type(''), 'default': ' .oOX', 'min_length': 2},
|
|
|
|
\ 'listsym_rejected': {'type': type(''), 'default': '-', 'length': 1},
|
|
|
|
\ 'map_prefix': {'type': type(''), 'default': '<Leader>w'},
|
2019-03-21 20:31:04 +01:00
|
|
|
\ 'markdown_header_style': {'type': type(0), 'default': 1, 'min':0, 'max': 2},
|
2018-07-12 15:47:47 +02:00
|
|
|
\ 'markdown_link_ext': {'type': type(0), 'default': 0, 'min': 0, 'max': 1},
|
2019-01-19 21:05:27 +01:00
|
|
|
\ 'menu': {'type': type(''), 'default': 'Vimwiki'},
|
|
|
|
\ 'table_auto_fmt': {'type': type(0), 'default': 1, 'min': 0, 'max': 1},
|
2019-03-23 15:23:58 +01:00
|
|
|
\ 'table_reduce_last_col': {'type': type(0), 'default': 0, 'min': 0, 'max': 1},
|
2019-01-19 21:05:27 +01:00
|
|
|
\ 'table_mappings': {'type': type(0), 'default': 1, 'min': 0, 'max': 1},
|
2019-03-21 20:31:04 +01:00
|
|
|
\ 'tags_header': {'type': type(''), 'default': 'Generated Tags', 'min_length': 1},
|
|
|
|
\ 'tags_header_level': {'type': type(0), 'default': 1, 'min': 1, 'max': 5},
|
2019-01-19 21:05:27 +01:00
|
|
|
\ 'toc_header': {'type': type(''), 'default': 'Contents', 'min_length': 1},
|
2019-03-13 15:28:22 +01:00
|
|
|
\ 'toc_header_level': {'type': type(0), 'default': 1, 'min': 1, 'max': 6},
|
2019-03-29 21:25:27 +01:00
|
|
|
\ 'toc_link_format': {'type': type(0), 'default': 0, 'min': 0, 'max': 1},
|
2019-01-19 21:05:27 +01:00
|
|
|
\ 'url_maxsave': {'type': type(0), 'default': 15, 'min': 0},
|
|
|
|
\ 'use_calendar': {'type': type(0), 'default': 1, 'min': 0, 'max': 1},
|
|
|
|
\ 'use_mouse': {'type': type(0), 'default': 0, 'min': 0, 'max': 1},
|
|
|
|
\ 'user_htmls': {'type': type(''), 'default': ''},
|
|
|
|
\ 'valid_html_tags': {'type': type(''), 'default':
|
|
|
|
\ 'b,i,s,u,sub,sup,kbd,br,hr,div,center,strong,em'},
|
|
|
|
\ 'w32_dir_enc': {'type': type(''), 'default': ''},
|
|
|
|
\ }
|
|
|
|
|
|
|
|
" copy the user's settings from variables of the form g:vimwiki_<option> into the dict
|
|
|
|
" g:vimwiki_global_vars (or set a default value)
|
|
|
|
for key in keys(global_settings)
|
|
|
|
if exists('g:vimwiki_'.key)
|
|
|
|
let users_value = g:vimwiki_{key}
|
|
|
|
let value_infos = global_settings[key]
|
|
|
|
|
|
|
|
call s:check_users_value(key, users_value, value_infos, 1)
|
|
|
|
|
|
|
|
let g:vimwiki_global_vars[key] = users_value
|
2019-04-26 19:06:09 +02:00
|
|
|
" Remove users_value to prevent type mismatch (E706) errors in vim <7.4.1546
|
|
|
|
unlet users_value
|
2019-01-19 21:05:27 +01:00
|
|
|
else
|
|
|
|
let g:vimwiki_global_vars[key] = global_settings[key].default
|
|
|
|
endif
|
|
|
|
endfor
|
|
|
|
|
|
|
|
" validate some settings individually
|
|
|
|
|
|
|
|
let key = 'diary_months'
|
|
|
|
let users_value = g:vimwiki_global_vars[key]
|
|
|
|
for month in range(1, 12)
|
|
|
|
if !has_key(users_value, month) || type(users_value[month]) != type('') ||
|
|
|
|
\ empty(users_value[month])
|
|
|
|
echom printf('Vimwiki Error: The provided value ''%s'' of the option ''g:vimwiki_%s'' is'
|
|
|
|
\ . ' invalid. See '':h g:vimwiki_%s''.', string(users_value), key, key)
|
|
|
|
break
|
|
|
|
endif
|
|
|
|
endfor
|
|
|
|
|
|
|
|
let key = 'ext2syntax'
|
|
|
|
let users_value = g:vimwiki_global_vars[key]
|
|
|
|
for ext in keys(users_value)
|
|
|
|
if empty(ext) || index(['markdown', 'media', 'mediawiki', 'default'], users_value[ext]) == -1
|
|
|
|
echom printf('Vimwiki Error: The provided value ''%s'' of the option ''g:vimwiki_%s'' is'
|
|
|
|
\ . ' invalid. See '':h g:vimwiki_%s''.', string(users_value), key, key)
|
|
|
|
break
|
|
|
|
endif
|
|
|
|
endfor
|
|
|
|
|
|
|
|
endfunction
|
|
|
|
|
|
|
|
|
|
|
|
function! s:normalize_global_settings()
|
|
|
|
let keys = keys(g:vimwiki_global_vars.ext2syntax)
|
|
|
|
for ext in keys
|
|
|
|
" ensure the file extensions in ext2syntax start with a dot
|
|
|
|
if ext[0] != '.'
|
|
|
|
let new_ext = '.' . ext
|
|
|
|
let g:vimwiki_global_vars.ext2syntax[new_ext] = g:vimwiki_global_vars.ext2syntax[ext]
|
|
|
|
call remove(g:vimwiki_global_vars.ext2syntax, ext)
|
|
|
|
endif
|
|
|
|
" for convenience, we also allow the term 'mediawiki'
|
|
|
|
if g:vimwiki_global_vars.ext2syntax[ext] ==# 'mediawiki'
|
|
|
|
let g:vimwiki_global_vars.ext2syntax[ext] = 'media'
|
|
|
|
endif
|
|
|
|
endfor
|
2019-04-27 05:17:35 +02:00
|
|
|
|
|
|
|
" ensure key_mappings dictionary has all required keys
|
|
|
|
if !has_key(g:vimwiki_global_vars.key_mappings, 'all_maps')
|
|
|
|
let g:vimwiki_global_vars.key_mappings.all_maps = 1
|
|
|
|
endif
|
|
|
|
if !has_key(g:vimwiki_global_vars.key_mappings, 'global')
|
|
|
|
let g:vimwiki_global_vars.key_mappings.global = 1
|
|
|
|
endif
|
|
|
|
if !has_key(g:vimwiki_global_vars.key_mappings, 'headers')
|
|
|
|
let g:vimwiki_global_vars.key_mappings.headers = 1
|
|
|
|
endif
|
|
|
|
if !has_key(g:vimwiki_global_vars.key_mappings, 'text_objs')
|
|
|
|
let g:vimwiki_global_vars.key_mappings.text_objs = 1
|
|
|
|
endif
|
|
|
|
if !has_key(g:vimwiki_global_vars.key_mappings, 'table_format')
|
|
|
|
let g:vimwiki_global_vars.key_mappings.table_format = 1
|
|
|
|
endif
|
|
|
|
if !has_key(g:vimwiki_global_vars.key_mappings, 'table_mappings')
|
|
|
|
let g:vimwiki_global_vars.key_mappings.table_mappings = 1
|
|
|
|
endif
|
|
|
|
if !has_key(g:vimwiki_global_vars.key_mappings, 'lists')
|
|
|
|
let g:vimwiki_global_vars.key_mappings.lists = 1
|
|
|
|
endif
|
|
|
|
if !has_key(g:vimwiki_global_vars.key_mappings, 'links')
|
|
|
|
let g:vimwiki_global_vars.key_mappings.links = 1
|
|
|
|
endif
|
|
|
|
if !has_key(g:vimwiki_global_vars.key_mappings, 'html')
|
|
|
|
let g:vimwiki_global_vars.key_mappings.html = 1
|
|
|
|
endif
|
|
|
|
if !has_key(g:vimwiki_global_vars.key_mappings, 'mouse')
|
|
|
|
let g:vimwiki_global_vars.key_mappings.mouse = 0
|
|
|
|
endif
|
|
|
|
|
|
|
|
" disable all key mappings if all_maps == 0
|
|
|
|
if !g:vimwiki_global_vars.key_mappings.all_maps
|
|
|
|
let g:vimwiki_global_vars.key_mappings.global = 0
|
|
|
|
let g:vimwiki_global_vars.key_mappings.headers = 0
|
|
|
|
let g:vimwiki_global_vars.key_mappings.text_objs = 0
|
|
|
|
let g:vimwiki_global_vars.key_mappings.table_format = 0
|
|
|
|
let g:vimwiki_global_vars.key_mappings.table_mappings = 0
|
|
|
|
let g:vimwiki_global_vars.table_mappings = 0 " kept for backwards compatibility
|
|
|
|
let g:vimwiki_global_vars.key_mappings.lists = 0
|
|
|
|
let g:vimwiki_global_vars.key_mappings.links = 0
|
|
|
|
let g:vimwiki_global_vars.key_mappings.html = 0
|
|
|
|
let g:vimwiki_global_vars.key_mappings.mouse = 0
|
|
|
|
let g:vimwiki_global_vars.use_mouse = 0 " kept for backwards compatibility
|
|
|
|
endif
|
|
|
|
|
|
|
|
" TODO remove these checks and the table_mappings and use_mouse variables
|
|
|
|
" backwards compatibility checks
|
|
|
|
" if the old option isn't its default value then overwrite the new option
|
|
|
|
if g:vimwiki_global_vars.table_mappings == 0
|
|
|
|
let g:vimwiki_global_vars.key_mappings.table_mappings = 0 && g:vimwiki_global_vars.key_mappings.table_mappings == 1
|
|
|
|
endif
|
|
|
|
if g:vimwiki_global_vars.use_mouse == 1 && g:vimwiki_global_vars.key_mappings.mouse == 0
|
|
|
|
let g:vimwiki_global_vars.key_mappings.mouse = 1
|
|
|
|
endif
|
|
|
|
|
2019-01-19 21:05:27 +01:00
|
|
|
endfunction
|
|
|
|
|
|
|
|
|
2016-12-21 17:09:25 +01:00
|
|
|
function! s:populate_wikilocal_options()
|
|
|
|
let default_values = {
|
2019-01-19 21:05:27 +01:00
|
|
|
\ 'auto_diary_index': {'type': type(0), 'default': 0, 'min': 0, 'max': 1},
|
|
|
|
\ 'auto_export': {'type': type(0), 'default': 0, 'min': 0, 'max': 1},
|
2019-03-22 00:11:03 +01:00
|
|
|
\ 'auto_generate_links': {'type': type(0), 'default': 0, 'min': 0, 'max': 1},
|
|
|
|
\ 'auto_generate_tags': {'type': type(0), 'default': 0, 'min': 0, 'max': 1},
|
2019-01-19 21:05:27 +01:00
|
|
|
\ 'auto_tags': {'type': type(0), 'default': 0, 'min': 0, 'max': 1},
|
|
|
|
\ 'auto_toc': {'type': type(0), 'default': 0, 'min': 0, 'max': 1},
|
|
|
|
\ 'automatic_nested_syntaxes': {'type': type(0), 'default': 1, 'min': 0, 'max': 1},
|
|
|
|
\ 'css_name': {'type': type(''), 'default': 'style.css', 'min_length': 1},
|
|
|
|
\ 'custom_wiki2html': {'type': type(''), 'default': ''},
|
|
|
|
\ 'custom_wiki2html_args': {'type': type(''), 'default': ''},
|
|
|
|
\ 'diary_header': {'type': type(''), 'default': 'Diary', 'min_length': 1},
|
|
|
|
\ 'diary_index': {'type': type(''), 'default': 'diary', 'min_length': 1},
|
2019-04-26 14:23:45 +02:00
|
|
|
\ 'diary_rel_path': {'type': type(''), 'default': 'diary/', 'min_length': 0},
|
2019-03-20 03:59:24 +01:00
|
|
|
\ 'diary_caption_level': {'type': type(0), 'default': 0, 'min': -1, 'max': 6},
|
2019-01-19 21:05:27 +01:00
|
|
|
\ 'diary_sort': {'type': type(''), 'default': 'desc', 'possible_values': ['asc', 'desc']},
|
2019-03-31 04:10:14 +02:00
|
|
|
\ 'exclude_files': {'type': type([]), 'default': []},
|
2019-01-19 21:05:27 +01:00
|
|
|
\ 'ext': {'type': type(''), 'default': '.wiki', 'min_length': 1},
|
|
|
|
\ 'index': {'type': type(''), 'default': 'index', 'min_length': 1},
|
2019-04-01 05:16:44 +02:00
|
|
|
\ 'links_space_char': {'type': type(''), 'default': ' ', 'min_length': 1},
|
2019-01-19 21:05:27 +01:00
|
|
|
\ 'list_margin': {'type': type(0), 'default': -1, 'min': -1},
|
|
|
|
\ 'maxhi': {'type': type(0), 'default': 0, 'min': 0, 'max': 1},
|
2019-04-21 21:05:01 +02:00
|
|
|
\ 'name': {'type': type(''), 'default': ''},
|
2019-01-19 21:05:27 +01:00
|
|
|
\ 'nested_syntaxes': {'type': type({}), 'default': {}},
|
|
|
|
\ 'path': {'type': type(''), 'default': $HOME . '/vimwiki/', 'min_length': 1},
|
|
|
|
\ 'path_html': {'type': type(''), 'default': ''},
|
|
|
|
\ 'syntax': {'type': type(''), 'default': 'default',
|
|
|
|
\ 'possible_values': ['default', 'markdown', 'media', 'mediawiki']},
|
|
|
|
\ 'template_default': {'type': type(''), 'default': 'default', 'min_length': 1},
|
|
|
|
\ 'template_ext': {'type': type(''), 'default': '.tpl'},
|
|
|
|
\ 'template_path': {'type': type(''), 'default': $HOME . '/vimwiki/templates/'},
|
2019-03-30 02:34:31 +01:00
|
|
|
\ 'html_filename_parameterization': {'type': type(0), 'default': 0, 'min': 0, 'max': 1},
|
2016-12-21 17:09:25 +01:00
|
|
|
\ }
|
|
|
|
|
|
|
|
let g:vimwiki_wikilocal_vars = []
|
|
|
|
|
2018-02-23 17:39:50 +01:00
|
|
|
let default_wiki_settings = {}
|
|
|
|
for key in keys(default_values)
|
|
|
|
if exists('g:vimwiki_'.key)
|
2019-01-19 21:05:27 +01:00
|
|
|
call s:check_users_value(key, g:vimwiki_{key}, default_values[key], 1)
|
2018-02-23 17:39:50 +01:00
|
|
|
let default_wiki_settings[key] = g:vimwiki_{key}
|
|
|
|
else
|
2019-01-19 21:05:27 +01:00
|
|
|
let default_wiki_settings[key] = default_values[key].default
|
2018-02-23 17:39:50 +01:00
|
|
|
endif
|
|
|
|
endfor
|
|
|
|
|
2017-11-11 21:52:07 +01:00
|
|
|
" set the wiki-local variables according to g:vimwiki_list (or the default settings)
|
2016-12-21 17:09:25 +01:00
|
|
|
if exists('g:vimwiki_list')
|
2018-02-23 17:39:50 +01:00
|
|
|
for users_wiki_settings in g:vimwiki_list
|
2016-12-25 21:35:56 +01:00
|
|
|
let new_wiki_settings = {}
|
2016-12-21 17:09:25 +01:00
|
|
|
for key in keys(default_values)
|
2018-02-23 17:39:50 +01:00
|
|
|
if has_key(users_wiki_settings, key)
|
2019-01-19 21:05:27 +01:00
|
|
|
call s:check_users_value(key, users_wiki_settings[key], default_values[key], 0)
|
2018-02-23 17:39:50 +01:00
|
|
|
let new_wiki_settings[key] = users_wiki_settings[key]
|
2016-12-21 17:09:25 +01:00
|
|
|
else
|
2019-01-19 21:05:27 +01:00
|
|
|
let new_wiki_settings[key] = default_wiki_settings[key]
|
2016-12-21 17:09:25 +01:00
|
|
|
endif
|
|
|
|
endfor
|
2016-12-25 21:35:56 +01:00
|
|
|
|
2017-11-11 21:52:07 +01:00
|
|
|
let new_wiki_settings.is_temporary_wiki = 0
|
2016-12-25 21:35:56 +01:00
|
|
|
|
|
|
|
call add(g:vimwiki_wikilocal_vars, new_wiki_settings)
|
2016-12-21 17:09:25 +01:00
|
|
|
endfor
|
2018-02-23 17:39:50 +01:00
|
|
|
else
|
|
|
|
" if the user hasn't registered any wiki, we register one wiki using the default values
|
|
|
|
let new_wiki_settings = deepcopy(default_wiki_settings)
|
|
|
|
let new_wiki_settings.is_temporary_wiki = 0
|
|
|
|
call add(g:vimwiki_wikilocal_vars, new_wiki_settings)
|
2016-12-21 17:09:25 +01:00
|
|
|
endif
|
|
|
|
|
|
|
|
" default values for temporary wikis
|
2018-02-23 17:39:50 +01:00
|
|
|
let temporary_wiki_settings = deepcopy(default_wiki_settings)
|
|
|
|
let temporary_wiki_settings.is_temporary_wiki = 1
|
|
|
|
call add(g:vimwiki_wikilocal_vars, temporary_wiki_settings)
|
2016-12-21 17:09:25 +01:00
|
|
|
|
2019-01-19 21:05:27 +01:00
|
|
|
" check some values individually
|
|
|
|
let key = 'nested_syntaxes'
|
|
|
|
for wiki_settings in g:vimwiki_wikilocal_vars
|
|
|
|
let users_value = wiki_settings[key]
|
|
|
|
for keyword in keys(users_value)
|
|
|
|
if type(keyword) != type('') || empty(keyword) || type(users_value[keyword]) != type('') ||
|
|
|
|
\ empty(users_value[keyword])
|
|
|
|
echom printf('Vimwiki Error: The provided value ''%s'' of the option ''g:vimwiki_%s'' is'
|
|
|
|
\ . ' invalid. See '':h g:vimwiki_%s''.', string(users_value), key, key)
|
|
|
|
break
|
|
|
|
endif
|
|
|
|
endfor
|
|
|
|
endfor
|
|
|
|
|
|
|
|
call s:normalize_wikilocal_settings()
|
2016-12-21 17:09:25 +01:00
|
|
|
endfunction
|
|
|
|
|
|
|
|
|
2019-01-19 21:05:27 +01:00
|
|
|
function! s:check_users_value(key, users_value, value_infos, comes_from_global_variable)
|
|
|
|
let type_code_to_name = {
|
|
|
|
\ type(0): 'number',
|
|
|
|
\ type(''): 'string',
|
|
|
|
\ type([]): 'list',
|
|
|
|
\ type({}): 'dictionary'}
|
|
|
|
|
|
|
|
let setting_origin = a:comes_from_global_variable ?
|
|
|
|
\ printf('''g:vimwiki_%s''', a:key) :
|
|
|
|
\ printf('''%s'' in g:vimwiki_list', a:key)
|
|
|
|
|
2019-05-04 14:31:13 +02:00
|
|
|
let help_text = a:comes_from_global_variable ?
|
|
|
|
\ 'g:vimwiki_' :
|
|
|
|
\ 'vimwiki-option-'
|
|
|
|
|
2019-01-19 21:05:27 +01:00
|
|
|
if has_key(a:value_infos, 'type') && type(a:users_value) != a:value_infos.type
|
|
|
|
echom printf('Vimwiki Error: The provided value of the option %s is a %s, ' .
|
2019-05-04 14:31:13 +02:00
|
|
|
\ 'but expected is a %s. See '':h '.help_text.'%s''.', setting_origin,
|
2019-01-19 21:05:27 +01:00
|
|
|
\ type_code_to_name[type(a:users_value)], type_code_to_name[a:value_infos.type], a:key)
|
|
|
|
endif
|
|
|
|
|
|
|
|
if a:value_infos.type == type(0) && has_key(a:value_infos, 'min') &&
|
|
|
|
\ a:users_value < a:value_infos.min
|
|
|
|
echom printf('Vimwiki Error: The provided value ''%i'' of the option %s is'
|
2019-05-04 14:31:13 +02:00
|
|
|
\ . ' too small. The minimum value is %i. See '':h '.help_text.'%s''.', a:users_value,
|
2019-01-19 21:05:27 +01:00
|
|
|
\ setting_origin, a:value_infos.min, a:key)
|
|
|
|
endif
|
|
|
|
|
|
|
|
if a:value_infos.type == type(0) && has_key(a:value_infos, 'max') &&
|
|
|
|
\ a:users_value > a:value_infos.max
|
|
|
|
echom printf('Vimwiki Error: The provided value ''%i'' of the option %s is'
|
2019-05-04 14:31:13 +02:00
|
|
|
\ . ' too large. The maximum value is %i. See '':h '.help_text.'%s''.', a:users_value,
|
2019-01-19 21:05:27 +01:00
|
|
|
\ setting_origin, a:value_infos.max, a:key)
|
|
|
|
endif
|
|
|
|
|
|
|
|
if has_key(a:value_infos, 'possible_values') &&
|
|
|
|
\ index(a:value_infos.possible_values, a:users_value) == -1
|
|
|
|
echom printf('Vimwiki Error: The provided value ''%s'' of the option %s is'
|
2019-05-04 14:31:13 +02:00
|
|
|
\ . ' invalid. Allowed values are %s. See '':h '.help_text.'%s''.', a:users_value,
|
2019-01-19 21:05:27 +01:00
|
|
|
\ setting_origin, string(a:value_infos.possible_values), a:key)
|
|
|
|
endif
|
|
|
|
|
|
|
|
if a:value_infos.type == type('') && has_key(a:value_infos, 'length') &&
|
|
|
|
\ strwidth(a:users_value) != a:value_infos.length
|
|
|
|
echom printf('Vimwiki Error: The provided value ''%s'' of the option %s must'
|
2019-05-04 14:31:13 +02:00
|
|
|
\ . ' contain exactly %i character(s) but has %i. See '':h '.help_text.'_%s''.',
|
2019-01-19 21:05:27 +01:00
|
|
|
\ a:users_value, setting_origin, a:value_infos.length, strwidth(a:users_value), a:key)
|
|
|
|
endif
|
|
|
|
|
|
|
|
if a:value_infos.type == type('') && has_key(a:value_infos, 'min_length') &&
|
|
|
|
\ strwidth(a:users_value) < a:value_infos.min_length
|
|
|
|
echom printf('Vimwiki Error: The provided value ''%s'' of the option %s must'
|
2019-05-04 14:31:13 +02:00
|
|
|
\ . ' have at least %d character(s) but has %d. See '':h '.help_text.'%s''.', a:users_value,
|
2019-01-19 21:05:27 +01:00
|
|
|
\ setting_origin, a:value_infos.min_length, strwidth(a:users_value), a:key)
|
|
|
|
endif
|
|
|
|
endfunction
|
|
|
|
|
|
|
|
|
|
|
|
function! s:normalize_wikilocal_settings()
|
2016-12-25 21:35:56 +01:00
|
|
|
for wiki_settings in g:vimwiki_wikilocal_vars
|
|
|
|
let wiki_settings['path'] = s:normalize_path(wiki_settings['path'])
|
2016-12-21 17:09:25 +01:00
|
|
|
|
2016-12-25 21:35:56 +01:00
|
|
|
let path_html = wiki_settings['path_html']
|
2016-12-21 17:09:25 +01:00
|
|
|
if !empty(path_html)
|
2016-12-25 21:35:56 +01:00
|
|
|
let wiki_settings['path_html'] = s:normalize_path(path_html)
|
2016-12-21 17:09:25 +01:00
|
|
|
else
|
2016-12-25 21:35:56 +01:00
|
|
|
let wiki_settings['path_html'] = s:normalize_path(
|
|
|
|
\ substitute(wiki_settings['path'], '[/\\]\+$', '', '').'_html/')
|
2016-12-21 17:09:25 +01:00
|
|
|
endif
|
|
|
|
|
2018-12-17 20:27:15 +01:00
|
|
|
let wiki_settings['template_path'] = s:normalize_path(wiki_settings['template_path'])
|
|
|
|
let wiki_settings['diary_rel_path'] = s:normalize_path(wiki_settings['diary_rel_path'])
|
|
|
|
|
|
|
|
let ext = wiki_settings['ext']
|
|
|
|
if !empty(ext) && ext[0] != '.'
|
|
|
|
let wiki_settings['ext'] = '.' . ext
|
|
|
|
endif
|
2019-01-19 21:05:27 +01:00
|
|
|
|
|
|
|
" for convenience, we also allow the term 'mediawiki'
|
|
|
|
if wiki_settings.syntax ==# 'mediawiki'
|
|
|
|
let wiki_settings.syntax = 'media'
|
|
|
|
endif
|
2016-12-21 17:09:25 +01:00
|
|
|
endfor
|
|
|
|
endfunction
|
|
|
|
|
|
|
|
|
2018-04-20 07:03:53 +02:00
|
|
|
function! s:normalize_path(path)
|
2018-02-15 18:38:39 +01:00
|
|
|
" trim trailing / and \ because otherwise resolve() doesn't work quite right
|
|
|
|
let path = substitute(a:path, '[/\\]\+$', '', '')
|
|
|
|
if path !~# '^scp:'
|
|
|
|
return resolve(expand(path)).'/'
|
|
|
|
else
|
|
|
|
return path.'/'
|
|
|
|
endif
|
2018-04-20 07:03:53 +02:00
|
|
|
endfunction
|
2018-02-15 18:38:39 +01:00
|
|
|
|
|
|
|
|
2016-12-28 22:17:08 +01:00
|
|
|
function! vimwiki#vars#populate_syntax_vars(syntax)
|
2016-12-21 17:09:25 +01:00
|
|
|
if !exists('g:vimwiki_syntax_variables')
|
|
|
|
let g:vimwiki_syntax_variables = {}
|
|
|
|
endif
|
2017-11-11 21:52:07 +01:00
|
|
|
|
|
|
|
if has_key(g:vimwiki_syntax_variables, a:syntax)
|
|
|
|
return
|
2016-12-28 22:17:08 +01:00
|
|
|
endif
|
|
|
|
|
2017-11-11 21:52:07 +01:00
|
|
|
let g:vimwiki_syntax_variables[a:syntax] = {}
|
|
|
|
|
2016-12-28 22:17:08 +01:00
|
|
|
execute 'runtime! syntax/vimwiki_'.a:syntax.'.vim'
|
|
|
|
|
|
|
|
" generic stuff
|
|
|
|
let header_symbol = g:vimwiki_syntax_variables[a:syntax].rxH
|
|
|
|
if g:vimwiki_syntax_variables[a:syntax].symH
|
|
|
|
" symmetric headers
|
|
|
|
for i in range(1,6)
|
2018-02-15 18:38:39 +01:00
|
|
|
let g:vimwiki_syntax_variables[a:syntax]['rxH'.i.'_Template'] =
|
|
|
|
\ repeat(header_symbol, i).' __Header__ '.repeat(header_symbol, i)
|
|
|
|
let g:vimwiki_syntax_variables[a:syntax]['rxH'.i] =
|
|
|
|
\ '^\s*'.header_symbol.'\{'.i.'}[^'.header_symbol.'].*[^'.header_symbol.']'
|
|
|
|
\ .header_symbol.'\{'.i.'}\s*$'
|
2019-03-20 03:59:24 +01:00
|
|
|
let g:vimwiki_syntax_variables[a:syntax]['rxH'.i.'_Text'] =
|
|
|
|
\ '^\s*'.header_symbol.'\{'.i.'}\zs[^'.header_symbol.'].*[^'.header_symbol.']\ze'
|
|
|
|
\ .header_symbol.'\{'.i.'}\s*$'
|
2018-02-15 18:38:39 +01:00
|
|
|
let g:vimwiki_syntax_variables[a:syntax]['rxH'.i.'_Start'] =
|
|
|
|
\ '^\s*'.header_symbol.'\{'.i.'}[^'.header_symbol.'].*[^'.header_symbol.']'
|
|
|
|
\ .header_symbol.'\{'.i.'}\s*$'
|
|
|
|
let g:vimwiki_syntax_variables[a:syntax]['rxH'.i.'_End'] =
|
|
|
|
\ '^\s*'.header_symbol.'\{1,'.i.'}[^'.header_symbol.'].*[^'.header_symbol.']'
|
|
|
|
\ .header_symbol.'\{1,'.i.'}\s*$'
|
2016-12-28 22:17:08 +01:00
|
|
|
endfor
|
2018-02-15 18:38:39 +01:00
|
|
|
let g:vimwiki_syntax_variables[a:syntax].rxHeader =
|
|
|
|
\ '^\s*\('.header_symbol.'\{1,6}\)\zs[^'.header_symbol.'].*[^'.header_symbol.']\ze\1\s*$'
|
2016-12-28 22:17:08 +01:00
|
|
|
else
|
|
|
|
" asymmetric
|
|
|
|
for i in range(1,6)
|
2018-02-15 18:38:39 +01:00
|
|
|
let g:vimwiki_syntax_variables[a:syntax]['rxH'.i.'_Template'] =
|
|
|
|
\ repeat(header_symbol, i).' __Header__'
|
|
|
|
let g:vimwiki_syntax_variables[a:syntax]['rxH'.i] =
|
|
|
|
\ '^\s*'.header_symbol.'\{'.i.'}[^'.header_symbol.'].*$'
|
2019-03-20 03:59:24 +01:00
|
|
|
let g:vimwiki_syntax_variables[a:syntax]['rxH'.i.'_Text'] =
|
|
|
|
\ '^\s*'.header_symbol.'\{'.i.'}\zs[^'.header_symbol.'].*\ze$'
|
2018-02-15 18:38:39 +01:00
|
|
|
let g:vimwiki_syntax_variables[a:syntax]['rxH'.i.'_Start'] =
|
|
|
|
\ '^\s*'.header_symbol.'\{'.i.'}[^'.header_symbol.'].*$'
|
|
|
|
let g:vimwiki_syntax_variables[a:syntax]['rxH'.i.'_End'] =
|
|
|
|
\ '^\s*'.header_symbol.'\{1,'.i.'}[^'.header_symbol.'].*$'
|
2016-12-28 22:17:08 +01:00
|
|
|
endfor
|
2018-02-15 18:38:39 +01:00
|
|
|
let g:vimwiki_syntax_variables[a:syntax].rxHeader =
|
|
|
|
\ '^\s*\('.header_symbol.'\{1,6}\)\zs[^'.header_symbol.'].*\ze$'
|
2016-12-28 22:17:08 +01:00
|
|
|
endif
|
|
|
|
|
2018-02-15 18:38:39 +01:00
|
|
|
let g:vimwiki_syntax_variables[a:syntax].rxPreStart =
|
|
|
|
\ '^\s*'.g:vimwiki_syntax_variables[a:syntax].rxPreStart
|
|
|
|
let g:vimwiki_syntax_variables[a:syntax].rxPreEnd =
|
|
|
|
\ '^\s*'.g:vimwiki_syntax_variables[a:syntax].rxPreEnd.'\s*$'
|
2016-12-28 22:17:08 +01:00
|
|
|
|
2018-02-15 18:38:39 +01:00
|
|
|
let g:vimwiki_syntax_variables[a:syntax].rxMathStart =
|
|
|
|
\ '^\s*'.g:vimwiki_syntax_variables[a:syntax].rxMathStart
|
|
|
|
let g:vimwiki_syntax_variables[a:syntax].rxMathEnd =
|
|
|
|
\ '^\s*'.g:vimwiki_syntax_variables[a:syntax].rxMathEnd.'\s*$'
|
2016-12-28 22:17:08 +01:00
|
|
|
|
2019-01-17 21:57:42 +01:00
|
|
|
" list stuff
|
|
|
|
let g:vimwiki_syntax_variables[a:syntax].rx_bullet_chars =
|
|
|
|
\ '['.join(g:vimwiki_syntax_variables[a:syntax].bullet_types, '').']\+'
|
|
|
|
|
|
|
|
let g:vimwiki_syntax_variables[a:syntax].multiple_bullet_chars =
|
|
|
|
\ g:vimwiki_syntax_variables[a:syntax].recurring_bullets
|
|
|
|
\ ? g:vimwiki_syntax_variables[a:syntax].bullet_types : []
|
|
|
|
|
|
|
|
let g:vimwiki_syntax_variables[a:syntax].number_kinds = []
|
|
|
|
let g:vimwiki_syntax_variables[a:syntax].number_divisors = ''
|
|
|
|
for i in g:vimwiki_syntax_variables[a:syntax].number_types
|
|
|
|
call add(g:vimwiki_syntax_variables[a:syntax].number_kinds, i[0])
|
|
|
|
let g:vimwiki_syntax_variables[a:syntax].number_divisors .= vimwiki#u#escape(i[1])
|
|
|
|
endfor
|
2016-12-28 22:17:08 +01:00
|
|
|
|
2016-12-31 20:47:19 +01:00
|
|
|
let char_to_rx = {'1': '\d\+', 'i': '[ivxlcdm]\+', 'I': '[IVXLCDM]\+',
|
2016-12-28 22:17:08 +01:00
|
|
|
\ 'a': '\l\{1,2}', 'A': '\u\{1,2}'}
|
|
|
|
|
|
|
|
"create regexp for bulleted list items
|
2016-12-31 20:47:19 +01:00
|
|
|
if !empty(g:vimwiki_syntax_variables[a:syntax].bullet_types)
|
2018-02-15 18:38:39 +01:00
|
|
|
let g:vimwiki_syntax_variables[a:syntax].rxListBullet =
|
2018-11-19 21:02:37 +01:00
|
|
|
\ join( map(copy(g:vimwiki_syntax_variables[a:syntax].bullet_types),
|
2018-02-15 18:38:39 +01:00
|
|
|
\'vimwiki#u#escape(v:val).'
|
|
|
|
\ .'repeat("\\+", g:vimwiki_syntax_variables[a:syntax].recurring_bullets)'
|
|
|
|
\ ) , '\|')
|
2016-12-31 20:47:19 +01:00
|
|
|
else
|
|
|
|
"regex that matches nothing
|
|
|
|
let g:vimwiki_syntax_variables[a:syntax].rxListBullet = '$^'
|
|
|
|
endif
|
2016-12-28 22:17:08 +01:00
|
|
|
|
|
|
|
"create regex for numbered list items
|
2016-12-31 20:47:19 +01:00
|
|
|
if !empty(g:vimwiki_syntax_variables[a:syntax].number_types)
|
|
|
|
let g:vimwiki_syntax_variables[a:syntax].rxListNumber = '\C\%('
|
|
|
|
for type in g:vimwiki_syntax_variables[a:syntax].number_types[:-2]
|
|
|
|
let g:vimwiki_syntax_variables[a:syntax].rxListNumber .= char_to_rx[type[0]] .
|
2016-12-28 22:17:08 +01:00
|
|
|
\ vimwiki#u#escape(type[1]) . '\|'
|
|
|
|
endfor
|
2018-02-15 18:38:39 +01:00
|
|
|
let g:vimwiki_syntax_variables[a:syntax].rxListNumber .=
|
|
|
|
\ char_to_rx[g:vimwiki_syntax_variables[a:syntax].number_types[-1][0]].
|
2016-12-31 20:47:19 +01:00
|
|
|
\ vimwiki#u#escape(g:vimwiki_syntax_variables[a:syntax].number_types[-1][1]) . '\)'
|
2016-12-28 22:17:08 +01:00
|
|
|
else
|
|
|
|
"regex that matches nothing
|
2016-12-31 20:47:19 +01:00
|
|
|
let g:vimwiki_syntax_variables[a:syntax].rxListNumber = '$^'
|
2016-12-28 22:17:08 +01:00
|
|
|
endif
|
|
|
|
|
2019-01-17 21:57:42 +01:00
|
|
|
"the user can set the listsyms as string, but vimwiki needs a list
|
|
|
|
let g:vimwiki_syntax_variables[a:syntax].listsyms_list =
|
|
|
|
\ split(vimwiki#vars#get_global('listsyms'), '\zs')
|
|
|
|
if match(vimwiki#vars#get_global('listsyms'), vimwiki#vars#get_global('listsym_rejected')) != -1
|
|
|
|
echomsg 'Vimwiki Warning: the value of g:vimwiki_listsym_rejected ('''
|
|
|
|
\ . vimwiki#vars#get_global('listsym_rejected')
|
|
|
|
\ . ''') must not be a part of g:vimwiki_listsyms (''' .
|
|
|
|
\ . vimwiki#vars#get_global('listsyms') . ''')'
|
|
|
|
endif
|
|
|
|
let g:vimwiki_syntax_variables[a:syntax].rxListItemWithoutCB =
|
|
|
|
\ '^\s*\%(\('.g:vimwiki_syntax_variables[a:syntax].rxListBullet.'\)\|\('
|
|
|
|
\ .g:vimwiki_syntax_variables[a:syntax].rxListNumber.'\)\)\s'
|
|
|
|
let g:vimwiki_syntax_variables[a:syntax].rxListItem =
|
|
|
|
\ g:vimwiki_syntax_variables[a:syntax].rxListItemWithoutCB
|
|
|
|
\ . '\+\%(\[\(['.vimwiki#vars#get_global('listsyms')
|
|
|
|
\ . vimwiki#vars#get_global('listsym_rejected').']\)\]\s\)\?'
|
|
|
|
if g:vimwiki_syntax_variables[a:syntax].recurring_bullets
|
|
|
|
let g:vimwiki_syntax_variables[a:syntax].rxListItemAndChildren =
|
|
|
|
\ '^\('.g:vimwiki_syntax_variables[a:syntax].rxListBullet.'\)\s\+\[['
|
|
|
|
\ . g:vimwiki_syntax_variables[a:syntax].listsyms_list[-1]
|
|
|
|
\ . vimwiki#vars#get_global('listsym_rejected') . ']\]\s.*\%(\n\%(\1\%('
|
|
|
|
\ .g:vimwiki_syntax_variables[a:syntax].rxListBullet.'\).*\|^$\|\s.*\)\)*'
|
|
|
|
else
|
|
|
|
let g:vimwiki_syntax_variables[a:syntax].rxListItemAndChildren =
|
|
|
|
\ '^\(\s*\)\%('.g:vimwiki_syntax_variables[a:syntax].rxListBullet.'\|'
|
|
|
|
\ . g:vimwiki_syntax_variables[a:syntax].rxListNumber.'\)\s\+\[['
|
|
|
|
\ . g:vimwiki_syntax_variables[a:syntax].listsyms_list[-1]
|
|
|
|
\ . vimwiki#vars#get_global('listsym_rejected') . ']\]\s.*\%(\n\%(\1\s.*\|^$\)\)*'
|
|
|
|
endif
|
|
|
|
|
2017-01-12 21:45:09 +01:00
|
|
|
" 0. URL : free-standing links: keep URL UR(L) strip trailing punct: URL; URL) UR(L))
|
|
|
|
" let g:vimwiki_rxWeblink = '[\["(|]\@<!'. g:vimwiki_rxWeblinkUrl .
|
|
|
|
" \ '\%([),:;.!?]\=\%([ \t]\|$\)\)\@='
|
2018-02-15 18:38:39 +01:00
|
|
|
let g:vimwiki_syntax_variables[a:syntax].rxWeblink =
|
2019-04-30 14:11:51 +02:00
|
|
|
\ '\<'. g:vimwiki_global_vars.rxWeblinkUrl . '[^[:space:]>]*'
|
2017-01-12 21:45:09 +01:00
|
|
|
" 0a) match URL within URL
|
2018-02-15 18:38:39 +01:00
|
|
|
let g:vimwiki_syntax_variables[a:syntax].rxWeblinkMatchUrl =
|
|
|
|
\ g:vimwiki_syntax_variables[a:syntax].rxWeblink
|
2017-01-12 21:45:09 +01:00
|
|
|
" 0b) match DESCRIPTION within URL
|
|
|
|
let g:vimwiki_syntax_variables[a:syntax].rxWeblinkMatchDescr = ''
|
|
|
|
|
2017-01-11 22:12:33 +01:00
|
|
|
" template for matching all wiki links with a given target file
|
|
|
|
let g:vimwiki_syntax_variables[a:syntax].WikiLinkMatchUrlTemplate =
|
|
|
|
\ g:vimwiki_global_vars.rx_wikilink_prefix .
|
|
|
|
\ '\zs__LinkUrl__\ze\%(#.*\)\?' .
|
|
|
|
\ g:vimwiki_global_vars.rx_wikilink_suffix .
|
|
|
|
\ '\|' .
|
|
|
|
\ g:vimwiki_global_vars.rx_wikilink_prefix .
|
|
|
|
\ '\zs__LinkUrl__\ze\%(#.*\)\?' .
|
|
|
|
\ g:vimwiki_global_vars.rx_wikilink_separator .
|
|
|
|
\ '.*' .
|
|
|
|
\ g:vimwiki_global_vars.rx_wikilink_suffix
|
|
|
|
|
|
|
|
" a) match [[URL|DESCRIPTION]]
|
|
|
|
let g:vimwiki_syntax_variables[a:syntax].rxWikiLink = g:vimwiki_global_vars.rx_wikilink_prefix.
|
|
|
|
\ g:vimwiki_global_vars.rxWikiLinkUrl.'\%('.g:vimwiki_global_vars.rx_wikilink_separator.
|
|
|
|
\ g:vimwiki_global_vars.rxWikiLinkDescr.'\)\?'.g:vimwiki_global_vars.rx_wikilink_suffix
|
2018-02-15 18:38:39 +01:00
|
|
|
let g:vimwiki_syntax_variables[a:syntax].rxAnyLink =
|
|
|
|
\ g:vimwiki_syntax_variables[a:syntax].rxWikiLink.'\|'.
|
|
|
|
\ g:vimwiki_global_vars.rxWikiIncl.'\|'.g:vimwiki_syntax_variables[a:syntax].rxWeblink
|
2017-01-11 22:12:33 +01:00
|
|
|
" b) match URL within [[URL|DESCRIPTION]]
|
2018-02-15 18:38:39 +01:00
|
|
|
let g:vimwiki_syntax_variables[a:syntax].rxWikiLinkMatchUrl =
|
|
|
|
\ g:vimwiki_global_vars.rx_wikilink_prefix . '\zs'. g:vimwiki_global_vars.rxWikiLinkUrl
|
|
|
|
\ .'\ze\%('. g:vimwiki_global_vars.rx_wikilink_separator
|
|
|
|
\ . g:vimwiki_global_vars.rxWikiLinkDescr.'\)\?'.g:vimwiki_global_vars.rx_wikilink_suffix
|
2017-01-12 21:45:09 +01:00
|
|
|
" c) match DESCRIPTION within [[URL|DESCRIPTION]]
|
2018-02-15 18:38:39 +01:00
|
|
|
let g:vimwiki_syntax_variables[a:syntax].rxWikiLinkMatchDescr =
|
|
|
|
\ g:vimwiki_global_vars.rx_wikilink_prefix . g:vimwiki_global_vars.rxWikiLinkUrl
|
|
|
|
\ . g:vimwiki_global_vars.rx_wikilink_separator.'\%(\zs'
|
|
|
|
\ . g:vimwiki_global_vars.rxWikiLinkDescr. '\ze\)\?'
|
|
|
|
\ . g:vimwiki_global_vars.rx_wikilink_suffix
|
2017-01-11 22:12:33 +01:00
|
|
|
|
|
|
|
if a:syntax ==# 'markdown'
|
|
|
|
call s:populate_extra_markdown_vars()
|
|
|
|
endif
|
|
|
|
endfunction
|
|
|
|
|
|
|
|
|
|
|
|
function! s:populate_extra_markdown_vars()
|
|
|
|
let mkd_syntax = g:vimwiki_syntax_variables['markdown']
|
|
|
|
|
|
|
|
" 0a) match [[URL|DESCRIPTION]]
|
2017-01-12 21:45:09 +01:00
|
|
|
let mkd_syntax.rxWikiLink0 = mkd_syntax.rxWikiLink
|
2017-01-11 22:12:33 +01:00
|
|
|
" 0b) match URL within [[URL|DESCRIPTION]]
|
2017-01-12 21:45:09 +01:00
|
|
|
let mkd_syntax.rxWikiLink0MatchUrl = mkd_syntax.rxWikiLinkMatchUrl
|
2017-01-11 22:12:33 +01:00
|
|
|
" 0c) match DESCRIPTION within [[URL|DESCRIPTION]]
|
2017-01-16 22:09:49 +01:00
|
|
|
let mkd_syntax.rxWikiLink0MatchDescr = mkd_syntax.rxWikiLinkMatchDescr
|
2017-01-11 22:12:33 +01:00
|
|
|
|
|
|
|
let wikilink_md_prefix = '['
|
2019-01-16 20:56:49 +01:00
|
|
|
let wikilink_md_suffix = ']'
|
|
|
|
let wikilink_md_separator = ']['
|
2017-01-11 22:12:33 +01:00
|
|
|
let rx_wikilink_md_separator = vimwiki#u#escape(wikilink_md_separator)
|
|
|
|
let mkd_syntax.rx_wikilink_md_prefix = vimwiki#u#escape(wikilink_md_prefix)
|
|
|
|
let mkd_syntax.rx_wikilink_md_suffix = vimwiki#u#escape(wikilink_md_suffix)
|
|
|
|
|
|
|
|
" [URL][]
|
|
|
|
let mkd_syntax.WikiLink1Template1 = wikilink_md_prefix . '__LinkUrl__'.
|
|
|
|
\ wikilink_md_separator. wikilink_md_suffix
|
|
|
|
" [DESCRIPTION][URL]
|
|
|
|
let mkd_syntax.WikiLink1Template2 = wikilink_md_prefix. '__LinkDescription__'.
|
|
|
|
\ wikilink_md_separator. '__LinkUrl__'. wikilink_md_suffix
|
2017-01-12 21:45:09 +01:00
|
|
|
|
|
|
|
let valid_chars = '[^\\\[\]]'
|
|
|
|
let mkd_syntax.rxWikiLink1Url = valid_chars.'\{-}'
|
|
|
|
let mkd_syntax.rxWikiLink1Descr = valid_chars.'\{-}'
|
|
|
|
let mkd_syntax.rxWikiLink1InvalidPrefix = '[\]\[]\@<!'
|
|
|
|
let mkd_syntax.rxWikiLink1InvalidSuffix = '[\]\[]\@!'
|
|
|
|
let mkd_syntax.rx_wikilink_md_prefix = mkd_syntax.rxWikiLink1InvalidPrefix.
|
|
|
|
\ mkd_syntax.rx_wikilink_md_prefix
|
|
|
|
let mkd_syntax.rx_wikilink_md_suffix = mkd_syntax.rx_wikilink_md_suffix.
|
|
|
|
\ mkd_syntax.rxWikiLink1InvalidSuffix
|
|
|
|
|
2019-01-16 20:56:49 +01:00
|
|
|
" 1. match [URL][], [DESCRIPTION][URL]
|
2017-01-12 21:45:09 +01:00
|
|
|
let mkd_syntax.rxWikiLink1 = mkd_syntax.rx_wikilink_md_prefix.
|
2017-01-16 22:09:49 +01:00
|
|
|
\ mkd_syntax.rxWikiLink1Url. rx_wikilink_md_separator.
|
2017-01-12 21:45:09 +01:00
|
|
|
\ mkd_syntax.rx_wikilink_md_suffix.
|
|
|
|
\ '\|'. mkd_syntax.rx_wikilink_md_prefix.
|
2017-01-16 22:09:49 +01:00
|
|
|
\ mkd_syntax.rxWikiLink1Descr . rx_wikilink_md_separator.
|
2017-01-12 21:45:09 +01:00
|
|
|
\ mkd_syntax.rxWikiLink1Url . mkd_syntax.rx_wikilink_md_suffix
|
2019-01-16 20:56:49 +01:00
|
|
|
" 2. match URL within [URL][], [DESCRIPTION][URL]
|
2017-01-12 21:45:09 +01:00
|
|
|
let mkd_syntax.rxWikiLink1MatchUrl = mkd_syntax.rx_wikilink_md_prefix.
|
2017-01-16 22:09:49 +01:00
|
|
|
\ '\zs'. mkd_syntax.rxWikiLink1Url. '\ze'. rx_wikilink_md_separator.
|
2017-01-12 21:45:09 +01:00
|
|
|
\ mkd_syntax.rx_wikilink_md_suffix.
|
|
|
|
\ '\|'. mkd_syntax.rx_wikilink_md_prefix.
|
2017-01-16 22:09:49 +01:00
|
|
|
\ mkd_syntax.rxWikiLink1Descr. rx_wikilink_md_separator.
|
2017-01-12 21:45:09 +01:00
|
|
|
\ '\zs'. mkd_syntax.rxWikiLink1Url. '\ze'. mkd_syntax.rx_wikilink_md_suffix
|
2019-01-16 20:56:49 +01:00
|
|
|
" 3. match DESCRIPTION within [DESCRIPTION][URL]
|
2017-01-12 21:45:09 +01:00
|
|
|
let mkd_syntax.rxWikiLink1MatchDescr = mkd_syntax.rx_wikilink_md_prefix.
|
2017-01-16 22:09:49 +01:00
|
|
|
\ '\zs'. mkd_syntax.rxWikiLink1Descr.'\ze'. rx_wikilink_md_separator.
|
2017-01-12 21:45:09 +01:00
|
|
|
\ mkd_syntax.rxWikiLink1Url . mkd_syntax.rx_wikilink_md_suffix
|
|
|
|
|
|
|
|
let mkd_syntax.rxWikiLink1Prefix1 = mkd_syntax.rx_wikilink_md_prefix
|
2017-01-16 22:09:49 +01:00
|
|
|
let mkd_syntax.rxWikiLink1Suffix1 = rx_wikilink_md_separator.
|
2017-01-12 21:45:09 +01:00
|
|
|
\ mkd_syntax.rxWikiLink1Url . mkd_syntax.rx_wikilink_md_suffix
|
|
|
|
|
|
|
|
" 1. match ANY wikilink
|
|
|
|
let mkd_syntax.rxWikiLink = mkd_syntax.rxWikiLink0 . '\|' . mkd_syntax.rxWikiLink1
|
|
|
|
" 2. match URL within ANY wikilink
|
|
|
|
let mkd_syntax.rxWikiLinkMatchUrl = mkd_syntax.rxWikiLink0MatchUrl . '\|' .
|
|
|
|
\ mkd_syntax.rxWikiLink1MatchUrl
|
|
|
|
" 3. match DESCRIPTION within ANY wikilink
|
|
|
|
let mkd_syntax.rxWikiLinkMatchDescr = mkd_syntax.rxWikiLink0MatchDescr . '\|' .
|
|
|
|
\ mkd_syntax.rxWikiLink1MatchDescr
|
|
|
|
|
|
|
|
" 0. URL : free-standing links: keep URL UR(L) strip trailing punct: URL; URL) UR(L))
|
|
|
|
let mkd_syntax.rxWeblink0 = mkd_syntax.rxWeblink
|
|
|
|
" 0a) match URL within URL
|
|
|
|
let mkd_syntax.rxWeblinkMatchUrl0 = mkd_syntax.rxWeblinkMatchUrl
|
|
|
|
" 0b) match DESCRIPTION within URL
|
|
|
|
let mkd_syntax.rxWeblinkMatchDescr0 = mkd_syntax.rxWeblinkMatchDescr
|
|
|
|
|
|
|
|
let mkd_syntax.rxWeblink1Prefix = '['
|
|
|
|
let mkd_syntax.rxWeblink1Suffix = ')'
|
2019-05-09 05:30:06 +02:00
|
|
|
let mkd_syntax.rxWeblink1EscapeCharsSuffix = '\(\\\)\@<!\()\)'
|
2017-01-12 21:45:09 +01:00
|
|
|
let mkd_syntax.rxWeblink1Separator = ']('
|
2018-07-12 15:47:47 +02:00
|
|
|
let mkd_syntax.rxWeblink1Ext = ''
|
|
|
|
if vimwiki#vars#get_global('markdown_link_ext')
|
|
|
|
let mkd_syntax.rxWeblink1Ext = vimwiki#vars#get_wikilocal('ext')
|
|
|
|
endif
|
2017-01-12 21:45:09 +01:00
|
|
|
" [DESCRIPTION](URL)
|
|
|
|
let mkd_syntax.Weblink1Template = mkd_syntax.rxWeblink1Prefix . '__LinkDescription__'.
|
2018-07-12 15:47:47 +02:00
|
|
|
\ mkd_syntax.rxWeblink1Separator. '__LinkUrl__'. mkd_syntax.rxWeblink1Ext.
|
2017-01-12 21:45:09 +01:00
|
|
|
\ mkd_syntax.rxWeblink1Suffix
|
2018-07-12 15:47:47 +02:00
|
|
|
" [DESCRIPTION](ANCHOR)
|
|
|
|
let mkd_syntax.Weblink2Template = mkd_syntax.rxWeblink1Prefix . '__LinkDescription__'.
|
|
|
|
\ mkd_syntax.rxWeblink1Separator. '__LinkUrl__'. mkd_syntax.rxWeblink1Suffix
|
2019-03-21 20:31:04 +01:00
|
|
|
" [DESCRIPTION](FILE#ANCHOR)
|
|
|
|
let mkd_syntax.Weblink3Template = mkd_syntax.rxWeblink1Prefix . '__LinkDescription__'.
|
|
|
|
\ mkd_syntax.rxWeblink1Separator. '__LinkUrl__'. mkd_syntax.rxWeblink1Ext.
|
|
|
|
\ '#__LinkAnchor__'. mkd_syntax.rxWeblink1Suffix
|
2017-01-12 21:45:09 +01:00
|
|
|
|
2019-05-09 04:55:56 +02:00
|
|
|
let valid_chars = '[^\\\]]'
|
2019-05-09 05:30:06 +02:00
|
|
|
" spaces and '\' must be allowed for filename and escaped chars
|
|
|
|
let valid_chars_url = '[^[:cntrl:]]'
|
2017-01-12 21:45:09 +01:00
|
|
|
|
|
|
|
let mkd_syntax.rxWeblink1Prefix = vimwiki#u#escape(mkd_syntax.rxWeblink1Prefix)
|
|
|
|
let mkd_syntax.rxWeblink1Separator = vimwiki#u#escape(mkd_syntax.rxWeblink1Separator)
|
2019-05-09 05:30:06 +02:00
|
|
|
let mkd_syntax.rxWeblink1Url = valid_chars_url.'\{-}'
|
2017-01-12 21:45:09 +01:00
|
|
|
let mkd_syntax.rxWeblink1Descr = valid_chars.'\{-}'
|
2019-05-04 05:19:05 +02:00
|
|
|
let mkd_syntax.WikiLinkMatchUrlTemplate =
|
|
|
|
\ mkd_syntax.rx_wikilink_md_prefix .
|
|
|
|
\ '.*' .
|
|
|
|
\ rx_wikilink_md_separator .
|
|
|
|
\ '\zs__LinkUrl__\ze\%(#.*\)\?\%('.vimwiki#vars#get_wikilocal('ext').'\)\?'.
|
|
|
|
\ mkd_syntax.rx_wikilink_md_suffix .
|
|
|
|
\ '\|' .
|
|
|
|
\ mkd_syntax.rx_wikilink_md_prefix .
|
|
|
|
\ '\zs__LinkUrl__\ze\%(#.*\)\?\%('.vimwiki#vars#get_wikilocal('ext').'\)\?'.
|
|
|
|
\ rx_wikilink_md_separator .
|
|
|
|
\ mkd_syntax.rx_wikilink_md_suffix .
|
|
|
|
\ '\|' .
|
|
|
|
\ mkd_syntax.rxWeblink1Prefix.
|
|
|
|
\ '.*' .
|
|
|
|
\ mkd_syntax.rxWeblink1Separator.
|
|
|
|
\ '\zs__LinkUrl__\ze\%(#.*\)\?\%('.vimwiki#vars#get_wikilocal('ext').'\)\?'.
|
2019-05-09 05:30:06 +02:00
|
|
|
\ mkd_syntax.rxWeblink1EscapeCharsSuffix
|
2017-01-12 21:45:09 +01:00
|
|
|
|
|
|
|
" 1. [DESCRIPTION](URL)
|
|
|
|
" 1a) match [DESCRIPTION](URL)
|
|
|
|
let mkd_syntax.rxWeblink1 = mkd_syntax.rxWeblink1Prefix.
|
2018-07-12 15:47:47 +02:00
|
|
|
\ mkd_syntax.rxWeblink1Descr . mkd_syntax.rxWeblink1Separator.
|
2019-05-09 05:30:06 +02:00
|
|
|
\ mkd_syntax.rxWeblink1Url . mkd_syntax.rxWeblink1EscapeCharsSuffix
|
2017-01-12 21:45:09 +01:00
|
|
|
" 1b) match URL within [DESCRIPTION](URL)
|
|
|
|
let mkd_syntax.rxWeblink1MatchUrl = mkd_syntax.rxWeblink1Prefix.
|
|
|
|
\ mkd_syntax.rxWeblink1Descr. mkd_syntax.rxWeblink1Separator.
|
2019-05-09 05:30:06 +02:00
|
|
|
\ '\zs' . mkd_syntax.rxWeblink1Url . '\ze' . mkd_syntax.rxWeblink1EscapeCharsSuffix
|
2017-01-12 21:45:09 +01:00
|
|
|
" 1c) match DESCRIPTION within [DESCRIPTION](URL)
|
|
|
|
let mkd_syntax.rxWeblink1MatchDescr = mkd_syntax.rxWeblink1Prefix.
|
|
|
|
\ '\zs'.mkd_syntax.rxWeblink1Descr.'\ze'. mkd_syntax.rxWeblink1Separator.
|
2019-05-09 05:30:06 +02:00
|
|
|
\ mkd_syntax.rxWeblink1Url. mkd_syntax.rxWeblink1EscapeCharsSuffix
|
2017-01-12 21:45:09 +01:00
|
|
|
|
2019-05-24 05:23:53 +02:00
|
|
|
" image ![DESCRIPTION](URL)
|
|
|
|
let mkd_syntax.rxImage = '!' . mkd_syntax.rxWeblink1Prefix.
|
|
|
|
\ mkd_syntax.rxWeblink1Descr . mkd_syntax.rxWeblink1Separator.
|
|
|
|
\ mkd_syntax.rxWeblink1Url . mkd_syntax.rxWeblink1EscapeCharsSuffix
|
|
|
|
|
2017-01-12 21:45:09 +01:00
|
|
|
let mkd_syntax.rxWeblink1Prefix1 = mkd_syntax.rxWeblink1Prefix
|
|
|
|
let mkd_syntax.rxWeblink1Suffix1 = mkd_syntax.rxWeblink1Separator.
|
2019-05-09 05:30:06 +02:00
|
|
|
\ mkd_syntax.rxWeblink1Url . mkd_syntax.rxWeblink1EscapeCharsSuffix
|
2017-01-12 21:45:09 +01:00
|
|
|
|
2019-05-24 05:23:53 +02:00
|
|
|
" *a) match ANY weblink (exclude image links starting with !)
|
|
|
|
let mkd_syntax.rxWeblink = '\(!\)\@<!'.
|
2017-01-12 21:45:09 +01:00
|
|
|
\ mkd_syntax.rxWeblink1.'\|'.
|
|
|
|
\ mkd_syntax.rxWeblink0
|
|
|
|
" *b) match URL within ANY weblink
|
|
|
|
let mkd_syntax.rxWeblinkMatchUrl = ''.
|
|
|
|
\ mkd_syntax.rxWeblink1MatchUrl.'\|'.
|
|
|
|
\ mkd_syntax.rxWeblinkMatchUrl0
|
|
|
|
" *c) match DESCRIPTION within ANY weblink
|
|
|
|
let mkd_syntax.rxWeblinkMatchDescr = ''.
|
|
|
|
\ mkd_syntax.rxWeblink1MatchDescr.'\|'.
|
|
|
|
\ mkd_syntax.rxWeblinkMatchDescr0
|
|
|
|
|
2017-01-16 22:09:49 +01:00
|
|
|
let mkd_syntax.rxAnyLink = mkd_syntax.rxWikiLink.'\|'.
|
2019-05-24 05:23:53 +02:00
|
|
|
\ g:vimwiki_global_vars.rxWikiIncl.'\|'.mkd_syntax.rxWeblink .'\|'.
|
|
|
|
\ mkd_syntax.rxImage
|
2017-01-12 21:45:09 +01:00
|
|
|
|
|
|
|
let mkd_syntax.rxMkdRef = '\['.g:vimwiki_global_vars.rxWikiLinkDescr.']:\%(\s\+\|\n\)'.
|
|
|
|
\ mkd_syntax.rxWeblink0
|
2018-02-15 18:38:39 +01:00
|
|
|
let mkd_syntax.rxMkdRefMatchDescr =
|
|
|
|
\ '\[\zs'.g:vimwiki_global_vars.rxWikiLinkDescr.'\ze]:\%(\s\+\|\n\)'. mkd_syntax.rxWeblink0
|
|
|
|
let mkd_syntax.rxMkdRefMatchUrl =
|
|
|
|
\ '\['.g:vimwiki_global_vars.rxWikiLinkDescr.']:\%(\s\+\|\n\)\zs'.
|
2017-01-12 21:45:09 +01:00
|
|
|
\ mkd_syntax.rxWeblink0.'\ze'
|
2016-12-21 17:09:25 +01:00
|
|
|
endfunction
|
|
|
|
|
|
|
|
|
|
|
|
function! vimwiki#vars#init()
|
|
|
|
call s:populate_global_variables()
|
|
|
|
call s:populate_wikilocal_options()
|
|
|
|
endfunction
|
|
|
|
|
|
|
|
|
2016-12-28 22:17:08 +01:00
|
|
|
function! vimwiki#vars#get_syntaxlocal(key, ...)
|
|
|
|
if a:0
|
|
|
|
let syntax = a:1
|
|
|
|
else
|
|
|
|
let syntax = vimwiki#vars#get_wikilocal('syntax')
|
|
|
|
endif
|
|
|
|
if !exists('g:vimwiki_syntax_variables') || !has_key(g:vimwiki_syntax_variables, syntax)
|
|
|
|
call vimwiki#vars#populate_syntax_vars(syntax)
|
2016-12-21 17:09:25 +01:00
|
|
|
endif
|
|
|
|
|
2016-12-28 22:17:08 +01:00
|
|
|
return g:vimwiki_syntax_variables[syntax][a:key]
|
2016-12-21 17:09:25 +01:00
|
|
|
endfunction
|
|
|
|
|
|
|
|
|
2017-01-13 16:33:41 +01:00
|
|
|
" Get a variable for the buffer we are currently in or for the given buffer (number or name).
|
2016-12-21 17:09:25 +01:00
|
|
|
" Populate the variable, if it doesn't exist.
|
2017-01-13 16:33:41 +01:00
|
|
|
function! vimwiki#vars#get_bufferlocal(key, ...)
|
|
|
|
let buffer = a:0 ? a:1 : '%'
|
|
|
|
|
|
|
|
let value = getbufvar(buffer, 'vimwiki_'.a:key, '/\/\')
|
|
|
|
if type(value) != 1 || value !=# '/\/\'
|
|
|
|
return value
|
2016-12-21 17:09:25 +01:00
|
|
|
elseif a:key ==# 'wiki_nr'
|
2017-01-13 16:33:41 +01:00
|
|
|
call setbufvar(buffer, 'vimwiki_wiki_nr', vimwiki#base#find_wiki(expand('%:p')))
|
2017-01-07 21:51:15 +01:00
|
|
|
elseif a:key ==# 'subdir'
|
2017-01-13 16:33:41 +01:00
|
|
|
call setbufvar(buffer, 'vimwiki_subdir', vimwiki#base#current_subdir())
|
2017-01-07 21:51:15 +01:00
|
|
|
elseif a:key ==# 'invsubdir'
|
|
|
|
let subdir = vimwiki#vars#get_bufferlocal('subdir')
|
2017-01-13 16:33:41 +01:00
|
|
|
call setbufvar(buffer, 'vimwiki_invsubdir', vimwiki#base#invsubdir(subdir))
|
2017-01-12 21:45:09 +01:00
|
|
|
elseif a:key ==# 'existing_wikifiles'
|
2017-01-13 16:33:41 +01:00
|
|
|
call setbufvar(buffer, 'vimwiki_existing_wikifiles',
|
|
|
|
\ vimwiki#base#get_wikilinks(vimwiki#vars#get_bufferlocal('wiki_nr'), 1))
|
2017-01-12 21:45:09 +01:00
|
|
|
elseif a:key ==# 'existing_wikidirs'
|
2017-01-13 16:33:41 +01:00
|
|
|
call setbufvar(buffer, 'vimwiki_existing_wikidirs',
|
|
|
|
\ vimwiki#base#get_wiki_directories(vimwiki#vars#get_bufferlocal('wiki_nr')))
|
|
|
|
elseif a:key ==# 'prev_link'
|
2017-01-16 22:09:49 +01:00
|
|
|
call setbufvar(buffer, 'vimwiki_prev_link', [])
|
|
|
|
elseif a:key ==# 'markdown_refs'
|
|
|
|
call setbufvar(buffer, 'vimwiki_markdown_refs', vimwiki#markdown_base#scan_reflinks())
|
|
|
|
else
|
|
|
|
echoerr 'Vimwiki Error: unknown buffer variable ' . string(a:key)
|
2016-12-21 17:09:25 +01:00
|
|
|
endif
|
2017-01-13 16:33:41 +01:00
|
|
|
|
|
|
|
return getbufvar(buffer, 'vimwiki_'.a:key)
|
2016-12-21 17:09:25 +01:00
|
|
|
endfunction
|
|
|
|
|
|
|
|
|
2017-01-13 16:33:41 +01:00
|
|
|
function! vimwiki#vars#set_bufferlocal(key, value, ...)
|
|
|
|
let buffer = a:0 ? a:1 : '%'
|
|
|
|
call setbufvar(buffer, 'vimwiki_' . a:key, a:value)
|
2016-12-21 17:09:25 +01:00
|
|
|
endfunction
|
|
|
|
|
|
|
|
|
|
|
|
function! vimwiki#vars#get_global(key)
|
|
|
|
return g:vimwiki_global_vars[a:key]
|
|
|
|
endfunction
|
|
|
|
|
|
|
|
|
2016-12-22 18:16:05 +01:00
|
|
|
" the second argument can be a wiki number. When absent, the wiki of the currently active buffer is
|
|
|
|
" used
|
|
|
|
function! vimwiki#vars#get_wikilocal(key, ...)
|
|
|
|
if a:0
|
|
|
|
return g:vimwiki_wikilocal_vars[a:1][a:key]
|
|
|
|
else
|
|
|
|
return g:vimwiki_wikilocal_vars[vimwiki#vars#get_bufferlocal('wiki_nr')][a:key]
|
|
|
|
endif
|
2016-12-21 17:09:25 +01:00
|
|
|
endfunction
|
|
|
|
|
|
|
|
|
2016-12-23 20:05:53 +01:00
|
|
|
function! vimwiki#vars#get_wikilocal_default(key)
|
|
|
|
return g:vimwiki_wikilocal_vars[-1][a:key]
|
|
|
|
endfunction
|
|
|
|
|
|
|
|
|
2016-12-22 18:16:05 +01:00
|
|
|
function! vimwiki#vars#set_wikilocal(key, value, wiki_nr)
|
2016-12-21 17:09:25 +01:00
|
|
|
if a:wiki_nr == len(g:vimwiki_wikilocal_vars) - 1
|
|
|
|
call insert(g:vimwiki_wikilocal_vars, {}, -1)
|
|
|
|
endif
|
|
|
|
let g:vimwiki_wikilocal_vars[a:wiki_nr][a:key] = a:value
|
|
|
|
endfunction
|
|
|
|
|
|
|
|
|
2016-12-25 21:35:56 +01:00
|
|
|
function! vimwiki#vars#add_temporary_wiki(settings)
|
|
|
|
let new_temp_wiki_settings = copy(g:vimwiki_wikilocal_vars[-1])
|
|
|
|
for [key, value] in items(a:settings)
|
|
|
|
let new_temp_wiki_settings[key] = value
|
|
|
|
endfor
|
|
|
|
call insert(g:vimwiki_wikilocal_vars, new_temp_wiki_settings, -1)
|
2019-01-19 21:05:27 +01:00
|
|
|
call s:normalize_wikilocal_settings()
|
2016-12-25 21:35:56 +01:00
|
|
|
endfunction
|
|
|
|
|
2018-04-20 07:03:53 +02:00
|
|
|
|
2016-12-21 17:09:25 +01:00
|
|
|
" number of registered wikis + temporary
|
|
|
|
function! vimwiki#vars#number_of_wikis()
|
|
|
|
return len(g:vimwiki_wikilocal_vars) - 1
|
|
|
|
endfunction
|