Browse Source

lazygit 2022-03-27 21:53

master
Gregory Leeman 3 years ago
parent
commit
965ab42cb2
  1. 9
      autoload/notecrate.vim
  2. 2
      syntax/notecrate.vim

9
autoload/notecrate.vim

@ -40,7 +40,7 @@ endfunction
" }}} " }}}
function! notecrate#apply_template(title) " {{{ function! notecrate#apply_template(title) " {{{
let l:template = "# " . a:title . "\n\n\n---\n\n" let l:template = "\n# " . a:title . "\n\n\n\n\n---\n\n"
call setreg("l", l:template) call setreg("l", l:template)
silent execute 'normal "lP4j' silent execute 'normal "lP4j'
call notecrate#update_backlinks() call notecrate#update_backlinks()
@ -76,6 +76,8 @@ endfunction
" }}} " }}}
function! notecrate#new_note(title, filename) " {{{ function! notecrate#new_note(title, filename) " {{{
let l:filename = expand('%:t') 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)) while !isdirectory(expand(b:notecrate_dir))
let choice = confirm('', b:notecrate_dir . " does not exist. Create? &Yes\n&No\n") let choice = confirm('', b:notecrate_dir . " does not exist. Create? &Yes\n&No\n")
if choice == 1 if choice == 1
@ -87,8 +89,11 @@ function! notecrate#new_note(title, filename) " {{{
let l:path = b:notecrate_dir . "/" . a:filename let l:path = b:notecrate_dir . "/" . a:filename
call add(b:notecrate_history, l:filename) call add(b:notecrate_history, l:filename)
silent execute "normal! :w\<CR>:e " . l:path . "\<CR>" 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#apply_template(a:title)
call notecrate#update_backlinks() call notecrate#update_backlinks()
write
endfunction endfunction
" }}} " }}}
@ -218,6 +223,7 @@ endfunction
" }}} " }}}
function! notecrate#grep(pattern) " {{{ function! notecrate#grep(pattern) " {{{
echom b:notecrate_dir
let l:files = [] let l:files = []
try try
silent execute 'vimgrep /' . a:pattern . '/j ' . b:notecrate_dir . '/*.md' silent execute 'vimgrep /' . a:pattern . '/j ' . b:notecrate_dir . '/*.md'
@ -260,6 +266,7 @@ function! notecrate#update_backlinks() " {{{
endif endif
call setreg("l", l:backlinks) call setreg("l", l:backlinks)
silent execute "normal! /^---\<CR>vG$\"lp" silent execute "normal! /^---\<CR>vG$\"lp"
silent execute "normal! gg/^# \<CR>jj"
endfunction endfunction
" }}} " }}}

2
syntax/notecrate.vim

@ -10,7 +10,7 @@ syn match NotecrateLinkConceal /!*\[\+\([^\]]*](\)\@=/ conceal
syn match NotecrateLinkConceal /\]\+\((\)\@=/ conceal syn match NotecrateLinkConceal /\]\+\((\)\@=/ conceal
syn match NotecrateLinkConceal /\(\[[^\]]*\]\)\@<=([^)]*)/ conceal contains=NotecrateLinkInternal syn match NotecrateLinkConceal /\(\[[^\]]*\]\)\@<=([^)]*)/ conceal contains=NotecrateLinkInternal
syn match NotecrateLink /\(\[\)\@<=[^\[\]]*\(\](\)\@=/ syn match NotecrateLink /\(\[\)\@<=[^\[\]]*\(\](\)\@=/
syn match NotecrateLinkImage /\(!\[\+\)\@<=[^\[\]]*\(\]\+\)\@=/ " syn match NotecrateLinkImage /\(!\[\+\)\@<=[^\[\]]*\(\]\+\)\@=/
syn match NotecrateHeader1 /\(^# \)\@<=.*/ syn match NotecrateHeader1 /\(^# \)\@<=.*/
syn match NotecrateHeader2 /\(^##\+ \)\@<=.*/ syn match NotecrateHeader2 /\(^##\+ \)\@<=.*/
syn match NotecrateRule /^---\+/ syn match NotecrateRule /^---\+/