From 048f7e1748d6d4e99a06910dbd2e874c7947461d Mon Sep 17 00:00:00 2001 From: Steven Noble <62277+snoblenet@users.noreply.github.com> Date: Thu, 1 Aug 2024 16:30:05 +1000 Subject: [PATCH 01/11] Fix test for Mac OS X, which automatic symlinks /var/ to /private/var/ --- tests/plenary/init_spec.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/plenary/init_spec.lua b/tests/plenary/init_spec.lua index b09f1b061..0069f1f46 100644 --- a/tests/plenary/init_spec.lua +++ b/tests/plenary/init_spec.lua @@ -37,7 +37,7 @@ describe('Init', function() end) it('should append files to paths', function() - local fname = vim.fn.tempname() .. '.org' + local fname = vim.fn.resolve(vim.fn.tempname() .. '.org') vim.fn.writefile({ '* Appended' }, fname) assert.is.Nil(org.files.files[fname]) From 930117bc321f3bfbd777f2017ffbce0f81bc8d88 Mon Sep 17 00:00:00 2001 From: Steven Noble <62277+snoblenet@users.noreply.github.com> Date: Thu, 1 Aug 2024 17:14:19 +1000 Subject: [PATCH 02/11] add test for when keymap is set as string --- tests/plenary/config/config_spec.lua | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/tests/plenary/config/config_spec.lua b/tests/plenary/config/config_spec.lua index 4afa8f44c..0203c9bf1 100644 --- a/tests/plenary/config/config_spec.lua +++ b/tests/plenary/config/config_spec.lua @@ -28,4 +28,22 @@ describe('Config', function() vim.fn.getcwd() .. '/tests/plenary/fixtures/archives_relative/refile.org_archive' ) end) + + it('should use the default key mapping when no override is provided', function() + local org = orgmode.setup({}) + local config = require('orgmode.config') + assert.are.same('g{', config:get_mappings('org').outline_up_heading.user_map) + end) + + it('should use the provided key mapping when the override is provided as a string', function() + local org = orgmode.setup({ + mappings = { + org = { + outline_up_heading = 'gouh', + } + } + }) + local config = require('orgmode.config') + assert.are.same('gouh', config:get_mappings('org').outline_up_heading.user_map) + end) end) From c26fe1a0ad962aca258a62e529d31525aed35361 Mon Sep 17 00:00:00 2001 From: Steven Noble <62277+snoblenet@users.noreply.github.com> Date: Sat, 3 Aug 2024 14:29:46 +1000 Subject: [PATCH 03/11] confirm existing support for tables in keymapping configs with new unit test --- tests/plenary/config/config_spec.lua | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/tests/plenary/config/config_spec.lua b/tests/plenary/config/config_spec.lua index 0203c9bf1..0e4547799 100644 --- a/tests/plenary/config/config_spec.lua +++ b/tests/plenary/config/config_spec.lua @@ -46,4 +46,16 @@ describe('Config', function() local config = require('orgmode.config') assert.are.same('gouh', config:get_mappings('org').outline_up_heading.user_map) end) + + it('should use the provided key mapping when the override is provided as a table', function() + local org = orgmode.setup({ + mappings = { + org = { + outline_up_heading = { 'gouh' }, + } + } + }) + local config = require('orgmode.config') + assert.are.same({ 'gouh' }, config:get_mappings('org').outline_up_heading.user_map) + end) end) From b3889b3d35f63481d70071b5dc7b3aea7cbfa3aa Mon Sep 17 00:00:00 2001 From: Steven Noble <62277+snoblenet@users.noreply.github.com> Date: Sat, 3 Aug 2024 16:50:11 +1000 Subject: [PATCH 04/11] allow user config of the desc field --- lua/orgmode/config/mappings/map_entry.lua | 6 +++ tests/plenary/config/config_spec.lua | 64 +++++++++++++++++++---- 2 files changed, 60 insertions(+), 10 deletions(-) diff --git a/lua/orgmode/config/mappings/map_entry.lua b/lua/orgmode/config/mappings/map_entry.lua index 6ba34e3a1..507ef4970 100644 --- a/lua/orgmode/config/mappings/map_entry.lua +++ b/lua/orgmode/config/mappings/map_entry.lua @@ -106,6 +106,12 @@ function MapEntry:attach(default_mapping, user_mapping, opts) map_opts.prefix = nil end + if user_mapping ~= nil then + if user_mapping.desc ~= nil then + map_opts.desc = user_mapping.desc + end + end + for _, map in ipairs(mapping) do if prefix ~= '' then map = map:gsub('', prefix) diff --git a/tests/plenary/config/config_spec.lua b/tests/plenary/config/config_spec.lua index 0e4547799..06669a968 100644 --- a/tests/plenary/config/config_spec.lua +++ b/tests/plenary/config/config_spec.lua @@ -1,4 +1,28 @@ local orgmode = require('orgmode') +local config = require('orgmode.config') + +local get_normal_mode_mapping_in_org_buffer = function(lhs) + local current_buffer = vim.api.nvim_buf_get_name(0) + + local refile_file = vim.fn.getcwd() .. '/tests/plenary/fixtures/refile.org' + vim.cmd('edit '..refile_file) + + local normal_mode_mappings_in_org_buffer = vim.api.nvim_buf_get_keymap(0, 'n') + + for _, keymap in ipairs(normal_mode_mappings_in_org_buffer) do + if keymap then + if keymap['lhs'] then + if keymap['lhs'] == lhs then + vim.cmd('edit '..current_buffer) + return keymap + end + end + end + end + + vim.cmd('edit '..current_buffer) + return nil +end describe('Config', function() local refile_file = vim.fn.getcwd() .. '/tests/plenary/fixtures/refile.org' @@ -9,7 +33,6 @@ describe('Config', function() org_default_notes_file = refile_file, org_archive_location = vim.fn.getcwd() .. '/tests/plenary/fixtures/archive/%s_archive::', }) - local config = require('orgmode.config') assert.are.same( config:parse_archive_location(refile_file), vim.fn.getcwd() .. '/tests/plenary/fixtures/archive/refile.org_archive' @@ -22,29 +45,33 @@ describe('Config', function() org_default_notes_file = refile_file, org_archive_location = 'archives_relative/%s_archive::', }) - local config = require('orgmode.config') assert.are.same( config:parse_archive_location(refile_file), vim.fn.getcwd() .. '/tests/plenary/fixtures/archives_relative/refile.org_archive' ) end) - + +---@diagnostic disable: need-check-nil it('should use the default key mapping when no override is provided', function() local org = orgmode.setup({}) - local config = require('orgmode.config') - assert.are.same('g{', config:get_mappings('org').outline_up_heading.user_map) + + local mapping = get_normal_mode_mapping_in_org_buffer('g{') + assert.are.same('lua require("orgmode").action("org_mappings.outline_up_heading")', mapping['rhs']) + assert.are.same('org goto parent headline', mapping['desc']) end) it('should use the provided key mapping when the override is provided as a string', function() local org = orgmode.setup({ mappings = { org = { - outline_up_heading = 'gouh', + outline_up_heading = { 'gouh' }, } } }) - local config = require('orgmode.config') - assert.are.same('gouh', config:get_mappings('org').outline_up_heading.user_map) + + local mapping = get_normal_mode_mapping_in_org_buffer('gouh') + assert.are.same('lua require("orgmode").action("org_mappings.outline_up_heading")', mapping['rhs']) + assert.are.same('org goto parent headline', mapping['desc']) end) it('should use the provided key mapping when the override is provided as a table', function() @@ -55,7 +82,24 @@ describe('Config', function() } } }) - local config = require('orgmode.config') - assert.are.same({ 'gouh' }, config:get_mappings('org').outline_up_heading.user_map) + + local mapping = get_normal_mode_mapping_in_org_buffer('gouh') + assert.are.same('lua require("orgmode").action("org_mappings.outline_up_heading")', mapping['rhs']) + assert.are.same('org goto parent headline', mapping['desc']) + end) + + it('should use the provided key mapping when the override is provided as a table including a new desc', function() + local org = orgmode.setup({ + mappings = { + org = { + outline_up_heading = { 'gouh', desc = 'Go To Parent Headline' }, + } + } + }) + + local mapping = get_normal_mode_mapping_in_org_buffer('gouh') + assert.are.same('lua require("orgmode").action("org_mappings.outline_up_heading")', mapping['rhs']) + assert.are.same('Go To Parent Headline', mapping['desc']) end) +---@diagnostic enable: need-check-nil end) From 2bb8338bed7066cde75624bef01a69339a88121e Mon Sep 17 00:00:00 2001 From: Steven Noble <62277+snoblenet@users.noreply.github.com> Date: Sat, 3 Aug 2024 17:00:34 +1000 Subject: [PATCH 05/11] update readme showing how to change the value of 'desc' --- DOCS.md | 33 +++++++++++++++++++++++++++++++-- 1 file changed, 31 insertions(+), 2 deletions(-) diff --git a/DOCS.md b/DOCS.md index efbb82ad6..fcc0cddc0 100644 --- a/DOCS.md +++ b/DOCS.md @@ -847,13 +847,42 @@ require('orgmode').setup({ org_agenda = false, org_capture = 'gC' }, - agenda = { - org_agenda_later = false + } +}) +``` + +To change a key mapping's `lhs` but not its `desc`, provide a string or a table: + +```lua +require('orgmode').setup({ + org_agenda_files = {'~/Dropbox/org/*', '~/my-orgs/**/*'}, + org_default_notes_file = '~/Dropbox/org/refile.org', + mappings = { + global = { + -- providing a string + org_agenda = '', + -- providing a table + org_capture = { '' } + }, + } +}) + +To change a key mapping's `lhs` and its `desc`, provide a table: + +```lua +require('orgmode').setup({ + org_agenda_files = {'~/Dropbox/org/*', '~/my-orgs/**/*'}, + org_default_notes_file = '~/Dropbox/org/refile.org', + mappings = { + global = { + org_capture = { '', desc = 'Open Capture Prompt' } } } }) ``` +(The `desc` value is displayed in tools like WhichKey.) + You can find the configuration file that holds all default mappings [here](./lua/orgmode/config/mappings/init.lua) **NOTE**: All mappings are normal mode mappings (`nnoremap`) with exception of `org_return` From e16995d6fed68a4cfe45677bf2f56c9890a9dd56 Mon Sep 17 00:00:00 2001 From: Steven Noble <62277+snoblenet@users.noreply.github.com> Date: Sat, 3 Aug 2024 17:37:43 +1000 Subject: [PATCH 06/11] linting fixes -- commas where required --- tests/plenary/config/config_spec.lua | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/tests/plenary/config/config_spec.lua b/tests/plenary/config/config_spec.lua index 06669a968..3602101c1 100644 --- a/tests/plenary/config/config_spec.lua +++ b/tests/plenary/config/config_spec.lua @@ -65,8 +65,8 @@ describe('Config', function() mappings = { org = { outline_up_heading = { 'gouh' }, - } - } + }, + }, }) local mapping = get_normal_mode_mapping_in_org_buffer('gouh') @@ -79,8 +79,8 @@ describe('Config', function() mappings = { org = { outline_up_heading = { 'gouh' }, - } - } + }, + }, }) local mapping = get_normal_mode_mapping_in_org_buffer('gouh') @@ -93,8 +93,8 @@ describe('Config', function() mappings = { org = { outline_up_heading = { 'gouh', desc = 'Go To Parent Headline' }, - } - } + }, + }, }) local mapping = get_normal_mode_mapping_in_org_buffer('gouh') From b902004b41b60f21370bee2a3409d87da5d6e2dc Mon Sep 17 00:00:00 2001 From: Steven Noble <62277+snoblenet@users.noreply.github.com> Date: Sat, 3 Aug 2024 17:41:42 +1000 Subject: [PATCH 07/11] linting fixes -- spaces and indentation --- tests/plenary/config/config_spec.lua | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/tests/plenary/config/config_spec.lua b/tests/plenary/config/config_spec.lua index 3602101c1..79d340843 100644 --- a/tests/plenary/config/config_spec.lua +++ b/tests/plenary/config/config_spec.lua @@ -5,7 +5,7 @@ local get_normal_mode_mapping_in_org_buffer = function(lhs) local current_buffer = vim.api.nvim_buf_get_name(0) local refile_file = vim.fn.getcwd() .. '/tests/plenary/fixtures/refile.org' - vim.cmd('edit '..refile_file) + vim.cmd('edit '.. refile_file) local normal_mode_mappings_in_org_buffer = vim.api.nvim_buf_get_keymap(0, 'n') @@ -20,7 +20,7 @@ local get_normal_mode_mapping_in_org_buffer = function(lhs) end end - vim.cmd('edit '..current_buffer) + vim.cmd('edit '.. current_buffer) return nil end @@ -51,7 +51,7 @@ describe('Config', function() ) end) ----@diagnostic disable: need-check-nil + ---@diagnostic disable: need-check-nil it('should use the default key mapping when no override is provided', function() local org = orgmode.setup({}) @@ -101,5 +101,5 @@ describe('Config', function() assert.are.same('lua require("orgmode").action("org_mappings.outline_up_heading")', mapping['rhs']) assert.are.same('Go To Parent Headline', mapping['desc']) end) ----@diagnostic enable: need-check-nil + ---@diagnostic enable: need-check-nil end) From a7ed24b59d5f096bc91a681a9b21374ad0e3c3e3 Mon Sep 17 00:00:00 2001 From: Steven Noble <62277+snoblenet@users.noreply.github.com> Date: Sat, 3 Aug 2024 17:44:28 +1000 Subject: [PATCH 08/11] linting fixes -- more spacing and indentation --- tests/plenary/config/config_spec.lua | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/tests/plenary/config/config_spec.lua b/tests/plenary/config/config_spec.lua index 79d340843..519181ac0 100644 --- a/tests/plenary/config/config_spec.lua +++ b/tests/plenary/config/config_spec.lua @@ -5,7 +5,7 @@ local get_normal_mode_mapping_in_org_buffer = function(lhs) local current_buffer = vim.api.nvim_buf_get_name(0) local refile_file = vim.fn.getcwd() .. '/tests/plenary/fixtures/refile.org' - vim.cmd('edit '.. refile_file) + vim.cmd('edit ' .. refile_file) local normal_mode_mappings_in_org_buffer = vim.api.nvim_buf_get_keymap(0, 'n') @@ -13,14 +13,14 @@ local get_normal_mode_mapping_in_org_buffer = function(lhs) if keymap then if keymap['lhs'] then if keymap['lhs'] == lhs then - vim.cmd('edit '..current_buffer) + vim.cmd('edit ' .. current_buffer) return keymap - end - end + end + end end end - vim.cmd('edit '.. current_buffer) + vim.cmd('edit ' .. current_buffer) return nil end @@ -50,7 +50,7 @@ describe('Config', function() vim.fn.getcwd() .. '/tests/plenary/fixtures/archives_relative/refile.org_archive' ) end) - + ---@diagnostic disable: need-check-nil it('should use the default key mapping when no override is provided', function() local org = orgmode.setup({}) From abd36470b210a3434903f3c4cf11c9e8f0915c7b Mon Sep 17 00:00:00 2001 From: Steven Noble <62277+snoblenet@users.noreply.github.com> Date: Sat, 3 Aug 2024 17:45:57 +1000 Subject: [PATCH 09/11] linting fixes -- more indentation --- tests/plenary/config/config_spec.lua | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/plenary/config/config_spec.lua b/tests/plenary/config/config_spec.lua index 519181ac0..9e7e77745 100644 --- a/tests/plenary/config/config_spec.lua +++ b/tests/plenary/config/config_spec.lua @@ -15,8 +15,8 @@ local get_normal_mode_mapping_in_org_buffer = function(lhs) if keymap['lhs'] == lhs then vim.cmd('edit ' .. current_buffer) return keymap - end - end + end + end end end From 57aa17e17f969e616935e3cb917aa33abb83737c Mon Sep 17 00:00:00 2001 From: Steven Noble <62277+snoblenet@users.noreply.github.com> Date: Sat, 3 Aug 2024 17:48:21 +1000 Subject: [PATCH 10/11] linting fixes -- remove trailing whitespace --- tests/plenary/config/config_spec.lua | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/plenary/config/config_spec.lua b/tests/plenary/config/config_spec.lua index 9e7e77745..bfb0edd15 100644 --- a/tests/plenary/config/config_spec.lua +++ b/tests/plenary/config/config_spec.lua @@ -15,8 +15,8 @@ local get_normal_mode_mapping_in_org_buffer = function(lhs) if keymap['lhs'] == lhs then vim.cmd('edit ' .. current_buffer) return keymap - end - end + end + end end end From 90ea9ea8ed0f3214c42e84fb5cc6e1a98b76a033 Mon Sep 17 00:00:00 2001 From: Steven Noble <62277+snoblenet@users.noreply.github.com> Date: Thu, 15 Aug 2024 10:10:08 +1000 Subject: [PATCH 11/11] Update lua/orgmode/config/mappings/map_entry.lua Co-authored-by: Kristijan Husak --- lua/orgmode/config/mappings/map_entry.lua | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/lua/orgmode/config/mappings/map_entry.lua b/lua/orgmode/config/mappings/map_entry.lua index 507ef4970..23e03cd97 100644 --- a/lua/orgmode/config/mappings/map_entry.lua +++ b/lua/orgmode/config/mappings/map_entry.lua @@ -106,10 +106,8 @@ function MapEntry:attach(default_mapping, user_mapping, opts) map_opts.prefix = nil end - if user_mapping ~= nil then - if user_mapping.desc ~= nil then - map_opts.desc = user_mapping.desc - end + if type(user_mapping) == 'table' and user_mapping.desc then + map_opts.desc = user_mapping.desc end for _, map in ipairs(mapping) do