Skip to content

Commit

Permalink
feat: add command and map for ExtractHeader
Browse files Browse the repository at this point in the history
refer: #149
  • Loading branch information
lervag committed Jun 4, 2021
1 parent ad4d5a8 commit 203a98e
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 0 deletions.
3 changes: 3 additions & 0 deletions autoload/wiki/buffer.vim
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ function! s:init_buffer_commands() abort " {{{1
command! -buffer WikiJournalIndex call wiki#journal#make_index()
command! -buffer WikiLinkNext call wiki#nav#next_link()
command! -buffer WikiLinkShow call wiki#link#show()
command! -buffer WikiLinkExtractHeader call wiki#link#set_text_from_header()
command! -buffer WikiLinkFollow call wiki#link#follow()
command! -buffer WikiLinkFollowSplit call wiki#link#follow('vsplit')
command! -buffer WikiLinkPrev call wiki#nav#prev_link()
Expand Down Expand Up @@ -89,6 +90,7 @@ function! s:init_buffer_mappings() abort " {{{1
nnoremap <silent><buffer> <plug>(wiki-journal-index) :WikiJournalIndex<cr>
nnoremap <silent><buffer> <plug>(wiki-link-next) :WikiLinkNext<cr>
nnoremap <silent><buffer> <plug>(wiki-link-show) :WikiLinkShow<cr>
nnoremap <silent><buffer> <plug>(wiki-link-extract-header) :WikiLinkExtractHeader<cr>
nnoremap <silent><buffer> <plug>(wiki-link-follow) :WikiLinkFollow<cr>
nnoremap <silent><buffer> <plug>(wiki-link-follow-split) :WikiLinkFollowSplit<cr>
nnoremap <silent><buffer> <plug>(wiki-link-prev) :WikiLinkPrev<cr>
Expand Down Expand Up @@ -150,6 +152,7 @@ function! s:init_buffer_mappings() abort " {{{1
\ '<plug>(wiki-link-next)': '<tab>',
\ '<plug>(wiki-link-prev)': '<s-tab>',
\ '<plug>(wiki-link-show)': '<leader>wll',
\ '<plug>(wiki-link-extract-header)': '<leader>wlh',
\ '<plug>(wiki-link-follow)': '<cr>',
\ '<plug>(wiki-link-follow-split)': '<c-w><cr>',
\ '<plug>(wiki-link-return)': '<bs>',
Expand Down
1 change: 1 addition & 0 deletions autoload/wiki/link.vim
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@ function! wiki#link#set_text_from_header() abort "{{{1
if l:link.scheme !=# 'wiki' | return | endif

let l:title = wiki#page#get_title(l:link)
if empty(l:title) | return | endif

try
let l:new = wiki#link#{l:link.type}#template(l:link.url_raw, l:title)
Expand Down
1 change: 1 addition & 0 deletions autoload/wiki/page.vim
Original file line number Diff line number Diff line change
Expand Up @@ -335,6 +335,7 @@ endfunction
" }}}1
function! wiki#page#get_title(...) abort " {{{1
let l:filename = s:get_anchors_filename(a:000)
if !filereadable(l:filename) | return '' | endif

let preblock = 0
for l:line in readfile(l:filename)
Expand Down
5 changes: 5 additions & 0 deletions doc/wiki.txt
Original file line number Diff line number Diff line change
Expand Up @@ -672,6 +672,10 @@ the commands are also available as mappings of the form `<plug>(wiki-[name])`.
*WikiLinkShow*
Show some info on link under cursor.

*<plug>(wiki-link-extract-header)*
*WikiLinkExtractHeader*
Set link title from the first header of the target file.

*<plug>(wiki-list-toggle)*
*WikiListToggle*
Toggle a list item. Map works in both normal and insert mode.
Expand Down Expand Up @@ -894,6 +898,7 @@ information about the different modes.
`n` <leader>wp |<plug>(wiki-export)|
`x` <leader>wp |<plug>(wiki-export)|
`n` <leader>wll |<plug>(wiki-link-show)|
`n` <leader>wlh |<plug>(wiki-link-extract-header)|
`n` <leader>wlk |<plug>(wiki-list-moveup)|
`n` <leader>wlj |<plug>(wiki-list-movedown)|
`n` <leader>wlu |<plug>(wiki-list-uniq)|
Expand Down

0 comments on commit 203a98e

Please sign in to comment.