Browse Source

vim / notes-links-for: use location window for links

This involves changing grepprg, running, and then changing it back.

Not entirely optimal, but the location window has some good features.

Changes notes-links-for output to match (ish) grep format.
master
Brennen Bearnes 1 year ago
parent
commit
4f83676267
2 changed files with 44 additions and 12 deletions
  1. +27
    -10
      home/.vim/vimrc
  2. +17
    -2
      home/bin/notes-links-for

+ 27
- 10
home/.vim/vimrc View File

@ -752,16 +752,16 @@ let mapleader = ","
" but i don't know what it is
function! s:RunFilter(filter)
let l:currentline = line('.')
exe ":%!" . a:filter
exe ":" . l:currentline
execute ":%!" . a:filter
execute ":" . l:currentline
endfunction
" do some normal-mode commands and return the cursor to its previous location
function! s:ExecNormalAndReturnCursor(commands)
let l:currentline = line('.')
" see http://learnvimscriptthehardway.stevelosh.com/chapters/30.html
exe "normal! " . a:commands
exe ":" . l:currentline
execute "normal! " . a:commands
execute ":" . l:currentline
endfunction
" set custom filetypes for some things - invoked by an autocommand above
@ -800,7 +800,7 @@ let mapleader = ","
if match(realpath, '_logscratch.wiki') > -1
return
endif
silent exe ":!notes-collect-metadata " . realpath
silent execute ":!notes-collect-metadata " . realpath
endfunction
" if editing a new p1k3 entry, auto-populate with a datestamp
@ -932,10 +932,26 @@ let mapleader = ","
call <SID>CommandOutputInNewWindow('timeslice -f ' . realpath)
endfunction
" try to run vimwiki-links-for for current path
function! s:VimwikiLinksForFile()
" run notes-links-for for current path and populate location list,
" like using grep:
function! s:NotesLinksForFile()
let realpath = system('readlink -fn ' . shellescape(expand('%')))
call <SID>CommandOutputInNewWindow('notes-links-for --file ' . realpath)
" override default grep so we can populate the location list:
setlocal grepprg=notes-links-for\ --file\ $*
silent execute "silent lgrep! " . realpath
" https://vim.fandom.com/wiki/Avoiding_the_%22Hit_ENTER_to_continue%22_prompts
" https://vi.stackexchange.com/questions/2809/silent-makes-my-vim-go-blank
" in short, this is necessary because otherwise the silent grep above can
" leave the display in a bonk state:
redraw!
" an alternative to the above:
" call <SID>CommandOutputInNewWindow('notes-links-for --file ' . realpath)
" restore global setting for grepprg:
setlocal grepprg<
lopen
endfunction
" this is fucking ridiculous
@ -944,7 +960,7 @@ let mapleader = ","
execute "normal! a\<C-r>\<C-r>=a:string\<CR>\<Space>\<Esc>"
endfunc
" try to run vimwiki-links-for for current path
" XXX: Experimental - make a link from an fzf-found page:
function! s:VimwikiMakeLink()
call fzf#run({
\ 'options': '--reverse',
@ -991,8 +1007,9 @@ let mapleader = ","
" colorscheme icansee
" colorscheme candycode
" colorscheme peppers
colorscheme iceberg
" colorscheme inkpot
colorscheme iceberg
" colorscheme ingretu
" }}}
" folding {{{


+ 17
- 2
home/bin/notes-links-for View File

@ -66,7 +66,7 @@ my $dbh = DBI->connect("dbi:SQLite:dbname=$dbfile", "", "");
my $sql = SQL::Abstract->new;
my ($query, @bind) = $sql->select(
'links',
'links JOIN pages ON links.page = pages.page',
'*',
\%where,
{-desc => 'target'}
@ -80,8 +80,23 @@ if ($debug) {
my $sth = $dbh->prepare($query);
$sth->execute(@bind);
# TODO: Note that the "1" here is, theoretically, a line number.
# Unfortunately, there's no obvious way to extract that from Pandoc's parsing
# of the original file, and thus no non-hacky way for notes-collect-metadata to
# store an approximate value in the database. We _could_ read the file
# line-by-line, or run grep, looking for the file's basename, but this is
# tricky to get right.
#
# If I keep using this long-term, I should solve this problem.
while (my $data = $sth->fetchrow_hashref()) {
say $data->{page};
print "$ENV{HOME}/notes/vimwiki/$data->{page}.wiki";
if ($data->{title}) {
print ":1:$data->{title}";
} else {
print ":1:$data->{page}"
}
print "\n";
}
$sth->execute();

Loading…
Cancel
Save