Add wikilocal option showing description in generated links

This commit is contained in:
Stefan Schuhbäck
2021-04-21 16:16:46 +02:00
committed by Tinmarino
parent 4c7ab73c51
commit f6c419fb87
4 changed files with 73 additions and 6 deletions
+9 -3
View File
@@ -437,12 +437,14 @@ function! vimwiki#base#generate_links(create, ...) abort
function! GeneratorLinks.f() abort
let lines = []
let links = vimwiki#base#get_wikilinks(vimwiki#vars#get_bufferlocal('wiki_nr'), 0, s:pattern)
let wiki_nr = vimwiki#vars#get_bufferlocal('wiki_nr')
let links = vimwiki#base#get_wikilinks(wiki_nr, 0, s:pattern)
call sort(links)
let bullet = repeat(' ', vimwiki#lst#get_list_margin()) . vimwiki#lst#default_symbol().' '
let l:diary_file_paths = vimwiki#diary#get_diary_files()
let use_caption = vimwiki#vars#get_wikilocal('generated_links_caption', wiki_nr)
for link in links
let link_infos = vimwiki#base#resolve_link(link)
if !vimwiki#base#is_diary_file(link_infos.filename, copy(l:diary_file_paths))
@@ -451,14 +453,18 @@ function! vimwiki#base#generate_links(create, ...) abort
let link_caption = vimwiki#base#read_caption(link_infos.filename)
if link_caption ==? '' " default to link if caption not found
let link_caption = link
else
if use_caption
" switch to [[URL|DESCRIPTION]] if caption is not empty
" Link2 is the same for mardown syntax
let link_tpl = vimwiki#vars#get_syntaxlocal('Link2')
endif
endif
" Replace Url, Description
let entry = s:safesubstitute(link_tpl, '__LinkUrl__', link, '')
let entry = s:safesubstitute(entry, '__LinkDescription__', link_caption, '')
" Replace Extension
let wiki_nr = vimwiki#vars#get_bufferlocal('wiki_nr')
let extension = vimwiki#vars#get_wikilocal('ext', wiki_nr)
let entry = substitute(entry, '__FileExtension__', extension, 'g')
+3
View File
@@ -507,6 +507,7 @@ function! s:get_default_wikilocal() abort
\ 'bullet_types': {'type': type([]), 'default': []},
\ 'cycle_bullets': {'type': type(0), 'default': 0},
\ 'html_filename_parameterization': {'type': type(0), 'default': 0, 'min': 0, 'max': 1},
\ 'generated_links_caption': {'type': type(0), 'default': 0 },
\ 'index': {'type': type(''), 'default': 'index', 'min_length': 1},
\ 'links_space_char': {'type': type(''), 'default': ' ', 'min_length': 1},
\ 'list_ignore_newline': {'type': type(0), 'default': 1, 'min': 0, 'max': 1},
@@ -1285,8 +1286,10 @@ function! s:normalize_syntax_settings(syntax) abort
" command generate link form file name (generate_link)
if a:syntax ==# 'markdown'
let syntax_dic.Link1 = syntax_dic.Weblink1Template
let syntax_dic.Link2 = syntax_dic.Weblink1Template
else
let syntax_dic.Link1 = vimwiki#vars#get_global('WikiLinkTemplate1')
let syntax_dic.Link2 = vimwiki#vars#get_global('WikiLinkTemplate2')
endif
endfunction
+15
View File
@@ -2672,6 +2672,18 @@ If set to 1 (true), cycle through |bullet_types| when changing list element
identation
*vimwiki-option-generated_links_caption*
------------------------------------------------------------------------------
Key Default value~
generated_links_caption 0
Default syntax only. If set to 1 (true), use the [[URL|DESCRIPTIOM]] when
calling |:VimwikiGenerateLinks|. DESCRIPTION will be the first header in the
corresbonding file found in the first n lines, where n is set by
|g:vimwiki_max_scan_for_caption| (Default 5). If no caption is found fallback
to [[URL]] only.
*vimwiki-option-listsyms*
------------------------------------------------------------------------------
Key Default value~
@@ -3900,6 +3912,7 @@ Contributors and their Github usernames in roughly chronological order:
- Fergus Collins (@C-Fergus)
- Matthew Toohey (@mtoohey31)
- Brennen Bearnes
- Stefan Schuhbäck (@stefanSchuhbaeck)
==============================================================================
16. Changelog *vimwiki-changelog*
@@ -3911,6 +3924,8 @@ http://code.google.com/p/vimwiki/issues/list. They may be accessible from
https://github.com/vimwiki-backup/vimwiki/issues.
New:~
* Feature: Add option to use link Description in default syntax if
caption is present. |generated_links_caption|
* PR #1106: Fix trailing closing brace and comma typo
* Feature: VimwikiColorize maps in visual and normal mode `<leader>wc`
* Feature: PR #686: add a flag lists_return to disable mappings
+46 -3
View File
@@ -1,6 +1,6 @@
# Automatic link generation
# Related to:
# - wiki file discovery
# - wiki file discovery
# - buffer list insertion (see: vimwiki#base#update_listing_in_buffer)
@@ -9,11 +9,11 @@ Execute (Reset sw to default (due to batch)):
# 1 VimwikiGenerateLinks {{{1
##########################
# Wiki Syntax {{{2
# Wiki Syntax (no caption, default) {{{2
#################
Execute (Log):
Log 'Wiki Syntax'
Log 'Wiki Syntax (no caption, default)'
call ReloadVimwiki()
AssertEqual '-1_margin', vimwiki#vars#get_wikilocal('list_margin') . '_margin'
@@ -52,6 +52,49 @@ Expect (The links with a header (bis)):
Execute (Clean Test.wiki):
call DeleteFile('$HOME/testwiki/Test.wiki')
# Wiki Syntax (with caption) {{{2
#################
Execute (Log):
Log 'Wiki Syntax (with caption)'
let vimwiki_default.generated_links_caption = 1
call ReloadVimwiki()
AssertEqual '-1_margin', vimwiki#vars#get_wikilocal('list_margin') . '_margin'
Given (Void):
Execute (VimwikiGenerateLinks):
edit $HOME/testwiki/Test.wiki
VimwikiGenerateLinks
Expect (The links with a header):
= Generated Links =
- [[buzz_bozz|Buzz Bozz]]
- [[index|Test Wiki]]
- [[link_syntax]]
- [[link_syntax/nested]]
Execute (VimwikiGenerateLinks x 2):
edit $HOME/testwiki/Test.wiki
VimwikiGenerateLinks
call append('$', 'Last Line')
VimwikiGenerateLinks
Expect (The links with a header (bis)):
= Generated Links =
- [[buzz_bozz|Buzz Bozz]]
- [[index|Test Wiki]]
- [[link_syntax]]
- [[link_syntax/nested]]
Last Line
Execute (Clean Test.wiki):
call DeleteFile('$HOME/testwiki/Test.wiki')
# Markdown Syntax {{{2
#################