From mboxrd@z Thu Jan 1 00:00:00 1970 From: Dan Davison Subject: [patch] window/frame options for code edit buffers Date: Sun, 25 Oct 2009 13:53:41 -0400 Message-ID: <87my3fpdga.fsf@stats.ox.ac.uk> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Return-path: Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1N27Hr-0001sD-7w for emacs-orgmode@gnu.org; Sun, 25 Oct 2009 13:53:51 -0400 Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1N27Hm-0001qO-5c for emacs-orgmode@gnu.org; Sun, 25 Oct 2009 13:53:50 -0400 Received: from [199.232.76.173] (port=45574 helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1N27Hm-0001qL-2c for emacs-orgmode@gnu.org; Sun, 25 Oct 2009 13:53:46 -0400 Received: from markov.stats.ox.ac.uk ([163.1.210.1]:43662) by monty-python.gnu.org with esmtp (Exim 4.60) (envelope-from ) id 1N27Hl-0007rU-Gh for emacs-orgmode@gnu.org; Sun, 25 Oct 2009 13:53:45 -0400 Received: from blackcap.stats.ox.ac.uk (blackcap.stats [163.1.210.5]) by markov.stats.ox.ac.uk (8.13.6/8.13.6) with ESMTP id n9PHrix2012502 for ; Sun, 25 Oct 2009 17:53:44 GMT List-Id: "General discussions about Org-mode." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: emacs-orgmode-bounces+geo-emacs-orgmode=m.gmane.org@gnu.org Errors-To: emacs-orgmode-bounces+geo-emacs-orgmode=m.gmane.org@gnu.org To: emacs org-mode mailing list 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 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 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 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 ;; Bastien Guerry +;; Dan Davison ;; 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