commit a51052cbe6676dad749ca4c54cc6957c41868c28
parent ee2d67751e80ced2530471f459dc8d6510eae5f1
Author: Tinmarino <tinmarino@gmail.com>
Date: Mon, 17 Aug 2020 22:28:15 -0400
Feature: VimwikiVar to list, get and set variables
Refaction:
- Add g:vimwiki_syntax_list to set syntaxlocal variables
- Delete: syntax/vimwiki_markdown.vim and friends
- Change: vimwiki_syntax_variables -> vimwiki_syntaxlocal_vars for consistency
- Include: some doc in design notes
Diffstat:
17 files changed, 814 insertions(+), 580 deletions(-)
diff --git a/autoload/vimwiki/base.vim b/autoload/vimwiki/base.vim
@@ -2163,7 +2163,7 @@ function! vimwiki#base#AddHeaderLevel(...) abort
endif
let lnum = line('.')
let line = getline(lnum)
- let rxHdr = vimwiki#vars#get_syntaxlocal('rxH')
+ let rxHdr = vimwiki#vars#get_syntaxlocal('header_symbol')
if line =~# '^\s*$'
return
endif
@@ -2197,7 +2197,7 @@ function! vimwiki#base#RemoveHeaderLevel(...) abort
endif
let lnum = line('.')
let line = getline(lnum)
- let rxHdr = vimwiki#vars#get_syntaxlocal('rxH')
+ let rxHdr = vimwiki#vars#get_syntaxlocal('header_symbol')
if line =~# '^\s*$'
return
endif
@@ -2269,7 +2269,7 @@ function! s:collect_headers() abort
endif
" Clause: markdown headers must start in the first column
if vimwiki#vars#get_wikilocal('syntax') ==# 'markdown'
- \ && stridx(line_content, vimwiki#vars#get_syntaxlocal('rxH')) > 0
+ \ && stridx(line_content, vimwiki#vars#get_syntaxlocal('header_symbol')) > 0
continue
endif
" Get header level
diff --git a/autoload/vimwiki/html.vim b/autoload/vimwiki/html.vim
@@ -1296,8 +1296,9 @@ function! s:parse_line(line, state) abort
" current line while not marking as processed in the scenario where some
" text remains that needs to go through additional processing
if !processed
- let mc_start = vimwiki#vars#get_syntaxlocal('rxMultilineCommentStart')
- let mc_end = vimwiki#vars#get_syntaxlocal('rxMultilineCommentEnd')
+ let mc_format = vimwiki#vars#get_syntaxlocal('multiline_comment_format')
+ let mc_start = mc_format.pre_mark
+ let mc_end = mc_format.post_mark
" If either start or end is empty, we want to skip multiline handling
if !empty(mc_start) && !empty(mc_end)
@@ -1396,7 +1397,7 @@ function! s:parse_line(line, state) abort
endif
if !processed
- if line =~# vimwiki#vars#get_syntaxlocal('rxComment')
+ if line =~# vimwiki#vars#get_syntaxlocal('comment_regex')
let processed = 1
endif
endif
diff --git a/autoload/vimwiki/u.vim b/autoload/vimwiki/u.vim
@@ -5,17 +5,22 @@
" Echo: msg
" :param: (1) <string> highlighting group
-" :param: (2) <string> echo suffix (ex: 'n', 'm'
+" :param: (2) <string> echo suffix (ex: 'n', 'm')
+" :param: (3) <string> message prefix, default Vimwiki
function! vimwiki#u#echo(msg, ...) abort
let hl_group = a:0 > 0 ? a:1 : ''
let echo_suffix = a:0 > 1 ? a:2 : ''
+ let msg_prefix = a:0 > 2 ? a:3 : 'Vimwiki: '
" Start highlighting
if hl_group !=# ''
exe 'echohl ' . hl_group
endif
- " Print
+
+ " Escape
let msg = substitute(a:msg, "'", "''", 'g')
- exe 'echo'.echo_suffix . " 'Vimwiki: " . msg . "'"
+ " Print
+ exe 'echo'.echo_suffix . " '" . msg_prefix . msg . "'"
+
" Stop highlighting
if hl_group !=# ''
echohl None
@@ -267,7 +272,7 @@ endfunction
" :param: syntax <string> to retrive, default to current
function! vimwiki#u#get_syntax_dic(...) abort
let syntax = a:0 ? a:1 : vimwiki#vars#get_wikilocal('syntax')
- return g:vimwiki_syntax_variables[syntax]
+ return g:vimwiki_syntaxlocal_vars[syntax]
endfunction
diff --git a/autoload/vimwiki/vars.vim b/autoload/vimwiki/vars.vim
@@ -17,7 +17,7 @@
" dictionaries, one dict for every registered wiki. The last dictionary contains default values
" (used for temporary wikis).
"
-" - syntax variables. Stored in the dict g:vimwiki_syntax_variables which holds all the regexes and
+" - syntax variables. Stored in the dict g:vimwiki_syntaxlocal_vars 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)
@@ -32,23 +32,177 @@ let s:margin_set_by_user = 0
" Init global and local variables
function! vimwiki#vars#init() abort
+ " Init && Populate: global variable container
+ let g:vimwiki_global_vars = {}
call s:populate_global_variables()
+
+ " Init && Populate: local variable container
+ let g:vimwiki_wikilocal_vars = []
call s:populate_wikilocal_options()
endfunction
+" Helper: Check user setting
+" warn user with message if not good type
+" Param: 1: key <string>: varaible name
+" Param: 2: vimwiki_key <obj>: user value
+" Param: 3: value_infod <dict>: type and default value
+" Param: 4: coming from a global variable <bool>
+function! s:check_users_value(key, users_value, value_infos, comes_from_global_variable) abort
+ 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)
+
+ let help_text = a:comes_from_global_variable ?
+ \ 'g:vimwiki_' :
+ \ 'vimwiki-option-'
+
+ if has_key(a:value_infos, 'type') && type(a:users_value) != a:value_infos.type
+ call vimwiki#u#error(printf('The provided value of the option %s is a %s, ' .
+ \ 'but expected is a %s. See '':h '.help_text.'%s''.', setting_origin,
+ \ 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
+ call vimwiki#u#error(printf('The provided value ''%i'' of the option %s is'
+ \ . ' too small. The minimum value is %i. See '':h '.help_text.'%s''.', a:users_value,
+ \ 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
+ call vimwiki#u#error(printf('The provided value ''%i'' of the option %s is'
+ \ . ' too large. The maximum value is %i. See '':h '.help_text.'%s''.', a:users_value,
+ \ 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
+ call vimwiki#u#error(printf('The provided value ''%s'' of the option %s is'
+ \ . ' invalid. Allowed values are %s. See '':h '.help_text.'%s''.', a:users_value,
+ \ 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
+ call vimwiki#u#error(printf('The provided value ''%s'' of the option %s must'
+ \ . ' contain exactly %i character(s) but has %i. See '':h '.help_text.'_%s''.',
+ \ 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
+ call vimwiki#u#error(printf('The provided value ''%s'' of the option %s must'
+ \ . ' have at least %d character(s) but has %d. See '':h '.help_text.'%s''.', a:users_value,
+ \ setting_origin, a:value_infos.min_length, strwidth(a:users_value), a:key))
+ endif
+endfunction
+
+
+" Helper: Treat special variables
+function! s:update_key(output_dic, key, old, new) abort
+ " Set list margin
+ if a:key ==# 'list_margin'
+ let s:margin_set_by_user = 1
+ let a:output_dic[a:key] = a:new
+ return
+ " Extend Tag format
+ elseif a:key ==# 'tag_format'
+ let a:output_dic[a:key] = {}
+ call extend(a:output_dic[a:key], a:old)
+ call extend(a:output_dic[a:key], a:new)
+ return
+ else
+ let a:output_dic[a:key] = a:new
+ return
+ endif
+endfunction
+
+
+
" ----------------------------------------------------------
" 1. Global {{{1
" ----------------------------------------------------------
+" Get default wikilocal values
+" Please: keep alphabetical sort
+function! s:get_default_global() abort
+ return {
+ \ 'CJK_length': {'type': type(0), 'default': 0, 'min': 0, 'max': 1},
+ \ 'auto_chdir': {'type': type(0), 'default': 0, 'min': 0, 'max': 1},
+ \ 'auto_header': {'type': type(0), 'default': 0, 'min': 0, 'max': 1},
+ \ 'autowriteall': {'type': type(0), 'default': 1, 'min': 0, 'max': 1},
+ \ 'conceallevel': {'type': type(0), 'default': 2, 'min': 0, 'max': 3},
+ \ 'conceal_onechar_markers': {'type': type(0), 'default': 1, 'min': 0, 'max': 1},
+ \ 'conceal_pre': {'type': type(0), 'default': 0, 'min': 0, 'max': 1},
+ \ 'create_link': {'type': type(0), 'default': 1, 'min':0, 'max': 1},
+ \ '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': ''},
+ \ 'emoji_enable': {'type': type(0), 'default': 3, 'min':0, 'max': 3},
+ \ 'ext2syntax': {'type': type({}), 'default': {'.md': 'markdown', '.mkdn': 'markdown',
+ \ '.mdwn': 'markdown', '.mdown': 'markdown', '.markdown': 'markdown', '.mw': 'media'}},
+ \ 'folding': {'type': type(''), 'default': '', 'possible_values': ['', 'expr', 'syntax',
+ \ 'list', 'custom', ':quick', 'expr:quick', 'syntax:quick', 'list:quick',
+ \ 'custom:quick']},
+ \ 'filetypes': {'type': type([]), 'default': []},
+ \ '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': ''},
+ \ '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,
+ \ }},
+ \ 'links_header': {'type': type(''), 'default': 'Generated Links', 'min_length': 1},
+ \ 'links_header_level': {'type': type(0), 'default': 1, 'min': 1, 'max': 6},
+ \ 'listsyms': {'type': type(''), 'default': ' .oOX', 'min_length': 2},
+ \ 'listsym_rejected': {'type': type(''), 'default': '-', 'length': 1},
+ \ 'map_prefix': {'type': type(''), 'default': '<Leader>w'},
+ \ 'markdown_header_style': {'type': type(0), 'default': 1, 'min':0, 'max': 2},
+ \ 'menu': {'type': type(''), 'default': 'Vimwiki'},
+ \ 'table_auto_fmt': {'type': type(0), 'default': 1, 'min': 0, 'max': 1},
+ \ 'table_reduce_last_col': {'type': type(0), 'default': 0, 'min': 0, 'max': 1},
+ \ 'table_mappings': {'type': type(0), 'default': 1, 'min': 0, 'max': 1},
+ \ 'tags_header': {'type': type(''), 'default': 'Generated Tags', 'min_length': 1},
+ \ 'tags_header_level': {'type': type(0), 'default': 1, 'min': 1, 'max': 5},
+ \ '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': ''},
+ \ }
+endfunction
+
+
" Populate global variable <- user & default
" Called: s:vimwiki#vars#init
function! s:populate_global_variables() abort
- let g:vimwiki_global_vars = {}
-
call s:read_global_settings_from_user()
call s:normalize_global_settings()
+ call s:internal_global_settings()
+endfunction
+
+" Read nromalized settings and create some more usefull variables to use internally
+function! s:internal_global_settings() abort
" non-configurable global variables:
" Scheme regexes must be defined even if syntax file is not loaded yet cause users should be
@@ -156,84 +310,38 @@ function! s:populate_global_variables() abort
endfunction
-" Read user global settings
-" Called: s:populate_global_variables
-function! s:read_global_settings_from_user() abort
- 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},
- \ 'auto_header': {'type': type(0), 'default': 0, 'min': 0, 'max': 1},
- \ 'autowriteall': {'type': type(0), 'default': 1, 'min': 0, 'max': 1},
- \ 'conceallevel': {'type': type(0), 'default': 2, 'min': 0, 'max': 3},
- \ 'conceal_onechar_markers': {'type': type(0), 'default': 1, 'min': 0, 'max': 1},
- \ 'conceal_pre': {'type': type(0), 'default': 0, 'min': 0, 'max': 1},
- \ 'create_link': {'type': type(0), 'default': 1, 'min':0, 'max': 1},
- \ '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': ''},
- \ 'emoji_enable': {'type': type(0), 'default': 3, 'min':0, 'max': 3},
- \ 'ext2syntax': {'type': type({}), 'default': {'.md': 'markdown', '.mkdn': 'markdown',
- \ '.mdwn': 'markdown', '.mdown': 'markdown', '.markdown': 'markdown', '.mw': 'media'}},
- \ 'folding': {'type': type(''), 'default': '', 'possible_values': ['', 'expr', 'syntax',
- \ 'list', 'custom', ':quick', 'expr:quick', 'syntax:quick', 'list:quick',
- \ 'custom:quick']},
- \ 'filetypes': {'type': type([]), 'default': []},
- \ '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': ''},
- \ '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,
- \ }},
- \ 'links_header': {'type': type(''), 'default': 'Generated Links', 'min_length': 1},
- \ 'links_header_level': {'type': type(0), 'default': 1, 'min': 1, 'max': 6},
- \ 'listsyms': {'type': type(''), 'default': ' .oOX', 'min_length': 2},
- \ 'listsym_rejected': {'type': type(''), 'default': '-', 'length': 1},
- \ 'map_prefix': {'type': type(''), 'default': '<Leader>w'},
- \ 'markdown_header_style': {'type': type(0), 'default': 1, 'min':0, 'max': 2},
- \ 'menu': {'type': type(''), 'default': 'Vimwiki'},
- \ 'table_auto_fmt': {'type': type(0), 'default': 1, 'min': 0, 'max': 1},
- \ 'table_reduce_last_col': {'type': type(0), 'default': 0, 'min': 0, 'max': 1},
- \ 'table_mappings': {'type': type(0), 'default': 1, 'min': 0, 'max': 1},
- \ 'tags_header': {'type': type(''), 'default': 'Generated Tags', 'min_length': 1},
- \ 'tags_header_level': {'type': type(0), 'default': 1, 'min': 1, 'max': 5},
- \ '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
+" Extend global dictionary <- default <- user
+function! s:extend_global(output_dic, default_dic) abort
+ " Note: user_dic is unused here because it comes from g:vimwiki_* vars
+ " 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)
+ for key in keys(a:default_dic)
+ let value_infos = a:default_dic[key]
if exists('g:vimwiki_'.key)
- let users_value = g:vimwiki_{key}
- let value_infos = global_settings[key]
+ let user_value = g:vimwiki_{key}
- call s:check_users_value(key, users_value, value_infos, 1)
+ call s:check_users_value(key, user_value, value_infos, 1)
- let g:vimwiki_global_vars[key] = users_value
- " Remove users_value to prevent type mismatch (E706) errors in vim <7.4.1546
- unlet users_value
+ call s:update_key(a:output_dic, key, value_infos.default, user_value)
+ " Remove user_value to prevent type mismatch (E706) errors in vim <7.4.1546
+ unlet user_value
else
- let g:vimwiki_global_vars[key] = global_settings[key].default
+ let a:output_dic[key] = value_infos.default
endif
endfor
+ return a:output_dic
+endfunction
- " validate some settings individually
+" Read user global settings
+" Called: s:populate_global_variables
+function! s:read_global_settings_from_user() abort
+ let default_dic = s:get_default_global()
+
+ " Update batch
+ call s:extend_global(g:vimwiki_global_vars, default_dic)
+
+ " Validate some settings individually
let key = 'diary_months'
let users_value = g:vimwiki_global_vars[key]
for month in range(1, 12)
@@ -337,21 +445,13 @@ endfunction
" ----------------------------------------------------------
-" 2. Buffer local {{{1
+" 3. Wiki local {{{1
" ----------------------------------------------------------
-" Populate local variable <- user & default
-" Called: s:vimwiki#vars#init
-function! s:populate_wikilocal_options() abort
- " TODO mutualise the g:vimwiki loop and the wiki_list
- " -- after tests on specific cases (format_tag and list_margin)
-
- " Init local variable container
- let g:vimwiki_wikilocal_vars = []
-
- " Declare default values
- " Please: keep alphabetical sort
- let default_values = {
+" Get default wikilocal values
+" Please: keep alphabetical sort
+function! s:get_default_wikilocal() abort
+ return {
\ 'auto_diary_index': {'type': type(0), 'default': 0, 'min': 0, 'max': 1},
\ 'auto_export': {'type': type(0), 'default': 0, 'min': 0, 'max': 1},
\ 'auto_generate_links': {'type': type(0), 'default': 0, 'min': 0, 'max': 1},
@@ -408,156 +508,79 @@ function! s:populate_wikilocal_options() abort
\ 'toc_header_level': {'type': type(0), 'default': 1, 'min': 1, 'max': 6},
\ 'toc_link_format': {'type': type(0), 'default': 0, 'min': 0, 'max': 1},
\ }
+endfunction
- " Fill default setting <- user or plugin values
- let default_wiki_settings = {}
- for key in keys(default_values)
- if exists('g:vimwiki_'.key)
- " Check type
- call s:check_users_value(key, g:vimwiki_{key}, default_values[key], 1)
- " List margin
- if key ==# 'list_margin'
- let s:margin_set_by_user = 1
- endif
- " Extend Tag format
- if key ==# 'tag_format'
- let default_wiki_settings[key] = default_values[key].default
- call extend(default_wiki_settings[key], g:vimwiki_{key})
- " Set if other var
- else
- let default_wiki_settings[key] = g:vimwiki_{key}
- endif
+" Extend syntaxlocal dictionary <- global <- user (default for type check)
+function! s:extend_local(output_dic, default_dic, global_dic, user_dic) abort
+ " IDEA: can work lazily and not on all wikis at first call
+ " IDEA: have a special variable for wikitmp
+ for key in keys(a:default_dic)
+ " Key present
+ if has_key(a:user_dic, key)
+ call s:check_users_value(key, a:user_dic[key], a:default_dic[key], 0)
+ call s:update_key(a:output_dic, key, a:global_dic[key], a:user_dic[key])
else
- let default_wiki_settings[key] = default_values[key].default
+ let a:output_dic[key] = a:global_dic[key]
endif
endfor
+ return a:output_dic
+endfunction
- " Set the wiki-local variables according to g:vimwiki_list (or the default settings)
- if exists('g:vimwiki_list')
- for users_wiki_settings in g:vimwiki_list
- let new_wiki_settings = {}
- for key in keys(default_values)
- " Key present
- if has_key(users_wiki_settings, key)
- call s:check_users_value(key, users_wiki_settings[key], default_values[key], 0)
- " Set list margin
- if key ==# 'list_margin'
- let s:margin_set_by_user = 1
- endif
- " Extend Tag format
- if key ==# 'tag_format'
- let new_wiki_settings[key] = extend({}, default_values[key].default)
- let new_wiki_settings[key] = extend(new_wiki_settings[key], users_wiki_settings[key])
- else
- let new_wiki_settings[key] = users_wiki_settings[key]
- endif
- else
- let new_wiki_settings[key] = default_wiki_settings[key]
- endif
- endfor
-
- let new_wiki_settings.is_temporary_wiki = 0
-
- call add(g:vimwiki_wikilocal_vars, new_wiki_settings)
- endfor
- else
+
+" Populate local variable <- user & default
+" Called: s:vimwiki#vars#init
+function! s:populate_wikilocal_options() abort
+ " Retrieve default
+ let default_dic = s:get_default_wikilocal()
+
+ " Extend from global setting
+ let global_wiki_dic = s:extend_global({}, default_dic)
+
+ " Extend from g:vimwiki_list
+ if !exists('g:vimwiki_list')
" 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)
+ let new_wiki_dic = deepcopy(global_wiki_dic)
+ let new_wiki_dic.is_temporary_wiki = 0
+ call add(g:vimwiki_wikilocal_vars, new_wiki_dic)
+ else
+ for user_dic in g:vimwiki_list
+ let new_wiki_dic = s:extend_local({}, default_dic, global_wiki_dic, user_dic)
+ let new_wiki_dic.is_temporary_wiki = 0
+ call add(g:vimwiki_wikilocal_vars, new_wiki_dic)
+ endfor
endif
- " default values for temporary wikis
- 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)
+ " Set default values for temporary wikis
+ let temp_dic = deepcopy(global_wiki_dic)
+ let temp_dic.is_temporary_wiki = 1
+ call add(g:vimwiki_wikilocal_vars, temp_dic)
+
+ " Check some values individually
+ """"""""""""""""""""""""""""""""
+
" Set up variables for the lists, depending on config and syntax
for wiki in g:vimwiki_wikilocal_vars
- if len(wiki.bullet_types) == 0
+ " Treat lists
+ " TODO remove me: I am syntaxlocal
+ if !has_key(wiki, 'bullet_types') || len(wiki.bullet_types) == 0
let wiki.bullet_types = vimwiki#vars#get_syntaxlocal('bullet_types', wiki.syntax)
endif
- call s:populate_list_vars(wiki)
- endfor
+ call s:populate_list_vars(wiki)
- " 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])
+ " Check nested syntax
+ for keyword in keys(wiki.nested_syntaxes)
+ if type(keyword) != type('') || empty(keyword) || type(wiki.nested_syntaxes[keyword]) != type('') ||
+ \ empty(wiki.nested_syntaxes[keyword])
call vimwiki#u#error(printf('The provided value ''%s'' of the option ''g:vimwiki_%s'' is'
- \ . ' invalid. See '':h g:vimwiki_%s''.', string(users_value), key, key))
+ \ . ' invalid. See '':h g:vimwiki_%s''.', string(wiki.nested_syntaxes), 'nested_syntaxes', 'nested_syntaxes'))
break
endif
endfor
endfor
- call s:normalize_wikilocal_settings()
-endfunction
-
-
-" Helper, Check user setting
-" warn user with message if not good type
-" Param: 1: key <string>: varaible name
-" Param: 2: vimwiki_key <obj>: user value
-" Param: 3: value_infod <dict>: type and default value
-" Param: 4: coming from a global variable <bool>
-function! s:check_users_value(key, users_value, value_infos, comes_from_global_variable) abort
- 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)
-
- let help_text = a:comes_from_global_variable ?
- \ 'g:vimwiki_' :
- \ 'vimwiki-option-'
-
- if has_key(a:value_infos, 'type') && type(a:users_value) != a:value_infos.type
- call vimwiki#u#error(printf('The provided value of the option %s is a %s, ' .
- \ 'but expected is a %s. See '':h '.help_text.'%s''.', setting_origin,
- \ 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
- call vimwiki#u#error(printf('The provided value ''%i'' of the option %s is'
- \ . ' too small. The minimum value is %i. See '':h '.help_text.'%s''.', a:users_value,
- \ 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
- call vimwiki#u#error(printf('The provided value ''%i'' of the option %s is'
- \ . ' too large. The maximum value is %i. See '':h '.help_text.'%s''.', a:users_value,
- \ 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
- call vimwiki#u#error(printf('The provided value ''%s'' of the option %s is'
- \ . ' invalid. Allowed values are %s. See '':h '.help_text.'%s''.', a:users_value,
- \ 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
- call vimwiki#u#error(printf('The provided value ''%s'' of the option %s must'
- \ . ' contain exactly %i character(s) but has %i. See '':h '.help_text.'_%s''.',
- \ 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
- call vimwiki#u#error(printf('The provided value ''%s'' of the option %s must'
- \ . ' have at least %d character(s) but has %d. See '':h '.help_text.'%s''.', a:users_value,
- \ setting_origin, a:value_infos.min_length, strwidth(a:users_value), a:key))
- endif
+ " Normalize and leave
+ call s:normalize_wikilocal_settings()
endfunction
@@ -609,33 +632,195 @@ endfunction
" ----------------------------------------------------------
-" 3. Syntax specific {{{1
+" 2. Syntax specific {{{1
" ----------------------------------------------------------
+" Get default syntaxlocal variable dictionary
+function! s:get_default_syntaxlocal() abort
+ " type, default, min, max, possible_values, min_length
+ return extend(s:get_common_syntaxlocal(), {
+ \ 'bold_match': {'type': type(''), 'default': '\%(^\|\s\|[[:punct:]]\)\@<=\*__Text__\*\%([[:punct:]]\|\s\|$\)\@='},
+ \ 'bold_search': {'type': type(''), 'default': '\%(^\|\s\|[[:punct:]]\)\@<=\*\zs\%([^*`[:space:]][^*`]*[^*`[:space:]]\|[^*`[:space:]]\)\ze\*\%([[:punct:]]\|\s\|$\)\@='},
+ \ 'bullet_types': {'type': type([]), 'default': ['-', '*', '#']},
+ \ 'header_match': {'type': type(''), 'default': '^\s*\(=\{1,6}\)=\@!\s*__Header__\s*\1=\@!\s*$'},
+ \ 'header_search': {'type': type(''), 'default': '^\s*\(=\{1,6}\)\([^=].*[^=]\)\1\s*$'},
+ \ 'list_markers': {'type': type([]), 'default': ['-', '1.', '*', 'I)', 'a)']},
+ \ 'number_types': {'type': type([]), 'default': ['1)', '1.', 'i)', 'I)', 'a)', 'A)']},
+ \ 'recurring_bullets': {'type': type(0), 'default': 0},
+ \ 'comment_regex': {'type': type(''), 'default': '^\s*%%.*$'},
+ \ 'header_symbol': {'type': type(''), 'default': '='},
+ \ 'rxHR': {'type': type(''), 'default': '^-----*$'},
+ \ 'rxListDefine': {'type': type(''), 'default': '::\(\s\|$\)'},
+ \ 'math_format': {'type': type({}), 'default': {
+ \ 'pre_mark': '{{\$',
+ \ 'post_mark': '}}\$'}},
+ \ 'multiline_comment_format': {'type': type({}), 'default': {
+ \ 'pre_mark': '%%+',
+ \ 'post_mark': '+%%'}},
+ \ 'pre_format': {'type': type({}), 'default': {
+ \ 'pre_mark': '{{{',
+ \ 'post_mark': '}}}'}},
+ \ 'symH': {'type': type(1), 'default': 1},
+ \ 'typeface': {'type': type({}), 'default': {
+ \ 'bold': vimwiki#u#hi_expand_regex([['\*', '\*']]),
+ \ 'italic': vimwiki#u#hi_expand_regex([['_', '_']]),
+ \ 'underline': vimwiki#u#hi_expand_regex([]),
+ \ 'bold_italic': vimwiki#u#hi_expand_regex([['\*_', '_\*'], ['_\*', '\*_']]),
+ \ 'code': [
+ \ ['\%(^\|[^`]\)\@<=`\%($\|[^`]\)\@=',
+ \ '\%(^\|[^`]\)\@<=`\%($\|[^`]\)\@='],
+ \ ['\%(^\|[^`]\)\@<=``\%($\|[^`]\)\@=',
+ \ '\%(^\|[^`]\)\@<=``\%($\|[^`]\)\@='],
+ \ ],
+ \ 'del': [['\~\~', '\~\~']],
+ \ 'sup': [['\^', '\^']],
+ \ 'sub': [[',,', ',,']],
+ \ 'eq': [['\%(^\|[^$]\)\@<=\$\%($\|[^$]\)\@=', '\%(^\|[^$]\)\@<=\$\%($\|[^$]\)\@=']],
+ \ }},
+ \ 'wikilink': {'type': type(''), 'default': '\[\[\zs[^\\\]|]\+\ze\%(|[^\\\]]\+\)\?\]\]'},
+ \ })
+endfunction
+
+function! s:get_markdown_syntaxlocal() abort
+ let atx_header_search = '^\s*\(#\{1,6}\)\([^#].*\)$'
+ let atx_header_match = '^\s*\(#\{1,6}\)#\@!\s*__Header__\s*$'
+
+ let setex_header_search = '^\s\{0,3}\zs[^>].*\ze\n'
+ let setex_header_search .= '^\s\{0,3}[=-]\{2,}$'
+
+ let setex_header_match = '^\s\{0,3}>\@!__Header__\n'
+ let setex_header_match .= '^\s\{0,3}[=-][=-]\+$'
+
+ return extend(s:get_common_syntaxlocal(), {
+ \ 'bold_match': {'type': type(''), 'default': '\%(^\|\s\|[[:punct:]]\)\@<=\*__Text__\*\%([[:punct:]]\|\s\|$\)\@='},
+ \ 'bold_search': {'type': type(''), 'default': '\%(^\|\s\|[[:punct:]]\)\@<=\*\zs\%([^*`[:space:]][^*`]*[^*`[:space:]]\|[^*`[:space:]]\)\ze\*\%([[:punct:]]\|\s\|$\)\@='},
+ \ 'bullet_types': {'type': type([]), 'default': ['*', '-', '+']},
+ \ 'header_match': {'type': type(''), 'default': '\%(' . atx_header_match . '\|' . setex_header_match . '\)'},
+ \ 'header_search': {'type': type(''), 'default': '\%(' . atx_header_search . '\|' . setex_header_search . '\)'},
+ \ 'list_markers': {'type': type([]), 'default': ['-', '*', '+', '1.']},
+ \ 'number_types': {'type': type([]), 'default': ['1.']},
+ \ 'recurring_bullets': {'type': type(0), 'default': 0},
+ \ 'comment_regex': {'type': type(''), 'default': '^\s*%%.*$\|<!--[^>]*-->'},
+ \ 'header_symbol': {'type': type(''), 'default': '#'},
+ \ 'rxHR': {'type': type(''), 'default': '\(^---*$\|^___*$\|^\*\*\**$\)'},
+ \ 'rxListDefine': {'type': type(''), 'default': '::\%(\s\|$\)'},
+ \ 'math_format': {'type': type({}), 'default': {
+ \ 'pre_mark': '\$\$',
+ \ 'post_mark': '\$\$'}},
+ \ 'multiline_comment_format': {'type': type({}), 'default': {
+ \ 'pre_mark': '',
+ \ 'post_mark': ''}},
+ \ 'pre_format': {'type': type({}), 'default': {
+ \ 'pre_mark': '\%(`\{3,}\|\~\{3,}\)',
+ \ 'post_mark': '\%(`\{3,}\|\~\{3,}\)'}},
+ \ 'symH': {'type': type(0), 'default': 0},
+ \ 'typeface': {'type': type({}), 'default': {
+ \ 'bold': vimwiki#u#hi_expand_regex([['__', '__'], ['\*\*', '\*\*']]),
+ \ 'italic': vimwiki#u#hi_expand_regex([['\*', '\*'], ['_', '_']]),
+ \ 'underline': vimwiki#u#hi_expand_regex([]),
+ \ 'bold_italic': vimwiki#u#hi_expand_regex([['\*_', '_\*'], ['_\*', '\*_'], ['\*\*\*', '\*\*\*'], ['___', '___']]),
+ \ 'code': [
+ \ ['\%(^\|[^`]\)\@<=`\%($\|[^`]\)\@=',
+ \ '\%(^\|[^`]\)\@<=`\%($\|[^`]\)\@='],
+ \ ['\%(^\|[^`]\)\@<=``\%($\|[^`]\)\@=',
+ \ '\%(^\|[^`]\)\@<=``\%($\|[^`]\)\@='],
+ \ ],
+ \ 'del': [['\~\~', '\~\~']],
+ \ 'sup': [['\^', '\^']],
+ \ 'sub': [[',,', ',,']],
+ \ 'eq': [['\%(^\|[^$]\)\@<=\$\%($\|[^$]\)\@=', '\%(^\|[^$]\)\@<=\$\%($\|[^$]\)\@=']],
+ \ }},
+ \ 'wikilink': {'type': type(''), 'default': '\[\[\zs[^\\\]|]\+\ze\%(|[^\\\]]\+\)\?\]\]'},
+ \ })
+endfunction
+
+function! s:get_media_syntaxlocal() abort
+ return extend(s:get_common_syntaxlocal(), {
+ \ 'bold_match': {'type': type(''), 'default': '''''''__Text__'''''''},
+ \ 'bold_search': {'type': type(''), 'default': "'''\\zs[^']\\+\\ze'''"},
+ \ 'bullet_types': {'type': type([]), 'default': ['*', '#']},
+ \ 'header_match': {'type': type(''), 'default': '^\s*\(=\{1,6}\)=\@!\s*__Header__\s*\1=\@!\s*$'},
+ \ 'header_search': {'type': type(''), 'default': '^\s*\(=\{1,6}\)\([^=].*[^=]\)\1\s*$'},
+ \ 'list_markers': {'type': type([]), 'default': ['*', '#']},
+ \ 'number_types': {'type': type([]), 'default': []},
+ \ 'recurring_bullets': {'type': type(1), 'default': 1},
+ \ 'comment_regex': {'type': type(''), 'default': '^\s*%%.*$'},
+ \ 'header_symbol': {'type': type(''), 'default': '='},
+ \ 'rxHR': {'type': type(''), 'default': '^-----*$'},
+ \ 'rxListDefine': {'type': type(''), 'default': '^\%(;\|:\)\s'},
+ \ 'math_format': {'type': type({}), 'default': {
+ \ 'pre_mark': '{{\$',
+ \ 'post_mark': '}}\$'}},
+ \ 'multiline_comment_format': {'type': type({}), 'default': {
+ \ 'pre_mark': '',
+ \ 'post_mark': ''}},
+ \ 'pre_format': {'type': type({}), 'default': {
+ \ 'pre_mark': '<pre>',
+ \ 'post_mark': '<\/pre>'}},
+ \ 'symH': {'type': type(1), 'default': 1},
+ \ 'typeface': {'type': type({}), 'default': {
+ \ 'bold': [['\S\@<=''''''\|''''''\S\@=', '\S\@<=''''''\|''''''\S\@=']],
+ \ 'italic': [['\S\@<=''''\|''''\S\@=', '\S\@<=''''\|''''\S\@=']],
+ \ 'underline': [],
+ \ 'bold_italic': [['\S\@<=''''''''''\|''''''''''\S\@=', '\S\@<=''''''''''\|''''''''''\S\@=']],
+ \ 'code': [
+ \ ['\%(^\|[^`]\)\@<=`\%($\|[^`]\)\@=',
+ \ '\%(^\|[^`]\)\@<=`\%($\|[^`]\)\@='],
+ \ ['\%(^\|[^`]\)\@<=``\%($\|[^`]\)\@=',
+ \ '\%(^\|[^`]\)\@<=``\%($\|[^`]\)\@='],
+ \ ],
+ \ 'del': [['\~\~', '\~\~']],
+ \ 'sup': [['\^', '\^']],
+ \ 'sub': [[',,', ',,']],
+ \ 'eq': [['\%(^\|[^$]\)\@<=\$\%($\|[^$]\)\@=', '\%(^\|[^$]\)\@<=\$\%($\|[^$]\)\@=']],
+ \ }},
+ \ 'wikilink': {'type': type(''), 'default': '\[\[\zs[^\\\]|]\+\ze\%(|[^\\\]]\+\)\?\]\]'},
+ \ })
+endfunction
+
+function! s:get_common_syntaxlocal() abort
+ let res = {}
+ let res.nested_extended = {'type': type(''), 'default': 'VimwikiError,VimwikiPre,VimwikiCode,VimwikiEqIn,VimwikiSuperScript,VimwikiSubScript,textSnipTEX'}
+ let res.nested_typeface = {'type': type(''), 'default': 'VimwikiBold,VimwikiItalic,VimwikiUmderline,VimwikiDelText'}
+ let res.nested = {'type': type(''), 'default': res.nested_extended.default . ',' . res.nested_typeface.default}
+ let res.rxTableSep = {'type': type(''), 'default': '|'}
+ return res
+endfunction
+
+
" Populate syntax variable
" Exported: syntax/vimwiki.vim
-" TODO refactor <= too big function
function! vimwiki#vars#populate_syntax_vars(syntax) abort
+ " TODO refactor <= too big function
+ " TODO permit user conf in some var like g:vimwiki_syntaxlocal_vars
+ " TODO internalize match and search (header and bold)
" Create is not exists
- if !exists('g:vimwiki_syntax_variables')
- let g:vimwiki_syntax_variables = {}
+ if !exists('g:vimwiki_syntaxlocal_vars')
+ let g:vimwiki_syntaxlocal_vars = {}
endif
" Clause: leave if already filled
- if has_key(g:vimwiki_syntax_variables, a:syntax)
+ if has_key(g:vimwiki_syntaxlocal_vars, a:syntax)
return
endif
- " Init syntax variable dictionary
- let g:vimwiki_syntax_variables[a:syntax] = {}
- let syntax_dic = g:vimwiki_syntax_variables[a:syntax]
-
- " Init Typeface (filled in custom syntax)
- let syntax_dic.dTypeface = {}
-
- " Autoload default syntax file
- execute 'runtime! syntax/vimwiki_'.a:syntax.'.vim'
-
+ " Init internal dic
+ let g:vimwiki_syntaxlocal_vars[a:syntax] = {}
+ let syntax_dic = g:vimwiki_syntaxlocal_vars[a:syntax]
+
+ " Get default dic
+ let default_dic = extend({}, function('s:get_' . a:syntax . '_syntaxlocal')())
+
+ " Extend <- default <- user global
+ call s:extend_global(syntax_dic, default_dic)
+ " Extend <- user wikilocal
+ let wikilocal = g:vimwiki_wikilocal_vars[vimwiki#vars#get_bufferlocal('wiki_nr')]
+ " TODO remake tests
+ "call s:extend_local(syntax_dic, default_dic, syntax_dic, wikilocal)
+ " Extend <- user syntaxlocal
+ if exists('g:vimwiki_syntax_list') && has_key(g:vimwiki_syntax_list, a:syntax)
+ call s:extend_local(syntax_dic, default_dic, syntax_dic, g:vimwiki_syntax_list[a:syntax])
+ endif
" TODO make that clean (i.e clearify what is local to syntax ot to buffer)
" Get from local vars
@@ -647,6 +832,7 @@ function! vimwiki#vars#populate_syntax_vars(syntax) abort
\ vimwiki#vars#get_wikilocal('cycle_bullets')
" Tag: get var
+ " TODO rename for internal
let syntax_dic.tag_format = {}
let tf = syntax_dic.tag_format
call extend(tf, vimwiki#vars#get_wikilocal('tag_format'))
@@ -683,7 +869,7 @@ function! vimwiki#vars#populate_syntax_vars(syntax) abort
" Populate generic stuff
- let header_symbol = syntax_dic.rxH
+ let header_symbol = syntax_dic.header_symbol
if syntax_dic.symH
" symmetric headers
for i in range(1,6)
@@ -727,14 +913,14 @@ function! vimwiki#vars#populate_syntax_vars(syntax) abort
endif
let syntax_dic.rxPreStart =
- \ '^\s*'.syntax_dic.rxPreStart
+ \ '^\s*'.syntax_dic.pre_format.pre_mark
let syntax_dic.rxPreEnd =
- \ '^\s*'.syntax_dic.rxPreEnd.'\s*$'
+ \ '^\s*'.syntax_dic.pre_format.post_mark.'\s*$'
let syntax_dic.rxMathStart =
- \ '^\s*'.syntax_dic.rxMathStart
+ \ '^\s*'.syntax_dic.math_format.pre_mark
let syntax_dic.rxMathEnd =
- \ '^\s*'.syntax_dic.rxMathEnd.'\s*$'
+ \ '^\s*'.syntax_dic.math_format.post_mark.'\s*$'
let syntax_dic.number_kinds = []
let syntax_dic.number_divisors = ''
@@ -886,7 +1072,7 @@ endfunction
" Populate markdown specific syntax variables
function! s:populate_extra_markdown_vars() abort
- let mkd_syntax = g:vimwiki_syntax_variables['markdown']
+ let mkd_syntax = g:vimwiki_syntaxlocal_vars['markdown']
" 0a) match [[URL|DESCRIPTION]]
let mkd_syntax.rxWikiLink0 = mkd_syntax.rxWikiLink
@@ -1058,9 +1244,9 @@ endfunction
" Normalize syntax setting
" so that we dont have to branch for the syntax at each operation
-" Called: vimwiki#vars#populate_syntax_vars
+" Called: populate_syntax_vars
function! s:normalize_syntax_settings(syntax) abort
- let syntax_dic = g:vimwiki_syntax_variables[a:syntax]
+ let syntax_dic = g:vimwiki_syntaxlocal_vars[a:syntax]
" Link1: used when:
" user press enter on a non-link (normalize_link)
@@ -1074,6 +1260,244 @@ endfunction
" ----------------------------------------------------------
+" 4. Command (exported) {{{1
+" ----------------------------------------------------------
+
+
+" Get variable anywhere
+" Returns: [value, location] where loc=global|wikilocal|syntaxlocal|bufferlocal|none
+" Called: cmd <- VimvikiVar
+" TODO get more preformant approach when this file has been well refactored:
+" -- calls only the necessary functions and not syntaxlocal anytime
+function! s:get_anywhere(key, ...) abort
+ " Alias common info
+ let s:syntax = vimwiki#vars#get_wikilocal('syntax')
+ let s:wiki_nr = vimwiki#vars#get_bufferlocal('wiki_nr')
+ let s:wikilocal = g:vimwiki_wikilocal_vars[s:wiki_nr]
+ let s:user_wiki = get(g:vimwiki_list, s:wiki_nr, {})
+
+ " Convert value
+ let value = ''
+ if a:0
+ exe 'let value = ' . a:1
+ endif
+
+ function! s:any_bufferlocal(key, value) abort
+ if !(v:version > 703 && exists('b:vimwiki_'.a:key)) | return | endif
+ exe 'let b:vimwiki_' . a:key . ' = ' . a:1
+ endfunction
+
+ " Define: Set syntax: only reparse wikilocal
+ " Note: call set_wikilocal before
+ function! s:any_syntaxlocal(key, value) abort
+ "let syntaxlocal[a:key] = a:1
+ " Prepare
+ if exists('b:current_syntax')
+ unlet b:current_syntax
+ endif
+ unlet g:vimwiki_syntaxlocal_vars
+
+ " Build vars
+ call vimwiki#vars#populate_syntax_vars(s:syntax)
+
+ " Update syntax
+ syntax clear
+ runtime syntax/vimwiki.vim
+ redraw
+ endfunction
+
+ " Define: Set local
+ function! s:any_wikilocal(key, value) abort
+ "let wikilocal[a:key] = a:1
+ " Clause: The key must be in the wikilocal keys
+ if !has_key(s:get_default_wikilocal(), a:key) | return | endif
+
+ " Set: Local
+ let s:user_wiki[a:key] = a:value
+ call vimwiki#vars#init()
+ call s:populate_wikilocal_options()
+ endfunction
+
+ function! s:any_global(key, value) abort
+ "let g:vimwiki_global_vars[a:key] = a:1
+ exe 'let g:vimwiki_' . a:key . ' = ' . string(a:value)
+ call s:populate_global_variables()
+ endfunction
+
+ " Switch
+ " -- Global
+ if has_key(s:get_default_global(), a:key)
+ if a:0
+ call s:any_global(a:key, value)
+ call s:any_wikilocal(a:key, value)
+ call s:any_syntaxlocal(a:key, value)
+ call s:any_bufferlocal(a:key, value)
+ endif
+ return [g:vimwiki_global_vars[a:key], 'global']
+
+ " -- Wiki Local
+ elseif has_key(s:get_default_wikilocal(), a:key)
+ if a:0
+ call s:any_wikilocal(a:key, value)
+ call s:any_syntaxlocal(a:key, value)
+ call s:any_bufferlocal(a:key, value)
+ endif
+ return [s:wikilocal[a:key], 'wikilocal']
+
+ " -- Syntax Local
+ elseif has_key(g:vimwiki_syntaxlocal_vars[s:syntax], a:key)
+ if a:0
+ call s:any_wikilocal(a:key, value)
+ call s:any_syntaxlocal(a:key, value)
+ call s:any_bufferlocal(a:key, value)
+ endif
+ return [g:vimwiki_syntaxlocal_vars[s:syntax][a:key], 'syntaxlocal']
+
+ " -- Buffer Local
+ elseif v:version > 703 && exists('b:vimwiki_'.a:key)
+ if a:0
+ call s:any_bufferlocal(a:key, value)
+ endif
+ return [get(getbufvar('%', ''), 'vimwiki_'.a:key, '/\/\'), 'bufferlocal']
+ else
+ return ['', 'none']
+ endif
+endfunction
+
+
+" Set or Get a vimwiki variable
+" :param: (1) key <string> [space] value <string>
+" -- name of the variable [space] value to evaluate and set the variable
+" Called: VimwikiVar
+function! vimwiki#vars#cmd(arg) abort
+ " Get key and value
+ let sep1 = stridx(a:arg, ' ')
+ let sep2 = sep1
+ while sep2!= -1 && a:arg[sep2] ==# ' ' | let sep2 += 1 | endwhile
+ let arg_key = sep1 == -1 ? a:arg : a:arg[:sep1-1]
+ let arg_value = a:arg[sep2 :]
+
+ " Case0: No argument => Print all keys and values
+ if arg_key ==# ''
+ " Get options keys
+ " Merge default dictionary
+ let d_global = s:get_default_global()
+ let d_wlocal = s:get_default_wikilocal()
+ let syntax = vimwiki#vars#get_wikilocal('syntax')
+ let d_slocal = function('s:get_' . syntax . '_syntaxlocal')()
+ let d_default = {}
+
+ " Define helpers
+ function! s:print_head(name) abort
+ call vimwiki#u#echo(repeat('-', 50), 'Statement', '', '')
+ call vimwiki#u#echo(' ' . a:name, 'Statement', '', '')
+ call vimwiki#u#echo(repeat('-', 50), 'Statement', '', '')
+ endfunction
+
+ " Print Global
+ call s:print_head('Global')
+ for key in sort(keys(d_global))
+ if !has_key(g:vimwiki_global_vars, key)
+ continue
+ endif
+ if string(g:vimwiki_global_vars[key]) == string(d_global[key].default)
+ let d_default[key] = string(d_global[key].default) . ' " From Global'
+ else
+ let msg = key . ' = ' . string(g:vimwiki_global_vars[key])
+ call vimwiki#u#echo(msg, '', 'm', '')
+ endif
+ endfor
+
+ " Print SyntaxLocal
+ let syntaxlocal = g:vimwiki_syntaxlocal_vars[syntax]
+ call s:print_head('Syntax: ' . toupper(syntax[0]) . syntax[1:])
+ for key in sort(keys(d_slocal))
+ if !has_key(syntaxlocal, key)
+ continue
+ endif
+ if string(syntaxlocal[key]) == string(d_slocal[key].default)
+ let d_default[key] = string(d_slocal[key].default) . ' " From SyntaxLocal'
+ else
+ let msg = key . ' = ' . string(syntaxlocal[key])
+ call vimwiki#u#echo(msg, '', 'm', '')
+ endif
+ endfor
+
+ " Print WikiLocal
+ let wiki_nr = vimwiki#vars#get_bufferlocal('wiki_nr')
+ let wikilocal = g:vimwiki_wikilocal_vars[wiki_nr]
+ call s:print_head('Local: ' . wiki_nr)
+ for key in sort(keys(d_wlocal))
+ if !has_key(wikilocal, key)
+ continue
+ endif
+ if string(wikilocal[key]) == string(d_wlocal[key].default)
+ let d_default[key] = string(d_wlocal[key].default) . ' " From WikiLocal'
+ else
+ let msg = key . ' = ' . string(wikilocal[key])
+ call vimwiki#u#echo(msg, '', 'm', '')
+ endif
+ endfor
+
+ " Print Default
+ call s:print_head('Default')
+ for key in sort(keys(d_default))
+ let msg = key . ' = ' . d_default[key]
+ call vimwiki#u#echo(msg, '', 'm', '')
+ endfor
+
+ " Case1: Only key => Print value
+ elseif sep1 == -1 || arg_value =~# '^\s*$'
+ let [val, loc] = s:get_anywhere(arg_key)
+ let msg = 'Got: ' . arg_key . ' = ' . string(val) . ' " <= From: ' . toupper(loc[0]) . loc[1:]
+ call vimwiki#u#echo(msg, '', 'm')
+
+ " Case2: Key and value => Set value
+ else
+ let [val, loc] = s:get_anywhere(arg_key, arg_value)
+ let msg = 'Set: ' . arg_key . ' = ' . string(val) . ' " => To: ' . toupper(loc[0]) . loc[1:]
+ call vimwiki#u#echo(msg, '', 'm')
+ endif
+endfunction
+
+
+function! vimwiki#vars#complete(arglead, cmdline, pos) abort
+ " Get key and value: faster than split
+ " -- And must treat potential multispace in value
+ let arg_list = split(a:cmdline, '\s\+')
+ let sep1 = stridx(a:cmdline, ' ')
+ while sep1!= -1 && a:cmdline[sep1] ==# ' ' | let sep1 += 1 | endwhile
+ let sep2 = stridx(a:cmdline, ' ', sep1+1)
+ while sep2!= -1 && a:cmdline[sep2] ==# ' ' | let sep2 += 1 | endwhile
+ let arg_key = a:cmdline[sep1 : sep2]
+ let arg_value = a:cmdline[sep2 :]
+
+ " Case1: Complete key
+ if arg_key[-1:-1] !=# ' '
+ " Get options keys
+ let keys = []
+ call extend(keys, keys(s:get_default_global()))
+ call extend(keys, keys(s:get_default_wikilocal()))
+
+ " Filter and Return
+ " -- Use smart case matching
+ let arg_re = substitute(arg_key, '\u', '[\0\l\0]', 'g')
+ " -- Match anywhere in variable name
+ let arg_re = '.*' . arg_re . '.*'
+ call filter(keys, '-1 != match(v:val, arg_re)')
+
+ return keys
+ " Case2: Complete value
+ else
+ " Remove trailing space
+ let arg_key = substitute(arg_key, '\s\+$', '', '')
+ let value = s:get_anywhere(arg_key)[0]
+ return [string(value)]
+ endif
+endfunction
+
+
+" ----------------------------------------------------------
" 4. Getter, Setter (exported) {{{1
" ----------------------------------------------------------
@@ -1089,12 +1513,12 @@ function! vimwiki#vars#get_syntaxlocal(key, ...) abort
endif
" Create syntax varaible dict if not exists (lazy)
- if !exists('g:vimwiki_syntax_variables') || !has_key(g:vimwiki_syntax_variables, syntax)
+ if !exists('g:vimwiki_syntaxlocal_vars') || !has_key(g:vimwiki_syntaxlocal_vars, syntax)
call vimwiki#vars#populate_syntax_vars(syntax)
endif
" Return d_syntax[a:key]
- return g:vimwiki_syntax_variables[syntax][a:key]
+ return g:vimwiki_syntaxlocal_vars[syntax][a:key]
endfunction
diff --git a/doc/design_notes.md b/doc/design_notes.md
@@ -1,12 +1,12 @@
# Design Notes
-This file is meant to document design decisions and algorithms inside vimwiki
+This file is meant to document design decisions and algorithms inside Vimwiki
which are too large for code comments, and not necessarily interesting to
users. Please create a new section to document each behavior.
## Formatting tables
-In vimwiki, formatting tables occurs dynamically, when navigating between cells
+In Vimwiki, formatting tables occurs dynamically, when navigating between cells
and adding new rows in a table in the Insert mode, or statically, when pressing
`gqq` or `gqw` (which are mappings for commands `VimwikiTableAlignQ` and
`VimwikiTableAlignW` respectively) in the Normal mode. It also triggers when
@@ -107,7 +107,7 @@ variable `g:vimwiki_table_auto_fmt` is set. This means that formatting of the
whole table is called on all those multiple interleaves between the Insert and
the Normal mode in `s:kbd_create_new_row` (notice `\<ESC>`, `o`, etc.).
-### The newer table formating algorithm
+### The newer table formatting algorithm
The newer algorithm was introduced to struggle against performance issues when
formatting large tables.
@@ -184,3 +184,55 @@ viewport) until one of the being edited cells grows in length to a value big
enough to trigger the older algorithm and the whole table gets aligned. When
partial formatting is not desirable, the whole table can be formatted by
pressing `gqq` in the Normal mode.
+
+
+## Scoped Variable
+
+Vimwiki's variables have a scope. They can be:
+
+1. Global [ex: `global_ext`]
+2. Wikilocal (1, 2, 3 ...) [ex: `path`]
+3. Syntaxlocal (default, markdown, media) [ex: `bullet_types`]
+4. Bufferlocal [ex: `b:vimwiki_wiki_nr`]
+
+They all can be configured, changed by user
+
+As a comparison, Vim's variables also have a scope (`:h variable-scope`) and
+can also be configured by users.
+
+While features kept stacking, it became more and more difficult to maintain the
+coherence and configurability between these variables: a type of markers, say
+`bullet_types`, can affect folding, highlighting, keystrokes mapping, indentation.
+All of those aspects often requires internal variables that should be calculated
+only once's when user is changing the variable and affect only the scope in which
+they are defined: a `markdown` syntax configuration should affect all `markdown`
+wikis but not `default` ones. So it was decided (#894) to keep a 3 global
+dictionaries to hold internal variables (there is only one bufferlocal variable
+so a dictionary was clearly overkill) and 3 other dictionaries for user
+configuration. The internal dictionaries get updated at startup (`:h extend`)
+with the user content but do not modify it. They can also be updated later with
+`VimwikiVar` function.
+
+Here, `key` is the variable name, `2` the wiki number and `markdown` the syntax
+
+```vim
+" External -> Internal
+g:vimwiki_{key} -> g:vimwiki_global_vars[key]
+g:vimwiki_syntax_list['markdown'][key]
+ -> g:vimwiki_syntaxlocal_vars['markdown'][key]
+g:vimwiki_list[2][key] -> g:vimwiki_wikilocal_vars[2][key]
+```
+
+All are defined in `vars.vim` and in case of a conflict while executing it, the
+innermost scope if privileged (as usual for variable scoping conflicts). The
+reasons for such a complex system is:
+1. The diversity of variables and developers
+2. The nature of new (2020) issues asking for some deep customisation (ex: of
+ the link format) or high functionality (ex: on demand wiki creation and
+ configuration)
+3. Historical excuses that Vimwiki was not designed to be highly configurable at
+ beginning and many temporary internal variables where created to "fix some
+ holes"
+
+
+<!-- vim: set tw=80: -->
diff --git a/doc/vimwiki.txt b/doc/vimwiki.txt
@@ -46,7 +46,8 @@ CONTENTS *vimwiki*
12.1. Registered Wiki |vimwiki-register-wiki|
12.2. Temporary Wiki |vimwiki-temporary-wiki|
12.3. Per-Wiki Options |vimwiki-local-options|
- 12.4. Global Options |vimwiki-global-options|
+ 12.4. Per-Syntax Options |vimwiki-syntax-options|
+ 12.5. Global Options |vimwiki-global-options|
13. Getting help |vimwiki-help|
14. Contributing & Bug reports |vimwiki-contributing|
15. Development |vimwiki-development|
@@ -722,6 +723,13 @@ These key mappings can be modified by replacing the default keys: >
Displays a list of registered wikis and opens the index file of the
selected wiki.
+*:VimwikiVar* [varname] [value]
+ Get / Set vimwiki variable. Depending on the number of argument:
+ 0. Echo vimwiki's variables
+ 1. Echo variable varname. Completion works with existing variables
+ 2. Set variable varname to value. Completion works with the current value
+ of variable
+
*:VimwikiDiaryIndex* [count]
Open diary index file of the current wiki. If a [count] is given the
corresponding wiki from |g:vimwiki_list| is opened instead.
@@ -2077,7 +2085,7 @@ before plugin/vimwiki.vim is sourced). If this is not possible, try this
command after the Vimwiki settings are (re-) set: >
:call vimwiki#vars#init()
If you also want to reload syntax variables, prefix the last command by: >
- :unlet g:vimwiki_syntax_variables
+ :unlet g:vimwiki_syntaxlocal_vars
------------------------------------------------------------------------------
12.1 Registered Wiki *g:vimwiki_list* *vimwiki-register-wiki*
@@ -2812,12 +2820,29 @@ Default: 0
------------------------------------------------------------------------------
-12.4 Global Options *vimwiki-global-options*
+12.4 Syntax Options *vimwiki-global-options*
+
+Syntax options are configured using the following pattern: >
+
+ let g:vimwiki_syntax_list['markdown']['bullet_type'] = ['*', '-', '+']
+
+Where:
+- `markdown` is the syntax name. It can be (`default`, `markdown` or `media`)
+- `bullet_type` is the option_name (see below)
+- `['*', '-', '+']` is the option value
+
+
+------------------------------------------------------------------------------
+12.5 Global Options *vimwiki-global-options*
Global options are configured using the following pattern: >
- let g:option_name = option_value
+ let g:vimwiki_global_ext = 1
+
+Where:
+- `global_ext` is the option name
+- `1` is the option value
------------------------------------------------------------------------------
@@ -3788,6 +3813,7 @@ http://code.google.com/p/vimwiki/issues/list. They may be accessible from
https://github.com/vimwiki-backup/vimwiki/issues.
New:~
+ * Feature: PR #988: Command VimwikiVar to list, get and set variables
* Feature: #837 extract web page <title> from URL under cursor and create
a nice wiki link
* Feature: #922 #928: g:vimwiki_tag_format to change the tag format
diff --git a/plugin/vimwiki.vim b/plugin/vimwiki.vim
@@ -380,6 +380,9 @@ command! VimwikiDiaryGenerateLinks
command! VimwikiShowVersion call s:get_version()
+command! -nargs=* -complete=customlist,vimwiki#vars#complete
+ \ VimwikiVar call vimwiki#vars#cmd(<q-args>)
+
" Declare global maps
" <Plug> global definitions
@@ -404,12 +407,12 @@ nnoremap <silent><script> <Plug>VimwikiMakeTomorrowDiaryNote
\ :<C-U>call vimwiki#diary#make_note(v:count, 0,
\ vimwiki#diary#diary_date_link(localtime(), 1))<CR>
-" Get the user defined prefix (default <leader>w)
-let s:map_prefix = vimwiki#vars#get_global('map_prefix')
-
" Set default global key mappings
if str2nr(vimwiki#vars#get_global('key_mappings').global)
+ " Get the user defined prefix (default <leader>w)
+ let s:map_prefix = vimwiki#vars#get_global('map_prefix')
+
call vimwiki#u#map_key('n', s:map_prefix . 'w', '<Plug>VimwikiIndex', 2)
call vimwiki#u#map_key('n', s:map_prefix . 't', '<Plug>VimwikiTabIndex', 2)
call vimwiki#u#map_key('n', s:map_prefix . 's', '<Plug>VimwikiUISelect', 2)
diff --git a/syntax/vimwiki.vim b/syntax/vimwiki.vim
@@ -21,43 +21,13 @@ let b:vimwiki_syntax_concealends = has('conceal') ? ' concealends' : ''
" Populate all syntax vars
" Include syntax/vimwiki_markdown.vim as "side effect"
call vimwiki#vars#populate_syntax_vars(s:current_syntax)
-let syntax_dic = g:vimwiki_syntax_variables[s:current_syntax]
+let syntax_dic = g:vimwiki_syntaxlocal_vars[s:current_syntax]
" Declare nesting capabilities
" -- to be embeded in standard: bold, italic, underline
-let syntax_dic.nested_extended = 'VimwikiError,VimwikiPre,VimwikiCode,VimwikiEqIn,VimwikiSuperScript,VimwikiSubScript,textSnipTEX'
-" -- to be embeded in exetended (the one above)
-let syntax_dic.nested_typeface = 'VimwikiBold,VimwikiItalic,VimwikiUmderline,VimwikiDelText'
-let syntax_dic.nested = syntax_dic.nested_extended . ',' . syntax_dic.nested_typeface
" text: `code` or ``code`` only inline
" Note: `\%(^\|[^`]\)\@<=` means after a new line or a non `
-let syntax_dic.dTypeface.code = [
- \ ['\%(^\|[^`]\)\@<=`\%($\|[^`]\)\@=',
- \ '\%(^\|[^`]\)\@<=`\%($\|[^`]\)\@='],
- \ ['\%(^\|[^`]\)\@<=``\%($\|[^`]\)\@=',
- \ '\%(^\|[^`]\)\@<=``\%($\|[^`]\)\@='],
- \ ]
-
-" text: ~~deleted text~~
-let syntax_dic.dTypeface.del = ([
- \ ['\~\~', '\~\~']])
-
-" text: ^superscript^
-let syntax_dic.dTypeface.sup = ([
- \ ['\^', '\^']])
-
-" text: ,,subscript,,
-let syntax_dic.dTypeface.sub = ([
- \ [',,', ',,']])
-
-" text: $ equation_inline $
-" Match only one $
-" ( ^ or not $) before $ and after: not $
-let syntax_dic.dTypeface.eq = ([
- \ ['\%(^\|[^$]\)\@<=\$\%($\|[^$]\)\@=',
- \ '\%(^\|[^$]\)\@<=\$\%($\|[^$]\)\@=']])
-
" LINKS: highlighting is complicated due to "nonexistent" links feature
function! s:add_target_syntax_ON(target, type) abort
@@ -236,7 +206,7 @@ execute 'syn match VimwikiLinkChar /'.vimwiki#vars#get_global('rxWikiInclSuffix1
" non concealed chars
execute 'syn match VimwikiHeaderChar contained /\%(^\s*'.
- \ vimwiki#vars#get_syntaxlocal('rxH').'\+\)\|\%('.vimwiki#vars#get_syntaxlocal('rxH').
+ \ vimwiki#vars#get_syntaxlocal('header_symbol').'\+\)\|\%('.vimwiki#vars#get_syntaxlocal('header_symbol').
\ '\+\s*$\)/'
@@ -308,10 +278,32 @@ syntax match VimwikiPlaceholderParam /.*/ contained
" Html Tag: <u>
if vimwiki#vars#get_global('valid_html_tags') !=? ''
- " Include: Source html file here
- execute 'source ' . expand('<sfile>:h') . '/vimwiki_html.vim'
+ let s:html_tags = join(split(vimwiki#vars#get_global('valid_html_tags'), '\s*,\s*'), '\|')
+ exe 'syntax match VimwikiHTMLtag #\c</\?\%('.s:html_tags.'\)\%(\s\{-1}\S\{-}\)\{-}\s*/\?>#'
+
+ " Typeface:
+ let html_typeface = {
+ \ 'bold': [['<b>', '</b\_s*>'], ['<strong>', '</strong\_s*>']],
+ \ 'italic': [['<i>', '</i\_s*>'], ['<em>', '</em\_s*>']],
+ \ 'underline': [['<u>', '</u\_s*>']],
+ \ 'code': [['<code>', '</code\_s*>']],
+ \ 'del': [['<del>', '</del\_s*>']],
+ \ 'eq': [],
+ \ 'sup': [['<sup>', '</sup\_s*>']],
+ \ 'sub': [['<sub>', '</sub\_s*>']],
+ \ }
+ call vimwiki#u#hi_typeface(html_typeface)
endif
+" Comment: home made
+execute 'syntax match VimwikiComment /'.vimwiki#vars#get_syntaxlocal('comment_regex').
+ \ '/ contains=@Spell,VimwikiTodo'
+" Only do syntax highlighting for multiline comments if they exist
+let mc_format = vimwiki#vars#get_syntaxlocal('multiline_comment_format')
+if !empty(mc_format.pre_mark) && !empty(mc_format.post_mark)
+execute 'syntax region VimwikiMultilineComment start=/'.mc_format.pre_mark.
+ \ '/ end=/'.mc_format.post_mark.'/ contains=@NoSpell,VimwikiTodo'
+endif
" Tag:
let tag_cmd = 'syntax match VimwikiTag /'.vimwiki#vars#get_syntaxlocal('rxTags').'/'
@@ -343,7 +335,7 @@ endif
" Typeface: -> u.vim
-let s:typeface_dic = vimwiki#vars#get_syntaxlocal('dTypeface')
+let s:typeface_dic = vimwiki#vars#get_syntaxlocal('typeface')
call vimwiki#u#hi_typeface(s:typeface_dic)
@@ -500,7 +492,7 @@ call vimwiki#base#nested_syntax('tex',
\ vimwiki#vars#get_syntaxlocal('rxMathEnd'), 'VimwikiMath')
" LaTeX: Inline
-for u in syntax_dic.dTypeface.eq
+for u in syntax_dic.typeface.eq
execute 'syntax region textSniptex matchgroup=texSnip'
\ . ' start="'.u[0].'" end="'.u[1].'"'
\ . ' contains=@texMathZoneGroup'
diff --git a/syntax/vimwiki_default.vim b/syntax/vimwiki_default.vim
@@ -1,74 +0,0 @@
-" vim:tabstop=2:shiftwidth=2:expandtab:textwidth=99
-" Vimwiki syntax file
-" Description: Defines default syntax
-" Home: https://github.com/vimwiki/vimwiki/
-
-
-" s:default_syntax is kind of a reference to the dict in
-" g:vimwiki_syntax_variables['default']. It is used here simply as an
-" abbreviation for the latter.
-let s:default_syntax = g:vimwiki_syntax_variables['default']
-
-
-" TODO mutualise
-" Get config: possibly concealed chars
-let b:vimwiki_syntax_conceal = exists('+conceallevel') ? ' conceal' : ''
-let b:vimwiki_syntax_concealends = has('conceal') ? ' concealends' : ''
-
-" text: *strong*
-let s:default_syntax.dTypeface.bold = vimwiki#u#hi_expand_regex([
- \ ['\*', '\*']])
-
-" text: _italic_
-let s:default_syntax.dTypeface.italic = vimwiki#u#hi_expand_regex([
- \ ['_', '_']])
-
-" text: no underline defined
-let s:default_syntax.dTypeface.underline = []
-
-" text: *_bold italic_* or _*italic bold*_
-let s:default_syntax.dTypeface.bold_italic = vimwiki#u#hi_expand_regex([
- \ ['\*_', '_\*'], ['_\*', '\*_']])
-
-" generic headers
-let s:default_syntax.rxH = '='
-let s:default_syntax.symH = 1
-
-
-
-" <hr>, horizontal rule
-let s:default_syntax.rxHR = '^-----*$'
-
-" Tables. Each line starts and ends with '|'; each cell is separated by '|'
-let s:default_syntax.rxTableSep = '|'
-
-" Lists
-let s:default_syntax.bullet_types = ['-', '*', '#']
-" 1 means the bullets can be repeatet to indicate the level, like * ** ***
-" 0 means the bullets stand on their own and the level is indicated by the indentation
-let s:default_syntax.recurring_bullets = 0
-let s:default_syntax.number_types = ['1)', '1.', 'i)', 'I)', 'a)', 'A)']
-"this should contain at least one element
-"it is used for i_<C-L><C-J> among other things
-let s:default_syntax.list_markers = ['-', '1.', '*', 'I)', 'a)']
-let s:default_syntax.rxListDefine = '::\(\s\|$\)'
-
-" Preformatted text
-let s:default_syntax.rxPreStart = '{{{'
-let s:default_syntax.rxPreEnd = '}}}'
-
-" Math block
-let s:default_syntax.rxMathStart = '{{\$'
-let s:default_syntax.rxMathEnd = '}}\$'
-
-let s:default_syntax.rxMultilineCommentStart = '%%+'
-let s:default_syntax.rxMultilineCommentEnd = '+%%'
-let s:default_syntax.rxComment = '^\s*%%.*$'
-
-let s:default_syntax.header_search = '^\s*\(=\{1,6}\)\([^=].*[^=]\)\1\s*$'
-let s:default_syntax.header_match = '^\s*\(=\{1,6}\)=\@!\s*__Header__\s*\1=\@!\s*$'
-let s:default_syntax.bold_search = '\%(^\|\s\|[[:punct:]]\)\@<=\*\zs\%([^*`[:space:]][^*`]*'.
- \ '[^*`[:space:]]\|[^*`[:space:]]\)\ze\*\%([[:punct:]]\|\s\|$\)\@='
-let s:default_syntax.bold_match = '\%(^\|\s\|[[:punct:]]\)\@<=\*__Text__\*'.
- \ '\%([[:punct:]]\|\s\|$\)\@='
-let s:default_syntax.wikilink = '\[\[\zs[^\\\]|]\+\ze\%(|[^\\\]]\+\)\?\]\]'
diff --git a/syntax/vimwiki_html.vim b/syntax/vimwiki_html.vim
@@ -1,39 +0,0 @@
-" vim:tabstop=2:shiftwidth=2:expandtab:textwidth=99
-" Vimwiki syntax file
-" Home: https://github.com/vimwiki/vimwiki/
-" Description: Defines html syntax
-" Loaded: conditionaly by syntax/vimwiki.vim
-" Copied from $VIMRUNTIME
-" Note: The me=s-1 was omited from the region definition
-" See: `syn region VimwikiBoldUnderlineItalic contained start="<i\>" end="</i\_s*>"me=s-1 contains=VimwikiHTMLTag...`
-" Note: Not configurable
-
-let s:html_tags = join(split(vimwiki#vars#get_global('valid_html_tags'), '\s*,\s*'), '\|')
-exe 'syntax match VimwikiHTMLtag #\c</\?\%('.s:html_tags.'\)\%(\s\{-1}\S\{-}\)\{-}\s*/\?>#'
-
-
-" Typeface:
-let html_typeface = {
- \ 'bold': [['<b>', '</b\_s*>'], ['<strong>', '</strong\_s*>']],
- \ 'italic': [['<i>', '</i\_s*>'], ['<em>', '</em\_s*>']],
- \ 'underline': [['<u>', '</u\_s*>']],
- \ 'code': [['<code>', '</code\_s*>']],
- \ 'del': [['<del>', '</del\_s*>']],
- \ 'eq': [],
- \ 'sup': [['<sup>', '</sup\_s*>']],
- \ 'sub': [['<sub>', '</sub\_s*>']],
- \ }
-call vimwiki#u#hi_typeface(html_typeface)
-
-
-" Comment: home made
-execute 'syntax match VimwikiComment /'.vimwiki#vars#get_syntaxlocal('rxComment').
- \ '/ contains=@Spell,VimwikiTodo'
-
-" Only do syntax highlighting for multiline comments if they exist
-let s:mc_start = vimwiki#vars#get_syntaxlocal('rxMultilineCommentStart')
-let s:mc_end = vimwiki#vars#get_syntaxlocal('rxMultilineCommentEnd')
-if !empty(s:mc_start) && !empty(s:mc_end)
-execute 'syntax region VimwikiMultilineComment start=/'.s:mc_start.
- \ '/ end=/'.s:mc_end.'/ contains=@NoSpell,VimwikiTodo'
-endif
diff --git a/syntax/vimwiki_markdown.vim b/syntax/vimwiki_markdown.vim
@@ -1,88 +0,0 @@
-" vim:tabstop=2:shiftwidth=2:expandtab:textwidth=99
-" Vimwiki syntax file
-" Home: https://github.com/vimwiki/vimwiki/
-" Description: Defines markdown syntax
-" Called: vars.vim => Many other (common) variables are defined there
-" More in u.vim, base.vim (nested_syntax for multiline code)
-
-let s:markdown_syntax = g:vimwiki_syntax_variables['markdown']
-
-
-" TODO mutualise
-" Get config: possibly concealed chars
-let b:vimwiki_syntax_conceal = exists('+conceallevel') ? ' conceal' : ''
-let b:vimwiki_syntax_concealends = has('conceal') ? ' concealends' : ''
-
-
-" text: **bold** or __bold__
-let s:markdown_syntax.dTypeface.bold = vimwiki#u#hi_expand_regex([
- \ ['__', '__'], ['\*\*', '\*\*']])
-
-" text: *italic* or _italic_
-let s:markdown_syntax.dTypeface.italic = vimwiki#u#hi_expand_regex([
- \ ['\*', '\*'], ['_', '_']])
-
-" text: no underline defined
-let s:markdown_syntax.dTypeface.underline = []
-
-" text: *_bold italic_* or _*italic bold*_ or ___bi___ or ***bi***
-let s:markdown_syntax.dTypeface.bold_italic = vimwiki#u#hi_expand_regex([
- \ ['\*_', '_\*'], ['_\*', '\*_'], ['\*\*\*', '\*\*\*'], ['___', '___']])
-
-
-" generic headers
-let s:markdown_syntax.rxH = '#'
-let s:markdown_syntax.symH = 0
-
-" <hr>, horizontal rule
-let s:markdown_syntax.rxHR = '\(^---*$\|^___*$\|^\*\*\**$\)'
-
-" Tables. Each line starts and ends with '|'; each cell is separated by '|'
-let s:markdown_syntax.rxTableSep = '|'
-
-" Lists
-let s:markdown_syntax.recurring_bullets = 0
-let s:markdown_syntax.number_types = ['1.']
-let s:markdown_syntax.list_markers = ['-', '*', '+', '1.']
-let s:markdown_syntax.rxListDefine = '::\%(\s\|$\)'
-let s:markdown_syntax.bullet_types = ['*', '-', '+']
-
-" Preformatted text (code blocks)
-let s:markdown_syntax.rxPreStart = '\%(`\{3,}\|\~\{3,}\)'
-let s:markdown_syntax.rxPreEnd = '\%(`\{3,}\|\~\{3,}\)'
-" TODO see syntax/vimwiki_markdown_custom.vim for more info
-" let s:markdown_syntax.rxIndentedCodeBlock = '\%(^\n\)\@1<=\%(\%(\s\{4,}\|\t\+\).*\n\)\+'
-
-" Math block
-let s:markdown_syntax.rxMathStart = '\$\$'
-let s:markdown_syntax.rxMathEnd = '\$\$'
-
-" NOTE: There is no multi-line comment syntax for Markdown
-let s:markdown_syntax.rxMultilineCommentStart = ''
-let s:markdown_syntax.rxMultilineCommentEnd = ''
-let s:markdown_syntax.rxComment = '^\s*%%.*$\|<!--[^>]*-->'
-
-
-" Used in code (base.vim)
-"""""""""""""""""""""""""
-
-" Header
-" TODO mutualise with rxHeader in vars.vim := Define atx_regex only onces
-" TODO regex_or function => (1|2)
-let atx_header_search = '^\s*\(#\{1,6}\)\([^#].*\)$'
-let atx_header_match = '^\s*\(#\{1,6}\)#\@!\s*__Header__\s*$'
-
-let setex_header_search = '^\s\{0,3}\zs[^>].*\ze\n'
-let setex_header_search .= '^\s\{0,3}[=-]\{2,}$'
-
-let setex_header_match = '^\s\{0,3}>\@!__Header__\n'
-let setex_header_match .= '^\s\{0,3}[=-][=-]\+$'
-
-let s:markdown_syntax.header_search = '\%(' . atx_header_search . '\|' . setex_header_search . '\)'
-let s:markdown_syntax.header_match = '\%(' . atx_header_match . '\|' . setex_header_match . '\)'
-
-let s:markdown_syntax.bold_search = '\%(^\|\s\|[[:punct:]]\)\@<=\*\zs'.
- \ '\%([^*`[:space:]][^*`]*[^*`[:space:]]\|[^*`[:space:]]\)\ze\*\%([[:punct:]]\|\s\|$\)\@='
-let s:markdown_syntax.bold_match = '\%(^\|\s\|[[:punct:]]\)\@<=\*__Text__\*'.
- \ '\%([[:punct:]]\|\s\|$\)\@='
-let s:markdown_syntax.wikilink = '\[\[\zs[^\\\]|]\+\ze\%(|[^\\\]]\+\)\?\]\]'
diff --git a/syntax/vimwiki_media.vim b/syntax/vimwiki_media.vim
@@ -1,68 +0,0 @@
-" vim:tabstop=2:shiftwidth=2:expandtab:textwidth=99
-" Vimwiki syntax file
-" Description: Defines mediaWiki syntax
-" Home: https://github.com/vimwiki/vimwiki/
-
-
-" see the comments in vimwiki_default.vim for some info about this file
-
-
-let s:media_syntax = g:vimwiki_syntax_variables['media']
-
-" text: '''strong'''
-let s:media_syntax.dTypeface['bold'] = [
- \ ['\S\@<=''''''\|''''''\S\@=', '\S\@<=''''''\|''''''\S\@='],
- \ ]
-
-" text: ''italic''
-let s:media_syntax.dTypeface['italic'] = [
- \ ['\S\@<=''''\|''''\S\@=', '\S\@<=''''\|''''\S\@='],
- \ ]
-
-" text: no underline defined
-let s:media_syntax.dTypeface['underline'] = []
-
-" text: '''''strong italic'''''
-let s:media_syntax.dTypeface['bold_italic'] = [
- \ ['\S\@<=''''''''''\|''''''''''\S\@=', '\S\@<=''''''''''\|''''''''''\S\@='],
- \ ]
-
-
-" generic headers
-let s:media_syntax.rxH = '='
-let s:media_syntax.symH = 1
-
-
-" <hr>, horizontal rule
-let s:media_syntax.rxHR = '^-----*$'
-
-" Tables. Each line starts and ends with '|'; each cell is separated by '|'
-let s:media_syntax.rxTableSep = '|'
-
-" Lists
-let s:media_syntax.bullet_types = ['*', '#']
-let s:media_syntax.recurring_bullets = 1
-let s:media_syntax.number_types = []
-let s:media_syntax.list_markers = ['*', '#']
-let s:media_syntax.rxListDefine = '^\%(;\|:\)\s'
-
-" Preformatted text
-let s:media_syntax.rxPreStart = '<pre>'
-let s:media_syntax.rxPreEnd = '<\/pre>'
-
-" Math block
-let s:media_syntax.rxMathStart = '{{\$'
-let s:media_syntax.rxMathEnd = '}}\$'
-
-" NOTE: There is no multi-line comment syntax for MediaWiki
-let s:media_syntax.rxMultilineCommentStart = ''
-let s:media_syntax.rxMultilineCommentEnd = ''
-let s:media_syntax.rxComment = '^\s*%%.*$'
-
-let s:media_syntax.header_search = '^\s*\(=\{1,6}\)\([^=].*[^=]\)\1\s*$'
-let s:media_syntax.header_match = '^\s*\(=\{1,6}\)=\@!\s*__Header__\s*\1=\@!\s*$'
-let s:media_syntax.bold_search = "'''\\zs[^']\\+\\ze'''"
-let s:media_syntax.bold_match = '''''''__Text__'''''''
-" ^- this strange looking thing is equivalent to "'''__Text__'''" but since we later
-" want to call escape() on this string, we must keep it in single quotes
-let s:media_syntax.wikilink = '\[\[\zs[^\\\]|]\+\ze\%(|[^\\\]]\+\)\?\]\]'
diff --git a/test/independent_runs/map.vader b/test/independent_runs/map.vader
@@ -39,7 +39,7 @@ Execute (Configure: Set vimwiki list to markdown resource):
\ 'g:loaded_vimwiki',
\ 'g:vimwiki_global_vars',
\ 'g:vimwiki_wikilocal_vars',
- \ 'g:vimwiki_syntax_variables',
+ \ 'g:vimwiki_syntaxlocal_vars',
\ ]
if exists(i)
exe 'unlet ' . i
@@ -467,8 +467,8 @@ Execute (file .md):
set sw=2
file toto.md
edit!
- let g:vimwiki_syntax_variables['markdown']['cycle_bullets'] = 1
- let g:vimwiki_syntax_variables['markdown']['bullet_types'] = ['*', '-', '+']
+ let g:vimwiki_syntaxlocal_vars['markdown']['cycle_bullets'] = 1
+ let g:vimwiki_syntaxlocal_vars['markdown']['bullet_types'] = ['*', '-', '+']
AssertEqual 'vimwiki', &ft
Do (gLl):
@@ -518,9 +518,9 @@ Execute (file toto.md):
file toto.md
edit!
Log "Cycle bullets"
- let g:vimwiki_syntax_variables['bullet_types'] = ['*', '-']
- let g:vimwiki_syntax_variables['markdown']['cycle_bullets'] = 1
- AssertEqual g:vimwiki_syntax_variables['markdown']['cycle_bullets'], 1
+ let g:vimwiki_syntaxlocal_vars['bullet_types'] = ['*', '-']
+ let g:vimwiki_syntaxlocal_vars['markdown']['cycle_bullets'] = 1
+ AssertEqual g:vimwiki_syntaxlocal_vars['markdown']['cycle_bullets'], 1
AssertEqual 'vimwiki', &ft
set sw=2
set expandtab " Otherwise, getting some tab before some items, when enought space
diff --git a/test/link_creation.vader b/test/link_creation.vader
@@ -18,8 +18,8 @@ Given vimwiki (abc def ghi jkl):
Execute (Set filename wiki_test.md):
call SetSyntax('markdown')
- let save_link = g:vimwiki_syntax_variables.markdown.Link1
- let g:vimwiki_syntax_variables.markdown.Link1 = vimwiki#vars#get_global('WikiLinkTemplate1')
+ let save_link = g:vimwiki_syntaxlocal_vars.markdown.Link1
+ let g:vimwiki_syntaxlocal_vars.markdown.Link1 = vimwiki#vars#get_global('WikiLinkTemplate1')
Do (vee<CR>):
vee\<CR>
@@ -28,7 +28,7 @@ Expect (append md suffix):
[[abc def]] ghi jkl
Execute (restore):
- let g:vimwiki_syntax_variables.markdown.Link1 = save_link
+ let g:vimwiki_syntaxlocal_vars.markdown.Link1 = save_link
# vimwiki_markdown_link_ext {{{1
diff --git a/test/syntax.vader b/test/syntax.vader
@@ -88,7 +88,7 @@ Given vimwiki (task list with code):
Execute (let g:vimwiki_hl_cb_checked = 1):
let g:vimwiki_hl_cb_checked = 1
- unlet g:vimwiki_syntax_variables
+ unlet g:vimwiki_syntaxlocal_vars
call vimwiki#vars#init()
call SetSyntax('markdown')
@@ -106,7 +106,7 @@ Given vimwiki (task list with code):
Execute (let g:vimwiki_hl_cb_checked = 2):
let g:vimwiki_hl_cb_checked = 2
- unlet g:vimwiki_syntax_variables
+ unlet g:vimwiki_syntaxlocal_vars
call vimwiki#vars#init()
call SetSyntax('markdown')
diff --git a/test/tag.vader b/test/tag.vader
@@ -13,7 +13,7 @@ Execute (Setup):
######################################################################
Execute (Change delimiter <tag1|tag2> {{{1):
let g:vimwiki_tag_format = {'pre_mark': '<', 'post_mark': '>', 'sep': '|'}
- unlet g:vimwiki_syntax_variables
+ unlet g:vimwiki_syntaxlocal_vars
call vimwiki#vars#init()
edit $HOME/testmarkdown/Test-Tag.md
AssertEqual $HOME . '/testmarkdown/Test-Tag.md', expand('%')
@@ -89,7 +89,7 @@ Expect (Good jump {{{3):
Execute (Clean Test-Tag and .vimwiki_tags -2):
let g:vimwiki_tag_format = {}
- unlet g:vimwiki_syntax_variables
+ unlet g:vimwiki_syntaxlocal_vars
call vimwiki#vars#init()
call system("rm $HOME/testmarkdown/Test.md")
call system("rm $HOME/testmarkdown/.vimwiki_tags")
diff --git a/test/vimrc b/test/vimrc
@@ -140,7 +140,7 @@
\ 'g:loaded_vimwiki',
\ 'g:vimwiki_global_vars',
\ 'g:vimwiki_wikilocal_vars',
- \ 'g:vimwiki_syntax_variables',
+ \ 'g:vimwiki_syntaxlocal_vars',
\ 'g:vimwiki_list',
\ ]
if exists(i)
@@ -172,7 +172,7 @@
function! ReloadVars()
" vars#init will not reload syntax varaible if not set
- unlet g:vimwiki_syntax_variables
+ unlet g:vimwiki_syntaxlocal_vars
call vimwiki#vars#init()
endfunction