Compare commits
3 Commits
7a82fe32db
...
55bbeecb0a
| Author | SHA1 | Date | |
|---|---|---|---|
| 55bbeecb0a | |||
| 553cf41c96 | |||
| 864b678b9e |
@@ -15,9 +15,9 @@ function denote#commands#load()
|
|||||||
return
|
return
|
||||||
endif
|
endif
|
||||||
" Register user commands
|
" Register user commands
|
||||||
command -nargs=* Denote call denote#notes#list(<q-args>) | lcl | lw
|
command -nargs=* Denote call denote#notes#list(<q-args>) | lcl | lopen
|
||||||
command -nargs=1 -complete=custom,s:tagList DenoteByTag call denote#notes#bytag(<q-args>) | lcl | lw
|
command -nargs=1 -complete=custom,s:tagList DenoteByTag call denote#notes#bytag(<q-args>) | lcl | lopen
|
||||||
command -nargs=+ DenoteGrep call denote#notes#grep(<q-args>) | lcl | lw
|
command -nargs=+ DenoteGrep call denote#notes#grep(<q-args>) | lcl | lopen
|
||||||
command -nargs=1 DenoteNew call denote#notes#new(<q-args>)
|
command -nargs=1 DenoteNew call denote#notes#new(<q-args>)
|
||||||
|
|
||||||
" Register auto commands
|
" Register auto commands
|
||||||
@@ -30,3 +30,9 @@ function denote#commands#load()
|
|||||||
" nnoremap <silent> <Plug>DenoteBackReferences :DenoteBackReferences<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
|
let g:denote_commands_loaded = v:true
|
||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
|
" Public commands for the denote-list location list
|
||||||
|
function denote#commands#loadll()
|
||||||
|
command DenoteReload call denote#
|
||||||
|
" command -nargs=1 DenoteSetTitle call denote#notes#settitle(<q-args>)
|
||||||
|
endfunction
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
" Functions to create the front matter
|
" Functions to manipulate and query the front matter
|
||||||
|
|
||||||
" Helper function to put string in double quotes, and remove inside double
|
" Helper function to put string in double quotes, and remove inside double
|
||||||
" quotes.
|
" quotes.
|
||||||
function s:escapeDQ(s)
|
function s:escapeDQ(s)
|
||||||
@@ -57,3 +58,21 @@ function denote#frontmatter#new(ft, id, title, tags=[])
|
|||||||
\ : g:denote_fm_md_type == 'toml' ? s:md_new_toml(a:id, a:title, a:tags)
|
\ : g:denote_fm_md_type == 'toml' ? s:md_new_toml(a:id, a:title, a:tags)
|
||||||
\ : s:md_new_yaml(a:id, a:title, a:tags)
|
\ : s:md_new_yaml(a:id, a:title, a:tags)
|
||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
|
" Return the frontmatter of the specified file (as a list)
|
||||||
|
function s:getFrontmatter(filename)
|
||||||
|
let l:ft = fnamemodify(a:filename, ':e')
|
||||||
|
let l:cnt = l:ft == 'org' ? 4
|
||||||
|
\ : l:ft == 'txt' ? 5
|
||||||
|
\ : 6
|
||||||
|
call bufload(a:filename)
|
||||||
|
return getbufline(a:filename, 1, 1 + l:cnt)
|
||||||
|
endfunction
|
||||||
|
|
||||||
|
" Get title from front matter
|
||||||
|
function denote#frontmatter#setTitle(filename, title)
|
||||||
|
" Retrieve front matter (number of lines depends on ft), and replace title
|
||||||
|
let l:frontmatter = s:getFrontmatter(a:filename)
|
||||||
|
call map(l:frontmatter, { _, v -> substitute(v, '^#\?+\?title:\?\s*"\?\zs.\{-\}\ze\"\?$', a:title, '')})
|
||||||
|
call setbufline(a:filename, 1, l:frontmatter)
|
||||||
|
endfunction
|
||||||
|
|||||||
@@ -20,7 +20,7 @@ function denote#ft#denote()
|
|||||||
setlocal includeexpr=s:gotofile()
|
setlocal includeexpr=s:gotofile()
|
||||||
" Back references command
|
" Back references command
|
||||||
let l:noteid = denote#meta#noteIdFromFile(expand('%:t'))
|
let l:noteid = denote#meta#noteIdFromFile(expand('%:t'))
|
||||||
exe 'command! DenoteBackReferences DenoteGrep /\<denote:' .. l:noteid .. '\>/gj'
|
exe 'command! -buffer DenoteBackReferences DenoteGrep /\<denote:' .. l:noteid .. '\>/gj'
|
||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
" Location-list specifics
|
" Location-list specifics
|
||||||
@@ -28,7 +28,8 @@ endfunction
|
|||||||
" This will be called for every location and quickfix, when data is loaded into
|
" 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.
|
" the list. This does nothing for such lists that are note 'denote' lists.
|
||||||
function denote#ft#qf()
|
function denote#ft#qf()
|
||||||
if getloclist(0, {'context': 1})['context'] != 'denote'
|
let l:context = getloclist(0, {'context': 1})['context']
|
||||||
|
if type(l:context) != v:t_dict || !has_key(l:context, 'denote')
|
||||||
" Clear settings
|
" Clear settings
|
||||||
set spell<
|
set spell<
|
||||||
nmapclear <buffer>
|
nmapclear <buffer>
|
||||||
@@ -36,4 +37,11 @@ function denote#ft#qf()
|
|||||||
endif
|
endif
|
||||||
setlocal nospell
|
setlocal nospell
|
||||||
nnoremap <buffer> q :lclose<CR>
|
nnoremap <buffer> q :lclose<CR>
|
||||||
|
if has_key(l:context, 'gfun')
|
||||||
|
nnoremap <buffer> <silent> r :call denote#loclist#reload()<CR>
|
||||||
|
endif
|
||||||
|
" Denote-list specific configuration
|
||||||
|
if l:context['denote'] == 'list'
|
||||||
|
command! -nargs=1 -range -buffer DenoteSetTitle :call denote#notes#settitle(<line1>, <q-args>)
|
||||||
|
endif
|
||||||
endfunction
|
endfunction
|
||||||
|
|||||||
@@ -50,14 +50,14 @@ endfor
|
|||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
" Re-populate location list with denote entries
|
" Re-populate location list with denote entries
|
||||||
function denote#loclist#fill(title, files)
|
function denote#loclist#fill(title, files, Gfun)
|
||||||
" Clear first
|
" Clear first
|
||||||
call setloclist(0, [], ' ')
|
call setloclist(0, [], ' ')
|
||||||
" Set properties
|
" Set properties
|
||||||
call setloclist(0, [], 'r',
|
call setloclist(0, [], 'r',
|
||||||
\ {'title': a:title,
|
\ {'title': a:title,
|
||||||
\ 'quickfixtextfunc' : 'denote#loclist#textNoteList',
|
\ 'quickfixtextfunc' : 'denote#loclist#textNoteList',
|
||||||
\ 'context' : 'denote'})
|
\ 'context' : {'denote': 'list', 'gfun': a:Gfun}})
|
||||||
" Populate
|
" Populate
|
||||||
let l:notes=[]
|
let l:notes=[]
|
||||||
for f in a:files
|
for f in a:files
|
||||||
@@ -70,9 +70,34 @@ function denote#loclist#fill(title, files)
|
|||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
" Specify location list as denote-grep list
|
" Specify location list as denote-grep list
|
||||||
function denote#loclist#setgrep(title)
|
function denote#loclist#setgrep(title, Gfun)
|
||||||
call setloclist(0, [], 'r',
|
call setloclist(0, [], 'r',
|
||||||
\ {'title': a:title,
|
\ {'title': a:title,
|
||||||
\ 'quickfixtextfunc' : 'denote#loclist#textReferences',
|
\ 'quickfixtextfunc' : 'denote#loclist#textReferences',
|
||||||
\ 'context' : 'denote'})
|
\ 'context' : {'denote': 'grep', 'gfun': a:Gfun}})
|
||||||
|
endfunction
|
||||||
|
|
||||||
|
" Reload location list
|
||||||
|
function denote#loclist#reload()
|
||||||
|
let l:context = getloclist(0, {'context': 1})['context']
|
||||||
|
if has_key(l:context, 'denote') && has_key(l:context, 'gfun')
|
||||||
|
execute ':lclose'
|
||||||
|
call l:context['gfun']()
|
||||||
|
execute ':lwindow'
|
||||||
|
endif
|
||||||
|
endfunction
|
||||||
|
|
||||||
|
" Jump to window this location list belongs to
|
||||||
|
function denote#loclist#jumptowindow()
|
||||||
|
let l:locprop = getloclist(0, {'filewinid': 0})
|
||||||
|
if type(l:locprop) != v:t_dict || !has_key(l:locprop, 'filewinid')
|
||||||
|
return
|
||||||
|
endif
|
||||||
|
let l:winid = l:locprop['filewinid']
|
||||||
|
if l:winid == 0
|
||||||
|
exe 'new'
|
||||||
|
exe 'wincmd K'
|
||||||
|
else
|
||||||
|
call win_gotoid(l:winid)
|
||||||
|
endif
|
||||||
endfunction
|
endfunction
|
||||||
|
|||||||
@@ -25,12 +25,22 @@ endfunction
|
|||||||
|
|
||||||
" Return the note title from the filename.
|
" Return the note title from the filename.
|
||||||
function denote#meta#noteTitleFromFile(file)
|
function denote#meta#noteTitleFromFile(file)
|
||||||
return a:file->fnamemodify(':t')->matchstr('--\zs.\{-\}\ze\(==\|@@\|__\|\..\)')->substitute('-', ' ', 'g')
|
return a:file->fnamemodify(':t')
|
||||||
|
\ ->matchstr('--\zs.\{-\}\ze\(==\|@@\|__\|\..\)')
|
||||||
|
\ ->substitute('-', ' ', 'g')
|
||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
" Return the note tags from the filename as a list.
|
" Return the note tags from the filename as a list.
|
||||||
function denote#meta#noteTagsFromFile(file)
|
function denote#meta#noteTagsFromFile(file)
|
||||||
return a:file->fnamemodify(':t')->matchstr('__\zs.\{-\}\ze\(==\|@@\|--\|\..\)')->split('_')
|
return a:file->fnamemodify(':t')
|
||||||
|
\ ->matchstr('__\zs.\{-\}\ze\(==\|@@\|--\|\..\)')
|
||||||
|
\ ->split('_')
|
||||||
|
endfunction
|
||||||
|
|
||||||
|
" Return the note signature from the filename.
|
||||||
|
function denote#meta#noteSignatureFromFile(file)
|
||||||
|
return a:file->fnamemodify(':t')
|
||||||
|
\ ->matchstr('==\zs.\{-\}\ze\(==\|@@\|__\|\..\)')
|
||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
" Identifier creation
|
" Identifier creation
|
||||||
@@ -39,3 +49,24 @@ function denote#meta#identifier_generate()
|
|||||||
\ ? strftime('%Y%m%dT%H%M%S')
|
\ ? strftime('%Y%m%dT%H%M%S')
|
||||||
\ : rand()
|
\ : rand()
|
||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
|
" This function removes illegal characters in parts of the filename.
|
||||||
|
function s:santizefnpart(part)
|
||||||
|
return a:part->tolower()
|
||||||
|
\ ->substitute('[^[:alnum:]]', '-', 'g')
|
||||||
|
\ ->substitute('-\+', '-', 'g')
|
||||||
|
\ ->substitute('_\+', '_', 'g')
|
||||||
|
\ ->substitute('=\+', '=', 'g')
|
||||||
|
\ ->substitute('@\+', '@', 'g')
|
||||||
|
\ ->trim('-_@=')
|
||||||
|
endfunction
|
||||||
|
|
||||||
|
" Function that returns the filename give all metadata. The filename is
|
||||||
|
" returned with the path to the denote directory.
|
||||||
|
function denote#meta#filename(ext, identifier, title='', tags=[], signature='')
|
||||||
|
let l:f = g:denote_directory .. '/' .. s:santizefnpart(a:identifier)
|
||||||
|
let l:f ..= len(a:signature) > 0 ? ('==' .. s:santizefnpart(a:signature)) : ''
|
||||||
|
let l:f ..= len(a:title) > 0 ? ('--' .. s:santizefnpart(a:title)) : ''
|
||||||
|
let l:f ..= len(a:tags) > 0 ? ('__' .. map(copy(a:tags), {_, v -> s:santizefnpart(v)})->join('_')) : ''
|
||||||
|
return l:f .. '.' .. a:ext
|
||||||
|
endfunction
|
||||||
|
|||||||
@@ -4,7 +4,8 @@ function denote#notes#list(search)
|
|||||||
let l:s = substitute(' ' .. a:search .. ' ', ' ', '*', 'g')
|
let l:s = substitute(' ' .. a:search .. ' ', ' ', '*', 'g')
|
||||||
let l:files = glob(g:denote_directory .. '/' .. l:s, 0, v:true)
|
let l:files = glob(g:denote_directory .. '/' .. l:s, 0, v:true)
|
||||||
let l:title = 'Denote notes search:' .. a:search
|
let l:title = 'Denote notes search:' .. a:search
|
||||||
call denote#loclist#fill(l:title, l:files)
|
let l:Gfun = function('denote#notes#list', [a:search])
|
||||||
|
call denote#loclist#fill(l:title, l:files, l:Gfun)
|
||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
" Put all notes of the given tag to the location list. The tag argument is
|
" Put all notes of the given tag to the location list. The tag argument is
|
||||||
@@ -12,7 +13,8 @@ endfunction
|
|||||||
function denote#notes#bytag(tag)
|
function denote#notes#bytag(tag)
|
||||||
let l:files = glob(g:denote_directory .. '/*_' .. a:tag .. '*', 0, v:true)->filter('v:val->split("/")[-1] =~ "_' .. a:tag .. '\\(==\\|@@\\|__\\|_\\|\\.\\)"')
|
let l:files = glob(g:denote_directory .. '/*_' .. a:tag .. '*', 0, v:true)->filter('v:val->split("/")[-1] =~ "_' .. a:tag .. '\\(==\\|@@\\|__\\|_\\|\\.\\)"')
|
||||||
let l:title = 'Denote notes: ' .. a:tag
|
let l:title = 'Denote notes: ' .. a:tag
|
||||||
call denote#loclist#fill(l:title, l:files)
|
let l:Gfun = function('denote#notes#bytag', [a:tag])
|
||||||
|
call denote#loclist#fill(l:title, l:files, l:Gfun)
|
||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
" Search in denote notes
|
" Search in denote notes
|
||||||
@@ -20,21 +22,53 @@ function denote#notes#grep(re)
|
|||||||
let l:title = 'Grep results for: ' .. a:re
|
let l:title = 'Grep results for: ' .. a:re
|
||||||
let l:fpat=map(copy(g:denote_note_file_extensions), {_, e -> g:denote_directory .. '/*.' .. e})->join()
|
let l:fpat=map(copy(g:denote_note_file_extensions), {_, e -> g:denote_directory .. '/*.' .. e})->join()
|
||||||
execute 'silent! lvimgrep ' .. a:re .. ' ' .. l:fpat
|
execute 'silent! lvimgrep ' .. a:re .. ' ' .. l:fpat
|
||||||
call denote#loclist#setgrep(l:title)
|
let l:Gfun = function('denote#notes#grep', [a:re])
|
||||||
|
call denote#loclist#setgrep(l:title, l:Gfun)
|
||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
" This creates a new denote entry with the given title and of the given
|
" This creates a new denote entry with the given title and of the given
|
||||||
" filetype. The title may be empty.
|
" filetype. The title may be empty.
|
||||||
function denote#notes#new(title, ft=g:denote_new_ft)
|
function denote#notes#new(title, ft=g:denote_new_ft)
|
||||||
let l:identifier=g:Denote_identifier_fun()
|
let l:identifier = g:Denote_identifier_fun()
|
||||||
let l:fn=l:identifier .. '--' .. a:title
|
let l:fn = denote#meta#filename(a:ft, l:identifier, a:title)
|
||||||
\ ->tolower()
|
" Jump to window this location list belongs to
|
||||||
\ ->substitute('[^[:fname:]]\|/', '-', 'g')
|
call denote#loclist#jumptowindow()
|
||||||
\ ->substitute('-\+', '-', 'g')
|
" Open file and write front matter
|
||||||
\ ->substitute('_\+', '_', 'g')
|
execute 'edit ' l:fn
|
||||||
\ ->substitute('=\+', '=', 'g')
|
|
||||||
\ ->substitute('@\+', '@', 'g')
|
|
||||||
\ ->trim('-_@=') .. '.' .. a:ft
|
|
||||||
execute 'edit ' .. g:denote_directory .. '/' .. l:fn
|
|
||||||
call setline(1, denote#frontmatter#new(a:ft, l:identifier, a:title))
|
call setline(1, denote#frontmatter#new(a:ft, l:identifier, a:title))
|
||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
|
" Function to set the title of the selected entry
|
||||||
|
function denote#notes#settitle(linenr, title)
|
||||||
|
" Get file first!
|
||||||
|
let l:items = getloclist(0, {'items': 1})['items']
|
||||||
|
if empty(l:items)
|
||||||
|
return
|
||||||
|
endif
|
||||||
|
let l:item = l:items[a:linenr-1]
|
||||||
|
let l:bufnr = l:item['bufnr']
|
||||||
|
let l:filename = bufname(l:bufnr)
|
||||||
|
let l:noteid = denote#meta#noteIdFromFile(l:filename)
|
||||||
|
let l:notetags = denote#meta#noteTagsFromFile(l:filename)
|
||||||
|
let l:notesignature = denote#meta#noteSignatureFromFile(l:filename)
|
||||||
|
let l:oldtitle = denote#meta#noteTitleFromFile (l:filename)
|
||||||
|
let l:ext = fnamemodify(l:filename, ':e')
|
||||||
|
let l:newfilename = denote#meta#filename(l:ext, l:noteid, a:title, l:notetags, l:notesignature)
|
||||||
|
" If this note has a front matter, we rewrite the front matter and rename the
|
||||||
|
" file. Otherwise, we rename the file only.
|
||||||
|
if index(g:denote_note_file_extensions, l:ext) >= 0
|
||||||
|
" Handle front matter
|
||||||
|
call denote#frontmatter#setTitle(l:filename, a:title)
|
||||||
|
call denote#loclist#jumptowindow()
|
||||||
|
exe l:bufnr .. 'buf'
|
||||||
|
exe 'silent file ' .. l:newfilename
|
||||||
|
exe 'silent w'
|
||||||
|
exe 'lopen'
|
||||||
|
call delete(l:filename)
|
||||||
|
else
|
||||||
|
if fnamemodify(l:filename, ':t') == fnamemodify(l:newfilename, ':t')
|
||||||
|
return
|
||||||
|
endif
|
||||||
|
call rename(l:filename, l:newfilename)
|
||||||
|
endif
|
||||||
|
endfunction
|
||||||
|
|||||||
@@ -8,6 +8,7 @@ CONTENTS *vim-denote* *denote*
|
|||||||
1. Introduction |denote-intro|
|
1. Introduction |denote-intro|
|
||||||
2. Commands |denote-commands|
|
2. Commands |denote-commands|
|
||||||
3. Settings |denote-settings|
|
3. Settings |denote-settings|
|
||||||
|
4. Keys |denote-keys|
|
||||||
|
|
||||||
==============================================================================
|
==============================================================================
|
||||||
*denote-intro*
|
*denote-intro*
|
||||||
@@ -143,4 +144,16 @@ generator and to specify, e.g.,
|
|||||||
<
|
<
|
||||||
|
|
||||||
|
|
||||||
|
*denote-keys*
|
||||||
|
Keys ~
|
||||||
|
|
||||||
|
The location windows generated by the present package, e.g., through the
|
||||||
|
command |:DenoteGrep| or |:DenoteByTag|, has the following key key-bindings.
|
||||||
|
|
||||||
|
*denote-r*
|
||||||
|
r Reload the location list.
|
||||||
|
|
||||||
|
*denote-q*
|
||||||
|
q Close the location list.
|
||||||
|
|
||||||
vim:tw=78:sw=4:ts=8:noet:ft=help:norl:
|
vim:tw=78:sw=4:ts=8:noet:ft=help:norl:
|
||||||
|
|||||||
Reference in New Issue
Block a user