Restrict the distance of tag to header to two lines

Suffices, I think.
Also, clean the code a bit and correct the help file.

Ref #85
This commit is contained in:
EinfachToll 2015-11-21 21:20:33 +01:00
parent debd308eea
commit b794a3bd3b
2 changed files with 11 additions and 9 deletions

View File

@ -62,7 +62,6 @@ endfunction " }}}
function! s:scan_tags(lines, page_name) "{{{ function! s:scan_tags(lines, page_name) "{{{
let entries = [] let entries = []
let page_name = a:page_name
" Code wireframe to scan for headers -- borrowed from " Code wireframe to scan for headers -- borrowed from
" vimwiki#base#get_anchors(), with minor modifications. " vimwiki#base#get_anchors(), with minor modifications.
@ -73,7 +72,7 @@ function! s:scan_tags(lines, page_name) "{{{
let anchor_level = ['', '', '', '', '', '', ''] let anchor_level = ['', '', '', '', '', '', '']
let current_complete_anchor = '' let current_complete_anchor = ''
let PROXIMITY_LINES_NR = 5 let PROXIMITY_LINES_NR = 2
let header_line_nr = - (2 * PROXIMITY_LINES_NR) let header_line_nr = - (2 * PROXIMITY_LINES_NR)
for line_nr in range(1, len(a:lines)) for line_nr in range(1, len(a:lines))
@ -121,11 +120,13 @@ function! s:scan_tags(lines, page_name) "{{{
let entry.lineno = line_nr let entry.lineno = line_nr
if line_nr <= PROXIMITY_LINES_NR && header_line_nr < 0 if line_nr <= PROXIMITY_LINES_NR && header_line_nr < 0
" Tag appeared at the top of the file " Tag appeared at the top of the file
let entry.link = page_name let entry.link = a:page_name
elseif line_nr <= (header_line_nr + PROXIMITY_LINES_NR) elseif line_nr <= (header_line_nr + PROXIMITY_LINES_NR)
let entry.link = page_name . '#' . current_complete_anchor " Tag appeared right below a header
let entry.link = a:page_name . '#' . current_complete_anchor
else else
let entry.link = page_name . '#' . tag " Tag stands on its own
let entry.link = a:page_name . '#' . tag
endif endif
call add(entries, entry) call add(entries, entry)
endfor endfor

View File

@ -1227,10 +1227,11 @@ A tag is a sequence of non-space characters between two colons: >
It is allowed to concatenate multiple tags in one line: > It is allowed to concatenate multiple tags in one line: >
:tag-one:tag-two: :tag-one:tag-two:
< <
If placed under a header, within 5 lines below it, the header is then "tagged" If placed in the first two lines of a file, the whole file is tagged. If
with this tag, and tag search commands will jump to this specific header. placed under a header, within the 2 lines below it, the header is then tagged
Otherwise the entire page is tagged, and search commands will jump with this tag, and the tag search commands will jump to this specific header.
accordingly. Otherwise, the tag stands of its own and the search command jumps directly to
it.
Typing tags can be simplified by using Vim's omni completion (see Typing tags can be simplified by using Vim's omni completion (see
|compl-omni|) like so: > |compl-omni|) like so: >