diff --git a/README.md b/README.md index 5642f5d..6954733 100644 --- a/README.md +++ b/README.md @@ -1,12 +1,5 @@ # dial.nvim -**NOTICE: This plugin is work-in-progress yet. User interface is subject to change without notice.** - -## FOR USERS OF THE PREVIOUS VERSION (v0.2.0) - -This plugin was released v0.3.0 on 2022/02/20 and is no longer compatible with the old interface. -If you have configured the settings for previous versions, please refer to [TROUBLESHOOTING.md](./TROUBLESHOOTING.md) and reconfigure them. - ## Abstract Extended increment/decrement plugin for [Neovim](https://github.com/neovim/neovim). Written in Lua. @@ -17,6 +10,7 @@ Extended increment/decrement plugin for [Neovim](https://github.com/neovim/neovi * Increment/decrement based on various type of rules * n-ary (`2 <= n <= 36`) integers + * decimal Fractions * date and time * constants (an ordered set of specific strings, such as a keyword or operator) * `true` ⇄ `false` @@ -39,7 +33,7 @@ Extended increment/decrement plugin for [Neovim](https://github.com/neovim/neovi ## Installation -`dial.nvim` requires Neovim `>=0.5.0` (`>=0.6.1` is recommended). +`dial.nvim` requires Neovim `>=0.11.0`. You can install `dial.nvim` by following the instructions of your favorite package manager. ## Usage @@ -48,18 +42,16 @@ This plugin does not provide or override any default key-mappings. To use this plugin, you need to assign the plugin key-mapping to the key you like, as shown below: ```vim -nmap (dial-increment) -nmap (dial-decrement) -nmap g g(dial-increment) -nmap g g(dial-decrement) -vmap (dial-increment) -vmap (dial-decrement) -vmap g g(dial-increment) -vmap g g(dial-decrement) +nnoremap (dial-increment) +nnoremap (dial-decrement) +nnoremap g (dial-g-increment) +nnoremap g (dial-g-decrement) +xnoremap (dial-increment) +xnoremap (dial-decrement) +xnoremap g (dial-g-increment) +xnoremap g (dial-g-decrement) ``` -Note: When you use "g(dial-increment)" or "g(dial-decrement)" on the right side, `remap` option must be enabled. - Or you can configure it with Lua as follows: ```lua @@ -75,16 +67,16 @@ end) vim.keymap.set("n", "g", function() require("dial.map").manipulate("decrement", "gnormal") end) -vim.keymap.set("v", "", function() +vim.keymap.set("x", "", function() require("dial.map").manipulate("increment", "visual") end) -vim.keymap.set("v", "", function() +vim.keymap.set("x", "", function() require("dial.map").manipulate("decrement", "visual") end) -vim.keymap.set("v", "g", function() +vim.keymap.set("x", "g", function() require("dial.map").manipulate("increment", "gvisual") end) -vim.keymap.set("v", "g", function() +vim.keymap.set("x", "g", function() require("dial.map").manipulate("decrement", "gvisual") end) ``` @@ -133,15 +125,14 @@ nmap a "=mygroup(dial-increment) Alternatively, you can set the same mapping without expression register: ```lua -vim.keymap.set("n", "a", require("dial.map").inc_normal("mygroup"), {noremap = true}) +vim.keymap.set("n", "a", require("dial.map").inc_normal("mygroup")) ``` When you don't specify any group name in the way described above, the addends in the `default` group is used instead. ### Example Configuration -```vim -lua << EOF +```lua local augend = require("dial.augend") require("dial.config").augends:register_group{ default = { @@ -149,12 +140,7 @@ require("dial.config").augends:register_group{ augend.integer.alias.hex, augend.date.alias["%Y/%m/%d"], }, - typescript = { - augend.integer.alias.decimal, - augend.integer.alias.hex, - augend.constant.new{ elements = {"let", "const"} }, - }, - visual = { + only_in_visual = { augend.integer.alias.decimal, augend.integer.alias.hex, augend.date.alias["%Y/%m/%d"], @@ -163,14 +149,21 @@ require("dial.config").augends:register_group{ }, } --- change augends in VISUAL mode -vim.keymap.set("v", "", require("dial.map").inc_visual("visual"), {noremap = true}) -vim.keymap.set("v", "", require("dial.map").dec_visual("visual"), {noremap = true}) -EOF +-- Use `only_in_visual` group only in VISUAL / +vim.keymap.set("x", "", function() + require("dial.map").manipulate("increment", "visual", "only_in_visual") +end) +vim.keymap.set("x", "", function() + require("dial.map").manipulate("decrement", "visual", "only_in_visual") +end) -" enable only for specific FileType -autocmd FileType typescript lua vim.api.nvim_buf_set_keymap(0, "n", "", require("dial.map").inc_normal("typescript"), {noremap = true}) -autocmd FileType typescript lua vim.api.nvim_buf_set_keymap(0, "n", "", require("dial.map").dec_normal("typescript"), {noremap = true}) +require("dial.config").augends:on_filetype { + typescript = { + augend.integer.alias.decimal, + augend.integer.alias.hex, + augend.constant.new{ elements = {"let", "const"} }, + }, +} ``` ## List of Augends diff --git a/README_ja.md b/README_ja.md index 9380923..29174b8 100644 --- a/README_ja.md +++ b/README_ja.md @@ -1,12 +1,5 @@ # dial.nvim -**NOTICE: 本プラグインはまだ開発段階であり、事前告知なくインターフェースが変更となることがあります。** - -## 旧バージョン (v0.2.0) を使っていた人へ - -2022/02/20 に v0.3.0 がリリースされ、既存のインターフェースとの互換性がなくなりました。 -以前のバージョン向けの設定を行っていた方は、[TROUBLESHOOTING.md](./TROUBLESHOOTING_ja.md) を参考に再設定を行ってください。 - ## 概要 [Neovim](https://github.com/neovim/neovim) の数値増減機能を拡張する Lua 製プラグイン。 @@ -18,6 +11,7 @@ * 数値をはじめとする様々なものの増減 * n 進数 (`2 <= n <= 36`) の整数 + * 小数 * 日付・時刻 * キーワードや演算子など、所定文字列のトグル * `true` ⇄ `false` @@ -41,8 +35,7 @@ ## インストール -本プラグインには Neovim 0.5.0 以上が必要です(Neovim 0.6.1 以降を推奨)。 - +本プラグインには Neovim 0.11.0 以上が必要です。 好きなパッケージマネージャの指示に従うことでインストールできます。 ## 使用方法 @@ -51,18 +44,16 @@ 本プラグインを有効にするには、いずれかのキーに以下のような割り当てを行う必要があります。 ```vim -nmap (dial-increment) -nmap (dial-decrement) -nmap g g(dial-increment) -nmap g g(dial-decrement) -vmap (dial-increment) -vmap (dial-decrement) -vmap g g(dial-increment) -vmap g g(dial-decrement) +nnoremap (dial-increment) +nnoremap (dial-decrement) +nnoremap g (dial-g-increment) +nnoremap g (dial-g-decrement) +xnoremap (dial-increment) +xnoremap (dial-decrement) +xnoremap g (dial-g-increment) +xnoremap g (dial-g-decrement) ``` -注意: `g(dial-increment)` や `g(dial-decrement)` を右辺で用いる場合は remap を有効にする必要があります。 - または Lua 上で以下のように設定することもできます。 ```lua @@ -78,16 +69,16 @@ end) vim.keymap.set("n", "g", function() require("dial.map").manipulate("decrement", "gnormal") end) -vim.keymap.set("v", "", function() +vim.keymap.set("x", "", function() require("dial.map").manipulate("increment", "visual") end) -vim.keymap.set("v", "", function() +vim.keymap.set("x", "", function() require("dial.map").manipulate("decrement", "visual") end) -vim.keymap.set("v", "g", function() +vim.keymap.set("x", "g", function() require("dial.map").manipulate("increment", "gvisual") end) -vim.keymap.set("v", "g", function() +vim.keymap.set("x", "g", function() require("dial.map").manipulate("decrement", "gvisual") end) ``` @@ -135,15 +126,14 @@ nmap a "=mygroup(dial-increment) また、 Lua 上で以下のように記述すれば expression register を使わずにマッピングを設定できます。 ```lua -vim.keymap.set("n", "a", require("dial.map").inc_normal("mygroup"), {noremap = true}) +vim.keymap.set("n", "a", require("dial.map").inc_normal("mygroup")) ``` expression register などでグループ名を指定しなかった場合、`default` グループにある被加数がかわりに用いられます。 ### 設定例 -```vim -lua << EOF +```lua local augend = require("dial.augend") require("dial.config").augends:register_group{ default = { @@ -151,12 +141,7 @@ require("dial.config").augends:register_group{ augend.integer.alias.hex, augend.date.alias["%Y/%m/%d"], }, - typescript = { - augend.integer.alias.decimal, - augend.integer.alias.hex, - augend.constant.new{ elements = {"let", "const"} }, - }, - visual = { + only_in_visual = { augend.integer.alias.decimal, augend.integer.alias.hex, augend.date.alias["%Y/%m/%d"], @@ -165,14 +150,21 @@ require("dial.config").augends:register_group{ }, } --- VISUAL モードでの被加数を変更する -vim.keymap.set("v", "", require("dial.map").inc_visual("visual"), {noremap = true}) -vim.keymap.set("v", "", require("dial.map").dec_visual("visual"), {noremap = true}) -EOF +-- Use `only_in_visual` group only in VISUAL / +vim.keymap.set("x", "", function() + require("dial.map").manipulate("increment", "visual", "only_in_visual") +end) +vim.keymap.set("x", "", function() + require("dial.map").manipulate("decrement", "visual", "only_in_visual") +end) -" 特定のファイルタイプでのみ有効にする -autocmd FileType typescript lua vim.api.nvim_buf_set_keymap(0, "n", "", require("dial.map").inc_normal("typescript"), {noremap = true}) -autocmd FileType typescript lua vim.api.nvim_buf_set_keymap(0, "n", "", require("dial.map").dec_normal("typescript"), {noremap = true}) +require("dial.config").augends:on_filetype { + typescript = { + augend.integer.alias.decimal, + augend.integer.alias.hex, + augend.constant.new{ elements = {"let", "const"} }, + }, +} ``` ## 被加数の種類と一覧 diff --git a/doc/dial.jax b/doc/dial.jax index 5746187..e195ddf 100644 --- a/doc/dial.jax +++ b/doc/dial.jax @@ -39,7 +39,7 @@ Interface |dial-interface| ============================================================================== REQUIREMENTS *dial-requirements* -* Neovim 0.6.1 or later(0.5.0 以降なら動くと考えられますが保証はしません) +* Neovim 0.11.0 or later ============================================================================== INTRODUCTION *dial-introduction* @@ -95,14 +95,14 @@ USAGE *dial-usage* |dial.nvim|自身はキーマップの設定および上書きを行わないため、プラグインを動作 させるために以下の設定を追加する必要があります。 > - nmap (dial-increment) - nmap (dial-decrement) - nmap g g(dial-increment) - nmap g g(dial-decrement) - vmap (dial-increment) - vmap (dial-decrement) - vmap g g(dial-increment) - vmap g g(dial-decrement) + nnoremap (dial-increment) + nnoremap (dial-decrement) + nnoremap g (dial-g-increment) + nnoremap g (dial-g-decrement) + xnoremap (dial-increment) + xnoremap (dial-decrement) + xnoremap g (dial-g-increment) + xnoremap g (dial-g-decrement) < もしくは Lua 上で以下のように設定することもできます。 @@ -1381,13 +1381,13 @@ ADDITIVE DOT REPEATING *dial-additive-dot-repeating* Vim の便利な機能の1つに、VISUAL モードにおける g があります (|v_g_CTRL-A| 参照)。これは加数を行ごとに1ずつ増やすことができる機能であり、 番号付きの箇条書きなどを生成する際に重宝します。もちろん |dial.nvim| でも同等 -の機能を備えています (|v_g(dial-increment)|)。この機能は便利ながら、増加 +の機能を備えています (|v_(dial-g-increment)|)。この機能は便利ながら、増加 対象が離れた場所にあると使いづらいという制限がありました。 これを解決するため、|dial.nvim| ではノーマルモードの g に相当する機能を提 供しています。これを有効にするには、以下の設定を書いておく必要があります: > - nmap g g(dial-increment) - nmap g g(dial-decrement) + nmap g (dial-g-increment) + nmap g (dial-g-decrement) < もしくは Lua 上で以下のように設定することもできます。 > @@ -1475,7 +1475,7 @@ MAPPING *dial-mapping* {VISUAL}["x](dial-decrement) *v_(dial-decrement)* VISUAL モードにおける CTRL-X に相当する機能を提供します。 -{VISUAL}["x]g(dial-increment) *v_g(dial-increment)* +{VISUAL}["x](dial-g-increment) *v_(dial-g-increment)* VISUAL モードにおける |v_g_CTRL-A| に相当する機能を提供します。 使用方法は|v_(dial-increment)| と似ているものの、上から数えてn行目に @@ -1497,14 +1497,14 @@ MAPPING *dial-mapping* < のように、1週間ごとの日付が得られます(日付の被加数が有効のときに限る)。 -{VISUAL}["x]g(dial-decrement) *v_g(dial-decrement)* +{VISUAL}["x](dial-g-decrement) *v_(dial-g-decrement)* VISUAL モードにおける |v_g_CTRL-X| に相当する機能を提供します。 -["x]g(dial-increment) *g(dial-increment)* +["x](dial-g-increment) *(dial-g-increment)* 基本的に |(dial-increment)| と同じですが、ドットリピートを実行したと きの挙動が異なります。 |dial-additive-dot-repeating| 参照。 -["x]g(dial-decrement) *g(dial-decrement)* +["x](dial-g-decrement) *(dial-g-decrement)* 基本的に |(dial-decrement)| と同じですが、ドットリピートを実行したと きの挙動が異なります。 |dial-additive-dot-repeating| 参照。 diff --git a/doc/dial.txt b/doc/dial.txt index 0aa2e32..d69654a 100644 --- a/doc/dial.txt +++ b/doc/dial.txt @@ -40,8 +40,7 @@ Interface |dial-interface| ============================================================================== REQUIREMENTS *dial-requirements* -* Neovim 0.6.1 or later - (0.5.0 or later will probably work, but not guaranteed) +* Neovim 0.11.0 or later ============================================================================== INTRODUCTION *dial-introduction* @@ -98,14 +97,14 @@ Since this plugin does not replace the default key-mapping, you need to add the following description to the configuration file after installing the plugin. > - nmap (dial-increment) - nmap (dial-decrement) - nmap g g(dial-increment) - nmap g g(dial-decrement) - vmap (dial-increment) - vmap (dial-decrement) - vmap g g(dial-increment) - vmap g g(dial-decrement) + nnoremap (dial-increment) + nnoremap (dial-decrement) + nnoremap g (dial-g-increment) + nnoremap g (dial-g-decrement) + xnoremap (dial-increment) + xnoremap (dial-decrement) + xnoremap g (dial-g-increment) + xnoremap g (dial-g-decrement) < Alternatively, you can configure with Lua as follows: @@ -122,16 +121,16 @@ Alternatively, you can configure with Lua as follows: vim.keymap.set("n", "g", function() require("dial.map").manipulate("decrement", "gnormal") end) - vim.keymap.set("v", "", function() + vim.keymap.set("x", "", function() require("dial.map").manipulate("increment", "visual") end) - vim.keymap.set("v", "", function() + vim.keymap.set("x", "", function() require("dial.map").manipulate("decrement", "visual") end) - vim.keymap.set("v", "g", function() + vim.keymap.set("x", "g", function() require("dial.map").manipulate("increment", "gvisual") end) - vim.keymap.set("v", "g", function() + vim.keymap.set("x", "g", function() require("dial.map").manipulate("decrement", "gvisual") end) < @@ -1434,14 +1433,14 @@ ADDITIVE DOT REPEATING *dial-additive-dot-repeating* One convenient feature of Vim is g in VISUAL mode (see |v_g_CTRL-A|). This allows you to increase the addend by one per line, which is useful for generating numbered list, etc. Of course, |dial.nvim| provides the same -functionality (|v_g(dial-increment)|). However, this feature had the +functionality (|v_(dial-g-increment)|). However, this feature had the limitation that it was difficult to use when the increase targets were located far away. To solve this, |dial.nvim| provides the equivalent of g in normal mode. To enable it, the following configuration must be written: . > - nmap g g(dial-increment) - nmap g g(dial-decrement) + nmap g (dial-g-increment) + nmap g (dial-g-decrement) Alternatively, you can configure with Lua as follows: > @@ -1533,7 +1532,7 @@ MAPPING *dial-mapping* {VISUAL}["x](dial-decrement) *v_(dial-decrement)* An alternative to the existing CTRL-X command in VISUAL mode. -{VISUAL}["x]g(dial-increment) *v_g(dial-increment)* +{VISUAL}["x](dial-g-increment) *v_(dial-g-increment)* An alternative to the existing |v_g_CTRL-A| command in VISUAL mode. Its usage is similar to |v_(dial-increment)|, but the number of addends on line n, counting from the top, is increased by n * [count]. It @@ -1555,14 +1554,14 @@ MAPPING *dial-mapping* 10/03 < -{VISUAL}["x]g(dial-decrement) *v_g(dial-decrement)* +{VISUAL}["x](dial-g-decrement) *v_(dial-g-decrement)* An alternative to the existing |v_g_CTRL-X| command in VISUAL mode. -["x]g(dial-increment) *g(dial-increment)* +["x](dial-g-increment) *(dial-g-increment)* Almost the same as |(dial-increment)|, but but the behavior differs during dot repeating. See |dial-additive-dot-repeating|. -["x]g(dial-decrement) *g(dial-decrement)* +["x](dial-g-decrement) *(dial-g-decrement)* Almost the same as |(dial-decrement)|, but but the behavior differs during dot repeating. See |dial-additive-dot-repeating|. diff --git a/lua/dial/util.lua b/lua/dial/util.lua index 0acd16d..33fa81c 100644 --- a/lua/dial/util.lua +++ b/lua/dial/util.lua @@ -1,9 +1,6 @@ -- utils local M = {} --- NOTE: Needed until compatibility with Neovim 0.9 is dropped -local islist = vim.fn.has('nvim-0.10') == 1 and vim.islist or vim.tbl_islist - ---@generic T ---@param cond boolean ---@param branch_true T @@ -41,7 +38,7 @@ end ---@param arg1 string | function ---@param arg2? string function M.validate_list(name, list, arg1, arg2) - if not islist(list) then + if not vim.islist(list) then error(("%s is not list."):format(name)) end @@ -163,7 +160,7 @@ end -- util.try_get_keys({foo = "bar", hoge = "fuga", teka = "pika"}, ["teka", "foo"]) -- -> ["pika", "bar"] function M.try_get_keys(tbl, keylst) - if not islist(keylst) then + if not vim.islist(keylst) then return nil, "the 2nd argument is not list." end diff --git a/plugin/dial.lua b/plugin/dial.lua new file mode 100644 index 0000000..8428c98 --- /dev/null +++ b/plugin/dial.lua @@ -0,0 +1,18 @@ +if vim.fn.exists "g:loaded_dial" then + return +end + +local cpo = vim.o.cpoptions +vim.cmd [[set cpo&vim]] + +vim.keymap.set("n", "(dial-increment)", require("dial.map").inc_normal()) +vim.keymap.set("n", "(dial-decrement)", require("dial.map").dec_normal()) +vim.keymap.set("n", "(dial-g-increment)", require("dial.map").inc_gnormal()) +vim.keymap.set("n", "(dial-g-decrement)", require("dial.map").dec_gnormal()) +vim.keymap.set("v", "(dial-increment)", require("dial.map").inc_visual() .. "gv") +vim.keymap.set("v", "(dial-decrement)", require("dial.map").dec_visual() .. "gv") +vim.keymap.set("v", "(dial-g-increment)", require("dial.map").inc_gvisual() .. "gv") +vim.keymap.set("v", "(dial-g-decrement)", require("dial.map").dec_gvisual() .. "gv") + +vim.o.cpoptions = cpo +vim.g.loaded_dial = 1 diff --git a/plugin/dial.vim b/plugin/dial.vim deleted file mode 100644 index 7cfed5a..0000000 --- a/plugin/dial.vim +++ /dev/null @@ -1,23 +0,0 @@ -if exists('g:loaded_dial') | finish | endif " prevent loading file twice - -let s:save_cpo = &cpo " save user coptions -set cpo&vim " reset them to defaults - -lua << EOF -vim.keymap.set("n", "(dial-increment)", require("dial.map").inc_normal()) -vim.keymap.set("n", "(dial-decrement)", require("dial.map").dec_normal()) -vim.keymap.set("n", "g(dial-increment)", require("dial.map").inc_gnormal()) -vim.keymap.set("n", "g(dial-decrement)", require("dial.map").dec_gnormal()) -vim.keymap.set("v", "(dial-increment)", require("dial.map").inc_visual() .. "gv") -vim.keymap.set("v", "(dial-decrement)", require("dial.map").dec_visual() .. "gv") -vim.keymap.set("v", "g(dial-increment)", require("dial.map").inc_gvisual() .. "gv") -vim.keymap.set("v", "g(dial-decrement)", require("dial.map").dec_gvisual() .. "gv") -EOF - -command! -range -nargs=? DialIncrement lua require"dial.command".command("increment", {from = , to = }, {}) -command! -range -nargs=? DialDecrement lua require"dial.command".command("decrement", {from = , to = }, {}) - -let &cpo = s:save_cpo " and restore after -unlet s:save_cpo - -let g:loaded_dial = 1