|
@ -1,3 +1,4 @@ |
|
|
|
|
|
" helper {{{ |
|
|
function! notecrate#get_visual_selection() " {{{ |
|
|
function! notecrate#get_visual_selection() " {{{ |
|
|
let [line_start, column_start] = getpos("'<")[1:2] |
|
|
let [line_start, column_start] = getpos("'<")[1:2] |
|
|
let [line_end, column_end] = getpos("'>")[1:2] |
|
|
let [line_end, column_end] = getpos("'>")[1:2] |
|
@ -38,130 +39,6 @@ function! notecrate#generate_filename() " {{{ |
|
|
return strftime("%Y%m%d%H%M%S") . ".md" |
|
|
return strftime("%Y%m%d%H%M%S") . ".md" |
|
|
endfunction |
|
|
endfunction |
|
|
|
|
|
|
|
|
" }}} |
|
|
|
|
|
function! notecrate#apply_template(title) " {{{ |
|
|
|
|
|
let l:template = "\n# " . a:title . "\n\n\n\n\n---\n\n" |
|
|
|
|
|
call setreg("l", l:template) |
|
|
|
|
|
silent execute 'normal "lP4j' |
|
|
|
|
|
call notecrate#update_backlinks() |
|
|
|
|
|
endfunction |
|
|
|
|
|
|
|
|
|
|
|
" }}} |
|
|
|
|
|
function! notecrate#convert() " {{{ |
|
|
|
|
|
execute "normal! :w!\<CR>:!pushd " . b:notecrate_dir . "; bash convert.sh;\<CR>" |
|
|
|
|
|
endfunction |
|
|
|
|
|
|
|
|
|
|
|
" }}} |
|
|
|
|
|
function! notecrate#save() " {{{ |
|
|
|
|
|
execute "normal! :!cd " . b:notecrate_dir . "; git add -A; git commit -m \"autocommit\"; git push;\<CR>" |
|
|
|
|
|
endfunction |
|
|
|
|
|
|
|
|
|
|
|
" }}} |
|
|
|
|
|
function! notecrate#todo_filter_view() " {{{ |
|
|
|
|
|
execute "normal! :!cd " . b:notecrate_dir . "; git add -A; git commit -m \"autocommit\"; git push;\<CR>" |
|
|
|
|
|
endfunction |
|
|
|
|
|
|
|
|
|
|
|
" }}} |
|
|
|
|
|
function! notecrate#follow_link() " {{{ |
|
|
|
|
|
let l:link = notecrate#get_link_at_cursor()" |
|
|
|
|
|
if type(l:link) == 4 |
|
|
|
|
|
if l:link['dest'] =~ '^.*\.md$' |
|
|
|
|
|
call notecrate#open_note(l:link['dest']) |
|
|
|
|
|
else |
|
|
|
|
|
silent execute "open " . l:link['dest'] |
|
|
|
|
|
endif |
|
|
|
|
|
endif |
|
|
|
|
|
endfunction |
|
|
|
|
|
|
|
|
|
|
|
" }}} |
|
|
|
|
|
function! notecrate#new_note(title, filename) " {{{ |
|
|
|
|
|
let l:filename = expand('%:t') |
|
|
|
|
|
let l:notecrate_dir = b:notecrate_dir |
|
|
|
|
|
let l:notecrate_history = b:notecrate_history |
|
|
|
|
|
while !isdirectory(expand(b:notecrate_dir)) |
|
|
|
|
|
let choice = confirm('', b:notecrate_dir . " does not exist. Create? &Yes\n&No\n") |
|
|
|
|
|
if choice == 1 |
|
|
|
|
|
silent execute "!mkdir " . b:notecrate_dir |
|
|
|
|
|
else |
|
|
|
|
|
return 0 |
|
|
|
|
|
endif |
|
|
|
|
|
endwhile |
|
|
|
|
|
let l:path = b:notecrate_dir . "/" . a:filename |
|
|
|
|
|
call add(b:notecrate_history, l:filename) |
|
|
|
|
|
silent execute "normal! :w\<CR>:e " . l:path . "\<CR>" |
|
|
|
|
|
let b:notecrate_dir = l:notecrate_dir |
|
|
|
|
|
let b:notecrate_history = l:notecrate_history |
|
|
|
|
|
call notecrate#apply_template(a:title) |
|
|
|
|
|
call notecrate#update_backlinks() |
|
|
|
|
|
write |
|
|
|
|
|
endfunction |
|
|
|
|
|
|
|
|
|
|
|
" }}} |
|
|
|
|
|
function! notecrate#new_note_from_prompt() " {{{ |
|
|
|
|
|
let l:title = input("Name of new note? ") |
|
|
|
|
|
let l:filename = notecrate#generate_filename() |
|
|
|
|
|
call notecrate#new_note(l:title, l:filename) |
|
|
|
|
|
endfunction |
|
|
|
|
|
|
|
|
|
|
|
" }}} |
|
|
|
|
|
function! notecrate#new_note_from_selection() " {{{ |
|
|
|
|
|
let l:title = notecrate#get_visual_selection() |
|
|
|
|
|
let l:filename = notecrate#generate_filename() |
|
|
|
|
|
silent execute "normal! :'<,'>s/\\%V.*\\%V/[" . l:title . "](" . l:filename . ")/e\<CR>" |
|
|
|
|
|
call notecrate#new_note(l:title, l:filename) |
|
|
|
|
|
endfunction |
|
|
|
|
|
|
|
|
|
|
|
" }}} |
|
|
|
|
|
function! notecrate#open_note(filename) " {{{ |
|
|
|
|
|
let l:filename = expand('%:t') |
|
|
|
|
|
let l:notecrate_dir = b:notecrate_dir |
|
|
|
|
|
let l:notecrate_history = b:notecrate_history |
|
|
|
|
|
let l:path = b:notecrate_dir . "/" . a:filename |
|
|
|
|
|
let l:reg = getreg('') |
|
|
|
|
|
if !filereadable(expand(l:path)) |
|
|
|
|
|
echo "Note does't exist!" |
|
|
|
|
|
return |
|
|
|
|
|
endif |
|
|
|
|
|
call add(b:notecrate_history, l:filename) |
|
|
|
|
|
silent execute "e " . l:path |
|
|
|
|
|
let b:notecrate_dir = l:notecrate_dir |
|
|
|
|
|
let b:notecrate_history = l:notecrate_history |
|
|
|
|
|
call notecrate#update_backlinks() |
|
|
|
|
|
silent execute "normal! /^#\<CR>" |
|
|
|
|
|
call setreg('', l:reg) |
|
|
|
|
|
endfunction |
|
|
|
|
|
|
|
|
|
|
|
" }}} |
|
|
|
|
|
function! notecrate#open_index() " {{{ |
|
|
|
|
|
while !isdirectory(expand(b:notecrate_dir)) |
|
|
|
|
|
let choice = confirm('', b:notecrate_dir . " does not exist. Create? &Yes\n&No\n") |
|
|
|
|
|
if choice == 1 |
|
|
|
|
|
silent execute "!mkdir " . b:notecrate_dir |
|
|
|
|
|
else |
|
|
|
|
|
return 0 |
|
|
|
|
|
endif |
|
|
|
|
|
endwhile |
|
|
|
|
|
let l:filename = "index.md" |
|
|
|
|
|
let l:path = b:notecrate_dir . "/" . l:filename |
|
|
|
|
|
if !filereadable(expand(l:path)) |
|
|
|
|
|
echo "Note does't exist!" |
|
|
|
|
|
return |
|
|
|
|
|
endif |
|
|
|
|
|
silent execute "e " . l:path |
|
|
|
|
|
call notecrate#update_backlinks() |
|
|
|
|
|
silent execute "normal! /^#\<CR>" |
|
|
|
|
|
endfunction |
|
|
|
|
|
|
|
|
|
|
|
" }}} |
|
|
|
|
|
function! notecrate#open_previous() " {{{ |
|
|
|
|
|
if len(b:notecrate_history) == 0 |
|
|
|
|
|
return |
|
|
|
|
|
endif |
|
|
|
|
|
let l:filename = remove(b:notecrate_history, -1) |
|
|
|
|
|
call notecrate#open_note(l:filename) |
|
|
|
|
|
call remove(b:notecrate_history, -1) |
|
|
|
|
|
endfunction |
|
|
|
|
|
|
|
|
|
|
|
" }}} |
|
|
" }}} |
|
|
function! notecrate#get_title(filename) " {{{ |
|
|
function! notecrate#get_title(filename) " {{{ |
|
|
let l:regex = '^# \(\S.*\)$' |
|
|
let l:regex = '^# \(\S.*\)$' |
|
@ -179,48 +56,6 @@ function! notecrate#get_id(filename) " {{{ |
|
|
return = matchstr(a:filename, '^.*\(\.md$\)\@=') |
|
|
return = matchstr(a:filename, '^.*\(\.md$\)\@=') |
|
|
endfunction |
|
|
endfunction |
|
|
|
|
|
|
|
|
" }}} |
|
|
|
|
|
function! notecrate#fzf_sink(sink_function) " {{{ |
|
|
|
|
|
" let l:additional_options = get(a:, 1, {}) |
|
|
|
|
|
let l:preview_options = { |
|
|
|
|
|
\ 'sink' : function(a:sink_function), |
|
|
|
|
|
\ 'down' : '~40%', |
|
|
|
|
|
\ 'dir' : b:notecrate_dir, |
|
|
|
|
|
\ 'options' : ['--exact', '--tiebreak=end'] |
|
|
|
|
|
\ } |
|
|
|
|
|
" call fzf#vim#ag("^(?=.)", fzf#vim#with_preview(l:preview_options)) |
|
|
|
|
|
call fzf#vim#ag("^# ", fzf#vim#with_preview(l:preview_options)) |
|
|
|
|
|
endfunction |
|
|
|
|
|
|
|
|
|
|
|
" }}} |
|
|
|
|
|
function! notecrate#search_open() " {{{ |
|
|
|
|
|
call notecrate#fzf_sink('notecrate#open_from_fzf') |
|
|
|
|
|
endfunction |
|
|
|
|
|
function! notecrate#open_from_fzf(line) |
|
|
|
|
|
let filename = substitute(a:line, ":[0-9]\*:[0-9]\*:.\*$", "", "") |
|
|
|
|
|
call notecrate#open_note(filename) |
|
|
|
|
|
endfunction |
|
|
|
|
|
|
|
|
|
|
|
" }}} |
|
|
|
|
|
function! notecrate#search_insert_link() " {{{ |
|
|
|
|
|
call notecrate#fzf_sink('notecrate#insert_link_from_fzf') |
|
|
|
|
|
endfunction |
|
|
|
|
|
function! notecrate#insert_link_from_fzf(line) |
|
|
|
|
|
let l:filename = substitute(a:line, ":[0-9]\*:[0-9]\*:.\*$", "", "") |
|
|
|
|
|
let l:title = notecrate#get_title(filename) |
|
|
|
|
|
execute "normal! a[" . l:title . "](" . l:filename . ")\<Esc>" |
|
|
|
|
|
endfunction |
|
|
|
|
|
|
|
|
|
|
|
" }}} |
|
|
|
|
|
function! notecrate#search_insert_link_selection() " {{{ |
|
|
|
|
|
call notecrate#fzf_sink('notecrate#insert_link_from_fzf_selection') |
|
|
|
|
|
endfunction |
|
|
|
|
|
function! notecrate#insert_link_from_fzf_selection(line) |
|
|
|
|
|
let l:filename = substitute(a:line, ":[0-9]\*:[0-9]\*:.\*$", "", "") |
|
|
|
|
|
let l:title = notecrate#get_visual_selection() |
|
|
|
|
|
silent execute "normal! :'<,'>s/\\%V.*\\%V/[" . l:title . "](" . l:filename . ")/e\<CR>" |
|
|
|
|
|
endfunction |
|
|
|
|
|
|
|
|
|
|
|
" }}} |
|
|
" }}} |
|
|
function! notecrate#grep(pattern) " {{{ |
|
|
function! notecrate#grep(pattern) " {{{ |
|
|
echom b:notecrate_dir |
|
|
echom b:notecrate_dir |
|
@ -251,43 +86,22 @@ function! notecrate#grep_links(pattern) " {{{ |
|
|
endfunction |
|
|
endfunction |
|
|
|
|
|
|
|
|
" }}} |
|
|
" }}} |
|
|
function! notecrate#update_backlinks() " {{{ |
|
|
function! notecrate#fzf_sink(sink_function) " {{{ |
|
|
let l:filename = expand('%:t') |
|
|
" let l:additional_options = get(a:, 1, {}) |
|
|
if l:filename == "index.md" |
|
|
let l:preview_options = { |
|
|
return |
|
|
\ 'sink' : function(a:sink_function), |
|
|
endif |
|
|
\ 'down' : '~40%', |
|
|
let l:pattern = '\[[^\]]*\](' . l:filename . ')\(\(.*\n\)*---\)\@=' |
|
|
\ 'dir' : b:notecrate_dir, |
|
|
let l:links = notecrate#grep_links(l:pattern) |
|
|
\ 'options' : ['--exact', '--tiebreak=end'] |
|
|
let l:backlinks = "---\n\n" |
|
|
\ } |
|
|
if len(l:links) == 0 |
|
|
" call fzf#vim#ag("^(?=.)", fzf#vim#with_preview(l:preview_options)) |
|
|
let l:backlinks = l:backlinks . "* [Index](index.md)" |
|
|
call fzf#vim#ag("^# ", fzf#vim#with_preview(l:preview_options)) |
|
|
else |
|
|
|
|
|
let l:backlinks = l:backlinks . join(uniq(l:links), "\n") . "\n\n* [Index](index.md)" |
|
|
|
|
|
endif |
|
|
|
|
|
call setreg("l", l:backlinks) |
|
|
|
|
|
silent execute "normal! /^---\<CR>vG$\"lp" |
|
|
|
|
|
silent execute "normal! gg/^# \<CR>jj" |
|
|
|
|
|
endfunction |
|
|
endfunction |
|
|
|
|
|
|
|
|
" }}} |
|
|
" }}} |
|
|
function! notecrate#delete_links(filename) " {{{ |
|
|
|
|
|
execute "!" . g:gsed_command . " -i 's/\\[\\([^]]*\\)\\](" . a:filename . ")/\\1/g' " . b:notecrate_dir . "/*md" |
|
|
|
|
|
endfunction |
|
|
|
|
|
|
|
|
|
|
|
" }}} |
|
|
|
|
|
function! notecrate#delete_note() " {{{ |
|
|
|
|
|
let l:filename = expand('%:t') |
|
|
|
|
|
let l:path = b:notecrate_dir . "/" . l:filename |
|
|
|
|
|
let choice = confirm('', "Delete " . l:filename . "? &Yes\n&No\n") |
|
|
|
|
|
if choice == 1 |
|
|
|
|
|
call delete(l:path) |
|
|
|
|
|
call notecrate#delete_links(l:filename) |
|
|
|
|
|
silent execute "!rm " l:path |
|
|
|
|
|
silent execute "normal :bp!\<CR>" |
|
|
|
|
|
endif |
|
|
|
|
|
endfunction |
|
|
|
|
|
|
|
|
|
|
|
" }}} |
|
|
" }}} |
|
|
|
|
|
" folding {{{ |
|
|
function! notecrate#indent_level(lnum) " {{{ |
|
|
function! notecrate#indent_level(lnum) " {{{ |
|
|
return indent(a:lnum) / &shiftwidth |
|
|
return indent(a:lnum) / &shiftwidth |
|
|
endfunction |
|
|
endfunction |
|
@ -371,3 +185,210 @@ function! notecrate#fold_text() " {{{ |
|
|
endfunction |
|
|
endfunction |
|
|
|
|
|
|
|
|
" }}} |
|
|
" }}} |
|
|
|
|
|
|
|
|
|
|
|
" }}} |
|
|
|
|
|
" git {{{ |
|
|
|
|
|
function! notecrate#push() " {{{ |
|
|
|
|
|
execute "normal! :!cd " . b:notecrate_dir . "; git add -A; git commit -m \"autocommit\"; git push;\<CR>" |
|
|
|
|
|
endfunction |
|
|
|
|
|
|
|
|
|
|
|
" }}} |
|
|
|
|
|
function! notecrate#pull() " {{{ |
|
|
|
|
|
execute "normal! :!cd " . b:notecrate_dir . "; git pull;\<CR>" |
|
|
|
|
|
endfunction |
|
|
|
|
|
|
|
|
|
|
|
" }}} |
|
|
|
|
|
|
|
|
|
|
|
" }}} |
|
|
|
|
|
" pandoc {{{ |
|
|
|
|
|
function! notecrate#convert() " {{{ |
|
|
|
|
|
execute "normal! :w!\<CR>:!pushd " . b:notecrate_dir . "; bash convert.sh;\<CR>" |
|
|
|
|
|
endfunction |
|
|
|
|
|
|
|
|
|
|
|
" }}} |
|
|
|
|
|
|
|
|
|
|
|
" }}} |
|
|
|
|
|
" navigation {{{ |
|
|
|
|
|
function! notecrate#follow_link() " {{{ |
|
|
|
|
|
let l:link = notecrate#get_link_at_cursor()" |
|
|
|
|
|
if type(l:link) == 4 |
|
|
|
|
|
if l:link['dest'] =~ '^.*\.md$' |
|
|
|
|
|
call notecrate#open_note(l:link['dest']) |
|
|
|
|
|
else |
|
|
|
|
|
silent execute "open " . l:link['dest'] |
|
|
|
|
|
endif |
|
|
|
|
|
endif |
|
|
|
|
|
endfunction |
|
|
|
|
|
|
|
|
|
|
|
" }}} |
|
|
|
|
|
function! notecrate#open_note(filename) " {{{ |
|
|
|
|
|
let l:filename = expand('%:t') |
|
|
|
|
|
let l:notecrate_dir = b:notecrate_dir |
|
|
|
|
|
let l:notecrate_history = b:notecrate_history |
|
|
|
|
|
let l:path = b:notecrate_dir . "/" . a:filename |
|
|
|
|
|
let l:reg = getreg('') |
|
|
|
|
|
if !filereadable(expand(l:path)) |
|
|
|
|
|
echo "Note does't exist!" |
|
|
|
|
|
return |
|
|
|
|
|
endif |
|
|
|
|
|
call add(b:notecrate_history, l:filename) |
|
|
|
|
|
silent execute "e " . l:path |
|
|
|
|
|
let b:notecrate_dir = l:notecrate_dir |
|
|
|
|
|
let b:notecrate_history = l:notecrate_history |
|
|
|
|
|
call notecrate#update_backlinks() |
|
|
|
|
|
silent execute "normal! /^#\<CR>" |
|
|
|
|
|
call setreg('', l:reg) |
|
|
|
|
|
endfunction |
|
|
|
|
|
|
|
|
|
|
|
" }}} |
|
|
|
|
|
function! notecrate#open_index() " {{{ |
|
|
|
|
|
while !isdirectory(expand(b:notecrate_dir)) |
|
|
|
|
|
let choice = confirm('', b:notecrate_dir . " does not exist. Create? &Yes\n&No\n") |
|
|
|
|
|
if choice == 1 |
|
|
|
|
|
silent execute "!mkdir " . b:notecrate_dir |
|
|
|
|
|
else |
|
|
|
|
|
return 0 |
|
|
|
|
|
endif |
|
|
|
|
|
endwhile |
|
|
|
|
|
let l:filename = "index.md" |
|
|
|
|
|
let l:path = b:notecrate_dir . "/" . l:filename |
|
|
|
|
|
if !filereadable(expand(l:path)) |
|
|
|
|
|
echo "Note does't exist!" |
|
|
|
|
|
return |
|
|
|
|
|
endif |
|
|
|
|
|
silent execute "e " . l:path |
|
|
|
|
|
call notecrate#update_backlinks() |
|
|
|
|
|
silent execute "normal! /^#\<CR>" |
|
|
|
|
|
endfunction |
|
|
|
|
|
|
|
|
|
|
|
" }}} |
|
|
|
|
|
function! notecrate#open_previous() " {{{ |
|
|
|
|
|
if len(b:notecrate_history) == 0 |
|
|
|
|
|
return |
|
|
|
|
|
endif |
|
|
|
|
|
let l:filename = remove(b:notecrate_history, -1) |
|
|
|
|
|
call notecrate#open_note(l:filename) |
|
|
|
|
|
call remove(b:notecrate_history, -1) |
|
|
|
|
|
endfunction |
|
|
|
|
|
|
|
|
|
|
|
" }}} |
|
|
|
|
|
function! notecrate#search_open() " {{{ |
|
|
|
|
|
call notecrate#fzf_sink('notecrate#open_from_fzf') |
|
|
|
|
|
endfunction |
|
|
|
|
|
function! notecrate#open_from_fzf(line) |
|
|
|
|
|
let filename = substitute(a:line, ":[0-9]\*:[0-9]\*:.\*$", "", "") |
|
|
|
|
|
call notecrate#open_note(filename) |
|
|
|
|
|
endfunction |
|
|
|
|
|
|
|
|
|
|
|
" }}} |
|
|
|
|
|
|
|
|
|
|
|
" }}} |
|
|
|
|
|
" notes {{{ |
|
|
|
|
|
function! notecrate#update_backlinks() " {{{ |
|
|
|
|
|
let l:filename = expand('%:t') |
|
|
|
|
|
if l:filename == "index.md" |
|
|
|
|
|
return |
|
|
|
|
|
endif |
|
|
|
|
|
let l:pattern = '\[[^\]]*\](' . l:filename . ')\(\(.*\n\)*---\)\@=' |
|
|
|
|
|
let l:links = notecrate#grep_links(l:pattern) |
|
|
|
|
|
let l:backlinks = "---\n\n" |
|
|
|
|
|
if len(l:links) == 0 |
|
|
|
|
|
let l:backlinks = l:backlinks . "* [Index](index.md)" |
|
|
|
|
|
else |
|
|
|
|
|
let l:backlinks = l:backlinks . join(uniq(l:links), "\n") . "\n\n* [Index](index.md)" |
|
|
|
|
|
endif |
|
|
|
|
|
call setreg("l", l:backlinks) |
|
|
|
|
|
silent execute "normal! /^---\<CR>vG$\"lp" |
|
|
|
|
|
silent execute "normal! gg/^# \<CR>jj" |
|
|
|
|
|
endfunction |
|
|
|
|
|
|
|
|
|
|
|
" }}} |
|
|
|
|
|
function! notecrate#apply_template(title) " {{{ |
|
|
|
|
|
let l:template = "\n# " . a:title . "\n\n\n\n\n---\n\n" |
|
|
|
|
|
call setreg("l", l:template) |
|
|
|
|
|
silent execute 'normal "lP4j' |
|
|
|
|
|
call notecrate#update_backlinks() |
|
|
|
|
|
endfunction |
|
|
|
|
|
|
|
|
|
|
|
" }}} |
|
|
|
|
|
function! notecrate#new_note(title, filename) " {{{ |
|
|
|
|
|
let l:filename = expand('%:t') |
|
|
|
|
|
let l:notecrate_dir = b:notecrate_dir |
|
|
|
|
|
let l:notecrate_history = b:notecrate_history |
|
|
|
|
|
while !isdirectory(expand(b:notecrate_dir)) |
|
|
|
|
|
let choice = confirm('', b:notecrate_dir . " does not exist. Create? &Yes\n&No\n") |
|
|
|
|
|
if choice == 1 |
|
|
|
|
|
silent execute "!mkdir " . b:notecrate_dir |
|
|
|
|
|
else |
|
|
|
|
|
return 0 |
|
|
|
|
|
endif |
|
|
|
|
|
endwhile |
|
|
|
|
|
let l:path = b:notecrate_dir . "/" . a:filename |
|
|
|
|
|
call add(b:notecrate_history, l:filename) |
|
|
|
|
|
silent execute "normal! :w\<CR>:e " . l:path . "\<CR>" |
|
|
|
|
|
let b:notecrate_dir = l:notecrate_dir |
|
|
|
|
|
let b:notecrate_history = l:notecrate_history |
|
|
|
|
|
call notecrate#apply_template(a:title) |
|
|
|
|
|
call notecrate#update_backlinks() |
|
|
|
|
|
write |
|
|
|
|
|
endfunction |
|
|
|
|
|
|
|
|
|
|
|
" }}} |
|
|
|
|
|
function! notecrate#new_note_from_prompt() " {{{ |
|
|
|
|
|
let l:title = input("Name of new note? ") |
|
|
|
|
|
let l:filename = notecrate#generate_filename() |
|
|
|
|
|
call notecrate#new_note(l:title, l:filename) |
|
|
|
|
|
endfunction |
|
|
|
|
|
|
|
|
|
|
|
" }}} |
|
|
|
|
|
function! notecrate#new_note_from_selection() " {{{ |
|
|
|
|
|
let l:title = notecrate#get_visual_selection() |
|
|
|
|
|
let l:filename = notecrate#generate_filename() |
|
|
|
|
|
silent execute "normal! :'<,'>s/\\%V.*\\%V/[" . l:title . "](" . l:filename . ")/e\<CR>" |
|
|
|
|
|
call notecrate#new_note(l:title, l:filename) |
|
|
|
|
|
endfunction |
|
|
|
|
|
|
|
|
|
|
|
" }}} |
|
|
|
|
|
function! notecrate#delete_note() " {{{ |
|
|
|
|
|
let l:filename = expand('%:t') |
|
|
|
|
|
let l:path = b:notecrate_dir . "/" . l:filename |
|
|
|
|
|
let choice = confirm('', "Delete " . l:filename . "? &Yes\n&No\n") |
|
|
|
|
|
if choice == 1 |
|
|
|
|
|
call delete(l:path) |
|
|
|
|
|
call notecrate#delete_links(l:filename) |
|
|
|
|
|
silent execute "!rm " l:path |
|
|
|
|
|
silent execute "normal :bp!\<CR>" |
|
|
|
|
|
endif |
|
|
|
|
|
endfunction |
|
|
|
|
|
|
|
|
|
|
|
" }}} |
|
|
|
|
|
|
|
|
|
|
|
" }}} |
|
|
|
|
|
" links {{{ |
|
|
|
|
|
function! notecrate#search_insert_link() " {{{ |
|
|
|
|
|
call notecrate#fzf_sink('notecrate#insert_link_from_fzf') |
|
|
|
|
|
endfunction |
|
|
|
|
|
function! notecrate#insert_link_from_fzf(line) |
|
|
|
|
|
let l:filename = substitute(a:line, ":[0-9]\*:[0-9]\*:.\*$", "", "") |
|
|
|
|
|
let l:title = notecrate#get_title(filename) |
|
|
|
|
|
execute "normal! a[" . l:title . "](" . l:filename . ")\<Esc>" |
|
|
|
|
|
endfunction |
|
|
|
|
|
|
|
|
|
|
|
" }}} |
|
|
|
|
|
function! notecrate#search_insert_link_selection() " {{{ |
|
|
|
|
|
call notecrate#fzf_sink('notecrate#insert_link_from_fzf_selection') |
|
|
|
|
|
endfunction |
|
|
|
|
|
function! notecrate#insert_link_from_fzf_selection(line) |
|
|
|
|
|
let l:filename = substitute(a:line, ":[0-9]\*:[0-9]\*:.\*$", "", "") |
|
|
|
|
|
let l:title = notecrate#get_visual_selection() |
|
|
|
|
|
silent execute "normal! :'<,'>s/\\%V.*\\%V/[" . l:title . "](" . l:filename . ")/e\<CR>" |
|
|
|
|
|
endfunction |
|
|
|
|
|
|
|
|
|
|
|
" }}} |
|
|
|
|
|
function! notecrate#delete_links(filename) " {{{ |
|
|
|
|
|
execute "!" . g:gsed_command . " -i 's/\\[\\([^]]*\\)\\](" . a:filename . ")/\\1/g' " . b:notecrate_dir . "/*md" |
|
|
|
|
|
endfunction |
|
|
|
|
|
|
|
|
|
|
|
" }}} |
|
|
|
|
|
|
|
|
|
|
|
" }}} |
|
|