functionality to add new notes
This commit is contained in:
@@ -10,6 +10,22 @@ 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.
|
||||
@@ -82,10 +98,24 @@ function s:tagList(ArgLead, cmdLine, CursorPos)
|
||||
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>
|
||||
|
||||
Reference in New Issue
Block a user