Skip to content

Commit e560124

Browse files
Merge pull request #151 from levouh/src-block-buf-edit
2 parents 96f0251 + 142096d commit e560124

File tree

13 files changed

+1294
-97
lines changed

13 files changed

+1294
-97
lines changed

DOCS.md

Lines changed: 38 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,9 @@
99
2. [Agenda mappings](#agenda-mappings)
1010
3. [Capture mappings](#capture-mappings)
1111
4. [Org mappings](#org-mappings)
12-
5. [Text objects](#text-objects)
13-
6. [Dot repeat](#dot-repeat)
12+
5. [Edit Src mappings](#edit-src)
13+
6. [Text objects](#text-objects)
14+
7. [Dot repeat](#dot-repeat)
1415
3. [Document Diagnostics](#document-diagnostics)
1516
4. [Autocompletion](#autocompletion)
1617
5. [Abbreviations](#abbreviations)
@@ -146,7 +147,6 @@ Marker used to indicate a folded headline.
146147
When set to `time`(default), adds `CLOSED` date when marking headline as done.<br />
147148
When set to `false`, it is disabled.
148149

149-
150150
#### **org_highlight_latex_and_related**
151151
*type*: `string|nil`<br />
152152
*default value*: `nil`<br />
@@ -166,6 +166,19 @@ Possible values:
166166
* `indent` - Use default indentation that follows headlines/checkboxes/previous line indent
167167
* `noindent` - Disable indentation. All lines start from 1st column
168168

169+
#### **org_src_window_setup**
170+
*type*: `string|function`<br />
171+
*default value*: "top 16new"<br />
172+
If the value is a string, it will be run directly as input to `:h vim.cmd`, otherwise if the value is a function it will be called. Both
173+
values have the responsibility of opening a buffer (within a window) to show the special edit buffer. The content of the buffer will be
174+
set automatically, so this option only needs to handle opening an empty buffer.
175+
176+
#### **org_edit_src_content_indentation**
177+
*type*: `number`<br />
178+
*default value*: 0<br />
179+
The indent value for content within `SRC` block types beyond the existing indent of the block itself. Only applied when exiting from
180+
an `org_edit_special` action on a `SRC` block.
181+
169182
#### **org_custom_exports**
170183
*type*: `table`<br />
171184
*default value*: `{}`<br />
@@ -623,6 +636,11 @@ using the '+' character. Example: `file:/home/user/.config/nvim/init.lua +10`
623636
* Headline with `CUSTOM_ID` property (starts with `#`)
624637
* Fallback: If file path, opens the file, otherwise, tries to find the Headline title.
625638
When date is under the cursor, open the agenda for that day.<br />
639+
#### **org_edit_special**
640+
*mapped to*: `<Leader>o'`<br />
641+
Open a source block for editing in a temporary buffer of the associated `filetype`.<br />
642+
This is useful for editing text with language servers attached, etc. When the buffer is closed, the text of the underlying source block in the original Org file is updated.
643+
*Note that if the Org file that the source block comes from is edited before the special edit buffer is closed, the edits will not be applied. The special edit buffer contents can be recovered from :messages output*
626644
#### **org_cycle**
627645
*mapped to*: `<TAB>`<br />
628646
Cycle folding for current headline
@@ -739,6 +757,22 @@ require('orgmode').setup({
739757
})
740758
```
741759

760+
### Edit Src
761+
762+
Mappings applied when editing a `SRC` block content via `org_edit_special`.
763+
764+
#### **org_edit_src_abort**
765+
*mapped to*: `<Leader>ok`<br />
766+
Abort changes made to temporary buffer created from the content of a `SRC` block, see above.<br />
767+
768+
#### **org_edit_src_save**
769+
*mapped to*: `<Leader>ow`<br />
770+
Apply changes from the special buffer to the source Org buffer<br />
771+
772+
#### **org_edit_src_show_help**
773+
*mapped to*: `g?`<br />
774+
Show help within the temporary buffer used to edit the content of a `SRC` block.<br />
775+
742776
### Text objects
743777

744778
Operator mappings for `org` files.<br />
@@ -919,6 +953,7 @@ For adding/changing TODO keyword colors see [org-todo-keyword-faces](#org_todo_k
919953

920954
* The following use vanilla _Vim_ syntax matching, and will work without _Treesitter_ highlighting enabled.
921955

956+
`OrgEditSrcHighlight`: The highlight for the source content in an _Org_ buffer while it is being edited in an edit special buffer
922957
`OrgAgendaDeadline`: A item deadline in the agenda view
923958
`OrgAgendaScheduled`: A scheduled item in the agenda view
924959
`OrgAgendaScheduledPast`: A item past its scheduled date in the agenda view

doc/orgmode.txt

Lines changed: 96 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,11 @@ CONTENTS *orgmode-content
2020
1.1.1.10. org_log_done..........................|orgmode-org_log_done|
2121
1.1.1.11. org_highlight_latex_and_related.|orgmode-org_highlight_latex_and_related|
2222
1.1.1.12. org_indent_mode....................|orgmode-org_indent_mode|
23-
1.1.1.13. org_custom_exports..............|orgmode-org_custom_exports|
24-
1.1.1.14. org_time_stamp_rounding_minutes.|orgmode-org_time_stamp_rounding_minutes|
25-
1.1.1.15. org_blank_before_new_entry.|orgmode-org_blank_before_new_entry|
23+
1.1.1.13. org_src_window_setup..........|orgmode-org_src_window_setup|
24+
1.1.1.14. org_edit_src_content_indentation.|orgmode-org_edit_src_content_indentation|
25+
1.1.1.15. org_custom_exports..............|orgmode-org_custom_exports|
26+
1.1.1.16. org_time_stamp_rounding_minutes.|orgmode-org_time_stamp_rounding_minutes|
27+
1.1.1.17. org_blank_before_new_entry.|orgmode-org_blank_before_new_entry|
2628
1.1.2. Agenda settings...........................|orgmode-agenda_settings|
2729
1.1.2.1. org_deadline_warning_days.|orgmode-org_deadline_warning_days|
2830
1.1.2.2. org_agenda_span.....................|orgmode-org_agenda_span|
@@ -90,47 +92,52 @@ CONTENTS *orgmode-content
9092
1.2.4.11. org_todo_prev........................|orgmode-org_todo_prev|
9193
1.2.4.12. org_toggle_checkbox............|orgmode-org_toggle_checkbox|
9294
1.2.4.13. org_open_at_point................|orgmode-org_open_at_point|
93-
1.2.4.14. org_cycle................................|orgmode-org_cycle|
94-
1.2.4.15. org_global_cycle..................|orgmode-org_global_cycle|
95-
1.2.4.16. org_archive_subtree............|orgmode-org_archive_subtree|
96-
1.2.4.17. org_set_tags_command..........|orgmode-org_set_tags_command|
97-
1.2.4.18. org_toggle_archive_tag......|orgmode-org_toggle_archive_tag|
98-
1.2.4.19. org_do_promote......................|orgmode-org_do_promote|
99-
1.2.4.20. org_do_demote........................|orgmode-org_do_demote|
100-
1.2.4.21. org_promote_subtree............|orgmode-org_promote_subtree|
101-
1.2.4.22. org_demote_subtree..............|orgmode-org_demote_subtree|
102-
1.2.4.23. org_meta_return....................|orgmode-org_meta_return|
103-
1.2.4.24. org_insert_heading_respect_content.|orgmode-org_insert_heading_respect_content|
104-
1.2.4.25. org_insert_todo_heading....|orgmode-org_insert_todo_heading|
105-
1.2.4.26. org_insert_todo_heading_respect_content.|orgmode-org_insert_todo_heading_respect_content|
106-
1.2.4.27. org_move_subtree_up............|orgmode-org_move_subtree_up|
107-
1.2.4.28. org_move_subtree_down........|orgmode-org_move_subtree_down|
108-
1.2.4.29. org_export..............................|orgmode-org_export|
109-
1.2.4.30. org_next_visible_heading..|orgmode-org_next_visible_heading|
110-
1.2.4.31. org_previous_visible_heading.|orgmode-org_previous_visible_heading|
111-
1.2.4.32. org_forward_heading_same_level.|orgmode-org_forward_heading_same_level|
112-
1.2.4.33. org_backward_heading_same_level.|orgmode-org_backward_heading_same_level|
113-
1.2.4.34. outline_up_heading..............|orgmode-outline_up_heading|
114-
1.2.4.35. org_deadline..........................|orgmode-org_deadline|
115-
1.2.4.36. org_schedule..........................|orgmode-org_schedule|
116-
1.2.4.37. org_time_stamp......................|orgmode-org_time_stamp|
117-
1.2.4.38. org_time_stamp_inactive....|orgmode-org_time_stamp_inactive|
118-
1.2.4.39. org_clock_in..........................|orgmode-org_clock_in|
119-
1.2.4.40. org_clock_out........................|orgmode-org_clock_out|
120-
1.2.4.41. org_clock_cancel..................|orgmode-org_clock_cancel|
121-
1.2.4.42. org_clock_goto......................|orgmode-org_clock_goto|
122-
1.2.4.43. org_set_effort......................|orgmode-org_set_effort|
123-
1.2.4.44. org_show_help........................|orgmode-org_show_help|
124-
1.2.5. Text objects.................................|orgmode-text_objects|
125-
1.2.5.1. inner_heading.........................|orgmode-inner_heading|
126-
1.2.5.2. around_heading.......................|orgmode-around_heading|
127-
1.2.5.3. inner_subtree.........................|orgmode-inner_subtree|
128-
1.2.5.4. around_subtree.......................|orgmode-around_subtree|
129-
1.2.5.5. inner_heading_from_root.....|orgmode-inner_heading_from_root|
130-
1.2.5.6. around_heading_from_root...|orgmode-around_heading_from_root|
131-
1.2.5.7. inner_subtree_from_root.....|orgmode-inner_subtree_from_root|
132-
1.2.5.8. around_subtree_from_root...|orgmode-around_subtree_from_root|
133-
1.2.6. Dot repeat.....................................|orgmode-dot_repeat|
95+
1.2.4.14. org_edit_special..................|orgmode-org_edit_special|
96+
1.2.4.15. org_cycle................................|orgmode-org_cycle|
97+
1.2.4.16. org_global_cycle..................|orgmode-org_global_cycle|
98+
1.2.4.17. org_archive_subtree............|orgmode-org_archive_subtree|
99+
1.2.4.18. org_set_tags_command..........|orgmode-org_set_tags_command|
100+
1.2.4.19. org_toggle_archive_tag......|orgmode-org_toggle_archive_tag|
101+
1.2.4.20. org_do_promote......................|orgmode-org_do_promote|
102+
1.2.4.21. org_do_demote........................|orgmode-org_do_demote|
103+
1.2.4.22. org_promote_subtree............|orgmode-org_promote_subtree|
104+
1.2.4.23. org_demote_subtree..............|orgmode-org_demote_subtree|
105+
1.2.4.24. org_meta_return....................|orgmode-org_meta_return|
106+
1.2.4.25. org_insert_heading_respect_content.|orgmode-org_insert_heading_respect_content|
107+
1.2.4.26. org_insert_todo_heading....|orgmode-org_insert_todo_heading|
108+
1.2.4.27. org_insert_todo_heading_respect_content.|orgmode-org_insert_todo_heading_respect_content|
109+
1.2.4.28. org_move_subtree_up............|orgmode-org_move_subtree_up|
110+
1.2.4.29. org_move_subtree_down........|orgmode-org_move_subtree_down|
111+
1.2.4.30. org_export..............................|orgmode-org_export|
112+
1.2.4.31. org_next_visible_heading..|orgmode-org_next_visible_heading|
113+
1.2.4.32. org_previous_visible_heading.|orgmode-org_previous_visible_heading|
114+
1.2.4.33. org_forward_heading_same_level.|orgmode-org_forward_heading_same_level|
115+
1.2.4.34. org_backward_heading_same_level.|orgmode-org_backward_heading_same_level|
116+
1.2.4.35. outline_up_heading..............|orgmode-outline_up_heading|
117+
1.2.4.36. org_deadline..........................|orgmode-org_deadline|
118+
1.2.4.37. org_schedule..........................|orgmode-org_schedule|
119+
1.2.4.38. org_time_stamp......................|orgmode-org_time_stamp|
120+
1.2.4.39. org_time_stamp_inactive....|orgmode-org_time_stamp_inactive|
121+
1.2.4.40. org_clock_in..........................|orgmode-org_clock_in|
122+
1.2.4.41. org_clock_out........................|orgmode-org_clock_out|
123+
1.2.4.42. org_clock_cancel..................|orgmode-org_clock_cancel|
124+
1.2.4.43. org_clock_goto......................|orgmode-org_clock_goto|
125+
1.2.4.44. org_set_effort......................|orgmode-org_set_effort|
126+
1.2.4.45. org_show_help........................|orgmode-org_show_help|
127+
1.2.5. Edit Src.........................................|orgmode-edit_src|
128+
1.2.5.1. org_edit_src_abort...............|orgmode-org_edit_src_abort|
129+
1.2.5.2. org_edit_src_save.................|orgmode-org_edit_src_save|
130+
1.2.5.3. org_edit_src_show_help.......|orgmode-org_edit_src_show_help|
131+
1.2.6. Text objects.................................|orgmode-text_objects|
132+
1.2.6.1. inner_heading.........................|orgmode-inner_heading|
133+
1.2.6.2. around_heading.......................|orgmode-around_heading|
134+
1.2.6.3. inner_subtree.........................|orgmode-inner_subtree|
135+
1.2.6.4. around_subtree.......................|orgmode-around_subtree|
136+
1.2.6.5. inner_heading_from_root.....|orgmode-inner_heading_from_root|
137+
1.2.6.6. around_heading_from_root...|orgmode-around_heading_from_root|
138+
1.2.6.7. inner_subtree_from_root.....|orgmode-inner_subtree_from_root|
139+
1.2.6.8. around_subtree_from_root...|orgmode-around_subtree_from_root|
140+
1.2.7. Dot repeat.....................................|orgmode-dot_repeat|
134141
1.3. Document Diagnostics.......................|orgmode-document_diagnostics|
135142
1.4. Autocompletion...................................|orgmode-autocompletion|
136143
1.5. Abbreviations.....................................|orgmode-abbreviations|
@@ -165,8 +172,9 @@ TABLE OF CONTENT *orgmode-table_of_conten
165172
2. Agenda mappings (#agenda-mappings)
166173
3. Capture mappings (#capture-mappings)
167174
4. Org mappings (#org-mappings)
168-
5. Text objects (#text-objects)
169-
6. Dot repeat (#dot-repeat)
175+
5. Edit Src mappings (#edit-src)
176+
6. Text objects (#text-objects)
177+
7. Dot repeat (#dot-repeat)
170178
3. Document Diagnostics (#document-diagnostics)
171179
4. Autocompletion (#autocompletion)
172180
5. Abbreviations (#abbreviations)
@@ -334,6 +342,21 @@ Possible values:
334342
* `indent` - Use default indentation that follows headlines/checkboxes/previous line indent
335343
* `noindent` - Disable indentation. All lines start from 1st column
336344

345+
ORG_SRC_WINDOW_SETUP *orgmode-org_src_window_setup*
346+
347+
type: `string|function`
348+
default value: "top 16new"
349+
If the value is a string, it will be run directly as input to `:h vim.cmd`, otherwise if the value is a function it will be called. Both
350+
values have the responsibility of opening a buffer (within a window) to show the special edit buffer. The content of the buffer will be
351+
set automatically, so this option only needs to handle opening an empty buffer.
352+
353+
ORG_EDIT_SRC_CONTENT_INDENTATION *orgmode-org_edit_src_content_indentation*
354+
355+
type: `number`
356+
default value: 0
357+
The indent value for content within `SRC` block types beyond the existing indent of the block itself. Only applied when exiting from
358+
an `org_edit_special` action on a `SRC` block.
359+
337360
ORG_CUSTOM_EXPORTS *orgmode-org_custom_exports*
338361

339362
type: `table`
@@ -894,6 +917,13 @@ using the '+' character. Example: `file:/home/user/.config/nvim/init.lua +10`
894917
* Fallback: If file path, opens the file, otherwise, tries to find the Headline title.
895918
When date is under the cursor, open the agenda for that day.
896919

920+
ORG_EDIT_SPECIAL *orgmode-org_edit_special*
921+
922+
mapped to: `<Leader>o'`
923+
Open a source block for editing in a temporary buffer of the associated `filetype`.
924+
This is useful for editing text with language servers attached, etc. When the buffer is closed, the text of the underlying source block in the original Org file is updated.
925+
Note that if the Org file that the source block comes from is edited before the special edit buffer is closed, the edits will not be applied. The special edit buffer contents can be recovered from :messages output
926+
897927
ORG_CYCLE *orgmode-org_cycle*
898928

899929
mapped to: `<TAB>`
@@ -1070,6 +1100,25 @@ These mappings live under `mappings.org`, and can be changed like this:
10701100
})
10711101
<
10721102

1103+
EDIT SRC *orgmode-edit_src*
1104+
1105+
Mappings applied when editing a `SRC` block content via `org_edit_special`.
1106+
1107+
ORG_EDIT_SRC_ABORT *orgmode-org_edit_src_abort*
1108+
1109+
mapped to: `<Leader>ok`
1110+
Abort changes made to temporary buffer created from the content of a `SRC` block, see above.
1111+
1112+
ORG_EDIT_SRC_SAVE *orgmode-org_edit_src_save*
1113+
1114+
mapped to: `<Leader>ow`
1115+
Apply changes from the special buffer to the source Org buffer
1116+
1117+
ORG_EDIT_SRC_SHOW_HELP *orgmode-org_edit_src_show_help*
1118+
1119+
mapped to: `g?`
1120+
Show help within the temporary buffer used to edit the content of a `SRC` block.
1121+
10731122
TEXT OBJECTS *orgmode-text_objects*
10741123

10751124
Operator mappings for `org` files.
@@ -1264,6 +1313,7 @@ HIGHLIGHT GROUPS *orgmode-highlight_group
12641313

12651314
* The following use vanilla Vim syntax matching, and will work without Treesitter highlighting enabled.
12661315

1316+
`OrgEditSrcHighlight`: The highlight for the source content in an Org buffer while it is being edited in an edit special buffer
12671317
`OrgAgendaDeadline`: A item deadline in the agenda view
12681318
`OrgAgendaScheduled`: A scheduled item in the agenda view
12691319
`OrgAgendaScheduledPast`: A item past its scheduled date in the agenda view

lua/orgmode/colors/highlights.lua

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,16 @@ function M.link_ts_highlights()
3636
end
3737
end
3838

39+
function M.link_highlights()
40+
local links = {
41+
OrgEditSrcHighlight = 'Visual',
42+
}
43+
44+
for src, def in pairs(links) do
45+
vim.cmd(string.format([[hi def link %s %s]], src, def))
46+
end
47+
end
48+
3949
function M.define_agenda_colors()
4050
local keyword_colors = colors.get_todo_keywords_colors()
4151
local c = {
@@ -124,6 +134,8 @@ function M.define_highlights()
124134
M.link_ts_highlights()
125135
end
126136

137+
M.link_highlights()
138+
127139
local faces = M.define_org_todo_keyword_colors(true)
128140
return M.define_org_headline_colors(faces)
129141
end

lua/orgmode/config/defaults.lua

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,8 @@ return {
3535
heading = true,
3636
plain_list_item = false,
3737
},
38+
org_src_window_setup = 'top 16new',
39+
org_edit_src_content_indentation = 0,
3840
diagnostics = true,
3941
notifications = {
4042
enabled = false,
@@ -101,6 +103,7 @@ return {
101103
org_todo_prev = 'ciT',
102104
org_toggle_checkbox = '<C-Space>',
103105
org_open_at_point = '<Leader>oo',
106+
org_edit_special = [[<Leader>o']],
104107
org_cycle = '<TAB>',
105108
org_global_cycle = '<S-TAB>',
106109
org_archive_subtree = '<Leader>o$',
@@ -133,6 +136,11 @@ return {
133136
org_set_effort = '<leader>oxe',
134137
org_show_help = 'g?',
135138
},
139+
edit_src = {
140+
org_edit_src_abort = '<Leader>ok',
141+
org_edit_src_save = '<Leader>ow',
142+
org_edit_src_show_help = 'g?',
143+
},
136144
text_objects = {
137145
inner_heading = 'ih',
138146
around_heading = 'ah',

lua/orgmode/config/mappings.lua

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ return {
4949
org_todo_prev = { 'org_mappings.todo_prev_state' },
5050
org_toggle_checkbox = { 'org_mappings.toggle_checkbox' },
5151
org_open_at_point = { 'org_mappings.open_at_point' },
52+
org_edit_special = { 'org_mappings.edit_special' },
5253
org_cycle = { 'org_mappings.cycle' },
5354
org_global_cycle = { 'org_mappings.global_cycle' },
5455
org_archive_subtree = { 'org_mappings.archive' },

0 commit comments

Comments
 (0)