Skip to content

Commit 8c2a601

Browse files
committed
Port to Neovim: Add public AcmeActivate function and fix mouse handling
Add AcmeActivate public function and key mappings. Add fallback in s:RightRelease to use getmousepos() when s:click is uninitialized. Fix mouse handling for Neovim 0.12+ where normal! with mouse key events is restricted. Use getline('.') in s:RightRelease for correct column-based plumbing pattern matching.
1 parent ba0ca65 commit 8c2a601

1 file changed

Lines changed: 69 additions & 15 deletions

File tree

plugin/acme.vim

Lines changed: 69 additions & 15 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

@@ -323,7 +323,7 @@ function s:JobEnv(buf)
323323
\ &buftype == '' ? expand('%:t') : '',
324324
\ 'COLUMNS': 80,
325325
\ 'LINES': 24,
326-
\ }
326+
\ }
327327
endfunc
328328

329329
function s:SetEnv(env)
@@ -345,7 +345,7 @@ function s:JobStart(cmd, outb, ctxb, opts, inp)
345345
\ 'out_io': 'buffer',
346346
\ 'out_buf': a:outb,
347347
\ 'out_msg': 0,
348-
\ }
348+
\ }
349349
call extend(opts, a:opts)
350350
let cwd = get(a:opts, 'cwd', getcwd())
351351
let env = s:SetEnv(s:JobEnv(a:outb))
@@ -536,7 +536,7 @@ function s:ScratchExec(cmd, dir, inp, title)
536536
let opts = {
537537
\ 'callback': function('s:ScratchCb', [b]),
538538
\ 'in_io': 'pipe',
539-
\ }
539+
\ }
540540
if a:dir != ''
541541
let opts.cwd = a:dir
542542
endif
@@ -551,7 +551,7 @@ function s:Exec(cmd)
551551
\ 'err_io': 'null',
552552
\ 'in_io': 'null',
553553
\ 'out_io': 'null',
554-
\ })
554+
\ })
555555
endif
556556
endfunc
557557

@@ -980,7 +980,12 @@ function s:MousePress(mode)
980980
if s:clickstatus != 0 || s:click.winid == 0
981981
return
982982
endif
983-
exe "normal! \<LeftMouse>"
983+
if has('nvim')
984+
exe win_id2win(s:click.winid).'wincmd w'
985+
call cursor(s:click.line, s:click.column)
986+
else
987+
exe "normal! \<LeftMouse>"
988+
endif
984989
let s:visual = s:SaveVisual()
985990
let s:clicksel = s:clickmode == 'v' && win_getid() == s:clickwin &&
986991
\ s:InSel()
@@ -1001,7 +1006,9 @@ function s:MiddleRelease(click)
10011006
endif
10021007
return
10031008
endif
1004-
exe "normal! \<LeftRelease>"
1009+
if !has('nvim')
1010+
exe "normal! \<LeftRelease>"
1011+
endif
10051012
let cmd = a:click <= 0 || s:clicksel ? s:Sel()[0] : expand('<cWORD>')
10061013
let vis = s:clickmode == 'v' && (a:click <= 0 || !s:clicksel)
10071014
call s:RestVisual(s:visual)
@@ -1020,6 +1027,14 @@ function s:MiddleRelease(click)
10201027
endfunc
10211028

10221029
function s:RightRelease(click)
1030+
if s:click.winid == 0
1031+
let s:click = getmousepos()
1032+
let s:clickwin = win_getid()
1033+
let s:clickstatus = s:click.line == 0 ? win_id2win(s:click.winid) : 0
1034+
let s:clickmode = 'n'
1035+
let s:clicksel = 0
1036+
endif
1037+
10231038
if s:click.winid == 0
10241039
return
10251040
elseif s:clickstatus != 0
@@ -1039,8 +1054,10 @@ function s:RightRelease(click)
10391054
endif
10401055
return
10411056
endif
1042-
exe "normal! \<LeftRelease>"
1043-
let cmd = a:click <= 0 || s:clicksel ? s:Sel()[0] : expand('<cWORD>')
1057+
if !has('nvim')
1058+
exe "normal! \<LeftRelease>"
1059+
endif
1060+
let cmd = a:click <= 0 || s:clicksel ? s:Sel()[0] : getline('.')
10441061
let vis = s:clickmode == 'v' && (a:click <= 0 || !s:clicksel)
10451062
call s:RestVisual(s:visual)
10461063
let w = win_getid()
@@ -1049,6 +1066,43 @@ function s:RightRelease(click)
10491066
call s:Open(cmd, a:click, dir, w)
10501067
endfunc
10511068

1069+
function AcmeActivate(mode)
1070+
let text = a:mode == 'v' ? trim(s:Sel()[0], "\r\n", 2) : getline('.')
1071+
let click = a:mode == 'v' ? -1 : col('.')
1072+
call s:Open(text, click, s:CtxDir(), win_getid())
1073+
endfunc
1074+
1075+
for m in ['', 'i']
1076+
for n in ['', '2-', '3-', '4-']
1077+
for c in ['Mouse', 'Drag', 'Release']
1078+
exe m.'noremap <'.n.'Middle'.c.'> <Nop>'
1079+
exe m.'noremap <'.n.'Right'.c.'> <Nop>'
1080+
endfor
1081+
endfor
1082+
exe m.'noremap <silent> <MiddleDrag> <LeftDrag>'
1083+
exe m.'noremap <silent> <RightDrag> <LeftDrag>'
1084+
endfor
1085+
for n in ['', '2-', '3-', '4-']
1086+
exe 'nnoremap <silent> <'.n.'MiddleMouse>'
1087+
\ ':call <SID>MousePress("")<CR>'
1088+
exe 'vnoremap <silent> <'.n.'MiddleMouse>'
1089+
\ ':<C-u>call <SID>MousePress("v")<CR>'
1090+
exe 'nnoremap <silent> <'.n.'MiddleRelease>'
1091+
\ ':call <SID>MiddleRelease(col("."))<CR>'
1092+
exe 'nnoremap <silent> <'.n.'RightMouse>'
1093+
\ ':call <SID>MousePress("")<CR>'
1094+
exe 'vnoremap <silent> <'.n.'RightMouse>'
1095+
\ ':<C-u>call <SID>MousePress("v")<CR>'
1096+
exe 'nnoremap <silent> <'.n.'RightRelease>'
1097+
\ ':call <SID>RightRelease(col("."))<CR>'
1098+
endfor
1099+
inoremap <silent> <MiddleMouse> <C-o>:call <SID>MousePress('')<CR>
1100+
inoremap <silent> <MiddleRelease> <C-o>:call <SID>MiddleRelease(col('.'))<CR>
1101+
vnoremap <silent> <MiddleRelease> :<C-u>call <SID>MiddleRelease(-1)<CR>
1102+
inoremap <silent> <RightMouse> <C-o>:call <SID>MousePress('')<CR>
1103+
inoremap <silent> <RightRelease> <C-o>:call <SID>RightRelease(col('.'))<CR>
1104+
vnoremap <silent> <RightRelease> :<C-u>call <SID>RightRelease(-1)<CR>
1105+
10521106
function s:Clear(b)
10531107
call deletebufline(a:b, 1, "$")
10541108
if has_key(s:scratch, a:b)
@@ -1194,7 +1248,7 @@ endfunc
11941248
function s:CtrlRecv(ch, data)
11951249
let len = strridx(a:data, "\x1e")
11961250
let len += len == -1 ? 0 : len(s:ctrlrx)
1197-
s:ctrlrx .= a:data
1251+
let s:ctrlrx .= a:data
11981252
if len == -1
11991253
return
12001254
endif
@@ -1353,13 +1407,13 @@ if s:ctrlexe != ''
13531407
let s:ctrl = jobstart([s:ctrlexe], {
13541408
\ 'on_stdout': function('s:NvimCtrlRecv'),
13551409
\ 'rpc': 0,
1356-
\ })
1410+
\ })
13571411
else
13581412
let s:ctrl = job_start([s:ctrlexe], {
13591413
\ 'callback': 's:CtrlRecv',
13601414
\ 'err_io': 'null',
13611415
\ 'mode': 'raw',
1362-
\ })
1416+
\ })
13631417
endif
13641418
let $EDITOR = s:ctrlexe
1365-
endif
1419+
endif

0 commit comments

Comments
 (0)