rename notes/and files

This commit is contained in:
2026-02-27 21:57:19 +01:00
parent 553cf41c96
commit 55bbeecb0a
6 changed files with 121 additions and 25 deletions

View File

@@ -29,15 +29,46 @@ 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 l:identifier=g:Denote_identifier_fun()
let l:fn=l:identifier .. '--' .. a:title
\ ->tolower()
\ ->substitute('[^[:fname:]]\|/', '-', 'g')
\ ->substitute('-\+', '-', 'g')
\ ->substitute('_\+', '_', 'g')
\ ->substitute('=\+', '=', 'g')
\ ->substitute('@\+', '@', 'g')
\ ->trim('-_@=') .. '.' .. a:ft
execute 'edit ' .. g:denote_directory .. '/' .. l:fn
let l:identifier = g:Denote_identifier_fun()
let l:fn = denote#meta#filename(a:ft, l:identifier, a:title)
" Jump to window this location list belongs to
call denote#loclist#jumptowindow()
" Open file and write front matter
execute 'edit ' l:fn
call setline(1, denote#frontmatter#new(a:ft, l:identifier, a:title))
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