Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

When i wanna create many custom augends, it there a way to avoid writing table.insert... over and over again? #9

Closed
AstroShen opened this issue Jan 7, 2022 · 9 comments

Comments

@AstroShen
Copy link

dial.augends["custom#boolean"] = dial.common.enum_cyclic{ strlist = {"true", "false"} }
dial.augends["custom#direction"] = dial.common.enum_cyclic{ strlist = {"North", "South", "West", "East"} }
dial.augends["custom#great"] = dial.common.enum_cyclic{ strlist = {">", "<"} }
dial.augends["custom#greatequal"] = dial.common.enum_cyclic{ strlist = {">=", "<="} }
dial.augends["custom#selfadd"] = dial.common.enum_cyclic{ strlist = {"++", "--"} }
table.insert(dial.config.searchlist.normal, "custom#boolean")
....
....
....

@monaqa
Copy link
Owner

monaqa commented Jan 8, 2022

There are two steps you need to take to add a custom augend:

  1. register the augends you want to add in dial.augends.
  2. list the augends you want to enable in dial.config.searchlist.normal / dial.config.searchlist.visual.

For example, you can do the following

dial.config.searchlist.normal = { "custom#boolean", "custom#direction" }

(but the default augends will not work in this case).

@AstroShen
Copy link
Author

It is a little trouble. But i think the plugin you devepled is very general and can be the best Ctrl-A/X plugin. Hope the more extensible way of custom augends.

@AstroShen
Copy link
Author

BTW, suggest support none-word character custom augends like "++, --", ">=, <=", ....

@axieax
Copy link

axieax commented Jan 12, 2022

@AstroShen you can use vim.list_extend to avoid repeated table.insert calls, for example:

local dial = require("dial")

local extra_augends = {
	"markup#markdown#header",
	"date#[%H:%M:%S]",
}

local custom_augends = {
	boolean = dial.common.enum_cyclic({ strlist = { "true", "false" } }),
	Boolean = dial.common.enum_cyclic({ strlist = { "True", "False" } }),
	-- on = dial.common.enum_cyclic({ strlist = { "on", "off" } }),
	-- ON = dial.common.enum_cyclic({ strlist = { "ON", "OFF" } }),
	-- On = dial.common.enum_cyclic({ strlist = { "On", "Off" } }),
	-- direction = dial.common.enum_cyclic({ strlist = { "north", "south", "west", "east" } }),
	-- Direction = dial.common.enum_cyclic({ strlist = { "North", "South", "West", "East" } }),
	greater = dial.common.enum_cyclic({ strlist = { ">", "<" } }),
	-- equal = dial.common.enum_cyclic({ strlist = { "==", "!=" } }),
	-- Equal = dial.common.enum_cyclic({ strlist = { "===", "!==" } }),
	-- greaterEqual = dial.common.enum_cyclic({ strlist = { ">=", "<=" } }),
	-- selfAdd = dial.common.enum_cyclic({ strlist = { "++", "--" } }),
}

-- register custom augends
for k, v in pairs(custom_augends) do
	local augend_name = "custom#" .. k
	dial.augends[augend_name] = v
	table.insert(extra_augends, augend_name)
end

-- extend capabilities
vim.list_extend(dial.config.searchlist.normal, extra_augends)
vim.list_extend(dial.config.searchlist.visual, extra_augends)

Unfortunately for me, my "greater", "equal", "Equal", "greaterEqual", "selfAdd" custom augments aren't working as expected, not sure why though..

For example:
Incrementing 1 < 2 with cursor on < will move the cursor to 2 and increment that number to 3, but incrementing a < b with cursor on < will do nothing.

I'm on nvim v0.6.1. Also, I see there hasn't been any updates to this plugin for a while. Is dps-dial.vim a replacement for this plugin?

Btw +1 to AstroShen's suggestion for supporting these extra augends as well :)

@monaqa
Copy link
Owner

monaqa commented Jan 18, 2022

@AstroShen @axieax I am sorry for late response, and thank you for your suggestions!

Recently, I've been fascinated by denops.vim, which can create plugins using TypeScript, and dps-dial.vim is a product of that. dps-dial.vim supports dot-repeat and is very versatile, but it requires Deno runtime to be installed.
To be honest, I am undecided which one I should focus on, dial.nvim or dps-dial.vim, because both of them have their advantages.

By the way, you can add non-word augends like this:

local custom_augends = {
  greater = dial.common.enum_cyclic({ strlist = { ">", "<" }, ptn_format = "\\C\\M\\(%s\\)" }),
}

@axieax
Copy link

axieax commented Jan 18, 2022

Interesting I see now! Is the functionality similar for both versions, other than dot-repeat and case switching (this sounds so cool!)? I'm curious as to what advantages each have over the other (definitely compatibility for Lua, speed and development should still be quite good as well tho?).

Thanks for the non-word augends guide btw! Most of them work now, except for the self increment ones (+=, ++) for some reason. This is what I'm currently using:

local non_word_pattern = "\\C\\M\\(%s\\)"
local custom_augends = {
  selfIncrementBy = dial.common.enum_cyclic({
    strlist = { "+=", "-=", "*=", "/=", "//=", "%=" },
    ptn_format = non_word_pattern,
  }),
  selfIncrementOne = dial.common.enum_cyclic({ strlist = { "++", "--" }, ptn_format = non_word_pattern }),
}

@monaqa
Copy link
Owner

monaqa commented Feb 16, 2022

Thank you, there was a bug that some characters (such as +, .) was treated as special characters of Lua.
I fixed it and now (3b70b2a) the following config should work as expected.

local non_word_pattern = "\\C\\M\\(%s\\)"
local custom_augends = {
  selfIncrementBy = dial.common.enum_cyclic({
    strlist = { "+=", "-=", "*=", "/=", "//=", "%=" },
    ptn_format = non_word_pattern,
  }),
  selfIncrementOne = dial.common.enum_cyclic({ strlist = { "++", "--" }, ptn_format = non_word_pattern }),
}

And I decided to reimplement the functionality of dps-dial in Lua and release it as a new version of dial.nvim.
I will update dial.nvim soon to support new features such as dot-repeat.

@axieax
Copy link

axieax commented Feb 16, 2022

Ahh this explains the bugged behaviour! Thanks for the fix :)
Looking forward to the new version!!

@monaqa
Copy link
Owner

monaqa commented Feb 20, 2022

A new version has been released with a completely new configuration interface. So this issue is now closed.
If you have any problems with the new interface, please open a new issue.

@monaqa monaqa closed this as completed Feb 20, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants