Browse Source

Restore the window configuration after editing table formulas

Karl Stump writes:

> Table Editing Cycle With Multiple Windows On One Buffer Does Not
> Return to Start State
>
> When I have two windows open on two buffers, one to a table in a
> file that I'm editing, the other to some other file of interest,
> the editing cycle of C-` ... C-c C-c works great, meaning that
> when the cycle is finished, the windows are restored to the start
> state.
>
> But when I have two windows open on the same buffer, one window
> on the table, and the other window somewhere else, the editing
> cycle does not restore to the beginning state.
Carsten Dominik 15 years ago
parent
commit
c855e4cbcc
3 changed files with 15 additions and 4 deletions
  1. 7 0
      lisp/ChangeLog
  2. 6 4
      lisp/org-table.el
  3. 2 0
      lisp/org.el

+ 7 - 0
lisp/ChangeLog

@@ -1,5 +1,12 @@
 2009-09-03  Carsten Dominik  <carsten.dominik@gmail.com>
 
+	* org.el (org-selected-window): New variable.
+
+	* org-table.el (org-table-edit-formulas): Remember the selected
+	window.
+	(org-table-fedit-finish, org-table-fedit-abort): Select the window
+	that was originally selected.
+
 	* org-exp.el (org-export-preprocess-apply-macros): Scan the
 	expansion of a macro for more macro definitions.
 

+ 6 - 4
lisp/org-table.el

@@ -2712,6 +2712,7 @@ Parameters get priority."
 	(pos (move-marker (make-marker) (point)))
 	(startline 1)
 	(wc (current-window-configuration))
+	(sel-win (selected-window))
 	(titles '((column . "# Column Formulas\n")
 		  (field . "# Field Formulas\n")
 		  (named . "# Named Field Formulas\n")))
@@ -2724,6 +2725,7 @@ Parameters get priority."
     (org-set-local 'font-lock-global-modes (list 'not major-mode))
     (org-set-local 'org-pos pos)
     (org-set-local 'org-window-configuration wc)
+    (org-set-local 'org-selected-window sel-win)
     (use-local-map org-table-fedit-map)
     (org-add-hook 'post-command-hook 'org-table-fedit-post-command t t)
     (easy-menu-add org-table-fedit-menu)
@@ -2944,7 +2946,7 @@ With prefix ARG, apply the new formulas to the table."
       (progn
 	(org-table-fedit-convert-buffer 'org-table-convert-refs-to-rc)
 	(setq org-table-buffer-is-an nil)))
-  (let ((pos org-pos) eql var form)
+  (let ((pos org-pos) (sel-win org-selected-window) eql var form)
     (goto-char (point-min))
     (while (re-search-forward
 	    "^\\(@[0-9]+\\$[0-9]+\\|\\$\\([a-zA-Z0-9]+\\)\\) *= *\\(.*\\(\n[ \t]+.*$\\)*\\)"
@@ -2960,7 +2962,7 @@ With prefix ARG, apply the new formulas to the table."
 	(push (cons var form) eql)))
     (setq org-pos nil)
     (set-window-configuration org-window-configuration)
-    (select-window (get-buffer-window (marker-buffer pos)))
+    (select-window sel-win)
     (goto-char pos)
     (unless (org-at-table-p)
       (error "Lost table position - cannot install formulae"))
@@ -2975,9 +2977,9 @@ With prefix ARG, apply the new formulas to the table."
   "Abort editing formulas, without installing the changes."
   (interactive)
   (org-table-remove-rectangle-highlight)
-  (let ((pos org-pos))
+  (let ((pos org-pos) (sel-win org-selected-window))
     (set-window-configuration org-window-configuration)
-    (select-window (get-buffer-window (marker-buffer pos)))
+    (select-window sel-win)
     (goto-char pos)
     (move-marker pos nil)
     (message "Formula editing aborted without installing changes")))

+ 2 - 0
lisp/org.el

@@ -3880,6 +3880,8 @@ Respect keys that are already there."
 
 (defvar org-window-configuration nil
   "Used in various places to store a window configuration.")
+(defvar org-selected-window nil
+  "Used in various places to store a window configuration.")
 (defvar org-finish-function nil
   "Function to be called when `C-c C-c' is used.
 This is for getting out of special buffers like remember.")