Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit c9027f9

Browse files
feat(edit_src): Add mapping to write and close special edit buffer
1 parent 034a5e7 commit c9027f9

File tree

5 files changed

+30
-1
lines changed

5 files changed

+30
-1
lines changed

DOCS.md

+5
Original file line numberDiff line numberDiff line change
@@ -1637,6 +1637,11 @@ Abort changes made to temporary buffer created from the content of a `SRC` block
16371637
_mapped to_: `<Leader>ow`<br />
16381638
Apply changes from the special buffer to the source Org buffer<br />
16391639

1640+
#### **org_edit_src_save_exit**
1641+
1642+
_mapped to_: `<Leader>'`<br />
1643+
Apply changes from the special buffer to the source Org buffer and close the edit special window<br />
1644+
16401645
#### **org_edit_src_show_help**
16411646

16421647
_mapped to_: `g?`<br />

lua/orgmode/config/_meta.lua

+2-1
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@
106106
---@field org_toggle_checkbox? string Default: '<C-Space>'
107107
---@field org_toggle_heading? string Default: '<prefix>*'
108108
---@field org_open_at_point? string Default: '<prefix>o'
109-
---@field org_edit_special? string Default: [[<prefix>']]
109+
---@field org_edit_special? string Default: "<prefix>'"
110110
---@field org_add_note? string Default: '<prefix>na'
111111
---@field org_cycle? string Default: '<TAB>'
112112
---@field org_global_cycle? string Default: '<S-TAB>'
@@ -158,6 +158,7 @@
158158
---@class OrgMappingsEditSrc
159159
---@field org_edit_src_abort? string Default: '<prefix>k'
160160
---@field org_edit_src_save? string Default: '<prefix>w'
161+
---@field org_edit_src_save_exit? string Default: "<prefix>'"
161162
---@field org_edit_src_show_help? string Default: 'g?'
162163
---
163164
---@class OrgEmacsConfig

lua/orgmode/config/defaults.lua

+1
Original file line numberDiff line numberDiff line change
@@ -188,6 +188,7 @@ local DefaultConfig = {
188188
edit_src = {
189189
org_edit_src_abort = '<prefix>k',
190190
org_edit_src_save = '<prefix>w',
191+
org_edit_src_save_exit = [[<prefix>']],
191192
org_edit_src_show_help = 'g?',
192193
},
193194
text_objects = {

lua/orgmode/config/mappings/init.lua

+9
Original file line numberDiff line numberDiff line change
@@ -373,6 +373,15 @@ return {
373373
[[<Cmd>lua require('orgmode.objects.edit_special'):new():write()<CR>]],
374374
{ opts = { desc = 'org save', help_desc = 'Apply changes from the special buffer to the source Org buffer' } }
375375
),
376+
org_edit_src_save_exit = m.custom(
377+
[[<Cmd>lua require('orgmode.objects.edit_special'):new():write_end_exit()<CR>]],
378+
{
379+
opts = {
380+
desc = 'org save and exit',
381+
help_desc = 'Apply changes from the special buffer to the source Org buffer and exit',
382+
},
383+
}
384+
),
376385
},
377386
text_objects = {
378387
inner_heading = m.text_object('inner_heading', { help_desc = 'Select inner headline' }),

lua/orgmode/objects/edit_special/init.lua

+13
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,19 @@ function EditSpecial:write()
119119
:write(ctx)
120120
end
121121

122+
function EditSpecial:write_end_exit()
123+
local ctx = self:get_context(vim.api.nvim_get_current_buf())
124+
125+
self.block_types[ctx.block_type]
126+
:new({
127+
org_bufnr = ctx.org_bufnr,
128+
org_pos = ctx.org_pos,
129+
file = ctx.file,
130+
})
131+
:write(ctx)
132+
vim.cmd([[q!]])
133+
end
134+
122135
function EditSpecial:done()
123136
local wiped_bufnr = vim.api.nvim_get_current_buf()
124137
local ctx = self:get_context(wiped_bufnr)

0 commit comments

Comments
 (0)