Giter VIP home page Giter VIP logo

nvim-libmodal's Introduction

nvim-libmodal's People

Contributors

iron-e avatar itsfrank avatar ve5li avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

nvim-libmodal's Issues

`TextChanged` isn't triggered in custom mode

Hi! I'm having a similar issue as #31 but for the TextChanged autocmd:

local M = {}

M.mode = {
  d = function() vim.cmd.delete() end
}

local text_changes = 0

vim.keymap.set('n', 'M', function()
  vim.api.nvim_create_autocmd('TextChanged', {
    callback = function()
      text_changes = text_changes + 1
      vim.notify('text_changes: ' .. text_changes)
    end,
  })

  require('libmodal').mode.enter('Mode', M.mode)
end)

Attempt to compare number with string in Mode.lua:296

Error detected while processing LspAttach Autocommands for "*":
Error during nvim-libmodal mode: 

...ocal/share/nvim/lazy/nvim-libmodal/lua/libmodal/Mode.lua:296: attempt to compare number with string

let me be honest, i'm a noob.
i don't understand the source code, is it something wrong i'm doing?

Error in command causes mode to exit

Hi @Iron-E,

This plugin is something I have been wanting to find for quite a while.
I was about to start playing with kana/vim-submode which doens't seem to be maintained anymore but thankfully I found this project too.

Thanks so much for such a cool plugin. I was able to write my first vim plugin thanks to some copy paste from your tabmode project.
Please take a look: https://github.com/DavidGamba/nvim-window-mode

I couldn't figure out how to handle errors (DavidGamba/nvim-window-mode#1) so when there is an error in the command then it exits the mode. I would like to stay in the mode I am in regardless of the error. Thankfully neovim is displaying the error so at least I can see why I am no longer in that mode.

Using default bindings from within a mode

For my plugin I need to be able to send key codes from Lua without the active Mode interfering. I'm not completely sure how the event loop inside a mode works, but even me setting a variable manually like this

if userInput == 'd' then
    vim.g.fooModePassthrough = true
    vim.api.nvim_input("d")
    vim.g.fooModePassthrough = false
end

would be sufficient for me. Is this possible?

Support mapping to function in Layer

Neovim 0.7 allows mapping to functions from Lua. Submodes always supported this (since they are not actually keymappings) but Layers should support this also

Indicator functionality within a Layer, OR cursor functionality within a Mode.

Hello!
Really love the plugin (I can't believe this hasn't blown up... such a good idea)

I wanted to ask a quick question/or maybe suggest a feature: I am currently working on building a plugin that allows the user to write musical notation inside of nvim. One mode (called score mode) will allow the user's curser to draw in musical symbols by performing all of the steps required to insert the specific UTF characters. Thus it needs to be able to move around and retain the cursor functionality.

I realize I could do this with a layer BUT I lose the super cool named indicator... I also want to create several submodes under this so an indicator would allow the user to keep track of where they are.

So I was curious as to HOW the plugin accesses nvim's Indicator (and is able to write --INSERT-- or --MY_MODE--) and is it possible to have a mode that also retains the cursor... OR is it possible to have a layer that allows you the indicator. (either would work).

Thanks!

`CursorMoved` / `CursorMovedI` isn't triggered inside custom mode

To reproduce:

M.mode = {
  k = function() vim.api.nvim_win_set_cursor(0, { 1, 0 }) end,
  j = function() vim.api.nvim_win_set_cursor(0, { 2, 0 }) end,
}

vim.keymap.set('n', 'M', function()
  vim.api.nvim_create_autocmd('CursorMoved', {
    callback = function()
      vim.notify('Cursor moved')
    end,
  })

  require('libmodal').mode.enter('Mode', M.mode)
end)
  1. Press M to enter custom mode
  2. Press k/j a couple of times (notice that no notification is sent from the autocmd)
  3. Press <esc> to leave mode
  4. Press k/j: now the notification is sent

Importing libmodal prevents pasting into command prompt

As far as i know this is the most basic use of this plugin:

In my vimrc:

lua require'foo'

in lua/foo.lua

local libmodal = require('libmodal')

This causes pasting into the command prompt (i.e. : -> cmd+v/whatever you bind paste to) to do nothing.

Cross Compatability with `vim-libmodal`

The ability to switch to nvim-libmodal without altering a configuration at all is desired. Unfortunately, this won't be possible until Neovim 0.5 as several important features are waiting for release in the master branch.

  • Support dict usage instead of tables.
  • Support funcref usage instead of functions.
    • Added with #6.

Bug: `vim.v.count` is always 0

Hi! I'm trying to use vim.v.count in a mode mapping. However, it seems to always be 0.

To reproduce:

local my_mode = {
  g = function()
    vim.notify('count: ' .. vim.v.count)
  end
}

vim.keymap.set('n', 'M', function()
  require('libmodal').mode.enter('My mode', my_mode)
end)
  • Press M
  • Press 3g
  • Notification says count: 0

Bug: cursor movements aren't updated until after leaving mode

Hi! First of all, thank you for making this super cool plugin!

I'm trying to create a custom mode using nvim-libmodal in which the cursor moves. However, the cursor movement isn't actually rendered until after leaving the mode.

Here's just a small example setup to illustrate the issue:

local libmodal = require 'libmodal'

vim.o.cursorline = true
vim.o.showmode   = false

local my_mode = {
  g = function() vim.api.nvim_win_set_cursor(0, { 1, 0 }) end,
}

vim.keymap.set('n', 'M', function()
  libmodal.mode.enter('my_mode', my_mode)
end)

To reproduce:

  1. Move to the bottom of a file
  2. Press M to enter my_mode
  3. Press g to trigger custom action
  4. Notice how cursorline moves to the top of the file, but the cursor is still drawn in the same spot as it were before you pressed g

I'm on Neovim nightly v0.10.0-dev-2355+g1c7b0b9d5

Modifier mappings don't seem to work support

Mappings with modifiers like ctrl/meta don't seem to work:

local M = {}

M.mode = {
  n = function()
    vim.notify('This works')
  end,
  ['<c-n>'] = function()
    vim.notify("This doesn't work")
  end,
  ['<m-n>'] = function()
    vim.notify("This throws error: 'attempt to compare number with string'")
  end
}

vim.keymap.set('n', 'M', function()
  require('libmodal').mode.enter('My mode', M.mode)
end)
  1. Press M to enter custom mode
  2. Pressing n produces notification 'This works'
  3. Pressing <c-n> doesn't produce a notification
  4. Pressing <m-n> throws an error

Error encountered: Expected lua string

Error message:

E5108: Error executing lua: ...k/packer/start/nvim-libmodal/lua/libmodal/utils/Help.lua:41: Expected lua string
stack traceback:
        [C]: in function 'nvim_strwidth'
        ...k/packer/start/nvim-libmodal/lua/libmodal/utils/Help.lua:41: in function 'new'
        ...te/pack/packer/start/nvim-libmodal/lua/libmodal/Mode.lua:217: in function 'new'
        ...te/pack/packer/start/nvim-libmodal/lua/libmodal/init.lua:35: in function 'enter'
        /Users/rgdpro/.config/nvim/lua/my/whichkey-functions.lua:38: in function 'windowlayer'
        ...g/nvim/lua/plugins/windows-splits-tabs-buffer-motion.lua:71: in function <...g/nvim/lua/plugins/windows-splits-tabs-buffer-motion.lua:70>

Part of the stack trace is when Help message was constructed?

It's trying to get "nvim_strwidth" of a function? Here's my libmodal.mode.enter.
image

Compatibility with `sindrets/winshift.nvim`

Before everything, AWESOME PLUGIN! many thanks to you good sir. ๐Ÿ™๐Ÿผ


Issue:
I added this function that enters a layer:

local function t(str)
	return vim.api.nvim_replace_termcodes(str, true, true, true)
end


_G.windowlayer = function()
	local ok, libmodal = pcall(require, "libmodal")
	if not ok then
		return
	end

	libmodal.mode.enter("WindowMode", {
		h = t("normal <C-w><"),
		j = t("normal <C-w>-"),
		k = t("normal <C-w>+"),
		l = t("normal <C-w>>"),
		["="] = t("normal <C-w>="),

		H = t("normal <Cmd>WinShift left<CR>"),
		J = t("normal <Cmd>WinShift down<CR>"),
		K = t("normal <Cmd>WinShift up<CR>"),
		L = t("normal <Cmd>WinShift right<CR>"),
		x = t("normal <Cmd>WinShift swap<CR>"),

		["<"] = t("normal :BufferLineMovePrev<CR>"),
		[">"] = t("normal :BufferLineMoveNext<CR>"),
	})
end

It seems when I press the x key, it doesn't wait for a response unlike when I run :WinShift swap in command line.

I'm a newb but I can try helping if this is really an issue, just point me where to fix this. Thanks!

feline archieved switch to lualine?

Hi, I wanted to try out your plugin but didn't found an example how to show the mods in lualine, then I saw that you use feline and saw that it's archived by the owner, do you plan to switch to some other plugin like lualine?

If yes, I would love to see your configuration for nvim-libmodal for it.

Layers don't seem to be reusable

This may be by design, but the OOP api for creating layer makes it seem like they should be reusable.


Repro

I created this simple layer using the OOP api:

local layer = libmodal.layer.new({})

local count = 1
layer:map("n", "a", function()
	print("From layer - " .. tostring(count))
	count = count + 1
end, {})

layer:map("n", "<esc>", function()
	layer:exit()
end, {})

vim.keymap.set("n", "<leader>l", function()
	layer:enter()
end, {})

Expected
I can enter and exit the layer multiple times. When the layer is active the a keybind prints the message

Actual
The layer works fine the first time it is entered, but if it is exited and re-entered afterwards, none of the keybinds defined in the layer work.


It feels like a layer should be able to be exited and re-entered without having to set all the keybinds on the layer object every-time it is exited.

consider move initialization to lua

I like the plugin very much. Thanks alot for creating! Since you do setups functional anyway, why not provide one for your plugin initialisation?
This would enable stuff like conditional setups for users etc.

Reasons to do:

  1. A pure lua profile would decrease startup time.
  2. The lua startup profiler would be more correct or simpler to get correct with this change. Otherwise one gets more wrong results.
  3. Try to be consistent as to use functionality of lua, if possible.
  4. Having a function to initialize makes separating things for user-specific settings while getting updates much easier (user may implement a different function to customize plugin).

Another related reason (bad practice/historical reasons): nvim-treesitter/module-template#1

Potentially related discussion for galaxyline: nvimdev/galaxyline.nvim#134

Relevant content for change:

if vim.g.loaded_libmodal == nil
  --finish stuff
end
vim.g.loaded_libmodal = 1;
if vim.o.timeout == nil -- timeout is an option, which should always exist => could be a bug in your code
	vim.o.timeout = true;
end
--highlight default link LibmodalPrompt ModeMsg --please check how pure lua plugins do this or the colorbuddy source
--highlight default link LibmodalStar StatusLine

Of course you could also use the more optimal vim.api functions for setting and getting variables as described in the nvim-lua-guide.

Shallowly switching between libmodal modes

Hi agan! I'm trying to switch between multiple libmodal modes. However, exiting libmodal seems to require one <Esc> press per mode switched. My expected behaviour is that pressing <Esc> would immediately take me to Normal mode, just like how all Vim modes work. Do you agree? If not, is there some other way to exit libmodal? There doesn't seem to be a require('libmodal').mode.exit() that I can create a mapping for ๐Ÿ™‚

To reproduce:

local M = {}

M.mode1 = {
  m = function()
    vim.notify('Mode 1')
  end,
  n = function()
    require('libmodal').mode.enter('My mode 2', M.mode2)
  end
}

M.mode2 = {
  m = function()
    vim.notify('Mode 2')
  end,
  n = function()
    require('libmodal').mode.enter('Mode 1', M.mode1)
  end
}

vim.keymap.set('n', 'M', function()
  require('libmodal').mode.enter('Mode 1', M.mode1)
end)
  1. Press M to enter Mode 1
  2. Press m: "Mode 1" is notified
  3. Press n
  4. Press n to enter Mode 2
  5. Press m: "Mode 2" is notified
  6. Now I have to press <Esc> twice to reach Normal mode

What's the best way to expose the mode keymaps table to my consumers?

Hi again! I'm trying to expose the keymaps table to the consumers of my plugin. Here's a simplified example:

local options = {
local libmodal = require('libmodal')

local M = {}

local options = {
  mode_keymaps = {
    n = function() vim.notify('foo') end,
    u = vim.cmd.undo, -- THIS DOESN'T CURRENTLY WORK
  }
}

vim.keymap.set('n', 'M', function()
  require('libmodal').mode.enter('Mode 1', mode_keymaps)
end)

function M.setup(opts)
  options = vim.tbl_deep_extend('force', options, opts or {})
end

The problem is the line u = vim.cmd.undo. Since libmodal passes the current mode as an agrument, that argument gets passed to vim.cmd.undo, causing the following error:

...ocal/share/nvim/lazy/nvim-libmodal/lua/libmodal/Mode.lua:125: invalid key: input

I could solve this by requiring my users to wrap each callback in a function like this:

u = function() vim.cmd.undo() end

But it feels like an ugly solution. I would prefer if I could abstract away libmodal. So I tried creating a function that iterates over all the mappings and wraps them with a function:

local function clean_mappings(mappings)
  local new_mappings = {}
  for keymap, fn in pairs(mappings) do
    new_mappings[keymap] = function() fn() end
  end

  return new_mappings
end

This solves the agove problem. However, I also want to use a mapping to switch mode with libmodal.mode.switch. That means that the Mode type argument passed to switches returned function gets lost.

Do you have any suggestions as to how I could solve this? Or is there any way for libmodal to determine whether it should or shouldn't pass an argument to the callback when calling it?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.