diff --git a/autoload/vimwiki/base.vim b/autoload/vimwiki/base.vim index 8e2ae71..1917718 100644 --- 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 index f9b9443..9061e1d 100644 --- 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 index abd295e..b7e350c 100644 --- a/autoload/vimwiki/u.vim +++ b/autoload/vimwiki/u.vim @@ -5,17 +5,22 @@ " Echo: msg " :param: (1) highlighting group -" :param: (2) echo suffix (ex: 'n', 'm' +" :param: (2) echo suffix (ex: 'n', 'm') +" :param: (3) 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 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 index 06373bb..4366c85 100644 --- 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 : varaible name +" Param: 2: vimwiki_key : user value +" Param: 3: value_infod : type and default value +" Param: 4: coming from a global variable +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': '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 +" 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_