emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
* [PATCH] org-src: Add option to restore window configuration after edit
@ 2020-02-17  3:50 Tom Gillespie
  2020-02-17  4:15 ` Kyle Meyer
  0 siblings, 1 reply; 3+ messages in thread
From: Tom Gillespie @ 2020-02-17  3:50 UTC (permalink / raw)
  To: emacs-orgmode

[-- Attachment #1: Type: text/plain, Size: 326 bytes --]

Hi all,
  After hours of frustration ending in a realization that I should really
just read the change logs, I tracked down the reason why editing
source blocks was now destroying my window layout. I restored the
old behavior hidden behind a custom variable. Let me know if it looks
ok, or if more work is needed. Thanks!
Tom

[-- Attachment #2: 0001-org-src-Add-option-to-restore-window-configuration-a.patch --]
[-- Type: text/x-patch, Size: 2892 bytes --]

From 362a45ff172af3f49050964aa8534d11374934ca Mon Sep 17 00:00:00 2001
From: Tom Gillespie <tgbugs@gmail.com>
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.
 \\<org-mode-map>
@@ -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


^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH] org-src: Add option to restore window configuration after edit
  2020-02-17  3:50 [PATCH] org-src: Add option to restore window configuration after edit Tom Gillespie
@ 2020-02-17  4:15 ` Kyle Meyer
  2020-02-17  5:27   ` Tom Gillespie
  0 siblings, 1 reply; 3+ messages in thread
From: Kyle Meyer @ 2020-02-17  4:15 UTC (permalink / raw)
  To: Tom Gillespie, emacs-orgmode

Hi Tom,

Tom Gillespie <tgbugs@gmail.com> writes:

> Hi all,
>   After hours of frustration ending in a realization that I should really
> just read the change logs, I tracked down the reason why editing
> source blocks was now destroying my window layout. I restored the
> old behavior hidden behind a custom variable. Let me know if it looks
> ok, or if more work is needed. Thanks!

I haven't looked at your proposed change closely, but I think this is
the same issue that was reported recently [0] and fixed by d833920de
(org-src: restore windows for some values of org-src-window-setup,
2019-12-23).  If you have a chance, please check whether that commit
resolves the issue for you.

[0]: https://lists.gnu.org/archive/html/emacs-orgmode/2019-12/msg00263.html

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] org-src: Add option to restore window configuration after edit
  2020-02-17  4:15 ` Kyle Meyer
@ 2020-02-17  5:27   ` Tom Gillespie
  0 siblings, 0 replies; 3+ messages in thread
From: Tom Gillespie @ 2020-02-17  5:27 UTC (permalink / raw)
  To: Kyle Meyer; +Cc: emacs-orgmode

Hi Kyle,
    Thank you for the pointer. That does indeed solve my issue. I must
have missed it because it wasn't merged into maint. The conversation
in that thread seems to indicate that the old behavior is the correct
default. I imagine that there might be a few other folks with Matt's
use case, but I guess that can wait. Thus, definitely ok to ignore
this patch. Best!
Tom

On Sun, Feb 16, 2020 at 8:16 PM Kyle Meyer <kyle@kyleam.com> wrote:
>
> Hi Tom,
>
> Tom Gillespie <tgbugs@gmail.com> writes:
>
> > Hi all,
> >   After hours of frustration ending in a realization that I should really
> > just read the change logs, I tracked down the reason why editing
> > source blocks was now destroying my window layout. I restored the
> > old behavior hidden behind a custom variable. Let me know if it looks
> > ok, or if more work is needed. Thanks!
>
> I haven't looked at your proposed change closely, but I think this is
> the same issue that was reported recently [0] and fixed by d833920de
> (org-src: restore windows for some values of org-src-window-setup,
> 2019-12-23).  If you have a chance, please check whether that commit
> resolves the issue for you.
>
> [0]: https://lists.gnu.org/archive/html/emacs-orgmode/2019-12/msg00263.html

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2020-02-17  5:28 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-02-17  3:50 [PATCH] org-src: Add option to restore window configuration after edit Tom Gillespie
2020-02-17  4:15 ` Kyle Meyer
2020-02-17  5:27   ` Tom Gillespie

Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).