From mboxrd@z Thu Jan 1 00:00:00 1970 From: Jack Kamm Subject: Re: [PATCH] restore window configuration after org-edit-src-exit Date: Thu, 09 Jan 2020 09:43:41 -0800 Message-ID: <875zhkjzjm.fsf@gmail.com> References: <87lfrc9qs6.fsf@nicolasgoaziou.fr> <87woavd8j4.fsf@kyleam.com> <87sgljf3e1.fsf@gmail.com> <87mubrf2mm.fsf@gmail.com> <87lfr45shp.fsf@nicolasgoaziou.fr> <87a77jddbb.fsf@gmail.com> <874kxr5ubv.fsf@nicolasgoaziou.fr> <8736dbc6a2.fsf@gmail.com> <87blrz3qn1.fsf@nicolasgoaziou.fr> <87woamc3d2.fsf@gmail.com> <8736crslbi.fsf@nicolasgoaziou.fr> Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" Return-path: Received: from eggs.gnu.org ([2001:470:142:3::10]:40404) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ipbrF-0000P8-1T for emacs-orgmode@gnu.org; Thu, 09 Jan 2020 12:44:34 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ipbrD-0000wI-Dt for emacs-orgmode@gnu.org; Thu, 09 Jan 2020 12:44:32 -0500 Received: from mail-pl1-x644.google.com ([2607:f8b0:4864:20::644]:34764) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1ipbrD-0000q3-1G for emacs-orgmode@gnu.org; Thu, 09 Jan 2020 12:44:31 -0500 Received: by mail-pl1-x644.google.com with SMTP id x17so2846987pln.1 for ; Thu, 09 Jan 2020 09:44:30 -0800 (PST) In-Reply-To: <8736crslbi.fsf@nicolasgoaziou.fr> List-Id: "General discussions about Org-mode." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-orgmode-bounces+geo-emacs-orgmode=m.gmane-mx.org@gnu.org Sender: "Emacs-orgmode" To: Nicolas Goaziou Cc: emacs-orgmode@gnu.org, Richard Kim --=-=-= Content-Type: text/plain Hello, Nicolas Goaziou writes: > Thank you for the patch! Some comments follow. > > It would be useful to also explain what happens when the value is > `reorganize-frame', `split-window-right', or `split-window-right', e.g., > that previous window configuration is restored. > > It may be useful to wrap `set-window-configuration' within > `unwind-protect' so we can still reset the > `org-src--saved-temp-window-config' variable even though something went > wrong. > > WDYT? Thank you for reviewing my patch, I agree with both of your suggestions, and have added them to the attached patch, which I also rebased on latest master. I am wondering whether this should be considered a new feature, or instead fixing a regression, in which case I could rebase on maint instead. Finally, I think we should consider moving to the display-buffer framework (https://www.gnu.org/software/emacs/manual/html_node/elisp/Choosing-Window.html#Choosing-Window), as this will provide a lot more flexibility, and simplify the code as well. We could also use `quit-restore-window' (https://www.gnu.org/software/emacs/manual/html_node/elisp/Quitting-Windows.html) to restore the window configuration after editing. I'll start a new thread/RFC/patch for this later this month, when I have a bit more time. --=-=-= Content-Type: text/x-patch Content-Disposition: attachment; filename=0001-org-src-restore-windows-for-some-values-of-org-src-w.patch >From 8d1cf7500d69823bc4869248bbe251758d3dcdda Mon Sep 17 00:00:00 2001 From: Jack Kamm Date: Mon, 23 Dec 2019 08:55:55 -0800 Subject: [PATCH] org-src: restore windows for some values of org-src-window-setup --- etc/ORG-NEWS | 5 +++++ lisp/org-src.el | 22 +++++++++++++++++----- 2 files changed, 22 insertions(+), 5 deletions(-) diff --git a/etc/ORG-NEWS b/etc/ORG-NEWS index 0f836d946..67c3ca2ed 100644 --- a/etc/ORG-NEWS +++ b/etc/ORG-NEWS @@ -30,6 +30,11 @@ group new datetime entries by month. Babel Java blocks recognize header argument =:cmdargs= and pass its 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 *** ~org-columns-toggle-or-columns-quit~ == bound to ~org-columns-toggle-or-columns-quit~ replaces the diff --git a/lisp/org-src.el b/lisp/org-src.el index 7876deaba..878821b14 100644 --- a/lisp/org-src.el +++ b/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. other-window Use `switch-to-buffer-other-window' to display edit buffer. 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. - 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 :type '(choice (const current-window) @@ -276,6 +278,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 +474,10 @@ 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 (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)) (beg (copy-marker (nth 0 area))) (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)))) ;; Clean up left-over markers and restore window configuration. (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) -- 2.24.1 --=-=-=--