Compare commits
5 commits
fzf-integr
...
main
Author | SHA1 | Date | |
---|---|---|---|
dfca541147 | |||
86856bf960 | |||
8f1f3cda87 | |||
8d3ded9659 | |||
2654861ab3 |
8 changed files with 96 additions and 22 deletions
|
@ -45,7 +45,7 @@ endsnippet
|
||||||
|
|
||||||
# Code
|
# Code
|
||||||
|
|
||||||
snippet `r "R Code Block" b
|
snippet rcode "R Code Block" b
|
||||||
\`\`\`{r}
|
\`\`\`{r}
|
||||||
${1:#| output: ${2:false}}
|
${1:#| output: ${2:false}}
|
||||||
${3:#| echo: ${4:false}}
|
${3:#| echo: ${4:false}}
|
||||||
|
@ -53,7 +53,7 @@ ${0:${VISUAL:# code...}}
|
||||||
\`\`\`
|
\`\`\`
|
||||||
endsnippet
|
endsnippet
|
||||||
|
|
||||||
snippet `py "Python Code Block" b
|
snippet pycode "Python Code Block" b
|
||||||
\`\`\`{python}
|
\`\`\`{python}
|
||||||
${1:#| output: ${2:false}}
|
${1:#| output: ${2:false}}
|
||||||
${3:#| echo: ${4:false}}
|
${3:#| echo: ${4:false}}
|
||||||
|
|
63
autoload/asyncomplete/sources/mbnotes.vim
Normal file
63
autoload/asyncomplete/sources/mbnotes.vim
Normal file
|
@ -0,0 +1,63 @@
|
||||||
|
function! asyncomplete#sources#mbnotes#get_source_options(opts)
|
||||||
|
let l:defaults = {
|
||||||
|
\ 'name': 'mbnotes',
|
||||||
|
\ 'completor': function('asyncomplete#sources#mbnotes#completor'),
|
||||||
|
\ 'allowlist': ['mbnotes']
|
||||||
|
\ }
|
||||||
|
|
||||||
|
return extend(l:defaults, a:opts)
|
||||||
|
endfunction
|
||||||
|
|
||||||
|
let s:notes = []
|
||||||
|
let s:notes_ttl = 0
|
||||||
|
let s:command = "rg -N --no-heading --color=never --smart-case "
|
||||||
|
\ .. "--glob='**/*.qmd' -m 1 -- '^#\\s' "
|
||||||
|
\ .. shellescape(g:mbnotes_dir)
|
||||||
|
|
||||||
|
function! asyncomplete#sources#mbnotes#format_cache_entry(key, line)
|
||||||
|
let l:line = substitute(a:line, g:mbnotes_dir .. "/", "", "")
|
||||||
|
let l:parts = split(l:line, '\.qmd:#\s*')
|
||||||
|
|
||||||
|
return ['[' .. l:parts[1] .. '](' .. l:parts[0] .. '.qmd)'] + l:parts
|
||||||
|
endfunction!
|
||||||
|
|
||||||
|
function! asyncomplete#sources#mbnotes#refresh_cache()
|
||||||
|
let l:output = systemlist(s:command)
|
||||||
|
|
||||||
|
let s:notes = mapnew(l:output, function('asyncomplete#sources#mbnotes#format_cache_entry'))
|
||||||
|
let s:notes_ttl = localtime() + 20
|
||||||
|
endfunction!
|
||||||
|
|
||||||
|
function! asyncomplete#sources#mbnotes#completor(opt, ctx)
|
||||||
|
let l:title_pattern = '\[[^\]]*$'
|
||||||
|
let l:title = matchstr(a:ctx['typed'], l:title_pattern)
|
||||||
|
|
||||||
|
if l:title !=# ''
|
||||||
|
if localtime() > s:notes_ttl
|
||||||
|
call asyncomplete#sources#mbnotes#refresh_cache()
|
||||||
|
endif
|
||||||
|
|
||||||
|
let l:col = a:ctx['col'] - len(l:title)
|
||||||
|
let l:matches = mapnew(s:notes, '{"word": v:val[0], "dup": 1, "menu": v:val[1], "abbr": v:val[2]}')
|
||||||
|
|
||||||
|
call asyncomplete#complete(a:opt['name'], a:ctx, l:col, l:matches)
|
||||||
|
|
||||||
|
return
|
||||||
|
endif
|
||||||
|
|
||||||
|
let l:link_pattern = '\]([^)]*$'
|
||||||
|
let l:link = matchstr(a:ctx['typed'], l:link_pattern)
|
||||||
|
|
||||||
|
if l:link !=# ''
|
||||||
|
if localtime() > s:notes_ttl
|
||||||
|
call asyncomplete#sources#mbnotes#refresh_cache()
|
||||||
|
endif
|
||||||
|
|
||||||
|
let l:col = a:ctx['col'] - len(l:link)
|
||||||
|
let l:matches = mapnew(s:notes, '{"word": "](" .. v:val[1] .. ".qmd)", "abbr": v:val[1]}')
|
||||||
|
|
||||||
|
call asyncomplete#complete(a:opt['name'], a:ctx, l:col, l:matches)
|
||||||
|
|
||||||
|
return
|
||||||
|
endif
|
||||||
|
endfunction
|
|
@ -40,7 +40,7 @@ export def RenderNote(format: string, buffer = "%")
|
||||||
endif
|
endif
|
||||||
else
|
else
|
||||||
if exists("g:mbnotes_open_command") && g:mbnotes_open_command != ""
|
if exists("g:mbnotes_open_command") && g:mbnotes_open_command != ""
|
||||||
execute "!" .. g:mbnotes_open_command .. " " .. output
|
execute "!" .. g:mbnotes_open_command .. " " .. shellescape(output)
|
||||||
endif
|
endif
|
||||||
|
|
||||||
if g:mbnotes_renderer_close_on_end
|
if g:mbnotes_renderer_close_on_end
|
||||||
|
@ -68,10 +68,11 @@ enddef
|
||||||
|
|
||||||
export def BeforeNoteSave()
|
export def BeforeNoteSave()
|
||||||
var full_path = expand('%:p')
|
var full_path = expand('%:p')
|
||||||
|
var directory = expand('%:p:h')
|
||||||
var daily_path = g:mbnotes_dir .. "/daily"
|
var daily_path = g:mbnotes_dir .. "/daily"
|
||||||
|
|
||||||
# Don't touch daily notes
|
# Only rename bona fide notes
|
||||||
if g:mbnotes_rename_on_save && daily_path != full_path[0 : len(daily_path) - 1]
|
if directory == expand(g:mbnotes_dir)
|
||||||
var base = expand('%:t')
|
var base = expand('%:t')
|
||||||
var date = base[0 : 9]
|
var date = base[0 : 9]
|
||||||
|
|
||||||
|
@ -83,7 +84,7 @@ export def BeforeNoteSave()
|
||||||
var title_line = search('^#\s\+')
|
var title_line = search('^#\s\+')
|
||||||
|
|
||||||
if title_line == 0
|
if title_line == 0
|
||||||
throw "Unable to save note: No title found."
|
return
|
||||||
endif
|
endif
|
||||||
|
|
||||||
var title = substitute(getline(title_line), '^#\s\+', '', '')
|
var title = substitute(getline(title_line), '^#\s\+', '', '')
|
||||||
|
@ -97,13 +98,14 @@ export def BeforeNoteSave()
|
||||||
normal! `s
|
normal! `s
|
||||||
setpos("'s", original_mark)
|
setpos("'s", original_mark)
|
||||||
|
|
||||||
b:new_name = date .. "_" .. sanitised .. ".qmd"
|
b:new_name = fnameescape(expand('%:p:h')) .. "/" .. date .. "_" .. sanitised .. ".qmd"
|
||||||
endif
|
endif
|
||||||
enddef
|
enddef
|
||||||
|
|
||||||
export def AfterNoteSave()
|
export def AfterNoteSave()
|
||||||
if exists("b:new_name")
|
if exists("b:new_name")
|
||||||
execute "silent Move " .. fnameescape(g:mbnotes_dir) .. "/" .. b:new_name
|
execute "silent Move " .. b:new_name
|
||||||
|
unlet b:new_name
|
||||||
endif
|
endif
|
||||||
enddef
|
enddef
|
||||||
|
|
||||||
|
|
|
@ -16,6 +16,7 @@
|
||||||
6. Integrations ...................... |mbnotes-integrations|
|
6. Integrations ...................... |mbnotes-integrations|
|
||||||
6.1. UltiSnips ................... |mbnotes-ultisnips|
|
6.1. UltiSnips ................... |mbnotes-ultisnips|
|
||||||
6.2. FZF ......................... |mbnotes-fzf|
|
6.2. FZF ......................... |mbnotes-fzf|
|
||||||
|
6.3. Asyncomplete ................ mbnotes-asyncomplete
|
||||||
|
|
||||||
==============================================================================
|
==============================================================================
|
||||||
1. Introduction *mbnotes*
|
1. Introduction *mbnotes*
|
||||||
|
@ -352,4 +353,20 @@ appended to that command.
|
||||||
|
|
||||||
Search all notes for a given tag using `g:mbnotes_search_command`.
|
Search all notes for a given tag using `g:mbnotes_search_command`.
|
||||||
|
|
||||||
|
==============================================================================
|
||||||
|
6.3. Asyncomplete *mbnotes-asyncomplete*
|
||||||
|
|
||||||
|
Completion is supported via asyncomplete, for links to other notes. To enable
|
||||||
|
this, include:
|
||||||
|
|
||||||
|
>vim
|
||||||
|
autocmd User asyncomplete_setup {
|
||||||
|
asyncomplete#register_source(
|
||||||
|
asyncomplete#sources#mbnotes#get_source_options({ 'priority': 9 })
|
||||||
|
)
|
||||||
|
}
|
||||||
|
<
|
||||||
|
|
||||||
|
This completion support depends on ripgrep being installed.
|
||||||
|
|
||||||
vim:tw=78:ts=8:noet:ft=help:norl:
|
vim:tw=78:ts=8:noet:ft=help:norl:
|
||||||
|
|
|
@ -4,7 +4,7 @@ def IsMBNotes()
|
||||||
var path_prefix = expand('%:p')[0 : len(g:mbnotes_dir) - 1]
|
var path_prefix = expand('%:p')[0 : len(g:mbnotes_dir) - 1]
|
||||||
|
|
||||||
if path_prefix == g:mbnotes_dir
|
if path_prefix == g:mbnotes_dir
|
||||||
set filetype=mbnotes.qmd
|
set filetype=mbnotes
|
||||||
endif
|
endif
|
||||||
enddef
|
enddef
|
||||||
|
|
||||||
|
|
|
@ -16,7 +16,7 @@ if !exists("g:mbnotes_dir")
|
||||||
echoerr "MBNotes: Error: g:mbnotes_dir not set."
|
echoerr "MBNotes: Error: g:mbnotes_dir not set."
|
||||||
finish
|
finish
|
||||||
else
|
else
|
||||||
silent mkdir(fnameescape(g:mbnotes_dir .. "/daily"), "p")
|
silent mkdir(g:mbnotes_dir .. "/daily", "p")
|
||||||
endif
|
endif
|
||||||
|
|
||||||
if !exists("g:mbnotes_out_dir")
|
if !exists("g:mbnotes_out_dir")
|
||||||
|
|
|
@ -1,12 +1,7 @@
|
||||||
import vim
|
import vim
|
||||||
from string import Template
|
from string import Template
|
||||||
from datetime import datetime, timedelta
|
from datetime import datetime, timedelta
|
||||||
daily_template = Template("""---
|
daily_template = Template("""# $date
|
||||||
title: "Daily Note"
|
|
||||||
date: "$date"
|
|
||||||
---
|
|
||||||
|
|
||||||
# $date
|
|
||||||
|
|
||||||
## Daily Note
|
## Daily Note
|
||||||
|
|
||||||
|
|
|
@ -1,6 +1,5 @@
|
||||||
vim9s
|
|
||||||
|
|
||||||
if exists("b:current_syntax")
|
if exists("b:current_syntax")
|
||||||
|
echom b:current_syntax
|
||||||
finish
|
finish
|
||||||
endif
|
endif
|
||||||
|
|
||||||
|
@ -17,9 +16,7 @@ syn region mbnCalloutImportant start=":::\s\+{\.callout-important\s*" end=":::$"
|
||||||
hi link mbnCalloutImportant SpellBad
|
hi link mbnCalloutImportant SpellBad
|
||||||
|
|
||||||
syn region mbnCalloutTip start=":::\s\+{\.callout-tip\s*" end=":::$" keepend
|
syn region mbnCalloutTip start=":::\s\+{\.callout-tip\s*" end=":::$" keepend
|
||||||
hi link mbnCalloutNote Question
|
hi link mbnCalloutTip Question
|
||||||
|
|
||||||
syn region mbnCalloutCaution start=":::\s\+{\.callout-caution\s*" end=":::$" keepend
|
syn region mbnCalloutCaution start=":::\s\+{\.callout-caution\s*" end=":::$" keepend
|
||||||
hi link mbnCalloutWarning SpellCap
|
hi link mbnCalloutCaution SpellCap
|
||||||
|
|
||||||
b:current_syntax = "mbnotes"
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue