|
@ -186,103 +186,8 @@ 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 {{{ |
|
|
" notes {{{ |
|
|
function! notecrate#update_backlinks() " {{{ |
|
|
function! notecrate#update_backlinks() " {{{ |
|
|
let l:filename = expand('%:t') |
|
|
let l:filename = expand('%:t') |
|
@ -412,3 +317,219 @@ 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 |
|
|
|
|
|
|
|
|
|
|
|
" }}} |
|
|
|
|
|
|
|
|
|
|
|
" }}} |
|
|
|
|
|
|
|
|
|
|
|
" 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 |
|
|
|
|
|
|
|
|
|
|
|
" }}} |
|
|
|
|
|
|
|
|
|
|
|
" }}} |
|
|
|
|
|
|
|
|
|
|
|
function! notecrate#update_mappings() " {{{ |
|
|
|
|
|
execute 'command! -nargs=1 Rename call notecrate#rename_note(<f-args>)' |
|
|
|
|
|
execute 'nnoremap <buffer> <leader>r :Rename<CR>' |
|
|
|
|
|
|
|
|
|
|
|
execute 'command! -buffer -nargs=0 Delete call notecrate#delete_note()' |
|
|
|
|
|
execute 'nnoremap <buffer> <leader>d :Delete<CR>' |
|
|
|
|
|
|
|
|
|
|
|
execute 'command! -buffer -nargs=0 Convert :call notecrate#script("convert")' |
|
|
|
|
|
execute 'nnoremap <buffer> <leader>c :Convert<CR>' |
|
|
|
|
|
|
|
|
|
|
|
execute 'command! -buffer -nargs=0 Presentation :call notecrate#script("marp")' |
|
|
|
|
|
execute 'nnoremap <buffer> <leader>p :Presentation<CR>' |
|
|
|
|
|
|
|
|
|
|
|
execute 'command! -buffer -nargs=0 SearchOpen :call notecrate#search_open()' |
|
|
|
|
|
execute 'nnoremap <buffer> <leader>o :SearchOpen<CR>' |
|
|
|
|
|
|
|
|
|
|
|
execute 'command! -buffer -nargs=0 InsertLink :call notecrate#search_insert_link()' |
|
|
|
|
|
execute 'nnoremap <buffer> <leader>i :InsertLink<CR>' |
|
|
|
|
|
|
|
|
|
|
|
execute 'command! -buffer -nargs=0 Backlinks :call notecrate#update_backlinks()' |
|
|
|
|
|
execute 'nnoremap <buffer> <leader>b :Backlinks<CR>' |
|
|
|
|
|
|
|
|
|
|
|
execute 'command! -buffer -nargs=0 New :call notecrate#new_note_from_prompt()' |
|
|
|
|
|
execute 'nnoremap <buffer> <leader>n :New<CR>' |
|
|
|
|
|
|
|
|
|
|
|
execute 'command! -buffer -nargs=0 Push :call notecrate#push()' |
|
|
|
|
|
execute 'nnoremap <buffer> <leader>s :Push<CR>' |
|
|
|
|
|
|
|
|
|
|
|
execute 'command! -buffer -nargs=0 Pull :call notecrate#pull()' |
|
|
|
|
|
execute 'nnoremap <buffer> <leader>u :Pull<CR>' |
|
|
|
|
|
|
|
|
|
|
|
execute 'command! -buffer -nargs=0 Follow :call notecrate#follow_link()' |
|
|
|
|
|
execute 'nnoremap <buffer> <CR> :Follow<CR>' |
|
|
|
|
|
|
|
|
|
|
|
execute 'nnoremap <buffer> <backspace> :call notecrate#open_previous()<CR>' |
|
|
|
|
|
|
|
|
|
|
|
execute 'nnoremap <buffer> <S-j> /\[[^\]]*\]([^)]*)<CR>:noh<CR>' |
|
|
|
|
|
execute 'nnoremap <buffer> <S-l> /\[[^\]]*\]([^)]*)<CR>:noh<CR>' |
|
|
|
|
|
execute 'nnoremap <buffer> <Tab> /\[[^\]]*\]([^)]*)<CR>:noh<CR>' |
|
|
|
|
|
execute 'nnoremap <buffer> <S-Tab> /\[[^\]]*\]([^)]*)<CR>NN:noh<CR>' |
|
|
|
|
|
execute 'nnoremap <buffer> <S-h> /\[[^\]]*\]([^)]*)<CR>NN:noh<CR>' |
|
|
|
|
|
execute 'nnoremap <buffer> <S-k> /\[[^\]]*\]([^)]*)<CR>NN:noh<CR>' |
|
|
|
|
|
|
|
|
|
|
|
execute 'command! -buffer -nargs=0 Insert :call notecrate#search_insert_link_selection()' |
|
|
|
|
|
execute 'vnoremap <buffer> <leader>i :Insert<CR>' |
|
|
|
|
|
|
|
|
|
|
|
execute 'vnoremap <buffer> <CR> :call notecrate#new_note_from_selection()<CR>' |
|
|
|
|
|
|
|
|
|
|
|
execute 'inoremap <buffer> <Tab> <C-t>' |
|
|
|
|
|
execute 'inoremap <buffer> <S-Tab> <C-d>' |
|
|
|
|
|
|
|
|
|
|
|
endfunction |
|
|
|
|
|
|
|
|
|
|
|
" }}} |
|
|
|
|
|
function! notecrate#update_syntax() " {{{ |
|
|
|
|
|
execute 'setlocal textwidth=79' |
|
|
|
|
|
execute 'setlocal autowriteall' |
|
|
|
|
|
execute 'setlocal comments+=b:*' |
|
|
|
|
|
execute 'setlocal foldlevel=3' |
|
|
|
|
|
execute 'setlocal foldmethod=expr' |
|
|
|
|
|
execute 'setlocal foldexpr=notecrate#nested_markdown_folds(v:lnum)' |
|
|
|
|
|
execute 'setlocal foldtext=notecrate#fold_text()' |
|
|
|
|
|
execute 'setlocal conceallevel=2' |
|
|
|
|
|
execute 'setlocal concealcursor=' |
|
|
|
|
|
execute 'setlocal wrap' |
|
|
|
|
|
|
|
|
|
|
|
execute 'syn match NotecrateLinkInternal /\(\](\)\@<=[^()]*\()\)\@=/' |
|
|
|
|
|
execute 'hi def link NotecrateLinkInternal orangeu' |
|
|
|
|
|
|
|
|
|
|
|
execute 'syn match NotecrateBoldConceal /\*\*/ conceal containedin=ALL' |
|
|
|
|
|
|
|
|
|
|
|
execute 'syn match NotecrateLinkConceal /!*\[\+\([^\]]*](\)\@=/ conceal' |
|
|
|
|
|
execute 'syn match NotecrateLinkConceal /\]\+\((\)\@=/ conceal' |
|
|
|
|
|
execute 'syn match NotecrateLinkConceal /\(\[[^\]]*\]\)\@<=([^)]*)/ conceal contains=NotecrateLinkInternal' |
|
|
|
|
|
execute 'hi def link NotecrateLinkConceal blue' |
|
|
|
|
|
|
|
|
|
|
|
execute 'syn match NotecrateLink /\(\[\)\@<=[^\[\]]*\(\](\)\@=/' |
|
|
|
|
|
execute 'hi def link NotecrateLink blueu' |
|
|
|
|
|
|
|
|
|
|
|
execute 'syn match NotecrateLinkImage /!\[\]/ containedin=ALL' |
|
|
|
|
|
execute 'hi def link NotecrateLinkImage redu' |
|
|
|
|
|
|
|
|
|
|
|
execute 'syn match NotecrateHeader1 /\(^# \)\@<=.*/' |
|
|
|
|
|
execute 'hi def link NotecrateHeader1 base3u' |
|
|
|
|
|
|
|
|
|
|
|
execute 'syn match NotecrateHeader2 /\(^##\+ \)\@<=.*/' |
|
|
|
|
|
execute 'hi def link NotecrateHeader2 base1u' |
|
|
|
|
|
|
|
|
|
|
|
execute 'syn match NotecrateRule /^---\+/' |
|
|
|
|
|
execute 'hi def link NotecrateRule base01' |
|
|
|
|
|
|
|
|
|
|
|
execute 'syn region NotecrateFrontCustomMatter start=/\%^---/ end=/^---/' |
|
|
|
|
|
execute 'hi def link NotecrateFrontCustomMatter base01' |
|
|
|
|
|
|
|
|
|
|
|
execute 'syn region NotecrateCode start=/^```/ end=/^```/' |
|
|
|
|
|
execute 'hi def link NotecrateCode red' |
|
|
|
|
|
|
|
|
|
|
|
execute 'syn region NotecrateBold start=/\*\*/ end=/\*\*/ contains=NotecrateBoldConceal keepend' |
|
|
|
|
|
execute 'hi def link NotecrateBold base2' |
|
|
|
|
|
|
|
|
|
|
|
execute 'syn match NotecrateQuote /^>.*$/' |
|
|
|
|
|
execute 'hi def link NotecrateQuote cyan' |
|
|
|
|
|
|
|
|
|
|
|
execute 'syn match NotecrateTag /#[^# ]\S*/' |
|
|
|
|
|
execute 'hi def link NotecrateTag cyanu' |
|
|
|
|
|
|
|
|
|
|
|
execute 'syn match NotecrateDone /#DONE/ containedin=NotecrateTag' |
|
|
|
|
|
execute 'hi def link NotecrateDone greenbg' |
|
|
|
|
|
|
|
|
|
|
|
execute 'syn match NotecrateTodo /#TODO/ containedin=NotecrateTag' |
|
|
|
|
|
execute 'hi def link NotecrateTodo redbg' |
|
|
|
|
|
|
|
|
|
|
|
endfunction |
|
|
|
|
|
|
|
|
|
|
|
" }}} |
|
|
|
|
|
|
|
|
|
|
|
function! notecrate#script(name) " {{{ |
|
|
|
|
|
let l:script = g:todo_plugin_dir . "/scripts/" . a:name . ".sh" |
|
|
|
|
|
let l:dir = getcwd() |
|
|
|
|
|
let l:file = expand('%:t') |
|
|
|
|
|
execute "cd " . b:notecrate_dir |
|
|
|
|
|
execute "!bash " . l:script . " " . l:file |
|
|
|
|
|
execute "cd " . l:dir |
|
|
|
|
|
endfunction |
|
|
|
|
|
|
|
|
|
|
|
" }}} |
|
|