From c3f3999e0269904c39cb043f09a5f45617751b7e Mon Sep 17 00:00:00 2001 From: Max Bucknell Date: Sun, 19 Jan 2025 11:41:02 +0000 Subject: [PATCH] Factor notes into plugin --- vim/vim.xdg.symlink/Ultisnips/quarto.snippets | 75 ------------- vim/vim.xdg.symlink/after/syntax/quarto.vim | 5 - vim/vim.xdg.symlink/colors/mpwb.vim | 60 ++++++----- vim/vim.xdg.symlink/vimrc | 102 ++++++++---------- 4 files changed, 75 insertions(+), 167 deletions(-) delete mode 100644 vim/vim.xdg.symlink/after/syntax/quarto.vim diff --git a/vim/vim.xdg.symlink/Ultisnips/quarto.snippets b/vim/vim.xdg.symlink/Ultisnips/quarto.snippets index 5cd0b89..7e67cb4 100644 --- a/vim/vim.xdg.symlink/Ultisnips/quarto.snippets +++ b/vim/vim.xdg.symlink/Ultisnips/quarto.snippets @@ -1,78 +1,3 @@ -snippet note "Note Front Matter" b ---- -title: "${1:Title}" -author: "${2:Max Bucknell}" -date: "${3:`date "+%A, %e, %B %Y"`}" -format: - html: - embed-resources: true - html-math-method: katex - mainfont: Lato - monofont: Input - theme: - light: flatly - dark: darkly - pdf: - documentclass: article - mainfont: Lato - monofont: Input - geometry: - - top=30mm - - left=20mm - - heightrounded - number-sections: true ---- - -# $1 - -$0 -endsnippet - -snippet :::n "Callout: Note" b -::: {.callout-note} -${0:${VISUAL:text...}} -::: -endsnippet - -snippet :::t "Callout: Tip" b -::: {.callout-tip} -${0:${VISUAL:text...}} -::: -endsnippet - -snippet :::w "Callout: Warning" b -::: {.callout-warning} -${0:${VISUAL:text...}} -::: -endsnippet - -snippet :::i "Callout: Important" b -::: {.callout-important} -${0:${VISUAL:text...}} -::: -endsnippet - -snippet `r "R Code Block" b -\`\`\`{r} -${1:#| output: ${2:false}} -${0:${VISUAL:# code...}} -\`\`\` -endsnippet - -snippet `py "Python Code Block" b -\`\`\`{python} -${1:#| output: ${2:false}} -${0:${VISUAL:# code...}} -\`\`\` -endsnippet - -snippet `ju "Julia Code Block" b -\`\`\`{julia} -${1:#| output: ${2:false}} -${0:${VISUAL:# code...}} -\`\`\` -endsnippet - snippet todo "Make a To-Do List!" b - [ ] ${0:What would you like to do..?} endsnippet diff --git a/vim/vim.xdg.symlink/after/syntax/quarto.vim b/vim/vim.xdg.symlink/after/syntax/quarto.vim deleted file mode 100644 index 33484c3..0000000 --- a/vim/vim.xdg.symlink/after/syntax/quarto.vim +++ /dev/null @@ -1,5 +0,0 @@ -syn region quartoCalloutNote start=":::\s\+{\.callout-note\s*" end=":::$" keepend -syn region quartoCalloutWarning start=":::\s\+{\.callout-warning\s*" end=":::$" keepend -syn region quartoCalloutImportant start=":::\s\+{\.callout-important\s*" end=":::$" keepend -syn region quartoCalloutTip start=":::\s\+{\.callout-tip\s*" end=":::$" keepend -syn region quartoCalloutCaution start=":::\s\+{\.callout-caution\s*" end=":::$" keepend diff --git a/vim/vim.xdg.symlink/colors/mpwb.vim b/vim/vim.xdg.symlink/colors/mpwb.vim index 6de6e4d..bea0f83 100644 --- a/vim/vim.xdg.symlink/colors/mpwb.vim +++ b/vim/vim.xdg.symlink/colors/mpwb.vim @@ -29,34 +29,36 @@ let s:is_dark=(&background == 'dark') " \ 'mpwb_green': '#20A92E', call extend(v:colornames, { - \ 'mpwb_fg': '#201C22', - \ 'mpwb_bg': '#E7E3E9', - \ 'mpwb_tintbg': '#FCF7FE', - \ 'mpwb_red': '#AD1C22', - \ 'mpwb_orange': '#AF5F27', - \ 'mpwb_yellow': '#AD9622', - \ 'mpwb_green': '#20A951', - \ 'mpwb_cyan': '#20A9AE', - \ 'mpwb_blue': '#2059AF', - \ 'mpwb_purple': '#721CAF', - \ 'mpwb_magenta': '#AB177B', - \ 'mpwb_callout_note': '#CCD7E8', - \ 'mpwb_callout_tip': '#D2E8CC', - \ 'mpwb_callout_important': '#E8CCCC', - \ 'mpwb_callout_warning': '#E8E3CC', + \ 'mpwb_light': '#e7e3e9', + \ 'mpwb_dark': '#201c22', + \ 'mpwb_fg': '#201c22', + \ 'mpwb_bg': '#e7e3e9', + \ 'mpwb_tintbg': '#fcf7fe', + \ 'mpwb_red': '#ad1c22', + \ 'mpwb_orange': '#af5f27', + \ 'mpwb_yellow': '#ad9622', + \ 'mpwb_green': '#20a951', + \ 'mpwb_cyan': '#20a9ae', + \ 'mpwb_blue': '#2059af', + \ 'mpwb_purple': '#721caf', + \ 'mpwb_magenta': '#ab177b', + \ 'mpwb_callout_note': '#ccd7e8', + \ 'mpwb_callout_tip': '#d2e8cc', + \ 'mpwb_callout_important': '#e8cccc', + \ 'mpwb_callout_warning': '#e8e3cc', \ 'mpwb_cursorline': '#c6c2c8' \ }, 'force') if s:is_dark call extend(v:colornames, { - \ 'mpwb_fg': '#E7E3E9', - \ 'mpwb_bg': '#201C22', - \ 'mpwb_tintbg': '#3B3440', - \ 'mpwb_callout_note': '#002A68', + \ 'mpwb_fg': '#e7e3e9', + \ 'mpwb_bg': '#201c22', + \ 'mpwb_tintbg': '#3b3440', + \ 'mpwb_callout_note': '#002a68', \ 'mpwb_callout_tip': '#156800', \ 'mpwb_callout_important': '#680000', \ 'mpwb_callout_warning': '#685700', - \ 'mpwb_cursorline': '#29242C', + \ 'mpwb_cursorline': '#29242c', \ }, 'force') endif @@ -91,9 +93,13 @@ hi! link MatchParen Search " Chrome is purple hi VertSplit guifg=mpwb_purple cterm=NONE -hi StatusLine guifg=mpwb_purple cterm=bold +hi StatusLine guibg=mpwb_light guifg=mpwb_purple hi StatusLineNC guifg=mpwb_purple cterm=NONE +hi TabLine guifg=mpwb_purple guibg=mpwb_bg +hi TabLineFill guibg=mpwb_bg guifg=mpwb_purple cterm=underline +hi TabLinesel guibg=mpwb_purple guifg=mpwb_light + hi Visual guibg=mpwb_fg guifg=mpwb_bg hi LineNr cterm=NONE guifg=mpwb_purple @@ -121,7 +127,7 @@ hi LspSigActiveParameter cterm=bold guifg=mpwb_bg guibg=mpwb_purple hi pandocBlockQuote cterm=NONE guifg=mpwb_fg hi link elixirUnusedVariable Normal -" Notes in Quarto +" Notes hi Title cterm=bold guifg=mpwb_fg hi link pandocAtxHeaderMark Title @@ -131,9 +137,9 @@ hi link pandocDelimitedCodeBlockLanguage Normal hi pandocBlockQuote cterm=italic hi pandocHRule guibg=mpwb_tintbg -hi quartoCalloutNote guibg=mpwb_callout_note -hi quartoCalloutWarning guibg=mpwb_callout_warning -hi quartoCalloutImportant guibg=mpwb_callout_important -hi quartoCalloutTip guibg=mpwb_callout_tip -hi quartoCalloutCaution guibg=mpwb_callout_warning +hi mbnCalloutNote guibg=mpwb_callout_note +hi mbnCalloutWarning guibg=mpwb_callout_warning +hi mbnCalloutImportant guibg=mpwb_callout_important +hi mbnCalloutTip guibg=mpwb_callout_tip +hi mbnCalloutCaution guibg=mpwb_callout_warning diff --git a/vim/vim.xdg.symlink/vimrc b/vim/vim.xdg.symlink/vimrc index d514ea4..4ecce93 100644 --- a/vim/vim.xdg.symlink/vimrc +++ b/vim/vim.xdg.symlink/vimrc @@ -19,13 +19,11 @@ Plug 'tpope/vim-fugitive' Plug 'tpope/vim-repeat' Plug 'tpope/vim-surround' +Plug 'arthurxavierx/vim-caser' + Plug '/opt/homebrew/opt/fzf' Plug 'junegunn/fzf.vim' -Plug 'SirVer/ultisnips' -Plug 'dense-analysis/ale' -Plug 'prabirshrestha/asyncomplete.vim' - Plug 'vim-pandoc/vim-pandoc-syntax' Plug 'quarto-dev/quarto-vim' @@ -35,6 +33,12 @@ Plug 'elixir-editors/vim-elixir' Plug 'bullets-vim/bullets.vim' +Plug 'maxbucknell/vim-mbnotes' + +Plug 'SirVer/ultisnips' +Plug 'dense-analysis/ale' +Plug 'prabirshrestha/asyncomplete.vim' + plug#end() # Language config @@ -251,11 +255,23 @@ enddef # Notes config +g:mbnotes_dir = $HOME .. "/Dropbox (Maestral)/Notes" +g:mbnotes_out_dir = g:mbnotes_dir .. "/_output" +g:mbnotes_open_daily_on_startup = true +g:mbnotes_renderer_show = true +g:mbnotes_renderer_close_on_end = true + +nnoremap t :MBNotesDaily +nnoremap n :MBNotes +nnoremap :MBNotesNew +nnoremap :MBNotesNewSplit +nnoremap :vertical MBNotesNewSplit + g:markdown_fenced_languages = ['r', 'elixir', 'python', 'html', 'rust'] g:pandoc#syntax#codeblocks#embeds#langs = ['r', 'elixir', 'python', 'html', 'rust'] # Enable bullets.vim in Quarto files -g:bullets_enabled_file_types = ['markdown', 'text', 'gitcommit', 'quarto'] +g:bullets_enabled_file_types = ['markdown', 'text', 'gitcommit', 'quarto', 'mbnotes', 'mbnotes.quarto'] # Disable the bullet changing on indents (for now) g:bullets_outline_levels = ['num', 'std-'] @@ -324,13 +340,16 @@ def EditCodeBlock() # Set file type, if it is correctly annotated if @f != '`' - execute 'set filetype=' .. @f + @f = substitute(@f, "[\{\}]", "", "g") + execute 'setf=' .. @f endif set nomodified enddef -def SaveCodeBlock() +command -nargs=0 EditCodeBlock EditCodeBlock() + +def g:SaveCodeBlock() var b = bufnr("%") silent :%yank c normal! mc @@ -345,67 +364,25 @@ enddef augroup CodeBlocks autocmd! - autocmd BufWriteCmd *.codeblock SaveCodeBlock() + autocmd BufWriteCmd *.codeblock g:SaveCodeBlock() augroup END augroup Notes - # autocmd Filetype quarto setl tw=80 fo+=croqt ts=4 sts=4 sw=4 comments=n:> + autocmd! - # Surround mappings for Quarto callouts - autocmd FileType quarto b:surround_110 = "::: {.callout-note}\n\r\n:::" - autocmd FileType quarto b:surround_116 = "::: {.callout-tip}\n\r\n:::" - autocmd FileType quarto b:surround_119 = "::: {.callout-warning}\n\r\n:::" - autocmd FileType quarto b:surround_105 = "::: {.callout-important}\n\r\n:::" + autocmd FileType mbnotes imap =g:Ultisnips_expand("\") + autocmd FileType mbnotes imap - autocmd FileType quarto imap =g:Ultisnips_expand("\") - autocmd FileType quarto imap - - autocmd FileType quarto onoremap cb :execute "normal! /^```\rk$ms?^```\rj:noh\rv`s" - autocmd FileType quarto nnoremap ec EditCodeBlock() - autocmd FileType quarto inoremap EditCodeBlock() + autocmd FileType mbnotes onoremap cb :execute "normal! /^```\rk$ms?^```\rj:noh\rv`s" + autocmd FileType mbnotes nnoremap ec :EditCodeBlock + autocmd FileType mbnotes inoremap :EditCodeBlock augroup END nnoremap x :silent keepp s/^- \[ \]/- [o]/e:silent keepp s/^- \[x\]/- [ ]/e:silent keepp s/^- \[o\]/- [x]/e -# Daily notes -def FormatOffset(offset: number): string - if offset == 0 - return "" - elseif offset > 0 - return "-v+" .. offset .. "d " - else - return "-v" .. offset .. "d " - endif -enddef - -def OpenDailyNote(offset = 0) - var command = "date -v-4H " .. FormatOffset(offset) .. "\"+%Y-%m-%d\"" - var date = trim(system(command)) - var filename = $DAILY_NOTES_PATH .. "/" .. date .. "-daily.qmd" - - if !filereadable(filename) - var template = $DAILY_NOTES_PATH .. "/template.py" - - system(shellescape(template) .. " " .. shellescape(date) .. " > " .. shellescape(filename)) - endif - - execute "silent edit " .. filename -enddef - - -command -nargs=? Daily OpenDailyNote() - -def StartUp() - if @% == "" - OpenDailyNote() - endif -enddef - augroup StartUp autocmd! - autocmd VimEnter * ++nested StartUp() - autocmd VimResized * wincmd = augroup END @@ -452,6 +429,10 @@ augroup Completion autocmd! autocmd User asyncomplete_setup { + asyncomplete#register_source( + asyncomplete#sources#mbnotes#get_source_options({ 'priority': 9 }) + ) + asyncomplete#register_source( asyncomplete#sources#ale#get_source_options({ 'priority': 10 }) ) @@ -468,10 +449,11 @@ def PreviewQuarto() ClosePreview() echom 'Starting preview job' - b:file = expand('%') - b:preview_job = job_start( - \ ['quarto', 'preview', b:file], - \ ) + b:preview_job = job_start([ + 'quarto', + 'preview', + expand('%') + ]) enddef def ClosePreview()