Skip to content

Commit bdd6204

Browse files
committed
Port to Neovim: Add public AcmeActivate function
1 parent 9324b07 commit bdd6204

1 file changed

Lines changed: 49 additions & 12 deletions

File tree

plugin/acme.vim

Lines changed: 49 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,8 @@ function s:FileWin(name)
1919
endfunc
2020

2121
function s:Sel()
22-
let text = getreg("'")
23-
let type = getregtype("'")
22+
let text = getreg('"')
23+
let type = getregtype('"')
2424
let view = winsaveview()
2525
silent normal! gv""y
2626
let sel = [getreg('"'), getregtype('"')]
@@ -93,7 +93,7 @@ function s:Started(job, buf, cmd)
9393
\ 'h': a:job,
9494
\ 'cmd': type(a:cmd) == type([]) ? join(a:cmd) : a:cmd,
9595
\ 'killed': 0,
96-
\ })
96+
\ })
9797
redrawstatus!
9898
endfunc
9999

@@ -292,7 +292,7 @@ function s:JobStartNvim(cmd, outb, ctxb, opts, inp)
292292
\ 'on_stderr': function('s:NvimOut'),
293293
\ 'buf': a:outb,
294294
\ 'callback': get(a:opts, 'callback', ''),
295-
\ }
295+
\ }
296296
if has_key(a:opts, 'cwd')
297297
let job_opts.cwd = a:opts.cwd
298298
endif
@@ -318,7 +318,7 @@ function s:JobEnv(buf)
318318
\ &buftype == '' ? expand('%:t') : '',
319319
\ 'COLUMNS': 80,
320320
\ 'LINES': 24,
321-
\ }
321+
\ }
322322
endfunc
323323

324324
function s:SetEnv(env)
@@ -340,7 +340,7 @@ function s:JobStart(cmd, outb, ctxb, opts, inp)
340340
\ 'out_io': 'buffer',
341341
\ 'out_buf': a:outb,
342342
\ 'out_msg': 0,
343-
\ }
343+
\ }
344344
call extend(opts, a:opts)
345345
let cwd = get(a:opts, 'cwd', getcwd())
346346
let env = s:SetEnv(s:JobEnv(a:outb))
@@ -531,7 +531,7 @@ function s:ScratchExec(cmd, dir, inp, title)
531531
let opts = {
532532
\ 'callback': function('s:ScratchCb', [b]),
533533
\ 'in_io': 'pipe',
534-
\ }
534+
\ }
535535
if a:dir != ''
536536
let opts.cwd = a:dir
537537
endif
@@ -546,7 +546,7 @@ function s:Exec(cmd)
546546
\ 'err_io': 'null',
547547
\ 'in_io': 'null',
548548
\ 'out_io': 'null',
549-
\ })
549+
\ })
550550
endif
551551
endfunc
552552

@@ -1052,6 +1052,43 @@ function s:RightRelease(click)
10521052
call s:Open(cmd, a:click, dir, w)
10531053
endfunc
10541054

1055+
function AcmeActivate(mode)
1056+
let text = a:mode == 'v' ? trim(s:Sel()[0], "\r\n", 2) : getline('.')
1057+
let click = a:mode == 'v' ? -1 : col('.')
1058+
call s:Open(text, click, s:CtxDir(), win_getid())
1059+
endfunc
1060+
1061+
for m in ['', 'i']
1062+
for n in ['', '2-', '3-', '4-']
1063+
for c in ['Mouse', 'Drag', 'Release']
1064+
exe m.'noremap <'.n.'Middle'.c.'> <Nop>'
1065+
exe m.'noremap <'.n.'Right'.c.'> <Nop>'
1066+
endfor
1067+
endfor
1068+
exe m.'noremap <silent> <MiddleDrag> <LeftDrag>'
1069+
exe m.'noremap <silent> <RightDrag> <LeftDrag>'
1070+
endfor
1071+
for n in ['', '2-', '3-', '4-']
1072+
exe 'nnoremap <silent> <'.n.'MiddleMouse>'
1073+
\ ':call <SID>MousePress("")<CR>'
1074+
exe 'vnoremap <silent> <'.n.'MiddleMouse>'
1075+
\ ':<C-u>call <SID>MousePress("v")<CR>'
1076+
exe 'nnoremap <silent> <'.n.'MiddleRelease>'
1077+
\ ':call <SID>MiddleRelease(col("."))<CR>'
1078+
exe 'nnoremap <silent> <'.n.'RightMouse>'
1079+
\ ':call <SID>MousePress("")<CR>'
1080+
exe 'vnoremap <silent> <'.n.'RightMouse>'
1081+
\ ':<C-u>call <SID>MousePress("v")<CR>'
1082+
exe 'nnoremap <silent> <'.n.'RightRelease>'
1083+
\ ':call <SID>RightRelease(col("."))<CR>'
1084+
endfor
1085+
inoremap <silent> <MiddleMouse> <C-o>:call <SID>MousePress('')<CR>
1086+
inoremap <silent> <MiddleRelease> <C-o>:call <SID>MiddleRelease(col('.'))<CR>
1087+
vnoremap <silent> <MiddleRelease> :<C-u>call <SID>MiddleRelease(-1)<CR>
1088+
inoremap <silent> <RightMouse> <C-o>:call <SID>MousePress('')<CR>
1089+
inoremap <silent> <RightRelease> <C-o>:call <SID>RightRelease(col('.'))<CR>
1090+
vnoremap <silent> <RightRelease> :<C-u>call <SID>RightRelease(-1)<CR>
1091+
10551092
function s:Clear(b)
10561093
call deletebufline(a:b, 1, "$")
10571094
if has_key(s:scratch, a:b)
@@ -1197,7 +1234,7 @@ endfunc
11971234
function s:CtrlRecv(ch, data)
11981235
let len = strridx(a:data, "\x1e")
11991236
let len += len == -1 ? 0 : len(s:ctrlrx)
1200-
s:ctrlrx .= a:data
1237+
let s:ctrlrx .= a:data
12011238
if len == -1
12021239
return
12031240
endif
@@ -1356,13 +1393,13 @@ if s:ctrlexe != ''
13561393
let s:ctrl = jobstart([s:ctrlexe], {
13571394
\ 'on_stdout': function('s:NvimCtrlRecv'),
13581395
\ 'rpc': 0,
1359-
\ })
1396+
\ })
13601397
else
13611398
let s:ctrl = job_start([s:ctrlexe], {
13621399
\ 'callback': 's:CtrlRecv',
13631400
\ 'err_io': 'null',
13641401
\ 'mode': 'raw',
1365-
\ })
1402+
\ })
13661403
endif
13671404
let $EDITOR = s:ctrlexe
1368-
endif
1405+
endif

0 commit comments

Comments
 (0)