Skip to content

Commit

Permalink
feat(edit_src): Add mapping to write and close special edit buffer
Browse files Browse the repository at this point in the history
  • Loading branch information
kristijanhusak committed Jan 16, 2025
1 parent 034a5e7 commit c9027f9
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 1 deletion.
5 changes: 5 additions & 0 deletions DOCS.md
Original file line number Diff line number Diff line change
Expand Up @@ -1637,6 +1637,11 @@ Abort changes made to temporary buffer created from the content of a `SRC` block
_mapped to_: `<Leader>ow`<br />
Apply changes from the special buffer to the source Org buffer<br />

#### **org_edit_src_save_exit**

_mapped to_: `<Leader>'`<br />
Apply changes from the special buffer to the source Org buffer and close the edit special window<br />

#### **org_edit_src_show_help**

_mapped to_: `g?`<br />
Expand Down
3 changes: 2 additions & 1 deletion lua/orgmode/config/_meta.lua
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@
---@field org_toggle_checkbox? string Default: '<C-Space>'
---@field org_toggle_heading? string Default: '<prefix>*'
---@field org_open_at_point? string Default: '<prefix>o'
---@field org_edit_special? string Default: [[<prefix>']]
---@field org_edit_special? string Default: "<prefix>'"
---@field org_add_note? string Default: '<prefix>na'
---@field org_cycle? string Default: '<TAB>'
---@field org_global_cycle? string Default: '<S-TAB>'
Expand Down Expand Up @@ -158,6 +158,7 @@
---@class OrgMappingsEditSrc
---@field org_edit_src_abort? string Default: '<prefix>k'
---@field org_edit_src_save? string Default: '<prefix>w'
---@field org_edit_src_save_exit? string Default: "<prefix>'"
---@field org_edit_src_show_help? string Default: 'g?'
---
---@class OrgEmacsConfig
Expand Down
1 change: 1 addition & 0 deletions lua/orgmode/config/defaults.lua
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,7 @@ local DefaultConfig = {
edit_src = {
org_edit_src_abort = '<prefix>k',
org_edit_src_save = '<prefix>w',
org_edit_src_save_exit = [[<prefix>']],
org_edit_src_show_help = 'g?',
},
text_objects = {
Expand Down
9 changes: 9 additions & 0 deletions lua/orgmode/config/mappings/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -373,6 +373,15 @@ return {
[[<Cmd>lua require('orgmode.objects.edit_special'):new():write()<CR>]],
{ opts = { desc = 'org save', help_desc = 'Apply changes from the special buffer to the source Org buffer' } }
),
org_edit_src_save_exit = m.custom(
[[<Cmd>lua require('orgmode.objects.edit_special'):new():write_end_exit()<CR>]],
{
opts = {
desc = 'org save and exit',
help_desc = 'Apply changes from the special buffer to the source Org buffer and exit',
},
}
),
},
text_objects = {
inner_heading = m.text_object('inner_heading', { help_desc = 'Select inner headline' }),
Expand Down
13 changes: 13 additions & 0 deletions lua/orgmode/objects/edit_special/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,19 @@ function EditSpecial:write()
:write(ctx)
end

function EditSpecial:write_end_exit()
local ctx = self:get_context(vim.api.nvim_get_current_buf())

self.block_types[ctx.block_type]
:new({
org_bufnr = ctx.org_bufnr,
org_pos = ctx.org_pos,
file = ctx.file,
})
:write(ctx)
vim.cmd([[q!]])
end

function EditSpecial:done()
local wiped_bufnr = vim.api.nvim_get_current_buf()
local ctx = self:get_context(wiped_bufnr)
Expand Down

0 comments on commit c9027f9

Please sign in to comment.