Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 12 additions & 14 deletions internal/action/bufpane.go
Original file line number Diff line number Diff line change
Expand Up @@ -321,18 +321,16 @@ func (h *BufPane) ResizePane(size int) {
}

// PluginCB calls all plugin callbacks with a certain name and displays an
// error if there is one and returns the aggregate boolean response
func (h *BufPane) PluginCB(cb string) bool {
b, err := config.RunPluginFnBool(h.Buf.Settings, cb, luar.New(ulua.L, h))
if err != nil {
screen.TermMessage(err)
// error if there is one and returns the aggregate boolean response.
// The bufpane is passed as the first argument to the callbacks,
// optional args are passed as the next arguments.
func (h *BufPane) PluginCB(cb string, args ...interface{}) bool {
largs := []lua.LValue{luar.New(ulua.L, h)}
for _, a := range args {
largs = append(largs, luar.New(ulua.L, a))
}
return b
}

// PluginCBRune is the same as PluginCB but also passes a rune to the plugins
func (h *BufPane) PluginCBRune(cb string, r rune) bool {
b, err := config.RunPluginFnBool(h.Buf.Settings, cb, luar.New(ulua.L, h), luar.New(ulua.L, string(r)))
b, err := config.RunPluginFnBool(h.Buf.Settings, cb, largs...)
if err != nil {
screen.TermMessage(err)
}
Expand Down Expand Up @@ -559,7 +557,7 @@ func (h *BufPane) execAction(action BufAction, name string, te *tcell.EventMouse
h.Buf.HasSuggestions = false
}

if !h.PluginCB("pre" + name) {
if !h.PluginCB("pre"+name, te) {
return false
}

Expand All @@ -570,7 +568,7 @@ func (h *BufPane) execAction(action BufAction, name string, te *tcell.EventMouse
case BufMouseAction:
success = a(h, te)
}
success = success && h.PluginCB("on"+name)
success = success && h.PluginCB("on"+name, te)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We add this now also for BufKeyAction too, right?
Furthermore...is this optional argument really backward compatible? 🤔

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We add this now also for BufKeyAction too, right?

Yes, but it is nil in that case.

Furthermore...is this optional argument really backward compatible? 🤔

Non-intuitively yes. You can try it. A lua function is free to receive less arguments than we pass to it, or more arguments than we pass to it.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, ok. Then it is legit. 👍


if _, ok := MultiActions[name]; ok {
if recordingMacro {
Expand Down Expand Up @@ -626,7 +624,7 @@ func (h *BufPane) DoRuneInsert(r rune) {
// Insert a character
h.Buf.SetCurCursor(c.Num)
h.Cursor = c
if !h.PluginCBRune("preRune", r) {
if !h.PluginCB("preRune", string(r)) {
continue
}
if c.HasSelection() {
Expand All @@ -645,7 +643,7 @@ func (h *BufPane) DoRuneInsert(r rune) {
curmacro = append(curmacro, r)
}
h.Relocate()
h.PluginCBRune("onRune", r)
h.PluginCB("onRune", string(r))
}
}

Expand Down