@@ -531,19 +531,16 @@ function s:Dir()
531531 return isdirectory (dir ) ? dir : getcwd ()
532532endfunc
533533
534- function s: Dirs ()
534+ function s: CtxDir ()
535535 let dir = s: Dir ()
536- let ctx = []
537536 if &buftype != ' '
538537 let [t , q ] = [' ing directory:? ' , " [`'\" ]" ]
539538 let l = searchpair (' \vEnter' .t .q , ' ' , ' \vLeav' .t .q , ' nW' ,
540539 \ ' ' , 0 , 50 )
541540 let m = matchlist (getline (l ), ' \vLeav' .t .q .' (.+)' .q )
542541 if m != []
543542 let d = m [1 ][0 ] == ' /' ? m [1 ] : dir .' /' .m [1 ]
544- if isdirectory (d )
545- call add (ctx, d )
546- endif
543+ let dir = isdirectory (d ) ? d : dir
547544 endif
548545 endif
549546 if dir = ~ ' /\.git/'
@@ -555,31 +552,32 @@ function s:Dirs()
555552 if ! isdirectory (d )
556553 let d = substitute (dir , ' /\.git/.*' , ' ' , ' ' )
557554 endif
558- call add (ctx, d )
555+ let dir = d
559556 endif
560- return ctx + [ dir ]
557+ return dir
561558endfunc
562559
563560function AcmeOpen (name, pos)
564- for f in a: name == ' ' ? [] : a: name = ~ ' ^[~/]' ? [a: name ] :
565- \ map (copy (s: plumbdirs ), ' v:val."/".a:name' )
566- let f = fnamemodify (f , ' :p' )
567- if isdirectory (f )
568- call s: FileOpen (f , ' ' )
569- elseif ! filereadable (f )
570- if s: plumbclick > 0 || a: pos != ' ' || a: name !~ ' /' ||
571- \ ! isdirectory (fnamemodify (f , ' :h' ))
572- continue
573- endif
574- call s: FileOpen (f , ' ' )
575- elseif join (readfile (f , ' ' , 4096 ), ' ' ) !~ ' \n'
576- " No null bytes found, not considered a binary file.
577- call s: FileOpen (f , a: pos )
578- else
579- call s: Exec (' xdg-open ' .shellescape (f ))
561+ if a: name == ' '
562+ return 0
563+ endif
564+ let f = a: name = ~ ' ^[~/]' ? a: name : s: plumbdir .' /' .a: name
565+ let f = fnamemodify (f , ' :p' )
566+ if isdirectory (f )
567+ call s: FileOpen (f , ' ' )
568+ elseif ! filereadable (f )
569+ if s: plumbclick > 0 || a: pos != ' ' || a: name !~ ' /' ||
570+ \ ! isdirectory (fnamemodify (f , ' :h' ))
571+ return 0
580572 endif
581- return 1
582- endfor
573+ call s: FileOpen (f , ' ' )
574+ elseif join (readfile (f , ' ' , 4096 ), ' ' ) !~ ' \n'
575+ " No null bytes found, not considered a binary file.
576+ call s: FileOpen (f , a: pos )
577+ else
578+ call s: Exec (' xdg-open ' .shellescape (f ))
579+ endif
580+ return 1
583581endfunc
584582
585583function s: RgOpen (pos)
@@ -599,14 +597,14 @@ function AcmeExec(title, cmd, ...)
599597 for arg in a: 000
600598 let cmd .= ' ' .shellescape (arg)
601599 endfor
602- let owd = chdir (s: plumbdirs [ 0 ] )
600+ let owd = chdir (s: plumbdir )
603601 let outp = systemlist (cmd)
604602 if owd != ' '
605603 call chdir (owd)
606604 endif
607605 if v: shell_error == 0
608606 if a: title != ' '
609- call s: ScratchNew (a: title , s: plumbdirs [ 0 ] )
607+ call s: ScratchNew (a: title , s: plumbdir )
610608 call setline (' $' , outp)
611609 call s: FiletypeDetect (win_getid ())
612610 endif
@@ -624,9 +622,9 @@ let s:plumbing = [
624622 \ [' \d+%([:,]\d+)?' , {m - > s: Goto (m [0 ])}],
625623\ ]
626624
627- function s: Open (text, click, dirs , win )
625+ function s: Open (text, click, dir , win )
628626 let s: plumbclick = a: click
629- let s: plumbdirs = a: dirs
627+ let s: plumbdir = a: dir
630628 let s: plumbwin = a: win
631629 let rc = index (s: plumbing , [])
632630 for [pat, Handler] in s: plumbing [0 :rc- 1 ] +
@@ -649,7 +647,7 @@ function s:FileComplete(arg, line, pos)
649647endfunc
650648
651649command -nargs =1 -complete =customlist ,s: FileComplete O
652- \ call s: Open (expand (<q-args> ), 0 , [ s: Dir ()] , win_getid ())
650+ \ call s: Open (expand (<q-args> ), 0 , s: Dir (), win_getid ())
653651
654652function s: InsComplete (findstart, base)
655653 let line = getline (' .' )
@@ -901,9 +899,9 @@ function s:RightRelease(click)
901899 let text = click <= 0 ? trim (s: Sel ()[0 ], " \r \n " , 2 ) : getline (' .' )
902900 call s: RestVisual (s: visual )
903901 let w = win_getid ()
904- let dirs = s: Dirs ()
902+ let dir = s: CtxDir ()
905903 exe win_id2win (s: clickwin ).' wincmd w'
906- call s: Open (text, click, dirs , w )
904+ call s: Open (text, click, dir , w )
907905endfunc
908906
909907for m in [' ' , ' i' ]
@@ -1135,7 +1133,7 @@ function s:CtrlRecv(ch, data)
11351133 call s: Diff (args )
11361134 let resp = []
11371135 elseif cmd == ' plumb' && len (args ) > 1
1138- call s: Open (args [1 ], 0 , [ args [0 ] ], 0 )
1136+ call s: Open (args [1 ], 0 , args [0 ], 0 )
11391137 endif
11401138 if resp != []
11411139 call s: CtrlSend ([cid] + resp)
0 commit comments