Fix and simplify the collection of anchors

This commit is contained in:
EinfachToll 2014-11-11 13:43:44 +01:00
parent 3906294180
commit d8853c5a34

View File

@ -695,6 +695,7 @@ function! vimwiki#base#get_anchors(filename, syntax) "{{{
let anchor_level = ['', '', '', '', '', '', ''] let anchor_level = ['', '', '', '', '', '', '']
let anchors = [] let anchors = []
let current_complete_anchor = ''
for line in readfile(a:filename) for line in readfile(a:filename)
" collect headers " collect headers
@ -702,40 +703,36 @@ function! vimwiki#base#get_anchors(filename, syntax) "{{{
if !empty(h_match) if !empty(h_match)
let header = vimwiki#u#trim(h_match[2]) let header = vimwiki#u#trim(h_match[2])
let level = len(h_match[1]) let level = len(h_match[1])
call add(anchors, header)
let anchor_level[level-1] = header let anchor_level[level-1] = header
for l in range(level, 6) for l in range(level, 6)
let anchor_level[l] = '' let anchor_level[l] = ''
endfor endfor
call add(anchors, header) if level == 1
let complete_anchor = '' let current_complete_anchor = header
for l in range(level-1) else
if anchor_level[l] != '' let current_complete_anchor = ''
let complete_anchor .= anchor_level[l].'#' for l in range(level-1)
endif if anchor_level[l] != ''
endfor let current_complete_anchor .= anchor_level[l].'#'
let complete_anchor .= header endif
call add(anchors, complete_anchor) endfor
let current_complete_anchor .= header
call add(anchors, current_complete_anchor)
endif
endif endif
" collect bold text (there can be several in one line) " collect bold text (there can be several in one line)
let bold_count = 0 let bold_count = 0
let bold_end = 0
while 1 while 1
let bold_text = matchstr(line, rxbold, bold_end, bold_count) let bold_text = matchstr(line, rxbold, 0, bold_count)
let bold_end = matchend(line, rxbold, bold_end, bold_count) + 1 if bold_text == ''
if bold_text == ""
break break
endif endif
call add(anchors, bold_text) call add(anchors, bold_text)
let anchor_level[6] = bold_text if current_complete_anchor != ''
let complete_anchor = '' call add(anchors, current_complete_anchor.'#'.bold_text)
for l in range(6) endif
if anchor_level[l] != ''
let complete_anchor .= anchor_level[l].'#'
endif
endfor
let complete_anchor .= bold_text
call add(anchors, complete_anchor)
let bold_count += 1 let bold_count += 1
endwhile endwhile