Keyboard shortcuts

Press ← or → to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

btv.contextmenu

btv.contextmenu.groups

btv.contextmenu.groups is the group registry: a table from a group’s name to the group. Change a group in place, or add your own:

btv.contextmenu.groups.clipboard = {
  -- The rows: a list, or a function `(ctx) -> list` that may return a promise.
  items = {
    {
      label = "Copy",
      action = function(ctx) end,  -- runs when the row is chosen; may return a promise
      detail = "Ctrl+C",           -- the right-hand hint: a string or `(ctx) -> string|nil`
      when = function(ctx) end,    -- hide the row unless this returns true
      enabled = function(ctx) end, -- grey it out unless this returns true
    },
  },
  when = function(ctx) end,        -- hide the whole group unless true (or `false`)
}

when and enabled may also be plain booleans. A field a group or a row doesn’t know about is an error naming the group, so a typo doesn’t silently drop a row.

Defined in contextmenu.lua.

btv.contextmenu.default

btv.contextmenu.default is the group list an editable buffer starts from, the first time its own list is asked for. Editing it changes what later buffers start with; a buffer that already has its list keeps it.

Defined in contextmenu.lua.

btv.contextmenu.default_readonly

btv.contextmenu.default_readonly is the group list a read-only buffer (one that isn’t 'modifiable': help, the quickfix list, a tree) starts from.

Defined in contextmenu.lua.

btv.contextmenu.list(buf)

btv.contextmenu.list(buf) -> buffer buf’s group list (0 or nil: the current buffer). The list is live: edit it in place to change that buffer’s menu, and no other’s. The first time it’s asked for, it’s made from btv.contextmenu.default (or default_readonly for a buffer that isn’t 'modifiable' at that moment).

table.insert(btv.contextmenu.list(buf), 1, "tree")

Defined in contextmenu.lua.

btv.contextmenu.set(buf, names)

btv.contextmenu.set(buf, names) replaces buffer buf’s group list with a copy of names (0 or nil: the current buffer). {} gives the buffer no menu.

Defined in contextmenu.lua.

btv.contextmenu.entries(buf)

btv.contextmenu.entries(buf) -> a promise of the rows buffer buf’s menu would show right now (0 or nil: the current buffer), as btv.ui.menu entries: each { label, detail, enabled, action }, with { separator = true } between groups. The testing and introspection seam: what open would show, without showing it.

Defined in contextmenu.lua.

btv.contextmenu.open()

btv.contextmenu.open() opens the current buffer’s menu at the pointer, which is what a right-click does. Returns a promise that settles once the chosen row’s action has run (an action that returns a promise is waited for), or once the menu closed with nothing chosen. A menu with no rows doesn’t open. Bound to a key with no click behind it, the menu opens at the text cursor.

Defined in contextmenu.lua.