Refactor: Vars: Make vimwiki_toc_header wiki local
Also: vimwiki_toc_header_level, vimwiki_toc_link_format
This commit is contained in:
parent
5651e744a6
commit
787e95b910
@ -2162,7 +2162,7 @@ endfunction
|
|||||||
" a:create == 0: update if TOC exists
|
" a:create == 0: update if TOC exists
|
||||||
function! vimwiki#base#table_of_contents(create) abort
|
function! vimwiki#base#table_of_contents(create) abort
|
||||||
let headers = s:collect_headers()
|
let headers = s:collect_headers()
|
||||||
let toc_header_text = vimwiki#vars#get_global('toc_header')
|
let toc_header_text = vimwiki#vars#get_wikilocal('toc_header')
|
||||||
|
|
||||||
if !a:create
|
if !a:create
|
||||||
" Do nothing if there is no TOC to update. (This is a small performance optimization -- if
|
" Do nothing if there is no TOC to update. (This is a small performance optimization -- if
|
||||||
@ -2198,7 +2198,7 @@ function! vimwiki#base#table_of_contents(create) abort
|
|||||||
for idx in range(h_level, 5) | let headers_levels[idx] = ['', 0] | endfor
|
for idx in range(h_level, 5) | let headers_levels[idx] = ['', 0] | endfor
|
||||||
|
|
||||||
let h_complete_id = ''
|
let h_complete_id = ''
|
||||||
if vimwiki#vars#get_global('toc_link_format') == 0
|
if vimwiki#vars#get_wikilocal('toc_link_format') == 0
|
||||||
for l in range(h_level-1)
|
for l in range(h_level-1)
|
||||||
if headers_levels[l][0] !=? ''
|
if headers_levels[l][0] !=? ''
|
||||||
let h_complete_id .= headers_levels[l][0].'#'
|
let h_complete_id .= headers_levels[l][0].'#'
|
||||||
@ -2217,7 +2217,7 @@ function! vimwiki#base#table_of_contents(create) abort
|
|||||||
for [lvl, link, desc] in complete_header_infos
|
for [lvl, link, desc] in complete_header_infos
|
||||||
if vimwiki#vars#get_wikilocal('syntax') ==# 'markdown'
|
if vimwiki#vars#get_wikilocal('syntax') ==# 'markdown'
|
||||||
let link_tpl = vimwiki#vars#get_syntaxlocal('Weblink2Template')
|
let link_tpl = vimwiki#vars#get_syntaxlocal('Weblink2Template')
|
||||||
elseif vimwiki#vars#get_global('toc_link_format') == 0
|
elseif vimwiki#vars#get_wikilocal('toc_link_format') == 0
|
||||||
let link_tpl = vimwiki#vars#get_global('WikiLinkTemplate2')
|
let link_tpl = vimwiki#vars#get_global('WikiLinkTemplate2')
|
||||||
else
|
else
|
||||||
let link_tpl = vimwiki#vars#get_global('WikiLinkTemplate1')
|
let link_tpl = vimwiki#vars#get_global('WikiLinkTemplate1')
|
||||||
@ -2238,7 +2238,7 @@ function! vimwiki#base#table_of_contents(create) abort
|
|||||||
\ toc_header_text,
|
\ toc_header_text,
|
||||||
\ links_rx,
|
\ links_rx,
|
||||||
\ 1,
|
\ 1,
|
||||||
\ vimwiki#vars#get_global('toc_header_level'),
|
\ vimwiki#vars#get_wikilocal('toc_header_level'),
|
||||||
\ a:create)
|
\ a:create)
|
||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
|
@ -1116,7 +1116,7 @@ function! s:process_tag_h(line, id) abort
|
|||||||
let h_id = s:escape_html_attribute(h_text)
|
let h_id = s:escape_html_attribute(h_text)
|
||||||
let centered = (a:line =~# '^\s')
|
let centered = (a:line =~# '^\s')
|
||||||
|
|
||||||
if h_text !=# vimwiki#vars#get_global('toc_header')
|
if h_text !=# vimwiki#vars#get_wikilocal('toc_header')
|
||||||
|
|
||||||
let a:id[h_level-1] = [h_text, a:id[h_level-1][1]+1]
|
let a:id[h_level-1] = [h_text, a:id[h_level-1][1]+1]
|
||||||
|
|
||||||
|
@ -207,9 +207,6 @@ function! s:read_global_settings_from_user() abort
|
|||||||
\ 'table_mappings': {'type': type(0), 'default': 1, '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': {'type': type(''), 'default': 'Generated Tags', 'min_length': 1},
|
||||||
\ 'tags_header_level': {'type': type(0), 'default': 1, 'min': 1, 'max': 5},
|
\ 'tags_header_level': {'type': type(0), 'default': 1, 'min': 1, 'max': 5},
|
||||||
\ 'toc_header': {'type': type(''), 'default': 'Contents', 'min_length': 1},
|
|
||||||
\ 'toc_header_level': {'type': type(0), 'default': 1, 'min': 1, 'max': 6},
|
|
||||||
\ 'toc_link_format': {'type': type(0), 'default': 0, 'min': 0, 'max': 1},
|
|
||||||
\ 'url_maxsave': {'type': type(0), 'default': 15, 'min': 0},
|
\ 'url_maxsave': {'type': type(0), 'default': 15, 'min': 0},
|
||||||
\ 'use_calendar': {'type': type(0), 'default': 1, 'min': 0, 'max': 1},
|
\ 'use_calendar': {'type': type(0), 'default': 1, 'min': 0, 'max': 1},
|
||||||
\ 'use_mouse': {'type': type(0), 'default': 0, 'min': 0, 'max': 1},
|
\ 'use_mouse': {'type': type(0), 'default': 0, 'min': 0, 'max': 1},
|
||||||
@ -395,6 +392,9 @@ function! s:populate_wikilocal_options() abort
|
|||||||
\ 'template_default': {'type': type(''), 'default': 'default', 'min_length': 1},
|
\ 'template_default': {'type': type(''), 'default': 'default', 'min_length': 1},
|
||||||
\ 'template_ext': {'type': type(''), 'default': '.tpl'},
|
\ 'template_ext': {'type': type(''), 'default': '.tpl'},
|
||||||
\ 'template_path': {'type': type(''), 'default': $HOME . '/vimwiki/templates/'},
|
\ 'template_path': {'type': type(''), 'default': $HOME . '/vimwiki/templates/'},
|
||||||
|
\ 'toc_header': {'type': type(''), 'default': 'Contents', 'min_length': 1},
|
||||||
|
\ 'toc_header_level': {'type': type(0), 'default': 1, 'min': 1, 'max': 6},
|
||||||
|
\ 'toc_link_format': {'type': type(0), 'default': 0, 'min': 0, 'max': 1},
|
||||||
\ }
|
\ }
|
||||||
|
|
||||||
" Fill default setting <- user or plugin values
|
" Fill default setting <- user or plugin values
|
||||||
@ -1076,7 +1076,7 @@ endfunction
|
|||||||
|
|
||||||
|
|
||||||
" Return: wiki local named varaible
|
" Return: wiki local named varaible
|
||||||
" Param: 1: variable name (alias key, <string>)
|
" Param: (1): variable name (alias key, <string>)
|
||||||
" Param: (2): wiki number (<int>). When absent, the wiki of the currently active buffer is
|
" Param: (2): wiki number (<int>). When absent, the wiki of the currently active buffer is
|
||||||
" used
|
" used
|
||||||
function! vimwiki#vars#get_wikilocal(key, ...) abort
|
function! vimwiki#vars#get_wikilocal(key, ...) abort
|
||||||
@ -1095,11 +1095,18 @@ endfunction
|
|||||||
|
|
||||||
|
|
||||||
" Set local variable
|
" Set local variable
|
||||||
function! vimwiki#vars#set_wikilocal(key, value, wiki_nr) abort
|
" Param: (2): wiki number (<int>). When absent, the wiki of the currently active buffer is
|
||||||
if a:wiki_nr == len(g:vimwiki_wikilocal_vars) - 1
|
" used
|
||||||
|
function! vimwiki#vars#set_wikilocal(key, value, ...) abort
|
||||||
|
if a:0
|
||||||
|
let wiki_nr = a:1
|
||||||
|
else
|
||||||
|
let wiki_nr = vimwiki#vars#get_bufferlocal('wiki_nr')
|
||||||
|
endif
|
||||||
|
if wiki_nr == len(g:vimwiki_wikilocal_vars) - 1
|
||||||
call insert(g:vimwiki_wikilocal_vars, {}, -1)
|
call insert(g:vimwiki_wikilocal_vars, {}, -1)
|
||||||
endif
|
endif
|
||||||
let g:vimwiki_wikilocal_vars[a:wiki_nr][a:key] = a:value
|
let g:vimwiki_wikilocal_vars[wiki_nr][a:key] = a:value
|
||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
|
|
||||||
|
@ -1,7 +1,11 @@
|
|||||||
# VimwikiTOC
|
# VimwikiTOC
|
||||||
|
#
|
||||||
|
# TODO (10min) test if g:vimwiki_to_header well readen
|
||||||
|
# TODO (10min) test vimviki_toc_link_format
|
||||||
|
# TODO (1h) test if really wiki dependant (for 2 diffrent wikis)
|
||||||
|
|
||||||
Execute (Reset TOC header to default):
|
Execute (Reset TOC header to default):
|
||||||
let g:vimwiki_global_vars['toc_header'] = "Contents"
|
call vimwiki#vars#set_wikilocal('toc_header', 'Contents')
|
||||||
|
|
||||||
Given vimwiki (Headings):
|
Given vimwiki (Headings):
|
||||||
# Header 1
|
# Header 1
|
||||||
@ -93,7 +97,7 @@ Expect (Brand new TOC):
|
|||||||
|
|
||||||
|
|
||||||
Execute (Let toc_header = Sommaire && VimwikiTOC):
|
Execute (Let toc_header = Sommaire && VimwikiTOC):
|
||||||
let g:vimwiki_global_vars['toc_header'] = "Sommaire"
|
call vimwiki#vars#set_wikilocal('toc_header', 'Sommaire')
|
||||||
VimwikiTOC
|
VimwikiTOC
|
||||||
|
|
||||||
Expect (Append a Sommaire && Leave Contents alone):
|
Expect (Append a Sommaire && Leave Contents alone):
|
||||||
@ -145,10 +149,10 @@ Expect (Brand new TOC with sommaire):
|
|||||||
|
|
||||||
|
|
||||||
Execute (call vimwiki#vars#set_global('toc_header_level', 6):
|
Execute (call vimwiki#vars#set_global('toc_header_level', 6):
|
||||||
call vimwiki#vars#set_global('toc_header_level', 6)
|
call vimwiki#vars#set_wikilocal('toc_header_level', 6)
|
||||||
VimwikiTOC
|
VimwikiTOC
|
||||||
# Reset default
|
# Reset default
|
||||||
call vimwiki#vars#set_global('toc_header_level', 1)
|
call vimwiki#vars#set_wikilocal('toc_header_level', 1)
|
||||||
|
|
||||||
Expect (Content prepended):
|
Expect (Content prepended):
|
||||||
###### Sommaire
|
###### Sommaire
|
||||||
|
Loading…
Reference in New Issue
Block a user