From 9ad611d7e29c974a0cb2fef38ae4f88359395122 Mon Sep 17 00:00:00 2001 From: SwissalpS Date: Sat, 20 Jun 2020 19:35:51 +0200 Subject: [PATCH 1/7] added plugin to list all keybindings use sort on the created document --- plugins/listkeybindings.lua | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) create mode 100644 plugins/listkeybindings.lua diff --git a/plugins/listkeybindings.lua b/plugins/listkeybindings.lua new file mode 100644 index 00000000..d485f0c1 --- /dev/null +++ b/plugins/listkeybindings.lua @@ -0,0 +1,25 @@ +local core = require "core" +local command = require "core.command" +local keymap = require "core.keymap" + +local function listkeybindings() + + local sOut = '' + + for k, v in pairs(keymap.map) do + sOut = sOut .. k + for _, x in ipairs(v) do + sOut = sOut .. ' ' .. x + end + sOut = sOut .. '\n' + end + + core.root_view:open_doc(core.open_doc()) + core.active_view.doc:text_input(sOut) + +end + +command.add("core.docview", { + ["listkeybindings:listkeybindings"] = listkeybindings +}) + From ec7943a17d6eb31daeb38aad22caaae4f7a1f7f7 Mon Sep 17 00:00:00 2001 From: SwissalpS Date: Fri, 26 Jun 2020 03:27:45 +0200 Subject: [PATCH 2/7] also offer binding first list previously was key first only --- plugins/listkeybindings.lua | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/plugins/listkeybindings.lua b/plugins/listkeybindings.lua index d485f0c1..ada7f37f 100644 --- a/plugins/listkeybindings.lua +++ b/plugins/listkeybindings.lua @@ -2,6 +2,22 @@ local core = require "core" local command = require "core.command" local keymap = require "core.keymap" +local function listbindingskey() + + local sOut = '' + + for k, v in pairs(keymap.map) do + for _, x in ipairs(v) do + sOut = sOut .. x .. ' ' + end + sOut = sOut .. k .. '\n' + end + + core.root_view:open_doc(core.open_doc()) + core.active_view.doc:text_input(sOut) + +end + local function listkeybindings() local sOut = '' @@ -20,6 +36,7 @@ local function listkeybindings() end command.add("core.docview", { - ["listkeybindings:listkeybindings"] = listkeybindings + ["listkeybindings:show-key-binding"] = listkeybindings, + ["listkeybindings:show-binding-key"] = listbindingskey, }) From 0324281f3e336d3be4090461ec69ffa4220e8b7b Mon Sep 17 00:00:00 2001 From: SwissalpS Date: Fri, 26 Jun 2020 03:28:38 +0200 Subject: [PATCH 3/7] added listkeybindings to plugins list --- README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/README.md b/README.md index e86d9c9a..5e30d885 100644 --- a/README.md +++ b/README.md @@ -57,6 +57,7 @@ Plugin | Description [`linecopypaste`](plugins/linecopypaste.lua?raw=1) | Copy, cut and paste the current line when nothing is selected [`lineguide`](plugins/lineguide.lua?raw=1) | Displays a line-guide at the line limit offset *([screenshot](https://user-images.githubusercontent.com/3920290/81476159-2cf70000-9208-11ea-928b-9dae3884c477.png))* [`linter`](https://github.com/drmargarido/linters)* | Linters for multiple languages +[`listkeybindings`](plugins/listkeybindings.lua?raw=1) | Dump all defined key bindings to a new document [`macmodkeys`](plugins/macmodkeys.lua?raw=1) | Remaps mac modkeys `command/option` to `ctrl/alt` [`markers`](plugins/markers.lua?raw=1) | Add markers to docs and jump between them quickly *([screenshot](https://user-images.githubusercontent.com/3920290/82252149-5faaa200-9946-11ea-9199-bea2efb7ee23.png))* [`motiontrail`](plugins/motiontrail.lua?raw=1) | Adds a motion-trail to the caret *([screenshot](https://user-images.githubusercontent.com/3920290/83256814-085ccb00-a1ab-11ea-9e35-e6633cbed1a9.gif))* From f3b47f5908bbad28aa75a073e68cc3fa392207d7 Mon Sep 17 00:00:00 2001 From: SwissalpS Date: Fri, 26 Jun 2020 13:38:18 +0200 Subject: [PATCH 4/7] prettier output also showing all duplicates now --- plugins/listkeybindings.lua | 49 +++++++++++++++++++++++++++++-------- 1 file changed, 39 insertions(+), 10 deletions(-) diff --git a/plugins/listkeybindings.lua b/plugins/listkeybindings.lua index ada7f37f..81941987 100644 --- a/plugins/listkeybindings.lua +++ b/plugins/listkeybindings.lua @@ -2,15 +2,41 @@ local core = require "core" local command = require "core.command" local keymap = require "core.keymap" -local function listbindingskey() +local function gatherLists() - local sOut = '' + local lKeys = {} + local lBindings = {} + local iLongestKey = 0 + local iLongestBinding = 0 + local iIndex = 0 for k, v in pairs(keymap.map) do + if iLongestKey < #k then iLongestKey = #k end for _, x in ipairs(v) do - sOut = sOut .. x .. ' ' + iIndex = iIndex + 1 + if iLongestBinding < #x then iLongestBinding = #x end + lKeys[iIndex] = k + lBindings[iIndex] = x end - sOut = sOut .. k .. '\n' + end + + return lKeys, lBindings, iLongestKey, iLongestBinding + +end -- gatherLists + +local function listbindingskey() + + local sOut = '' + local lKeys, lBindings, iLongestKey, iLongestBinding = gatherLists() + + -- format pretty output + local sSpace, k, v + local iLongest = iLongestBinding + 1 + for i = 1, #lKeys, 1 do + k = lBindings[i] + v = lKeys[i] + sSpace = string.rep(' ', iLongest - #k) + sOut = sOut .. k .. sSpace .. v .. '\n' end core.root_view:open_doc(core.open_doc()) @@ -21,13 +47,16 @@ end local function listkeybindings() local sOut = '' + local lKeys, lBindings, iLongestKey, iLongestBinding = gatherLists() - for k, v in pairs(keymap.map) do - sOut = sOut .. k - for _, x in ipairs(v) do - sOut = sOut .. ' ' .. x - end - sOut = sOut .. '\n' + -- format pretty output + local sSpace, k, v + local iLongest = iLongestKey + 1 + for i = 1, #lKeys, 1 do + v = lBindings[i] + k = lKeys[i] + sSpace = string.rep(' ', iLongest - #k) + sOut = sOut .. k .. sSpace .. v .. '\n' end core.root_view:open_doc(core.open_doc()) From 9820aa4862ac6b75257c332cf6dd679b9be705e6 Mon Sep 17 00:00:00 2001 From: SwissalpS Date: Sat, 27 Jun 2020 15:29:27 +0200 Subject: [PATCH 5/7] proper camel case --- plugins/listkeybindings.lua | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/plugins/listkeybindings.lua b/plugins/listkeybindings.lua index 81941987..15497705 100644 --- a/plugins/listkeybindings.lua +++ b/plugins/listkeybindings.lua @@ -24,7 +24,7 @@ local function gatherLists() end -- gatherLists -local function listbindingskey() +local function listBindingsKey() local sOut = '' local lKeys, lBindings, iLongestKey, iLongestBinding = gatherLists() @@ -44,7 +44,7 @@ local function listbindingskey() end -local function listkeybindings() +local function listKeyBindings() local sOut = '' local lKeys, lBindings, iLongestKey, iLongestBinding = gatherLists() @@ -65,7 +65,7 @@ local function listkeybindings() end command.add("core.docview", { - ["listkeybindings:show-key-binding"] = listkeybindings, - ["listkeybindings:show-binding-key"] = listbindingskey, + ["listkeybindings:show-key-binding"] = listKeyBindings, + ["listkeybindings:show-binding-key"] = listBindingsKey, }) From 7b6cc8d61c149dda65db953a0feafa42516b01bd Mon Sep 17 00:00:00 2001 From: SwissalpS Date: Sat, 27 Jun 2020 15:30:06 +0200 Subject: [PATCH 6/7] sort output if sort plugin is installed --- plugins/listkeybindings.lua | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/plugins/listkeybindings.lua b/plugins/listkeybindings.lua index 15497705..b96ce90c 100644 --- a/plugins/listkeybindings.lua +++ b/plugins/listkeybindings.lua @@ -2,6 +2,16 @@ local core = require "core" local command = require "core.command" local keymap = require "core.keymap" +local function pasteAndSort(sOut) + core.root_view:open_doc(core.open_doc()) + core.active_view.doc:text_input(sOut) + if command.map['sort:sort'] then + command.perform('doc:select-all') + command.perform('sort:sort') + command.perform('doc:select-none') + end +end + local function gatherLists() local lKeys = {} @@ -39,8 +49,7 @@ local function listBindingsKey() sOut = sOut .. k .. sSpace .. v .. '\n' end - core.root_view:open_doc(core.open_doc()) - core.active_view.doc:text_input(sOut) + pasteAndSort(sOut) end @@ -59,8 +68,7 @@ local function listKeyBindings() sOut = sOut .. k .. sSpace .. v .. '\n' end - core.root_view:open_doc(core.open_doc()) - core.active_view.doc:text_input(sOut) + pasteAndSort(sOut) end From eb640a6af5bc2c5a4d586d58356ecaa95534ee15 Mon Sep 17 00:00:00 2001 From: SwissalpS Date: Sat, 27 Jun 2020 15:30:38 +0200 Subject: [PATCH 7/7] added header with some documentation --- plugins/listkeybindings.lua | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/plugins/listkeybindings.lua b/plugins/listkeybindings.lua index b96ce90c..3601b9fa 100644 --- a/plugins/listkeybindings.lua +++ b/plugins/listkeybindings.lua @@ -1,3 +1,14 @@ +--[[ + listkeybindings.lua + creates a new document and lists all key-bindings + version: 20200627_152637 + originally by SwissalpS + + show-key-binding will list key first then binding + show-binding-key will list binding first then key + + If sort plugin is installed, the list will also be sorted. +--]] local core = require "core" local command = require "core.command" local keymap = require "core.keymap"