lib/soywiki.vim in soywiki-0.2.1 vs lib/soywiki.vim in soywiki-0.2.2
- old
+ new
@@ -110,32 +110,31 @@
" strip off non-letters at the end and beginning (e.g., a comma)
if ! s:has_namespace(link)
let link = s:infer_namespace(link)
endif
if match(link, s:wiki_link_pattern) == -1
- if match(link, s:http_link_pattern) != -1
- call s:open_href()
- endif
return ""
else
return link
end
endfunc
-" follows a camel case link to a new page
-func! s:follow_link(split)
- let link = s:link_under_cursor()
- if link == ""
- let link = s:find_next_wiki_link(0)
- if link == ""
- return ""
- endif
- endif
- call s:load_page(link, a:split)
+func! s:find_next_wiki_link(backward)
+ let n = 0
+ " don't wrap
+ let result = search(s:wiki_link_pattern, 'W' . (a:backward == 1 ? 'b' : ''))
+ if (result == 0)
+ return ""
+ end
+ return s:link_under_cursor()
endfunc
func! s:follow_link_under_cursor(split)
+ if match(expand("<cWORD>>"), s:http_link_pattern) != -1
+ call s:open_href_under_cursor()
+ return
+ endif
let link = s:link_under_cursor()
if link == ""
echom link . " is not a wiki link"
return ""
elseif line('.') == 1
@@ -148,18 +147,22 @@
else
call s:load_page(link, a:split)
endif
endfunc
-func! s:find_next_wiki_link(backward)
- let n = 0
- " don't wrap
- let result = search(s:wiki_link_pattern, 'W' . (a:backward == 1 ? 'b' : ''))
- if (result == 0)
- return ""
- end
- return s:link_under_cursor()
+
+" If no link under cursor, tries to find the next one
+func! s:fuzzy_follow_link(split)
+ let link = s:link_under_cursor()
+ if link == ""
+ let link = s:find_next_wiki_link(0)
+ if link == ""
+ echom "No links found"
+ return
+ endif
+ endif
+ call s:load_page(link, a:split)
endfunc
" --------------------------------------------------------------------------------
" LOAD PAGE
@@ -525,17 +528,24 @@
silent! normal 1G
redraw
echom "Expanded " . (a:seamless == 0 ? 'seamfully' : 'seamlessly') . "."
endfunc
"------------------------------------------------------------------------
-func! s:open_href()
- let line = search(s:http_link_pattern, 'cw')
+func! s:open_href_under_cursor()
let href = expand("<cWORD>")
let command = g:SoyWiki#browser_command . " '" . href . "' "
call system(command)
echom command
endfunc
+
+func! s:find_next_href_and_open()
+ let res = search(s:http_link_pattern, 'cw')
+ if res != 0
+ call s:open_href_under_cursor()
+ endif
+endfunc
+
" --------------------------------------------------------------------------------
" HELP
func! s:show_help()
let command = g:SoyWiki#browser_command . ' ' . shellescape('http://danielchoi.com/software/soywiki.html')
call system(command)
@@ -543,11 +553,11 @@
"------------------------------------------------------------------------
func! s:global_mappings()
noremap <leader>m :call <SID>list_pages()<CR>
noremap <leader>M :call <SID>list_pages_linking_in()<CR>
- noremap <silent> <leader>o :call <SID>open_href()<cr>
+ noremap <silent> <leader>o :call <SID>find_next_href_and_open()<cr>
nnoremap <silent> q :close<cr>
" reflow text
nnoremap \ gwap
" insert a line
@@ -573,10 +583,10 @@
if (s:is_wiki_page())
set textwidth=72
nnoremap <buffer> <cr> :call <SID>follow_link_under_cursor(0)<cr>
nnoremap <buffer> <c-l> :call <SID>follow_link_under_cursor(2)<cr>
nnoremap <buffer> <c-h> :call <SID>follow_link_under_cursor(1)<cr>
- noremap <buffer> <leader>f :call <SID>follow_link(0)<CR>
+ noremap <buffer> <leader>f :call <SID>fuzzy_follow_link(0)<CR>
noremap <buffer> <c-j> :call <SID>find_next_wiki_link(0)<CR>
noremap <buffer> <c-k> :call <SID>find_next_wiki_link(1)<CR>
command! -bar -nargs=1 -range -complete=file SWCreate :call <SID>create_page(<f-args>)
command! -bar -nargs=1 -range -complete=file SWRenameTo :call <SID>rename_page(<f-args>)