Task syntax - [status] vs -[ ] Task [attribute: key]

Short request :
While graphics interface are really helpfull, mots of the time , note/report activity is made through manual text input.

From latest library activities regarding task management :
- [status] seems to be abandonned in favor of - [ ] task [attribute : key ]
(enabling to accurately define custom attribute etc ..., no problem)

Yet when manually typing notes, we miss the cycling/completion help with previous - [status] syntax.
--> Would it be possible to have a kind of completion :

  • Task [attribute:{choice completion based on attribute}] ?

For sure one can make dedicated shortcut... but keeping already existing attribute data helps keeping consistent data....

Disclaimer : I'm not programmer and have absolutely no idea how hard this could be.

1 Like

Try this:

Configuration space-lua

 config.set("taskAttrKeys", {
   "priority", "due", "scheduled", "status", "taskID", "contact", "est"
 })

 config.set("taskAttrValues", {
   { "priority", { "1", "2", "3", "4", "5" } },
   { "status",   { "todo", "doing", "review", "done" } },
   { "est",      { "15m", "30m", "1h", "2h", "4h" } }
 })

Implementation space-lua


-- priority: -1

-- =========================================================
-- ======= Task Attribute Autocomplete =====================
-- =========================================================
-- Config example:
--
-- config.set("taskAttrKeys", {
--   "priority", "due", "scheduled", "status", "taskID", "contact", "est"
-- })
--
-- config.set("taskAttrValues", {
--   { "priority", { "1", "2", "3", "4", "5" } },
--   { "status",   { "todo", "doing", "review", "done" } },
--   { "est",      { "15m", "30m", "1h", "2h", "4h" } }
-- })

event.listen {
  name = "editor:complete",
  run = function(e)
    local linePrefix = e.data.linePrefix or ""
    local pos        = e.data.pos or 0

    -- Helper: returns the character immediately after the cursor.
    -- Used to detect and consume the auto-closed ] SilverBullet inserts.
    local function charAfterCursor()
      local line = editor.getCurrentLine()
      local offsetInLine = pos - line.from
      return line.text:sub(offsetInLine + 1, offsetInLine + 1)
    end

    -- Helper: if SilverBullet auto-closed [ to [], the ] sits right after
    local function toPos()
      if charAfterCursor() == "]" then
        return pos + 1
      end
      return pos
    end

    -- ---------------------------------------------------------
    -- Phase 2: value completion — [key: <partial>
    -- ---------------------------------------------------------
    local keyMatch, valPartial = string.match(linePrefix, "%[([%w_%-]+):%s*([%w_%-\"]*)$")

    if keyMatch then
      local attrValues = config.get("taskAttrValues") or {}
      local opts = {}

      for _, entry in ipairs(attrValues) do
        if tostring(entry[1]):lower() == keyMatch:lower() then
          for _, v in ipairs(entry[2]) do
            local vStr = tostring(v)
            -- Show all values when nothing typed yet; filter once user starts typing
            if string.find(vStr:lower(), valPartial:lower(), 1, true) then
              table.insert(opts, {
                label  = vStr,
                detail = "[" .. keyMatch .. ": ...]",
                apply  = function()
                  editor.dispatch({
                    changes = {
                      from   = pos - string.len(valPartial),
                      to     = toPos(),
                      insert = '"' .. vStr .. '"]'
                    }
                  })
                end
              })
            end
          end
          break
        end
      end

      if #opts > 0 then
        return {
          from    = pos - string.len(valPartial),
          options = opts
        }
      end

      -- Key exists but has no configured values — return without suggestions
      -- so the user can type freely without an empty dropdown appearing.
      return
    end

    -- ---------------------------------------------------------
    -- Phase 1: key completion — [<partial>
    -- Triggers immediately on [ because keyPartial can be "".
    -- ---------------------------------------------------------
    local keyPartial = string.match(linePrefix, "%[([%w_%-]*)$")

    if not keyPartial then return end

    local attrKeys = config.get("taskAttrKeys") or {}
    local opts = {}

    for _, key in ipairs(attrKeys) do
      local keyStr = tostring(key)
      if string.find(keyStr:lower(), keyPartial:lower(), 1, true) then
        table.insert(opts, {
          label  = keyStr,
          detail = "task attribute",
          apply  = function()
            editor.dispatch({
              changes = {
                -- Replace from the [ bracket through to the cursor.
                -- Leave any auto-closed ] in place — phase 2 will consume it via toPos().
                from   = pos - string.len(keyPartial) - 1,
                to     = pos,
                insert = "[" .. keyStr .. ":"
              }
            })
            -- Immediately open phase 2 completion without requiring a keystroke.
            pcall(function() editor.complete() end)
          end
        })
      end
    end

    if #opts == 0 then return end

    return {
      from    = pos - string.len(keyPartial),
      options = opts
    }
  end
}

How to use:

  1. Type [ to open the Autocomplete dropdown menu.
  2. Select option (attribute key)
  3. press space to open Second Phase
  4. Select option (attribute value) or start typing

3 Likes

Hello @Mr.Red

Sorry not working on my side ???
(also not a big of modal shortcut -> noise pollution: I more willing typing stuff)

task completion

implentation and completion copy pasted in CONFIG
config extract :

1 Like

did you do a System: Reload after copy/pasting the code?

Try to also reload/refresh the page after you do "System: Reload" (F5 or Ctrl-R)

what SB version are you on? stable or edge?
which edhge version?

I'm on: SilverBullet 2.4.1-3ddfab51e828a1b105264cb7f51101b461419d4f-2026-02-13T19-05-36Z, and it's working

maybe try this: Queries and slash commands stopped working - #2 by Mike

1 Like

maybe try this: Queries and slash commands stopped working - #2 by Mike
thanks for the link, as sais in this post, reloaded, F5 and so on but did not thought about browser. Cleaning cache did the job.

Thanks, so thanks for this helpufull support & code

2 Likes

So cool as always, thank you @Mr.Red!

For certain date attributes like scheduled, is it possible to specify that for autocompletion, it should open up your awesome date picker ?

1 Like