code: cleaned up

This commit is contained in:
2026-02-25 16:11:35 +01:00
parent ba939661c7
commit 2015c0e32c
7 changed files with 76 additions and 89 deletions

View File

@@ -1,33 +1,33 @@
" 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
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
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
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
let l:title = 'Grep results for: ' .. a:re
let l:fpat=map(copy(g:denote_note_file_extensions), {_, e -> g:denote_directory .. '/*.' .. e})->join()
execute 'silent! lvimgrep ' .. a:re .. ' ' .. l: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
let l:identifier=denote#meta#identifier_generate()
let l:fn=l:identifier .. '--' .. a:title
\ ->tolower()
\ ->substitute('[^[:fname:]]\|/', '-', 'g')
\ ->substitute('-\+', '-', 'g')
@@ -35,6 +35,6 @@ function denote#notes#new(title, ft=g:denote_new_ft)
\ ->substitute('=\+', '=', 'g')
\ ->substitute('@\+', '@', 'g')
\ ->trim('-_@=') .. '.' .. a:ft
execute "edit " .. g:denote_directory .. "/" .. fn
call setline(1, denote#frontmatter#new(a:ft, identifier, a:title))
execute 'edit ' .. g:denote_directory .. '/' .. l:fn
call setline(1, denote#frontmatter#new(a:ft, l:identifier, a:title))
endfunction