emacs-orgmode
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Orgmode] [patch] window/frame options for code edit buffers


From: Dan Davison
Subject: [Orgmode] [patch] window/frame options for code edit buffers
Date: Sun, 25 Oct 2009 13:53:41 -0400
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/23.0.91 (gnu/linux)

These proposed changes provide control over the frame and window in
which the edit buffer appears when using C-c ' on a code block, and fix
a couple of minor bugs. The options are the same as for the agenda
buffer:

current-window, other-window, reorganize-frame, other-frame

With other-frame, the new frame is killed when exiting the edit
buffer. Also like the agenda, I've set the default to reorganize-frame,
although I wasn't sure which default was most appropriate (probably
either reorganize-frame or current-window, or maybe the default should
be whatever the value of org-agenda-window-setup is?).

Alternatively, an idea for the future would be to introduce a variable
that specifies frame/window preferences for potential "pop-ups" that
apply to the whole of org-mode, with finer-grained control provided in
specific instances (agenda, src code edit buffers, ?remember buffers,
etc).

These changes allow the org buffer to stay in view while you edit the
code, so keeping the code block hidden with tab on the begin_src line
(or #+startup: hideblocks) may be an attractive option.

The changes are in branch org-src-window-setup at
git://repo.or.cz/org-mode/babel.git, and also pasted below.

Dan

p.s. Can anyone tell me how to tell emacs to always split frames
vertically?


>From 81d5f6c82a75af69fd323e80f1aa79b2fb74dbb5 Mon Sep 17 00:00:00 2001
From: Dan Davison <address@hidden>
Date: Sun, 25 Oct 2009 11:06:03 -0400
Subject: [PATCH] org-src-mode bug fix.

Go straight to edit buffer if
org-src-ask-before-returning-to-edit-buffer is nil
---
 lisp/org-src.el |    4 ++--
 1 files changed, 2 insertions(+), 2 deletions(-)

diff --git a/lisp/org-src.el b/lisp/org-src.el
index a5d3643..2dc8d72 100644
--- a/lisp/org-src.el
+++ b/lisp/org-src.el
@@ -197,8 +197,8 @@ the edited version."
        (error "No such language mode: %s" lang-f))
       (org-goto-line line)
       (if (and (setq buffer (org-edit-src-find-buffer beg end))
-              org-src-ask-before-returning-to-edit-buffer
-              (y-or-n-p "Return to existing edit buffer? [n] will revert 
changes: "))
+              (if org-src-ask-before-returning-to-edit-buffer
+                  (y-or-n-p "Return to existing edit buffer? [n] will revert 
changes: ") t))
          (switch-to-buffer buffer)
        (when buffer
          (with-current-buffer buffer
-- 
1.6.0.4

>From 25c995ceb162d43d331f25e4cf82eb4a89a0165c Mon Sep 17 00:00:00 2001
From: Dan Davison <address@hidden>
Date: Sun, 25 Oct 2009 12:33:25 -0400
Subject: [PATCH] org-src-mode bug fix

In org-edit-src-save, point and mark were being restored inside the
save-window-excursion. As it happens, although mark is lost, point
nevertheless retained its position with switch-to-buffer being used to
switch between org and edit buffers, as is currently the
case. However, the failure to restore point correctly is exposed if
more complex options controlling window and frame management are
provided for the edit buffer.
---
 lisp/org-src.el |   12 ++++++------
 1 files changed, 6 insertions(+), 6 deletions(-)

diff --git a/lisp/org-src.el b/lisp/org-src.el
index 2dc8d72..126ab91 100644
--- a/lisp/org-src.el
+++ b/lisp/org-src.el
@@ -530,15 +530,15 @@ the language, a switch telling if the content should be 
in a single line."
 (defun org-edit-src-save ()
   "Save parent buffer with current state source-code buffer."
   (interactive)
-  (save-window-excursion
-    (let ((p (point)) (m (mark)) msg)
+  (let ((p (point)) (m (mark)) msg)
+    (save-window-excursion
       (org-edit-src-exit)
       (save-buffer)
       (setq msg (current-message))
-      (org-edit-src-code)
-      (push-mark m 'nomessage)
-      (goto-char (min p (point-max)))
-      (message (or msg "")))))
+      (org-edit-src-code))
+    (push-mark m 'nomessage)
+    (goto-char (min p (point-max)))
+    (message (or msg ""))))
 
 (defun org-src-mode-configure-edit-buffer ()
   (when org-edit-src-from-org-mode
-- 
1.6.0.4

>From 226c4b249404340453685c0b8bab01a05934aab0 Mon Sep 17 00:00:00 2001
From: Dan Davison <address@hidden>
Date: Sun, 25 Oct 2009 12:36:33 -0400
Subject: [PATCH] Provide frame/window control when switching to source code 
edit buffer.

These changes provides frame / window management preferences for the
edit buffer generated using C-c ' on a source code block. Preferences
are specified by a new variable org-src-window-setup, which is based
on org-agenda-window-setup and has the same four options:
current-window, other-window, reorganize-frame, other-frame. These
behave as follows:

* current-window
The edit buffer appears in the current window

* other-window
`switch-to-buffer-other-window' is used to switch to the edit buffer
in the same frame.

* reorganize-frame
The current frame is reorganized so that it is split between the
source code edit buffer and the parent org buffer.

* other-frame
The edit buffer appears in a new frame. That frame is deleted when
exiting the edit buffer with C-c '.
---
 lisp/org-src.el |   61 ++++++++++++++++++++++++++++++++++++++++++++++++------
 1 files changed, 54 insertions(+), 7 deletions(-)

diff --git a/lisp/org-src.el b/lisp/org-src.el
index 126ab91..f95a4e4 100644
--- a/lisp/org-src.el
+++ b/lisp/org-src.el
@@ -5,6 +5,7 @@
 ;;
 ;; Author: Carsten Dominik <carsten at orgmode dot org>
 ;;        Bastien Guerry <bzg AT altern DOT org>
+;;         Dan Davison <davison at stats dot ox dot ac dot uk>
 ;; Keywords: outlines, hypermedia, calendar, wp
 ;; Homepage: http://orgmode.org
 ;; Version: 6.31trans
@@ -109,6 +110,23 @@ When nil, the message will only be shown intermittently in 
the echo area."
   :type 'boolean)
 
 
+(defcustom org-src-window-setup 'reorganize-frame
+  "How the source code edit buffer should be displayed.
+Possible values for this option are:
+
+current-window    Show edit buffer in 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.
+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
+  :type '(choice
+         (const current-window)
+         (const other-frame)
+         (const other-window)
+         (const reorganize-frame)))
+
 (defvar org-src-mode-hook nil
   "Hook  run after Org switched a source code snippet to its Emacs mode.
 This hook will run
@@ -199,7 +217,7 @@ the edited version."
       (if (and (setq buffer (org-edit-src-find-buffer beg end))
               (if org-src-ask-before-returning-to-edit-buffer
                   (y-or-n-p "Return to existing edit buffer? [n] will revert 
changes: ") t))
-         (switch-to-buffer buffer)
+         (org-src-switch-to-buffer buffer 'return)
        (when buffer
          (with-current-buffer buffer
            (if (boundp 'org-edit-src-overlay)
@@ -218,7 +236,7 @@ the edited version."
                           (define-key map [mouse-1] 'org-edit-src-continue)
                           map))
        (org-overlay-put ovl :read-only "Leave me alone")
-       (switch-to-buffer buffer)
+       (org-src-switch-to-buffer buffer 'edit)
        (if (eq single 'macro-definition)
            (setq code (replace-regexp-in-string "\\\\n" "\n" code t t)))
        (insert code)
@@ -256,9 +274,35 @@ the edited version."
   (interactive "e")
   (mouse-set-point e)
   (let ((buf (get-char-property (point) 'edit-buffer)))
-    (if buf (switch-to-buffer buf)
+    (if buf (org-src-switch-to-buffer buf 'continue)
       (error "Something is wrong here"))))
 
+(defun org-src-switch-to-buffer (buffer context)
+  (case org-src-window-setup
+    ('current-window
+     (switch-to-buffer buffer))
+    ('other-window
+     (switch-to-buffer-other-window buffer))
+    ('other-frame
+     (case context
+       ('exit
+       (kill-buffer (current-buffer))
+       (delete-frame)
+       (switch-to-buffer buffer))
+       ('save
+       (kill-buffer (current-buffer))
+       (switch-to-buffer buffer))
+       (t
+       (switch-to-buffer-other-frame buffer))))
+    ('reorganize-frame
+     (if (eq context 'edit) (delete-other-windows))
+     (org-switch-to-buffer-other-window buffer)
+     (if (eq context 'exit) (delete-other-windows)))
+    (t
+     (message "Invalid value %s for org-src-window-setup"
+             (symbol-name org-src-window-setup))
+     (switch-to-buffer buffer))))
+
 (defun org-src-construct-edit-buffer-name (org-buffer-name lang)
   "Construct the buffer name for a source editing buffer"
   (concat "*Org Src " org-buffer-name "[ " lang " ]*"))
@@ -457,7 +501,7 @@ the language, a switch telling if the content should be in 
a single line."
     (goto-char pos)
     (org-get-indentation)))
 
-(defun org-edit-src-exit ()
+(defun org-edit-src-exit (&optional context)
   "Exit special edit and protect problematic lines."
   (interactive)
   (unless org-edit-src-from-org-mode
@@ -515,7 +559,7 @@ the language, a switch telling if the content should be in 
a single line."
        (setq total-nindent (+ total-nindent 2)))
     (setq code (buffer-string))
     (set-buffer-modified-p nil)
-    (switch-to-buffer (marker-buffer beg))
+    (org-src-switch-to-buffer (marker-buffer beg) (or context 'exit))
     (kill-buffer buffer)
     (goto-char beg)
     (delete-region beg end)
@@ -532,10 +576,13 @@ the language, a switch telling if the content should be 
in a single line."
   (interactive)
   (let ((p (point)) (m (mark)) msg)
     (save-window-excursion
-      (org-edit-src-exit)
+      (org-edit-src-exit 'save)
       (save-buffer)
       (setq msg (current-message))
-      (org-edit-src-code))
+      (if (eq org-src-window-setup 'other-frame)
+         (let ((org-src-window-setup 'current-window))
+           (org-edit-src-code))
+       (org-edit-src-code)))
     (push-mark m 'nomessage)
     (goto-char (min p (point-max)))
     (message (or msg ""))))
-- 
1.6.0.4





reply via email to

[Prev in Thread] Current Thread [Next in Thread]