123 lines
3.9 KiB
VimL
123 lines
3.9 KiB
VimL
" Global configurations {{{1
|
|
|
|
" Restrict basic operations to these files:
|
|
if !exists('g:denote_note_file_extensions')
|
|
let g:denote_note_file_extensions=['md', 'org', 'txt']
|
|
endif
|
|
|
|
" Number of columns used for the title in the location window.
|
|
if !exists('g:denote_loc_title_columns')
|
|
let g:denote_loc_title_columns=40
|
|
endif
|
|
|
|
" Default filetype for newly created denote entries
|
|
if !exists('g:denote_new_ft')
|
|
let g:denote_new_ft='md'
|
|
endif
|
|
|
|
" Default front-matter type for markdown notes, may be one of 'yaml' or 'toml'
|
|
if !exists('g:denote_fm_md_type')
|
|
let g:denote_fm_md_type='yaml'
|
|
endif
|
|
|
|
" By using the following global variable, the user may specify a custom
|
|
" function for creating identifiers.
|
|
if !exists('g:denote_identifier_fun')
|
|
let g:denote_identifier_fun=''
|
|
endif
|
|
|
|
" Local functions {{{1
|
|
" Put all notes of the given tag to the location list. The tag argument is
|
|
" mandatory.
|
|
function s:DenoteNotesByTag(tag)
|
|
" Clear location list
|
|
call denote#loclist#clear()
|
|
" Find files
|
|
let files = glob("*_" .. a:tag .. "*", 0, v:true)->filter('v:val =~ "_' .. a:tag .. '\\(==\\|@@\\|__\\|_\\|\\.\\)"')
|
|
" Populate location list
|
|
let locTitle="Denote notes: " .. a:tag
|
|
call setloclist(0, [], 'r',
|
|
\ {'title': locTitle,
|
|
\ 'quickfixtextfunc' : 'denote#loclist#textNoteList'})
|
|
let notes=[]
|
|
for f in files
|
|
call add(notes, {
|
|
\ 'filename' : f,
|
|
\ 'lnum' : 1
|
|
\ })
|
|
endfor
|
|
call setloclist(0, notes, 'a')
|
|
endfunction
|
|
|
|
" Put all notes of the given tag to the location list. The search argument may be
|
|
" empty. For improving search, white spaces are replaced by the * |wildcard|.
|
|
function s:DenoteNotes(search)
|
|
let s = substitute(" " .. a:search .. " ", " ", "*", "g")
|
|
" Clear location list
|
|
call denote#loclist#clear()
|
|
" Find files
|
|
let files = glob(s, 0, v:true)
|
|
" Populate location list
|
|
let locTitle="Denote notes search:" .. a:search
|
|
call setloclist(0, [], 'r',
|
|
\ {'title': locTitle,
|
|
\ 'quickfixtextfunc' : 'denote#loclist#textNoteList'})
|
|
let notes=[]
|
|
for f in files
|
|
call add(notes, {
|
|
\ 'filename' : f,
|
|
\ 'lnum' : 1
|
|
\ })
|
|
endfor
|
|
call setloclist(0, notes, 'a')
|
|
endfunction
|
|
|
|
" This function implements the similar functionality of :vimgrep, but for
|
|
" denote notes.
|
|
function s:DenoteGrep(search)
|
|
" Clear location list
|
|
call denote#loclist#clear()
|
|
" Grep all greppable files
|
|
let fpat=map(copy(g:denote_note_file_extensions), {_, e -> "*." .. e})->join()
|
|
execute "lvimgrep " .. a:search .. " " .. fpat
|
|
" Adjust location list: set title and specify display function
|
|
call setloclist(0, [], 'r',
|
|
\ {'title': 'Denote grep: ' .. a:search,
|
|
\ 'quickfixtextfunc' : 'denote#loclist#textReferences'})
|
|
lclose
|
|
lopen
|
|
endfunction
|
|
|
|
" This function is used to autocomplete the tags in user commands.
|
|
function s:tagList(ArgLead, cmdLine, CursorPos)
|
|
let files=glob("*", 0, v:true)
|
|
let tags=[]
|
|
for f in files
|
|
let tags=extend(tags, denote#meta#noteTagsFromFile(f))
|
|
endfor
|
|
return uniq(sort(tags))->join("\n")
|
|
endfunction
|
|
|
|
" This creates a new denote entry with the given title and of the given
|
|
" filetype. The title may be empty.
|
|
function s:DenoteNew(title, ft=g:denote_new_ft)
|
|
let identifier=denote#meta#identifier_generate()
|
|
let fn=identifier .. '--' .. a:title
|
|
\ ->tolower()
|
|
\ ->substitute('[^[:fname:]]\|/', '-', 'g')
|
|
\ ->substitute('-\+', '-', 'g')
|
|
\ ->trim('-') .. '.' .. a:ft
|
|
execute "edit " .. fn
|
|
call setline(1, denote#frontmatter#new(a:ft, identifier, a:title))
|
|
endfunction
|
|
|
|
" Public commands and key mappings {{{1
|
|
command -nargs=* Denote :call <SID>DenoteNotes(<q-args>)
|
|
command -nargs=1 -complete=custom,<SID>tagList DenoteTag :call <SID>DenoteNotesByTag(<q-args>)
|
|
command -nargs=+ DenoteGrep :call <SID>DenoteGrep(<q-args>)
|
|
command -nargs=1 DenoteNew :call <SID>DenoteNew(<q-args>)
|
|
|
|
" Useful key mappings
|
|
nnoremap <silent> <Plug>DenoteList :Denote<CR>:lclose<CR>:lopen<CR>:resize 20<CR>
|
|
nnoremap <silent> <Plug>DenoteBackReferences :DenoteBackReferences<CR>:lclose<CR>:lopen<CR>:resize 20<CR>
|