Skip to content

Commit fbcb662

Browse files
committed
Simplify prompt and shorthand
1 parent d8509aa commit fbcb662

File tree

6 files changed

+36
-62
lines changed

6 files changed

+36
-62
lines changed

plugin/acid.vim

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,25 @@ function! AcidOpfunc(callback, block)
99
endif
1010
let s:ret = getreg('s')
1111
call setreg('s', s:tmp)
12-
exec a:callback 'opfunc' s:ret
12+
exec a:callback s:ret
13+
endfunction
14+
15+
function! AcidPrompt(callback)
16+
call inputsave()
17+
let s:ret = input(a:callback . "")
18+
call inputrestore()
19+
exec a:callback s:ret
20+
endfunction
21+
22+
function! AcidShorthand(callback, shorthand)
23+
let s:tmp = getreg('s')
24+
let s:iskw = &iskeyword
25+
setl iskeyword+=/
26+
silent exec a:shorthand
27+
exec "setl iskeyword=".s:iskw
28+
let s:ret = getreg('s')
29+
call setreg('s', s:tmp)
30+
exec a:callback s:ret
1331
endfunction
1432

1533
function! s:require()

rplugin/python3/acid/commands/__init__.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -82,18 +82,20 @@ def build_interfaces(cls, nvim):
8282
convert_case(cmd_name)
8383
)
8484
mapping = getattr(
85-
cls, 'shortand_mapping',"{}{}".format(
85+
cls, 'shorthand_mapping',"{}{}".format(
8686
mapping, mapping[-1]
8787
) if mapping is not None else None
8888
)
8989
mapping = nvim.vars.get(shorthand_mapping, mapping)
90+
shorthand = cls.shorthand
9091
cmd.append(silent_map(
91-
mapping, ':{} shorthand<CR>'.format(cmd_name)
92+
mapping,
93+
':call AcidShorthand("{}", "{}")<CR>'.format(cmd_name, shorthand)
9294
))
9395

9496
if hasattr(cls, 'prompt'):
95-
prompt = 'command! -buffer -nargs=0 {}Prompt AcidCommand {} prompt'
96-
cmd.append(prompt.format(cmd_name, cls.name))
97+
prompt = 'command! -buffer -nargs=0 {}Prompt call AcidPrompt("{}")'
98+
cmd.append(prompt.format(cmd_name, cmd_name))
9799

98100
return cmd
99101

rplugin/python3/acid/commands/eval.py

Lines changed: 3 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -12,28 +12,8 @@ class Command(BaseCommand):
1212
opfunc = True
1313
nargs='*'
1414
op = "eval"
15+
shorthand = '''normal! mx$?^("sy%`x'''
1516

16-
def prompt(self):
17-
self.nvim.call("inputsave")
18-
ret = self.nvim.call("input", "acid - eval> ")
19-
self.nvim.call("inputrestore")
20-
return ret
17+
def prepare_payload(self, *args):
2118

22-
def shorthand(self):
23-
cmd = '''silent exec 'normal! mx$?^("sy%`x' | nohl'''
24-
self.nvim.command(cmd)
25-
return self.nvim.funcs.getreg('s')
26-
27-
def prepare_payload(self, mode, *args):
28-
ns = get_acid_ns(self.nvim)
29-
30-
if mode == 'shorthand':
31-
ret = self.shorthand()
32-
elif mode == 'prompt':
33-
ret = self.prompt()
34-
elif mode == 'opfunc':
35-
ret = " ".join(args)
36-
else:
37-
ret = " ".join([mode, *args])
38-
39-
return {"code": ret, "ns": ns}
19+
return {"code": " ".join(args), "ns": get_acid_ns(self.nvim)}

rplugin/python3/acid/commands/format_edn.py

Lines changed: 2 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -13,18 +13,5 @@ class Command(BaseCommand):
1313
nargs='*'
1414
op = "format-edn"
1515

16-
def prompt(self):
17-
self.nvim.call("inputsave")
18-
ret = self.nvim.call("input", "acid - format-edn> ")
19-
self.nvim.call("inputrestore")
20-
return ret
21-
22-
def prepare_payload(self, mode, *args):
23-
if mode == 'prompt':
24-
ret = self.prompt()
25-
elif mode == 'opfunc':
26-
ret = " ".join(args)
27-
else:
28-
ret = " ".join([mode, *args])
29-
30-
return {'edn': ret, 'pprint-fn': 'clojure.pprint/pprint'}
16+
def prepare_payload(self, *args):
17+
return {'edn': " ".join(args), 'pprint-fn': 'clojure.pprint/pprint'}

rplugin/python3/acid/commands/goto.py

Lines changed: 3 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -11,19 +11,7 @@ class Command(BaseCommand):
1111
handlers = ['Goto']
1212
op = "info"
1313
shorthand_mapping = 'gd'
14+
shorthand="call setreg('s', expand('<cword>'))"
1415

15-
def shorthand(self):
16-
iskw = self.nvim.current.buffer.options['iskeyword']
17-
self.nvim.current.buffer.options['iskeyword'] = \
18-
','.join(set(iskw.split(',')) | {"/"})
19-
data = self.nvim.funcs.expand('<cword>')
20-
self.nvim.current.buffer.options['iskeyword'] = iskw
21-
return data
22-
23-
def prepare_payload(self, mode, *args):
24-
ns = path_to_ns(self.nvim)
25-
if mode == 'shorthand':
26-
data = self.shorthand()
27-
else:
28-
data = mode
29-
return {"symbol": data, "ns": ns}
16+
def prepare_payload(self, *args):
17+
return {"symbol": " ".join(args), "ns": path_to_ns(self.nvim)}

rplugin/python3/acid/commands/usage.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,10 @@ class Command(BaseCommand):
77
priority = 0
88
cmd_name = 'AcidFindUsage'
99
handlers = ['Usage']
10-
mapping = 'gu'
1110
with_acid = True
1211
op = "info"
12+
shorthand_mapping = 'gu'
13+
shorthand="call setreg('s', expand('<cword>'))"
1314

1415
def prepare_payload(self, *args):
15-
data = self.nvim.funcs.expand('<cword>')
16-
ns = path_to_ns(self.nvim)
17-
return {"symbol": data, "ns": ns}
16+
return {"symbol": " ".join(args), "ns": path_to_ns(self.nvim)}

0 commit comments

Comments
 (0)