org-edit-src-code gains extra optional arguments `code' and
`edit-buffer-name'. If `code' is supplied, then this code forms the
contents of the edit buffer, which is made read-only. In this case,
the mechanisms for writing back to the org buffer on save are
disabled.
Optional argument `edit-buffer-name' allows a name for the edit buffer
to be supplied.
This support was totally broken. It works now again. Unfortunately
it is not possible to edit the table directly in the org-mode buffer
anymore - to edit such a table, you have to use C-c '
Saving the edit buffer is achieved by calling org-edit-src-exit,
saving the org buffer and returning to the edit buffer with
org-edit-src-code. When those two functions are used in this context,
they should not attempt to restore the saved window configuration, nor
alter the saved window configuration.
These changes provides frame / window management preferences for the
edit buffer generated using C-c ' on a source code block. Preferences
are specified by a new variable org-src-window-setup, which is based
on org-agenda-window-setup and has the same four options:
current-window, other-window, reorganize-frame, other-frame. These
behave as follows:
* current-window
The edit buffer appears in the current window.
* other-window
`switch-to-buffer-other-window' is used to switch to the edit buffer
in the same frame.
* reorganize-frame [default]
The current frame is reorganized so that it is split between the
source code edit buffer and the parent org buffer.
* other-frame
The edit buffer appears in a new frame. That frame is deleted when
exiting the edit buffer with C-c '.
In org-edit-src-save, point and mark were being restored inside the
save-window-excursion. As it happens, although mark is lost, point
nevertheless retained its position with switch-to-buffer being used to
switch between org and edit buffers, as is currently the
case. However, the failure to restore point correctly is exposed if
more complex options controlling window and frame management are
provided for the edit buffer.
If an active edit buffer exists for a source block, and this variable
is non-nil, then org-edit-src-code will not ask before returning to
the edit buffer, and future saves will overwrite the source block's
contents.
New customizable variable org-src-preserve-indentation, if non-nil,
prevents automatic removal of rectangular blocks of leading whitespace
in source code blocks. This is necessary when embedding python code in
an org file with a view to extracting all python blocks into a single
file (because whitespace indentation is critical in python code). The
changes in this commit also fix two bugs:
- Setting org-edit-src-content-indentation to zero resulted in an
infinite loop in org-edit-src-exit.
- Fixed width regions are defined by lines starting with a colon, with
optional leading whitespace. However, if there was any leading
whitespace, org-edit-src-exit behaved incorrectly, causing the leading
whitespace to grow.
Eric Schulte writes:
> Attached is a small patch for a small issue.
>
> Sometimes a language uses a major mode which can't be guessed
> from it's name. This patch introduces the `org-src-lang-modes'
> variable which can be used to map language names to major modes
> when this is the case. This is used when editing a source-code
> block, or when exporting fontified source-code with htmlize.
>
> So far the only instance of this that I know of is ocaml and
> tuareg-mode, so that's the only thing that `org-src-lang-modes'
> is pre-populated with. Maybe there are other instances as well?
Allow whitespace in code references. Allow the -r switch to remove the
references in the source code even when the lines are not numbered: the
labels can be explicit enough. Note that "-r -k" is the same than no
switch - as expected.
Thanks to Ulf Stegemann for bring this up.
This commit adds a new hook `org-src-mode-hook'.
The Hook run after Org switched a source code snippet to
its Emacs mode. This hook will run
- when editing a source code snippet with \"C-c '\".
- When formatting a source code snippet for export with htmlize.
You may want to use this hook for example to turn off `outline-minor-mode'
or similar things which you want to have when editing a source code file,
but which mess up the display of a snippet in Org exported files.