BREAKING: Unify lua and plug API mappings
All checks were successful
ci/woodpecker/push/woodpecker Pipeline was successful

Made the names of the functions to invoke the plugin the same.
This is a BREAKING change if using the lua mappings.

On the other hand, it should stay pretty stable for the foreseeable
future, with only new ones added and possibly vim commands added.
This commit is contained in:
Marty Oehme 2022-01-21 18:33:13 +01:00
parent 49f0b10fde
commit 0e77624689
Signed by: Marty
GPG key ID: B7538B8F50A1C800
3 changed files with 23 additions and 21 deletions

View file

@ -32,13 +32,15 @@ but there's not much here yet.
## Usage
The one mapping you probably want to undertake (replacing the mapping as needed) is:
All exposed functionality of the plugin can be reached either through lua bindings or through vim `<Plug>` mappings.
The one mapping you probably want to undertake (replacing the mapping as needed) is the following link mapping:
### Linking
```vim
nnoremap <cr> :lua require 'zettelkasten'.open_or_make_link()<cr>
vnoremap <cr> :lua require 'zettelkasten'.open_or_make_link(true)<cr>
nnoremap <cr> :lua require 'zettelkasten'.link_follow()<cr>
vnoremap <cr> :lua require 'zettelkasten'.link_follow(true)<cr>
```
This will allow you to create new links when over any text,
@ -52,8 +54,8 @@ The function is also exposed as vim mapping `<Plug>zettel_link_follow`, so can b
set via `map <cr> <Plug>zettel_link_follow` to get the same result as above.
```vim
:lua require 'zettelkasten'.open_link()
:lua require 'zettelkasten'.make_link(visualmode)
:lua require 'zettelkasten'.link_open()
:lua require 'zettelkasten'.link_make(visualmode)
```
allows you to separate the link following and creation set by one function above.
@ -66,7 +68,7 @@ The functions are again exposed as `<Plug>zettel_link_open` and
### Index
```vim
nnoremap <leader>w :lua require 'zettelkasten'.open_index()<cr>
nnoremap <leader>w :lua require 'zettelkasten'.index_open()<cr>
```
allows you to map going to your defined zettel index file.

View file

@ -17,26 +17,26 @@ end
function ZK.get_anchor() return anchor.create() end
-- Open link under cursor, or next on line
function ZK.open_link() return action.open_selected() end
function ZK.link_open() return action.open_selected() end
-- Create a new link under cursor
function ZK.make_link(visual) return action.make_link(visual) end
function ZK.link_make(visual) return action.make_link(visual) end
-- If invoked in reach of a valid link will try to follow said link.
-- Otherwise will take the current context and make a link out of it.
function ZK.open_or_make_link(visual)
if not ZK.open_link() then ZK.make_link(visual) end
function ZK.link_follow(visual)
if not ZK.link_open() then ZK.link_make(visual) end
end
-- Open index file at zettel root directory. If title is passed in opens
-- `title`.<extension> file, otherwise defaults to `index`.<extension>.
function ZK.open_index(title) return action.open_index_file(title) end
function ZK.index_open(title) return action.open_index_file(title) end
return {
get_zettel_list = ZK.get_zettel_list,
get_anchor = ZK.get_anchor,
open_link = ZK.open_link,
make_link = ZK.make_link,
open_or_make_link = ZK.open_or_make_link,
open_index = ZK.open_index
link_open = ZK.link_open,
link_make = ZK.link_make,
link_follow = ZK.link_follow,
index_open = ZK.index_open
}

View file

@ -2,14 +2,14 @@ if exists('g:loaded_zettelkasten')
finish
endif
noremap <Plug>zettel_link_open :lua require 'zettelkasten'.open_link()<cr>
noremap <Plug>zettel_link_open :lua require 'zettelkasten'.link_open()<cr>
nnoremap <Plug>zettel_link_make :lua require 'zettelkasten'.make_link()<cr>
vnoremap <Plug>zettel_link_make :lua require 'zettelkasten'.make_link(true)<cr>
nnoremap <Plug>zettel_link_make :lua require 'zettelkasten'.link_make()<cr>
vnoremap <Plug>zettel_link_make :lua require 'zettelkasten'.link_make(true)<cr>
nnoremap <Plug>zettel_link_follow :lua require 'zettelkasten'.open_or_make_link()<cr>
vnoremap <Plug>zettel_link_follow :lua require 'zettelkasten'.open_or_make_link(true)<cr>
nnoremap <Plug>zettel_link_follow :lua require 'zettelkasten'.link_follow()<cr>
vnoremap <Plug>zettel_link_follow :lua require 'zettelkasten'.link_follow(true)<cr>
nnoremap <Plug>zettel_index_open :lua require 'zettelkasten'.open_index()<cr>
nnoremap <Plug>zettel_index_open :lua require 'zettelkasten'.index_open()<cr>
let g:loaded_zettelkasten = 1