From 362a45ff172af3f49050964aa8534d11374934ca Mon Sep 17 00:00:00 2001 From: Tom Gillespie Date: Sun, 16 Feb 2020 19:21:16 -0800 Subject: [PATCH] org-src: Add option to restore window configuration after edit * lisp/org-src.el: Add an option to restore the previous window configuration after exiting from editing a source block. The variable is called `org-src-window-restore' and is only relevant when `org-src-window-setup' is set to `reorganize-frame'. This commit retains the default behavior in version 9.3 while restoring the old behavior behind a custom variable, it effectively reverts 819e98afd018cad3c13fd58bfcbd979ab36dfbc7 and adds an option to reenable the old behavior. --- lisp/org-src.el | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/lisp/org-src.el b/lisp/org-src.el index 7876deaba..f8f236ebd 100644 --- a/lisp/org-src.el +++ b/lisp/org-src.el @@ -169,6 +169,12 @@ other-frame Use `switch-to-buffer-other-frame' to display edit buffer. (const other-window) (const reorganize-frame))) +(defcustom org-src-window-restore nil + "Non-nil means that org mode will restore the layout of the windows +that was present before the org-src window was initially opened. This +option is only involved if `org-src-window-setup' is set to +`reorganize-frame'") + (defvar org-src-mode-hook nil "Hook run after Org switched a source code snippet to its Emacs mode. \\ @@ -276,6 +282,9 @@ issued in the language major mode buffer." (defvar-local org-src--remote nil) (put 'org-src--remote 'permanent-local t) +(defvar-local org-src--saved-temp-window-config nil) +(put 'org-src--saved-temp-window-config 'permanent-local t) + (defvar-local org-src--source-type nil "Type of element being edited, as a symbol.") (put 'org-src--source-type 'permanent-local t) @@ -469,6 +478,9 @@ When REMOTE is non-nil, do not try to preserve point or mark when moving from the edit area to the source. Leave point in edit buffer." + (when (and (eq org-src-window-setup 'reorganize-frame) + org-src-window-restore) + (setq org-src--saved-temp-window-config (current-window-configuration))) (let* ((area (org-src--contents-area datum)) (beg (copy-marker (nth 0 area))) (end (copy-marker (nth 1 area) t)) @@ -1182,7 +1194,12 @@ Throw an error if there is no such buffer." (write-back (org-src--goto-coordinates coordinates beg end)))) ;; Clean up left-over markers and restore window configuration. (set-marker beg nil) - (set-marker end nil))) + (set-marker end nil) + (when (and (eq org-src-window-setup 'reorganize-frame) + org-src-window-restore + org-src--saved-temp-window-config) + (set-window-configuration org-src--saved-temp-window-config) + (setq org-src--saved-temp-window-config nil)))) (provide 'org-src) -- 2.24.1