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

@@ -5,10 +5,10 @@ endfunction
" Local helper function to retrieve and format the title.
function s:titleFromBuf(buf)
let name=denote#meta#noteTitleFromFile(bufname(a:buf))
return strchars(name, 1) <= g:denote_loc_title_columns
\ ? printf('%' .. g:denote_loc_title_columns .. 's', name)
\ : printf('%.' .. (g:denote_loc_title_columns - 1) .. 's', name) .. '…'
let l:name=denote#meta#noteTitleFromFile(bufname(a:buf))
return strchars(l:name, 1) <= g:denote_loc_title_columns
\ ? printf('%' .. g:denote_loc_title_columns .. 's', l:name)
\ : printf('%.' .. (g:denote_loc_title_columns - 1) .. 's', l:name) .. '…'
endfunction
" Local helper function to truncate text with match at the given column as a
@@ -21,44 +21,32 @@ endfunction
" This modifies the location list for pretty display.
function denote#loclist#textReferences(info)
let items=getloclist(a:info.winid)
let l=[]
let width=winwidth(0) - g:denote_loc_title_columns - 19
let l:items=getloclist(a:info.winid)
let l:l=[]
let l:width=winwidth(0) - g:denote_loc_title_columns - 19
for idx in range(a:info.start_idx - 1, a:info.end_idx - 1)
let e=items[idx]
let name=s:titleFromBuf(e.bufnr)
let lnum=printf('%5d', e.lnum)
let col=printf('%3d', e.col)
call add(l, name ..
\ ' | ' .. lnum .. ' col ' .. col ..
\ ' | ' .. s:formatText(items[idx].text, col, width))
let l:e=l:items[idx]
let l:name=s:titleFromBuf(l:e.bufnr)
let l:lnum=printf('%5d', l:e.lnum)
let l:col=printf('%3d', l:e.col)
call add(l:l, l:name ..
\ ' | ' .. l:lnum .. ' l:col ' .. l:col ..
\ ' | ' .. s:formatText(l:items[idx].text, l:col, l:width))
endfor
return l
return l:l
endfunction
" This modifies the location list for pretty display.
function denote#loclist#textNoteList(info)
let items=getloclist(a:info.winid)
let l=[]
let l:items=getloclist(a:info.winid)
let l:l=[]
for idx in range(a:info.start_idx - 1, a:info.end_idx - 1)
let e=items[idx]
let name=s:titleFromBuf(e.bufnr)
let ntags=denote#meta#noteTagsFromFile(bufname(e.bufnr))->join()
call add(l, name .. ' | ' .. ntags)
let l:e=l:items[idx]
let l:name=s:titleFromBuf(l:e.bufnr)
let l:ntags=denote#meta#noteTagsFromFile(bufname(l:e.bufnr))->join()
call add(l:l, l:name .. ' | ' .. l:ntags)
endfor
return l
endfunction
" Load all references to the given note into the location list.
function denote#loclist#references(noteId)
" Populate location list
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)
call setloclist(0, [], 'r',
\ {'title': 'References to ' .. noteTitle .. ' (' .. a:noteId .. ')',
\ 'quickfixtextfunc' : 'denote#loclist#textReferences'})
return l:l
endfunction
" Re-populate location list with denote entries