Compare commits

..

1 commit

Author SHA1 Message Date
f75ce87324
Update documentation 2025-01-15 13:51:37 +00:00
8 changed files with 22 additions and 96 deletions

View file

@ -45,7 +45,7 @@ endsnippet
# Code # Code
snippet rcode "R Code Block" b snippet `r "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 pycode "Python Code Block" b snippet `py "Python Code Block" b
\`\`\`{python} \`\`\`{python}
${1:#| output: ${2:false}} ${1:#| output: ${2:false}}
${3:#| echo: ${4:false}} ${3:#| echo: ${4:false}}

View file

@ -1,63 +0,0 @@
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

View file

@ -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 .. " " .. shellescape(output) execute "!" .. g:mbnotes_open_command .. " " .. output
endif endif
if g:mbnotes_renderer_close_on_end if g:mbnotes_renderer_close_on_end
@ -68,11 +68,10 @@ 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"
# Only rename bona fide notes # Don't touch daily notes
if directory == expand(g:mbnotes_dir) if g:mbnotes_rename_on_save && daily_path != full_path[0 : len(daily_path) - 1]
var base = expand('%:t') var base = expand('%:t')
var date = base[0 : 9] var date = base[0 : 9]
@ -84,7 +83,7 @@ export def BeforeNoteSave()
var title_line = search('^#\s\+') var title_line = search('^#\s\+')
if title_line == 0 if title_line == 0
return throw "Unable to save note: No title found."
endif endif
var title = substitute(getline(title_line), '^#\s\+', '', '') var title = substitute(getline(title_line), '^#\s\+', '', '')
@ -98,14 +97,13 @@ export def BeforeNoteSave()
normal! `s normal! `s
setpos("'s", original_mark) setpos("'s", original_mark)
b:new_name = fnameescape(expand('%:p:h')) .. "/" .. date .. "_" .. sanitised .. ".qmd" b:new_name = 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 " .. b:new_name execute "silent Move " .. fnameescape(g:mbnotes_dir) .. "/" .. b:new_name
unlet b:new_name
endif endif
enddef enddef

View file

@ -16,7 +16,6 @@
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*
@ -353,20 +352,4 @@ 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:

View file

@ -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 set filetype=mbnotes.qmd
endif endif
enddef enddef

View file

@ -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(g:mbnotes_dir .. "/daily", "p") silent mkdir(fnameescape(g:mbnotes_dir .. "/daily"), "p")
endif endif
if !exists("g:mbnotes_out_dir") if !exists("g:mbnotes_out_dir")

View file

@ -1,7 +1,12 @@
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("""# $date daily_template = Template("""---
title: "Daily Note"
date: "$date"
---
# $date
## Daily Note ## Daily Note

View file

@ -1,5 +1,6 @@
vim9s
if exists("b:current_syntax") if exists("b:current_syntax")
echom b:current_syntax
finish finish
endif endif
@ -16,7 +17,9 @@ 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 mbnCalloutTip Question hi link mbnCalloutNote Question
syn region mbnCalloutCaution start=":::\s\+{\.callout-caution\s*" end=":::$" keepend syn region mbnCalloutCaution start=":::\s\+{\.callout-caution\s*" end=":::$" keepend
hi link mbnCalloutCaution SpellCap hi link mbnCalloutWarning SpellCap
b:current_syntax = "mbnotes"