tris203 / precognition.nvim

💭👀precognition.nvim - Precognition uses virtual text and gutter signs to show available motions.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Feature request - Expose visible value as subcommand

osamuaoki opened this issue · comments

Issue:

When I want to setup precognition.toggle() to be mapped to <leader>uP with msg ="Toggle precognition", it will be nice if pop-up message generated upon such key is as consistent as other toggle commands which normally generate notification message with new toggle state. ( I am using this with AstroNvim but situation is the same for LazyVim)

FYI: I start nvim without activating precognition to make this OPT-IN feature.

Possible solution:

Please tell me the following is a reasonable approach or not. (I understand the state indicator pop-up is not as important as other toggled features since it is so obvious but it doesn't hurt ...)

I made a patch to lua/precognition/init.lua for my use along:

@@ -320,6 +320,7 @@ local function create_command()
         toggle = M.toggle,
         show = M.show,
         hide = M.hide,
+        visible = M.visible,
     }
 
     local function execute(args)
@@ -415,6 +416,11 @@ function M.toggle()
     end
 end
 
+--- Expose visible value as function
+function M.visible()
+    return visible
+end
+
 ---@param opts Precognition.PartialConfig
 function M.setup(opts)
     config = vim.tbl_deep_extend("force", default, opts or {})

This enables me to write user.lua for AstroNvim:

  {
    -- "tris203/precognition.nvim",
    "osamuaoki/precognition.nvim",
    event = "User AstroFile",
    dependencies = {
      {
        "AstroNvim/astrocore",
        opts = function(_, opts)
          local maps = opts.mappings
          maps.n["<Leader>uP"] = {
            function()
              local precognition = require "precognition"
              local notify = require("astrocore").notify
              precognition.toggle()
              if precognition.visible() then
                notify "Enabled precognition"
              else
                notify "Disabled precognition"
              end
            end,
            desc = "Toggle precognition",
          }
        end,
      },
    },
    opts = {
      -- override default opts for precognition to start invisible
      startVisible = false,
    },
  },

AstroNvim provided notify is used here which is a wrapper of vim.notify.

Rather than expose a new function.
We could just add a return to the toggle feature that returns the status and you could capture the variable from that?

Yes, that's better.

Yes, that's better.

Did you want to submit a PR @osamuaoki ?

Yes.

See my first try at "Return visible #73"