Compare commits
2 Commits
00af1c53b9
...
24cadefafc
| Author | SHA1 | Date | |
|---|---|---|---|
| 24cadefafc | |||
| 83ea4f2bcf |
19
README.md
19
README.md
@@ -32,15 +32,22 @@ the help files. This will allow you to get more help using `:help denote` or
|
|||||||
similar commands.
|
similar commands.
|
||||||
|
|
||||||
### Usage
|
### Usage
|
||||||
For following links, simply move your cursor to the denote link, and press
|
For _following links,_ simply move your cursor to the denote link, and press
|
||||||
`gf`.
|
`gf`.
|
||||||
|
|
||||||
Browsing and searching notes is implemented using the [location
|
This package also provides denote _link completion_ using the
|
||||||
|
[|'omnifunc'|](https://vimhelp.org/options.txt.html#%27omnifunc%27) option. So,
|
||||||
|
the link is completed after pressing `<C-X><C-O>` while typing any prefix of a
|
||||||
|
denote link `denote:<identifier>`. Even more so, if this completion is invoked
|
||||||
|
after typing `denote:<str>`, then the link is completed for denote entries
|
||||||
|
that have `<str>` as part of the title.
|
||||||
|
|
||||||
|
_Browsing_ and _searching notes_ is implemented using the [location
|
||||||
list](https://vimhelp.org/quickfix.txt.html#location-list).
|
list](https://vimhelp.org/quickfix.txt.html#location-list).
|
||||||
So, after running any of the following commands, you may navigate your notes
|
This means that you may navigate your notes using, e.g., `:lopen` to open the
|
||||||
using, e.g., `:lopen` to open the list, `:lnext` and `:lprev`, to move to the next or
|
list, `:lnext` and `:lprev`, to move to the next or previous entry (the list
|
||||||
previous entry (the list does not need to be opened for that), and `:lclose`
|
does not need to be opened for that), and `:lclose` for closing the location
|
||||||
for closing the location list.
|
list.
|
||||||
|
|
||||||
#### Commands
|
#### Commands
|
||||||
This package defines the following user commands:
|
This package defines the following user commands:
|
||||||
|
|||||||
@@ -1,3 +1,6 @@
|
|||||||
|
" Link completion {{{1
|
||||||
|
set omnifunc=denote#completion#get
|
||||||
|
|
||||||
" Go to file command |gf| adjustments {{{1
|
" Go to file command |gf| adjustments {{{1
|
||||||
" This resolves denote links. The function has access to the variable v:fname,
|
" This resolves denote links. The function has access to the variable v:fname,
|
||||||
" which corresponds to the filename under the cursor.
|
" which corresponds to the filename under the cursor.
|
||||||
|
|||||||
59
autoload/denote/completion.vim
Normal file
59
autoload/denote/completion.vim
Normal file
@@ -0,0 +1,59 @@
|
|||||||
|
" Find the column where the completion starts. This must be between 1 and
|
||||||
|
" col('.'). Denote links are of this form: `denote:<identifier>`.
|
||||||
|
function s:column()
|
||||||
|
" Get the substring from the start of the line until col('.')
|
||||||
|
let l = getline(".")[:col('.')]
|
||||||
|
" Take the shortest prefix of a denote link. This may be any of
|
||||||
|
" \<d$
|
||||||
|
" ..
|
||||||
|
" \<denote:$
|
||||||
|
" \<denote:\f$
|
||||||
|
" \<denote:\f\f$
|
||||||
|
" etc.
|
||||||
|
let res = l->matchstrpos('\<denote:\f*$')
|
||||||
|
if res[1] >= 0
|
||||||
|
return res[1]
|
||||||
|
endif
|
||||||
|
let res = l->matchstrpos('\<d\f*$')
|
||||||
|
if res[1] == -1
|
||||||
|
return -3
|
||||||
|
endif
|
||||||
|
return 'denote:' =~ '^' .. res[0] ? res[1] : -3
|
||||||
|
endfunction
|
||||||
|
|
||||||
|
" Return completion items given by the base
|
||||||
|
function s:suggestions(base)
|
||||||
|
let prefix = a:base->matchstr('^denote:\zs.*$')
|
||||||
|
let flist = glob(prefix ? "*" .. prefix .. "*" : "*", 0, v:true)
|
||||||
|
let res = []
|
||||||
|
for filename in flist
|
||||||
|
let noteId = denote#meta#noteIdFromFile(filename)
|
||||||
|
let noteTitle = denote#meta#noteTitleFromFile(filename)
|
||||||
|
if noteId == v:false || (noteId !~ '^' .. prefix && noteTitle !~ prefix)
|
||||||
|
continue
|
||||||
|
endif
|
||||||
|
let noteTitle = noteTitle ?? '(no title)'
|
||||||
|
let noteTags = denote#meta#noteTagsFromFile(filename)
|
||||||
|
let res = res->add({
|
||||||
|
\ 'word' : 'denote:' .. noteId,
|
||||||
|
\ 'abbr' : noteTitle,
|
||||||
|
\ 'menu' : noteTags->join(', ')
|
||||||
|
\ })
|
||||||
|
endfor
|
||||||
|
return res
|
||||||
|
endfunction
|
||||||
|
|
||||||
|
function! Myomni(findstart, base)
|
||||||
|
if a:findstart == 1
|
||||||
|
let tmp = s:column()
|
||||||
|
return tmp
|
||||||
|
else
|
||||||
|
let tmp = s:suggestions(a:base)
|
||||||
|
return tmp
|
||||||
|
endif
|
||||||
|
endfunction
|
||||||
|
|
||||||
|
" Completion function for denote links
|
||||||
|
function denote#completion#get(findstart, base)
|
||||||
|
return a:findstart == 1 ? s:column() : s:suggestions(a:base)
|
||||||
|
endfunction
|
||||||
@@ -23,10 +23,9 @@ function denote#meta#noteIdFromFile(filename)
|
|||||||
\ ?? v:false
|
\ ?? v:false
|
||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
" Return the note title from the filename. On failure, v:false is returned.
|
" Return the note title from the filename.
|
||||||
function denote#meta#noteTitleFromFile(filename)
|
function denote#meta#noteTitleFromFile(filename)
|
||||||
return a:filename->matchstr("--\\zs.\\{-\\}\\ze\\(==\\|@@\\|__\\|\\..\\)")->substitute("-", " ", "g")
|
return a:filename->matchstr("--\\zs.\\{-\\}\\ze\\(==\\|@@\\|__\\|\\..\\)")->substitute("-", " ", "g")
|
||||||
\ ?? v:false
|
|
||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
" Return the note tags from the filename as a list.
|
" Return the note tags from the filename as a list.
|
||||||
|
|||||||
@@ -21,7 +21,7 @@ do adjusting the tags or changing the title of a note. The official manual is
|
|||||||
available online:
|
available online:
|
||||||
https://protesilaos.com/emacs/denote
|
https://protesilaos.com/emacs/denote
|
||||||
|
|
||||||
The denote plugin adds denote-functionality to vim --- the vim way. We are
|
The denote plugin adds denote functionality to vim --- _the vim way._ We are
|
||||||
aware of two other plugins, but we fear that these plugins are not flexible
|
aware of two other plugins, but we fear that these plugins are not flexible
|
||||||
enough, and more importantly, do not follow the vim philosophy for handling
|
enough, and more importantly, do not follow the vim philosophy for handling
|
||||||
denote notes. These mentioned plugins are available here:
|
denote notes. These mentioned plugins are available here:
|
||||||
@@ -29,10 +29,13 @@ denote notes. These mentioned plugins are available here:
|
|||||||
https://git.sr.ht/~ashton314/vim-denote
|
https://git.sr.ht/~ashton314/vim-denote
|
||||||
|
|
||||||
In contrast to these plugins, the present package relies on the
|
In contrast to these plugins, the present package relies on the
|
||||||
|location-list| features for displaying denote entries, and on and
|
|location-list| features for displaying denote entries, and on the options
|
||||||
|'includeexpr'| option for following the links (see, |gf|). This plugin also
|
|'quickfixtextfunc'|, |'includeexpr'|, and |'omnifunc'|. With these, denote
|
||||||
provides custom location-list formatting using the option
|
links can be followed using |gf|, and completed using omni comletion (see,
|
||||||
|'quickfixtextfunc'|.
|
|compl-omni|). For link completion, press |i_CTRL-X_CTRL-O| after typing any
|
||||||
|
prefix of a denote link. This completion also works with titles: by invoking
|
||||||
|
omni completion after typing "denote:foo", denote links are completed for
|
||||||
|
entries containing "foo" in the title.
|
||||||
|
|
||||||
*denote-commands*
|
*denote-commands*
|
||||||
Commands ~
|
Commands ~
|
||||||
|
|||||||
Reference in New Issue
Block a user