Explorar o código

org-src: restore windows for some values of org-src-window-setup

Jack Kamm %!s(int64=5) %!d(string=hai) anos
pai
achega
d833920def
Modificáronse 2 ficheiros con 22 adicións e 5 borrados
  1. 5 0
      etc/ORG-NEWS
  2. 17 5
      lisp/org-src.el

+ 5 - 0
etc/ORG-NEWS

@@ -30,6 +30,11 @@ group new datetime entries by month.
 Babel Java blocks recognize header argument =:cmdargs= and pass its
 Babel Java blocks recognize header argument =:cmdargs= and pass its
 value in call to =java=.
 value in call to =java=.
 
 
+*** Refinement in window behavior on exiting Org source buffer
+
+After editing a source block, Org will restore the window layout when
+~org-src-window-setup~ is set to a value that modifies the layout.
+
 ** New functions
 ** New functions
 *** ~org-columns-toggle-or-columns-quit~
 *** ~org-columns-toggle-or-columns-quit~
 =<C-c C-c>= bound to ~org-columns-toggle-or-columns-quit~ replaces the
 =<C-c C-c>= bound to ~org-columns-toggle-or-columns-quit~ replaces the

+ 17 - 5
lisp/org-src.el

@@ -156,10 +156,12 @@ split-window-right Show edit buffer to the right of the current window,
                    keeping all other windows.
                    keeping all other windows.
 other-window       Use `switch-to-buffer-other-window' to display edit buffer.
 other-window       Use `switch-to-buffer-other-window' to display edit buffer.
 reorganize-frame   Show only two windows on the current frame, the current
 reorganize-frame   Show only two windows on the current frame, the current
-                   window and the edit buffer.  When exiting the edit buffer,
-                   return to one window.
+                   window and the edit buffer.
 other-frame        Use `switch-to-buffer-other-frame' to display edit buffer.
 other-frame        Use `switch-to-buffer-other-frame' to display edit buffer.
-                   Also, when exiting the edit buffer, kill that frame."
+                   Also, when exiting the edit buffer, kill that frame.
+
+Values that modify the window layout (reorganize-frame, split-window-below,
+split-window-right) will restore the layout after exiting the edit buffer."
   :group 'org-edit-structure
   :group 'org-edit-structure
   :type '(choice
   :type '(choice
 	  (const current-window)
 	  (const current-window)
@@ -276,6 +278,9 @@ issued in the language major mode buffer."
 (defvar-local org-src--remote nil)
 (defvar-local org-src--remote nil)
 (put 'org-src--remote 'permanent-local t)
 (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
 (defvar-local org-src--source-type nil
   "Type of element being edited, as a symbol.")
   "Type of element being edited, as a symbol.")
 (put 'org-src--source-type 'permanent-local t)
 (put 'org-src--source-type 'permanent-local t)
@@ -469,6 +474,10 @@ When REMOTE is non-nil, do not try to preserve point or mark when
 moving from the edit area to the source.
 moving from the edit area to the source.
 
 
 Leave point in edit buffer."
 Leave point in edit buffer."
+  (when (memq org-src-window-setup '(reorganize-frame
+				     split-window-below
+				     split-window-right))
+    (setq org-src--saved-temp-window-config (current-window-configuration)))
   (let* ((area (org-src--contents-area datum))
   (let* ((area (org-src--contents-area datum))
 	 (beg (copy-marker (nth 0 area)))
 	 (beg (copy-marker (nth 0 area)))
 	 (end (copy-marker (nth 1 area) t))
 	 (end (copy-marker (nth 1 area) t))
@@ -1182,8 +1191,11 @@ Throw an error if there is no such buffer."
        (write-back (org-src--goto-coordinates coordinates beg end))))
        (write-back (org-src--goto-coordinates coordinates beg end))))
     ;; Clean up left-over markers and restore window configuration.
     ;; Clean up left-over markers and restore window configuration.
     (set-marker beg nil)
     (set-marker beg nil)
-    (set-marker end nil)))
-
+    (set-marker end nil)
+    (when org-src--saved-temp-window-config
+      (unwind-protect
+	  (set-window-configuration org-src--saved-temp-window-config)
+	(setq org-src--saved-temp-window-config nil)))))
 
 
 (provide 'org-src)
 (provide 'org-src)