refacotred and split
This commit is contained in:
32
autoload/denote/commands.vim
Normal file
32
autoload/denote/commands.vim
Normal file
@@ -0,0 +1,32 @@
|
||||
" This function is used to autocomplete the tags in user commands.
|
||||
function s:tagList(ArgLead, cmdLine, CursorPos)
|
||||
let files=glob(g:denote_directory .. "/*", 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
|
||||
|
||||
|
||||
" Public commands
|
||||
function denote#commands#load()
|
||||
if exists('g:denote_commands_loaded') && g:denote_commands_loaded
|
||||
return
|
||||
endif
|
||||
" Register user commands
|
||||
command -nargs=* Denote call denote#notes#list(<q-args>) | lcl | lw
|
||||
command -nargs=1 -complete=custom,s:tagList DenoteByTag call denote#notes#bytag(<q-args>) | lcl | lw
|
||||
command -nargs=+ DenoteGrep call denote#notes#grep(<q-args>) | lcl | lw
|
||||
command -nargs=1 DenoteNew call denote#notes#new(<q-args>)
|
||||
|
||||
" Register auto commands
|
||||
autocmd BufReadPost quickfix call denote#ft#qf()
|
||||
let l:aupat = map(copy(g:denote_note_file_extensions), {_, v -> '*.' .. v})->join(',')
|
||||
exe 'autocmd BufReadPost ' .. l:aupat .. ' call denote#ft#denote()'
|
||||
|
||||
" Useful key mappings
|
||||
" nnoremap <silent> <Plug>DenoteList :DenoteSearch<CR>:lclose<CR>:lopen<CR>:resize 20<CR>
|
||||
" nnoremap <silent> <Plug>DenoteBackReferences :DenoteBackReferences<CR>:lclose<CR>:lopen<CR>:resize 20<CR>
|
||||
let g:denote_commands_loaded = v:true
|
||||
endfunction
|
||||
@@ -24,7 +24,7 @@ endfunction
|
||||
" Return completion items given by the base
|
||||
function s:suggestions(base)
|
||||
let prefix = a:base->matchstr('^denote:\zs.*$')
|
||||
let flist = glob(t:denote_directory .. (prefix ? "*" .. prefix .. "*" : "*"), 0, v:true)
|
||||
let flist = glob(g:denote_directory .. "/" .. (prefix ? "*" .. prefix .. "*" : "*"), 0, v:true)
|
||||
let res = []
|
||||
for filename in flist
|
||||
let noteId = denote#meta#noteIdFromFile(filename)
|
||||
|
||||
40
autoload/denote/ft.vim
Normal file
40
autoload/denote/ft.vim
Normal file
@@ -0,0 +1,40 @@
|
||||
" Go to file command |gf| adjustments
|
||||
" This resolves denote links. The function has access to the variable v:fname,
|
||||
" which corresponds to the filename under the cursor.
|
||||
function s:gotofile()
|
||||
return v:fname !~ "^denote:"
|
||||
\ ? v:fname
|
||||
\ : denote#meta#fileFromNoteId(v:fname[7:]) ?? v:fname
|
||||
endfunction
|
||||
|
||||
" Denote note specifics
|
||||
function denote#ft#denote()
|
||||
if expand('%:p:h') != g:denote_directory
|
||||
return
|
||||
endif
|
||||
" Link completion
|
||||
setlocal omnifunc=denote#completion#get
|
||||
" Denote links are of the form 'denote:<note id>'; we require the column.
|
||||
setlocal isfname+=:
|
||||
" Set the function to resolve the filename under the cursor (see |gf|).
|
||||
setlocal includeexpr=s:gotofile()
|
||||
" Back references command
|
||||
let l:noteid = denote#meta#noteIdFromFile(expand("%:t"))
|
||||
exe 'command! DenoteBackReferences DenoteGrep /\<denote:' .. l:noteid .. '\>/gj'
|
||||
endfunction
|
||||
|
||||
" Location-list specifics
|
||||
"
|
||||
" This will be called for every location and quickfix, when data is loaded into
|
||||
" the list. This does nothing for such lists that are note 'denote' lists.
|
||||
function denote#ft#qf()
|
||||
if getloclist(0, {'context': 1})['context'] != 'denote'
|
||||
" Clear settings
|
||||
set spell<
|
||||
nmapclear <buffer>
|
||||
" nunmap <buffer> q
|
||||
return
|
||||
endif
|
||||
setlocal nospell
|
||||
nnoremap <buffer> q :lclose<CR>
|
||||
endfunction
|
||||
@@ -51,13 +51,8 @@ endfunction
|
||||
|
||||
" Load all references to the given note into the location list.
|
||||
function denote#loclist#references(noteId)
|
||||
if !exists('t:denote_directory')
|
||||
echohl WarningMsg
|
||||
echom "Denote directory not specified, see |vim-denote|."
|
||||
return
|
||||
endif
|
||||
" Populate location list
|
||||
silent! execute "lvimgrep /\\<denote:" .. a:noteId .. "\\>/gj " .. t:denote_directory .. "*"
|
||||
silent! execute "lvimgrep /\\<denote:" .. a:noteId .. "\\>/gj " .. g:denote_directory .. "/*"
|
||||
" Adjust location list: set title and specify display function
|
||||
let file=denote#meta#fileFromNoteId(a:noteId)
|
||||
let noteTitle=denote#meta#noteTitleFromFile(file)
|
||||
@@ -65,3 +60,31 @@ function denote#loclist#references(noteId)
|
||||
\ {'title': 'References to ' .. noteTitle .. ' (' .. a:noteId .. ')',
|
||||
\ 'quickfixtextfunc' : 'denote#loclist#textReferences'})
|
||||
endfunction
|
||||
|
||||
" Re-populate location list with denote entries
|
||||
function denote#loclist#fill(title, files)
|
||||
" Clear first
|
||||
call setloclist(0, [], ' ')
|
||||
" Set properties
|
||||
call setloclist(0, [], 'r',
|
||||
\ {'title': a:title,
|
||||
\ 'quickfixtextfunc' : 'denote#loclist#textNoteList',
|
||||
\ 'context' : 'denote'})
|
||||
" Populate
|
||||
let l:notes=[]
|
||||
for f in a:files
|
||||
call add(l:notes, {
|
||||
\ 'filename' : f,
|
||||
\ 'lnum' : 1
|
||||
\ })
|
||||
endfor
|
||||
call setloclist(0, l:notes, 'a')
|
||||
endfunction
|
||||
|
||||
" Specify location list as denote-grep list
|
||||
function denote#loclist#setgrep(title)
|
||||
call setloclist(0, [], 'r',
|
||||
\ {'title': a:title,
|
||||
\ 'quickfixtextfunc' : 'denote#loclist#textReferences',
|
||||
\ 'context' : 'denote'})
|
||||
endfunction
|
||||
|
||||
@@ -10,7 +10,7 @@ function denote#meta#fileFromNoteId(noteId)
|
||||
" (A) First, we get all files that contain the note id as substring.
|
||||
" (B) Then we ensure that the note id is followed by another field or by the
|
||||
" file extension.
|
||||
let files = glob(t:denote_directory .. "*" .. a:noteId .. "*", 0, v:true)
|
||||
let files = glob(g:denote_directory .. "/*" .. a:noteId .. "*", 0, v:true)
|
||||
\ ->filter('v:val->split("/")[-1] =~ "' .. a:noteId .. '\\(==\\|--\\|__\\|\\.\\)"')
|
||||
\ ->filter('v:val->split("/")[-1] =~ "^' .. a:noteId .. '\\|@@' .. a:noteId .. '"')
|
||||
return empty(files) ? v:false : files[0]
|
||||
|
||||
40
autoload/denote/notes.vim
Normal file
40
autoload/denote/notes.vim
Normal file
@@ -0,0 +1,40 @@
|
||||
" 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 denote#notes#list(search)
|
||||
let l:s = substitute(" " .. a:search .. " ", " ", "*", "g")
|
||||
let l:files = glob(g:denote_directory .. "/" .. l:s, 0, v:true)
|
||||
let l:title = "Denote notes search:" .. a:search
|
||||
call denote#loclist#fill(l:title, l:files)
|
||||
endfunction
|
||||
|
||||
" Put all notes of the given tag to the location list. The tag argument is
|
||||
" mandatory.
|
||||
function denote#notes#bytag(tag)
|
||||
let files = glob(g:denote_directory .. "/*_" .. a:tag .. "*", 0, v:true)->filter('v:val->split("/")[-1] =~ "_' .. a:tag .. '\\(==\\|@@\\|__\\|_\\|\\.\\)"')
|
||||
let l:title = "Denote notes: " .. a:tag
|
||||
call denote#loclist#fill(l:title, l:files)
|
||||
endfunction
|
||||
|
||||
" Search in denote notes
|
||||
function denote#notes#grep(re)
|
||||
let l:title = "Grep results for: " .. a:re
|
||||
let fpat=map(copy(g:denote_note_file_extensions), {_, e -> g:denote_directory .. "/*." .. e})->join()
|
||||
execute "silent! lvimgrep " .. a:re .. " " .. fpat
|
||||
call denote#loclist#setgrep(l:title)
|
||||
endfunction
|
||||
|
||||
" This creates a new denote entry with the given title and of the given
|
||||
" filetype. The title may be empty.
|
||||
function denote#notes#new(title, ft=g:denote_new_ft)
|
||||
let identifier=denote#meta#identifier_generate()
|
||||
let fn=identifier .. '--' .. a:title
|
||||
\ ->tolower()
|
||||
\ ->substitute('[^[:fname:]]\|/', '-', 'g')
|
||||
\ ->substitute('-\+', '-', 'g')
|
||||
\ ->substitute('_\+', '_', 'g')
|
||||
\ ->substitute('=\+', '=', 'g')
|
||||
\ ->substitute('@\+', '@', 'g')
|
||||
\ ->trim('-_@=') .. '.' .. a:ft
|
||||
execute "edit " .. g:denote_directory .. "/" .. fn
|
||||
call setline(1, denote#frontmatter#new(a:ft, identifier, a:title))
|
||||
endfunction
|
||||
Reference in New Issue
Block a user