@@ -321,18 +321,16 @@ func (h *BufPane) ResizePane(size int) {
321321}
322322
323323// PluginCB calls all plugin callbacks with a certain name and displays an
324- // error if there is one and returns the aggregate boolean response
325- func (h * BufPane ) PluginCB (cb string ) bool {
326- b , err := config .RunPluginFnBool (h .Buf .Settings , cb , luar .New (ulua .L , h ))
327- if err != nil {
328- screen .TermMessage (err )
324+ // error if there is one and returns the aggregate boolean response.
325+ // The bufpane is passed as the first argument to the callbacks,
326+ // optional args are passed as the next arguments.
327+ func (h * BufPane ) PluginCB (cb string , args ... interface {}) bool {
328+ largs := []lua.LValue {luar .New (ulua .L , h )}
329+ for _ , a := range args {
330+ largs = append (largs , luar .New (ulua .L , a ))
329331 }
330- return b
331- }
332332
333- // PluginCBRune is the same as PluginCB but also passes a rune to the plugins
334- func (h * BufPane ) PluginCBRune (cb string , r rune ) bool {
335- b , err := config .RunPluginFnBool (h .Buf .Settings , cb , luar .New (ulua .L , h ), luar .New (ulua .L , string (r )))
333+ b , err := config .RunPluginFnBool (h .Buf .Settings , cb , largs ... )
336334 if err != nil {
337335 screen .TermMessage (err )
338336 }
@@ -559,7 +557,7 @@ func (h *BufPane) execAction(action BufAction, name string, te *tcell.EventMouse
559557 h .Buf .HasSuggestions = false
560558 }
561559
562- if ! h .PluginCB ("pre" + name ) {
560+ if ! h .PluginCB ("pre" + name , te ) {
563561 return false
564562 }
565563
@@ -570,7 +568,7 @@ func (h *BufPane) execAction(action BufAction, name string, te *tcell.EventMouse
570568 case BufMouseAction :
571569 success = a (h , te )
572570 }
573- success = success && h .PluginCB ("on" + name )
571+ success = success && h .PluginCB ("on" + name , te )
574572
575573 if _ , ok := MultiActions [name ]; ok {
576574 if recordingMacro {
@@ -626,7 +624,7 @@ func (h *BufPane) DoRuneInsert(r rune) {
626624 // Insert a character
627625 h .Buf .SetCurCursor (c .Num )
628626 h .Cursor = c
629- if ! h .PluginCBRune ("preRune" , r ) {
627+ if ! h .PluginCB ("preRune" , string ( r ) ) {
630628 continue
631629 }
632630 if c .HasSelection () {
@@ -645,35 +643,35 @@ func (h *BufPane) DoRuneInsert(r rune) {
645643 curmacro = append (curmacro , r )
646644 }
647645 h .Relocate ()
648- h .PluginCBRune ("onRune" , r )
646+ h .PluginCB ("onRune" , string ( r ) )
649647 }
650648}
651649
652650// VSplitIndex opens the given buffer in a vertical split on the given side.
653651func (h * BufPane ) VSplitIndex (buf * buffer.Buffer , right bool ) * BufPane {
654652 e := NewBufPaneFromBuf (buf , h .tab )
655- e .splitID = MainTab () .GetNode (h .splitID ).VSplit (right )
656- currentPaneIdx := MainTab () .GetPane (h .splitID )
653+ e .splitID = h . tab .GetNode (h .splitID ).VSplit (right )
654+ currentPaneIdx := h . tab .GetPane (h .splitID )
657655 if right {
658656 currentPaneIdx ++
659657 }
660- MainTab () .AddPane (e , currentPaneIdx )
661- MainTab () .Resize ()
662- MainTab () .SetActive (currentPaneIdx )
658+ h . tab .AddPane (e , currentPaneIdx )
659+ h . tab .Resize ()
660+ h . tab .SetActive (currentPaneIdx )
663661 return e
664662}
665663
666664// HSplitIndex opens the given buffer in a horizontal split on the given side.
667665func (h * BufPane ) HSplitIndex (buf * buffer.Buffer , bottom bool ) * BufPane {
668666 e := NewBufPaneFromBuf (buf , h .tab )
669- e .splitID = MainTab () .GetNode (h .splitID ).HSplit (bottom )
670- currentPaneIdx := MainTab () .GetPane (h .splitID )
667+ e .splitID = h . tab .GetNode (h .splitID ).HSplit (bottom )
668+ currentPaneIdx := h . tab .GetPane (h .splitID )
671669 if bottom {
672670 currentPaneIdx ++
673671 }
674- MainTab () .AddPane (e , currentPaneIdx )
675- MainTab () .Resize ()
676- MainTab () .SetActive (currentPaneIdx )
672+ h . tab .AddPane (e , currentPaneIdx )
673+ h . tab .Resize ()
674+ h . tab .SetActive (currentPaneIdx )
677675 return e
678676}
679677
0 commit comments