emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
From: Jack Kamm <jackkamm@gmail.com>
To: Nicolas Goaziou <mail@nicolasgoaziou.fr>
Cc: emacs-orgmode@gnu.org, Richard Kim <Richard.Kim1@synopsys.com>
Subject: [PATCH] restore window configuration after org-edit-src-exit
Date: Mon, 23 Dec 2019 10:18:33 -0800	[thread overview]
Message-ID: <87woamc3d2.fsf@gmail.com> (raw)
In-Reply-To: <87blrz3qn1.fsf@nicolasgoaziou.fr>

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

Attached is a patch to restore the window configuration after exiting an
org source buffer, when org-src-window-setup is one of reorganize-frame,
split-window-below, or split-window-right.

References:
https://lists.gnu.org/archive/html/emacs-orgmode/2019-12/msg00263.html
https://lists.gnu.org/archive/html/emacs-orgmode/2018-11/msg00253.html


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: 0001-org-src-restore-windows-for-some-values-of-org-src-w.patch --]
[-- Type: text/x-patch, Size: 3144 bytes --]

From 03a2b9433f1ad15ac21a49e7f0c6c5390e9e4375 Mon Sep 17 00:00:00 2001
From: Jack Kamm <jackkamm@gmail.com>
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    |  3 +++
 lisp/org-src.el | 16 ++++++++++++----
 2 files changed, 15 insertions(+), 4 deletions(-)

diff --git a/etc/ORG-NEWS b/etc/ORG-NEWS
index 44dfd5459..8cb611aee 100644
--- a/etc/ORG-NEWS
+++ b/etc/ORG-NEWS
@@ -24,6 +24,9 @@ for all headlines.
 *** New option to group captured datetime entries by month
 A new `:tree-type month' option was added to org-capture-templates to
 group new datetime entries by month.
+*** 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~
 =<C-c C-c>= bound to ~org-columns-toggle-or-columns-quit~ replaces the
diff --git a/lisp/org-src.el b/lisp/org-src.el
index 5e50a1b47..5a2f07d53 100644
--- a/lisp/org-src.el
+++ b/lisp/org-src.el
@@ -156,8 +156,7 @@ 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."
   :group 'org-edit-structure
@@ -276,6 +275,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 +471,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 +1188,10 @@ 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
+      (set-window-configuration org-src--saved-temp-window-config)
+      (setq org-src--saved-temp-window-config nil))))
 
 (provide 'org-src)
 
-- 
2.24.1


  reply	other threads:[~2019-12-23 18:19 UTC|newest]

Thread overview: 16+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-12-14 19:06 restore window configuration after org-edit-src-exit Richard Kim
2019-12-16 16:30 ` Nicolas Goaziou
2019-12-17  1:51   ` Kyle Meyer
2019-12-17 14:11     ` Jack Kamm
2019-12-17 14:28       ` Jack Kamm
2019-12-17 15:16         ` Fraga, Eric
2019-12-22 14:45         ` Nicolas Goaziou
2019-12-23  1:46           ` Jack Kamm
2019-12-23  8:17             ` Nicolas Goaziou
2019-12-23 17:15               ` Jack Kamm
2019-12-23 17:20                 ` Nicolas Goaziou
2019-12-23 18:18                   ` Jack Kamm [this message]
2020-01-07  8:49                     ` [PATCH] " Nicolas Goaziou
2020-01-09 15:03                       ` Matt Price
2020-01-09 17:43                       ` Jack Kamm
2020-01-14 23:10                         ` Jack Kamm

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.orgmode.org/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=87woamc3d2.fsf@gmail.com \
    --to=jackkamm@gmail.com \
    --cc=Richard.Kim1@synopsys.com \
    --cc=emacs-orgmode@gnu.org \
    --cc=mail@nicolasgoaziou.fr \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).