Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Denite Source and Option to expand leader keys #7

Open
wants to merge 40 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
40 commits
Select commit Hold shift + click to select a range
bb66f70
add denite source
thecontinium Feb 2, 2020
5478f7e
move to correct denite dir
thecontinium Feb 2, 2020
cb8b96a
move to correct denite dir
thecontinium Feb 2, 2020
9b82bc9
make output easier to read
thecontinium Feb 2, 2020
7f84004
adjust formatting
thecontinium Feb 2, 2020
1bc8c3a
adjust command
thecontinium Feb 2, 2020
9785ddb
enabled feedkey
thecontinium Feb 3, 2020
2352821
enabled feedkey
thecontinium Feb 3, 2020
ef12100
enabled feedkey
thecontinium Feb 3, 2020
ea709f1
enabled feedkey
thecontinium Feb 3, 2020
c4ca967
enabled feedkey
thecontinium Feb 3, 2020
dabd29a
enabled feedkey
thecontinium Feb 3, 2020
f346c57
enabled feedkey
thecontinium Feb 3, 2020
38bf50b
enabled feedkey
thecontinium Feb 3, 2020
4327953
enabled feedkey
thecontinium Feb 3, 2020
1a8151b
enabled feedkey
thecontinium Feb 3, 2020
4a93951
enabled feedkey
thecontinium Feb 3, 2020
d661be6
enabled feedkey
thecontinium Feb 3, 2020
3872785
enabled feedkey
thecontinium Feb 3, 2020
3a96422
enabled feedkey
thecontinium Feb 3, 2020
5c549f7
enabled feedkey
thecontinium Feb 3, 2020
29698bf
enable feedkey:
thecontinium Feb 3, 2020
d9f43a9
enabled feedkey
thecontinium Feb 3, 2020
f0f266d
enabled feedkey
thecontinium Feb 3, 2020
0f8fa2e
enabled feedkey
thecontinium Feb 3, 2020
933433c
enabled feedkey
thecontinium Feb 3, 2020
7765f0e
enabled feedkey
thecontinium Feb 3, 2020
73a2fab
enabled feedkey
thecontinium Feb 3, 2020
73929d4
enabled feedkey
thecontinium Feb 3, 2020
f2eca9f
add option to expand leader key
thecontinium Feb 5, 2020
8f9a78a
add option to expand leader key
thecontinium Feb 5, 2020
a7da0a6
add option to expand leader key
thecontinium Feb 5, 2020
44026bd
add option to expand leader key
thecontinium Feb 5, 2020
6f91628
add option to expand leader key
thecontinium Feb 5, 2020
8476a0f
add option to expand leader
thecontinium Feb 5, 2020
98f0ec7
add option to expand leader key
thecontinium Feb 5, 2020
a30662c
Update README.md
thecontinium Feb 11, 2020
c5bf517
Update README.md
thecontinium Feb 11, 2020
7800ea6
Update README.md
thecontinium Feb 11, 2020
4f27738
Update shortcut.txt
thecontinium Feb 11, 2020
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ typing more shortcut keys or parts of shortcut descriptions shown in the menu.
## Requirements

* [fzf.vim] plugin.
* [denite.nvim](https://github.com/Shougo/denite.nvim) optional plugin.

## Usage

Expand All @@ -21,10 +22,14 @@ typing more shortcut keys or parts of shortcut descriptions shown in the menu.

* Use the `:Shortcuts` command to display a searchable menu of shortcuts.

* Use the `:Denite shortcut` command to display a searcheable menu of shourtcuts through the denite interface

* Use the `g:shortcuts` variable to access shortcuts keys and descriptions.

* Use the `g:shortcuts_overwrite_warning` variable to detect any conflicts.

* Use the `g:shortcut_expand_leader_keys` variable to indicate whether to expand leader keys in the Shortcuts list.

### Discovery & fallback shortcuts

I recommend that you define these two shortcuts for discovery and fallback
Expand Down
18 changes: 18 additions & 0 deletions doc/shortcut.txt
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,10 @@ USAGE *shortcut-usage*

* Use the |g:shortcuts_overwrite_warning| variable to detect any conflicts.

* Use the |g:shortcut_expand_leader_keys| variable to indicate whether to
expand leader keys in the Shortcuts list.


------------------------------------------------------------------------------
SETUP *shortcut-setup*
------------------------------------------------------------------------------
Expand Down Expand Up @@ -67,6 +71,15 @@ g:shortcuts_overwrite_warning *g:shortcuts_overwrite_warning*
let g:shortcuts_overwrite_warning = 1 " enable this warning
<

g:g:shortcut_expand_leader_keys *g:shortcuts_expand_leader_keys*
Option to expand leader keys in list.If you have the leader key
set to <Space> it is useful to not expand.
This is enabled by default. Assign 0 to disable this feature.
>
let g:shortcut_expand_leader_keys = 0 " disables expansion
<


------------------------------------------------------------------------------
COMMANDS *shortcut-cmd*
------------------------------------------------------------------------------
Expand Down Expand Up @@ -96,6 +109,11 @@ COMMANDS *shortcut-cmd*
To avoid this limitation, just trigger the shortcut directly
(without choosing through a menu) or use |:Shortcuts| instead.

:Denite shortcut *:Denite shortcut*
Display a |denite.nvim| menu of shortcuts described in |g:shortcuts|.
When an item is chosen from the menu, its shortcut {keys} are
synthetically replayed (as if you typed them) via |feedkeys()|.

:Shortcut! {keys} {description} *:Shortcut!*
Associate an existing shortcut's {keys} to its {description}
in the |g:shortcuts| dictionary. Extra whitespace is ignored.
Expand Down
16 changes: 15 additions & 1 deletion plugin/shortcut.vim
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,13 @@ if !exists('g:shortcuts')
let g:shortcuts = {}
endif

if !exists('g:shortcut_expand_leader_keys')
let g:shortcut_expand_leader_keys = 1
endif

command! -range -bang Shortcuts <line1>,<line2>call s:shortcut_menu_command(<bang>0)
command! -range -bang ShortcutsRangeless call s:shortcut_menu_command(<bang>0)
let s:is_from_visual = ''

function! s:shortcut_menu_command(fullscreen) range abort
let s:is_from_visual = a:firstline == line("'<") && a:lastline == line("'>")
Expand All @@ -20,11 +25,20 @@ function! s:shortcut_menu_command(fullscreen) range abort
endfunction

function! s:shortcut_menu_items() abort
let labels = map(copy(g:shortcuts), 'ShortcutLeaderKeys(v:key)')
let apply = 'v:key'
if g:shortcut_expand_leader_keys
let apply = 'ShortcutLeaderKeys(v:key)'
endif
let labels = map(copy(g:shortcuts), apply)
let width = max(map(values(labels), 'len(v:val)')) + 4
return values(map(labels, "printf('%-".width."S%s', v:val, g:shortcuts[v:key])"))
endfunction

function! ShortcutFeedKeys(choice) range abort
let s:is_from_visual = a:firstline == line("'<") && a:lastline == line("'>")
call s:shortcut_menu_item_action(a:choice)
endfunction

function! s:shortcut_menu_item_action(choice) abort
let shortcut = substitute(a:choice, '\s.*', '', '')
let keystrokes = ShortcutKeystrokes(shortcut)
Expand Down
49 changes: 49 additions & 0 deletions rplugin/python3/denite/source/shortcut.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
# ============================================================================
# FILE: shortcut.py
# ============================================================================

from os import path

from denite.base.source import Base
from denite.kind.command import Kind as Command

from denite.util import globruntime, Nvim, UserContext, Candidates


class Source(Base):

def __init__(self, vim: Nvim) -> None:
super().__init__(vim)

self.name = 'shortcut'
self.kind = Kind(vim)

def gather_candidates(self, context: UserContext) -> Candidates:
shortcuts = {}

for shortcut, description in self.vim.vars["shortcuts"].items():
if self.vim.vars['shortcut_expand_leader_keys'] == 1:
shortcut = self.vim.eval(f'ShortcutLeaderKeys("{shortcut}")')

shortcuts[shortcut] = {
'word': '{0:<12} -- {1}'.format(shortcut, description),
'action__command': shortcut
}

return sorted(shortcuts.values(), key=lambda value: value['word'])


class Kind(Command):

def __init__(self, vim: Nvim) -> None:
super().__init__(vim)

self.name = 'shortcut'

def action_execute(self, context: UserContext) -> None:
target = context['targets'][0]
command = target['action__command']
self.vim.command(f'call ShortcutFeedKeys("{command}")')

def action_edit(self, context: UserContext) -> None:
return super().action_execute(context)