emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
* [PATCH] Patches for agenda exiting commands
@ 2015-01-02 23:04 Kyle Meyer
  2015-01-03 11:25 ` Nicolas Goaziou
  0 siblings, 1 reply; 4+ messages in thread
From: Kyle Meyer @ 2015-01-02 23:04 UTC (permalink / raw)
  To: Org-mode

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

Hello,

I've attached a few patches related to the agenda exiting commands.
Please let me know any comments.

-- 
Kyle


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: 0001-org-agenda-Fix-exiting-function-docstrings.patch --]
[-- Type: text/x-diff, Size: 2265 bytes --]

From eda6e1d681ba11d427fe37cfe8af966e82ebab2d Mon Sep 17 00:00:00 2001
From: Kyle Meyer <kyle@kyleam.com>
Date: Fri, 2 Jan 2015 17:38:19 -0500
Subject: [PATCH 1/5] org-agenda: Fix exiting function docstrings

* lisp/org-agenda.el (org-agenda-Quit):
* lisp/org-agenda.el (org-agenda-quit):
* lisp/org-agenda.el (org-agenda-exit): Correct and expand docstrings.
---
 lisp/org-agenda.el | 24 +++++++++++++++++-------
 1 file changed, 17 insertions(+), 7 deletions(-)

diff --git a/lisp/org-agenda.el b/lisp/org-agenda.el
index 5990bbb..49eb07b 100644
--- a/lisp/org-agenda.el
+++ b/lisp/org-agenda.el
@@ -7173,8 +7173,9 @@ (defun org-agenda-check-type (error &rest types)
 	nil))))
 
 (defun org-agenda-Quit ()
-  "Exit the agenda and kill buffers loaded by `org-agenda'.
-Also restore the window configuration."
+  "Exit the agenda, killing the agenda buffer.
+Like `org-agenda-quit', but kill the buffer even when
+`org-agenda-sticky' is non-nil."
   (interactive)
   (if org-agenda-columns-active
       (org-columns-quit)
@@ -7202,8 +7203,16 @@ (defun org-agenda-Quit ()
 	 (setq org-agenda-pre-window-conf nil))))
 
 (defun org-agenda-quit ()
-  "Exit the agenda and restore the window configuration.
-When `org-agenda-sticky' is non-nil, only bury the agenda."
+  "Exit the agenda.
+
+When `org-agenda-sticky' is non-nil, bury the agenda buffer
+instead of killing it.
+
+When `org-agenda-restore-windows-after-quit' is non-nil, restore
+the pre-agenda window configuration.
+
+When column view is active, exit column view instead of the
+agenda."
   (interactive)
   (if (and (eq org-indirect-buffer-display 'other-window)
 	   org-last-indirect-buffer)
@@ -7232,9 +7241,10 @@ (defun org-agenda-quit ()
       (org-agenda-Quit))))
 
 (defun org-agenda-exit ()
-  "Exit the agenda and restore the window configuration.
-Also kill Org-mode buffers loaded by `org-agenda'.  Org-mode
-buffers visited directly by the user will not be touched."
+  "Exit the agenda, killing Org buffers loaded by the agenda.
+Like `org-agenda-Quit', but kill any buffers that were created by
+the agenda.  Org buffers visited directly by the user will not be
+touched."
   (interactive)
   (org-release-buffers org-agenda-new-buffers)
   (setq org-agenda-new-buffers nil)
-- 
2.2.1


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #3: 0002-org-agenda-exit-Check-column-view.patch --]
[-- Type: text/x-diff, Size: 1606 bytes --]

From 44b71bf3a82ca16037252b13aee491e9807a7c4a Mon Sep 17 00:00:00 2001
From: Kyle Meyer <kyle@kyleam.com>
Date: Fri, 2 Jan 2015 17:38:24 -0500
Subject: [PATCH 2/5] org-agenda-exit: Check column view

* lisp/org-agenda.el (org-agenda-exit): Exit column view before trying to
  exit agenda.

Running org-agenda-exit in column view deleted all buffers loaded by the
agenda, but it didn't actually exit the agenda because, if the agenda is
in column view, org-agenda-Quit turns off column view instead of killing
the agenda.  So org-agenda-exit should either just quit column view if
it is active (and not delete the loaded buffers or quit the agenda) or
make sure that the agenda is not in column view before killing it.
Since org-agenda-Quit and org-agenda-quit already do the former, make
org-agenda-exit completely exit the agenda regardless of whether it is
in column view.
---
 lisp/org-agenda.el | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/lisp/org-agenda.el b/lisp/org-agenda.el
index 49eb07b..1446d21 100644
--- a/lisp/org-agenda.el
+++ b/lisp/org-agenda.el
@@ -7244,8 +7244,10 @@ (defun org-agenda-exit ()
   "Exit the agenda, killing Org buffers loaded by the agenda.
 Like `org-agenda-Quit', but kill any buffers that were created by
 the agenda.  Org buffers visited directly by the user will not be
-touched."
+touched.  Also, exit the agenda even if it is in column view."
   (interactive)
+  (when org-agenda-columns-active
+    (org-columns-quit))
   (org-release-buffers org-agenda-new-buffers)
   (setq org-agenda-new-buffers nil)
   (org-agenda-Quit))
-- 
2.2.1


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #4: 0003-org-agenda-Quit-Remove-unnecessary-function-calls.patch --]
[-- Type: text/x-diff, Size: 1393 bytes --]

From 6af4d934882720e36228c4b7cc3013829e9bab0b Mon Sep 17 00:00:00 2001
From: Kyle Meyer <kyle@kyleam.com>
Date: Fri, 2 Jan 2015 17:38:30 -0500
Subject: [PATCH 3/5] org-agenda-Quit: Remove unnecessary function calls

* lisp/org-agenda.el (org-agenda-Quit): Remove unnecessary function calls.

- org-agenda-Quit turns off column view if it is active, instead of
  killing the agenda buffer, so there is no need to call
  org-columns-remove-overlays when killing the buffer.
- org-agenda-reset-markers is already called when the kill-buffer-hook
  is run.
---
 lisp/org-agenda.el | 4 ----
 1 file changed, 4 deletions(-)

diff --git a/lisp/org-agenda.el b/lisp/org-agenda.el
index 1446d21..2fbfacc 100644
--- a/lisp/org-agenda.el
+++ b/lisp/org-agenda.el
@@ -7182,17 +7182,13 @@ (defun org-agenda-Quit ()
     (let ((buf (current-buffer)))
       (if (eq org-agenda-window-setup 'other-frame)
 	  (progn
-	    (org-agenda-reset-markers)
 	    (kill-buffer buf)
-	    (org-columns-remove-overlays)
 	    (setq org-agenda-archives-mode nil)
 	    (delete-frame))
 	(and (not (eq org-agenda-window-setup 'current-window))
 	     (not (one-window-p))
 	     (delete-window))
-	(org-agenda-reset-markers)
 	(kill-buffer buf)
-	(org-columns-remove-overlays)
 	(setq org-agenda-archives-mode nil)))
     (setq org-agenda-buffer nil)
     ;; Maybe restore the pre-agenda window configuration.
-- 
2.2.1


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #5: 0004-org-agenda-Track-last-indirect-buffer.patch --]
[-- Type: text/x-diff, Size: 3721 bytes --]

From 25c6bb500ae0c3e583200bc7d8d67da86c4f1d10 Mon Sep 17 00:00:00 2001
From: Kyle Meyer <kyle@kyleam.com>
Date: Fri, 2 Jan 2015 17:38:34 -0500
Subject: [PATCH 4/5] org-agenda: Track last indirect buffer

* lisp/org-agenda.el (org-agenda-tree-to-indirect-buffer): Record last
  indirect buffer for agenda.
* lisp/org-agenda.el (org-agenda-quit): Delete window for
  org-agenda-last-indirect-buffer, not org-last-indirect-buffer.

If an indirect buffer for an Org subtree was present as a window,
org-agenda-quit deleted this window regardless of whether it was created
from the agenda.  Introduce a new variable,
org-agenda-last-indirect-buffer, that is specific for the agenda (and
perhaps a particular agenda buffer, if org-agenda-sticky is set).

org-agenda-quit checked for indirect buffers while org-agenda-Quit did
not.  There doesn't seem to be any reason for this difference in
behavior, so make org-agenda-Quit treat windows for indirect buffers the
same way as org-agenda-quit.
---
 lisp/org-agenda.el | 23 ++++++++++++++++-------
 1 file changed, 16 insertions(+), 7 deletions(-)

diff --git a/lisp/org-agenda.el b/lisp/org-agenda.el
index 2fbfacc..7ecea43 100644
--- a/lisp/org-agenda.el
+++ b/lisp/org-agenda.el
@@ -2078,6 +2078,7 @@ (defvar org-agenda-last-prefix-arg nil)
 (defvar org-agenda-this-buffer-name nil)
 (defvar org-agenda-doing-sticky-redo nil)
 (defvar org-agenda-this-buffer-is-sticky nil)
+(defvar org-agenda-last-indirect-buffer nil)
 
 (defconst org-agenda-local-vars
   '(org-agenda-this-buffer-name
@@ -2102,6 +2103,7 @@ (defconst org-agenda-local-vars
     org-agenda-effort-filter
     org-agenda-markers
     org-agenda-last-search-view-search-was-boolean
+    org-agenda-last-indirect-buffer
     org-agenda-filtered-by-category
     org-agenda-filter-form
     org-agenda-cycle-counter
@@ -7177,6 +7179,12 @@ (defun org-agenda-Quit ()
 Like `org-agenda-quit', but kill the buffer even when
 `org-agenda-sticky' is non-nil."
   (interactive)
+  (let ((org-agenda-last-indirect-window
+	 (and (eq org-indirect-buffer-display 'other-window)
+	      org-agenda-last-indirect-buffer
+	      (get-buffer-window org-agenda-last-indirect-buffer))))
+    (when org-agenda-last-indirect-window
+      (delete-window org-agenda-last-indirect-window)))
   (if org-agenda-columns-active
       (org-columns-quit)
     (let ((buf (current-buffer)))
@@ -7210,12 +7218,12 @@ (defun org-agenda-quit ()
 When column view is active, exit column view instead of the
 agenda."
   (interactive)
-  (if (and (eq org-indirect-buffer-display 'other-window)
-	   org-last-indirect-buffer)
-      (let ((org-last-indirect-window
-	     (get-buffer-window org-last-indirect-buffer)))
-	(if org-last-indirect-window
-	    (delete-window org-last-indirect-window))))
+  (let ((org-agenda-last-indirect-window
+	 (and (eq org-indirect-buffer-display 'other-window)
+	      org-agenda-last-indirect-buffer
+	      (get-buffer-window org-agenda-last-indirect-buffer))))
+    (when org-agenda-last-indirect-window
+      (delete-window org-agenda-last-indirect-window)))
   (if org-agenda-columns-active
       (org-columns-quit)
     (if org-agenda-sticky
@@ -8758,7 +8766,8 @@ (defun org-agenda-tree-to-indirect-buffer (arg)
 	  (and indirect-window (select-window indirect-window))
 	  (switch-to-buffer org-last-indirect-buffer :norecord)
 	  (fit-window-to-buffer indirect-window)))
-      (select-window (get-buffer-window agenda-buffer)))))
+      (select-window (get-buffer-window agenda-buffer))
+      (setq org-agenda-last-indirect-buffer org-last-indirect-buffer))))
 
 (defun org-agenda-do-tree-to-indirect-buffer (arg)
   "Same as `org-agenda-tree-to-indirect-buffer' without saving window."
-- 
2.2.1


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #6: 0005-org-agenda-Fix-issues-with-restoring-windows.patch --]
[-- Type: text/x-diff, Size: 5531 bytes --]

From 514ca4bf4c057cf781d85391c5ffd1530cdf2a05 Mon Sep 17 00:00:00 2001
From: Kyle Meyer <kyle@kyleam.com>
Date: Fri, 2 Jan 2015 17:38:39 -0500
Subject: [PATCH 5/5] org-agenda: Fix issues with restoring windows

* lisp/org-agenda.el (org-agenda-prepare-window): Update window
  configuration even when agenda buffer exists in background.
* lisp/org-agenda.el (org-agenda-Quit): Use buffer value for
  org-agenda-pre-window-conf to allow for local values used with sticky
  agenda buffers.
* lisp/org-agenda.el (org-agenda-quit): Reset local, not global, value for
  org-agenda-pre-window-conf.

The pre-agenda window configuration was not being updated, resulting in
a window configuration other than the one prior to the most recent
agenda call being restored, in the following cases:

- The user exited or buried the buffer without using q, Q, or x.
- org-agenda-sticky was non-nil and the user buried the buffer with q.
  This was because the global, not buffer-local, value for
  org-agenda-pre-window-conf was not being reset.

Also, when org-agenda-sticky was non-nil, pressing Q (org-agenda-Quit)
restored the global, not the buffer-local, value for
org-agenda-pre-window-conf.

Along with these changes, merge the duplicated functionality in
org-agenda-quit and org-agenda-Quit.
---
 lisp/org-agenda.el | 82 +++++++++++++++++++++---------------------------------
 1 file changed, 32 insertions(+), 50 deletions(-)

diff --git a/lisp/org-agenda.el b/lisp/org-agenda.el
index 7ecea43..7bce68d 100644
--- a/lisp/org-agenda.el
+++ b/lisp/org-agenda.el
@@ -3632,7 +3632,7 @@ (defun org-agenda-prepare-window (abuf filter-alist)
     (unless (equal (current-buffer) abuf)
       (org-pop-to-buffer-same-window abuf))
     (setq org-agenda-pre-window-conf
-	  (or org-agenda-pre-window-conf wconf))))
+	  (or wconf org-agenda-pre-window-conf))))
 
 (defun org-agenda-prepare (&optional name)
   (let ((filter-alist (if org-agenda-persistent-filter
@@ -7179,32 +7179,7 @@ (defun org-agenda-Quit ()
 Like `org-agenda-quit', but kill the buffer even when
 `org-agenda-sticky' is non-nil."
   (interactive)
-  (let ((org-agenda-last-indirect-window
-	 (and (eq org-indirect-buffer-display 'other-window)
-	      org-agenda-last-indirect-buffer
-	      (get-buffer-window org-agenda-last-indirect-buffer))))
-    (when org-agenda-last-indirect-window
-      (delete-window org-agenda-last-indirect-window)))
-  (if org-agenda-columns-active
-      (org-columns-quit)
-    (let ((buf (current-buffer)))
-      (if (eq org-agenda-window-setup 'other-frame)
-	  (progn
-	    (kill-buffer buf)
-	    (setq org-agenda-archives-mode nil)
-	    (delete-frame))
-	(and (not (eq org-agenda-window-setup 'current-window))
-	     (not (one-window-p))
-	     (delete-window))
-	(kill-buffer buf)
-	(setq org-agenda-archives-mode nil)))
-    (setq org-agenda-buffer nil)
-    ;; Maybe restore the pre-agenda window configuration.
-    (and org-agenda-restore-windows-after-quit
-	 (not (eq org-agenda-window-setup 'other-frame))
-	 org-agenda-pre-window-conf
-	 (set-window-configuration org-agenda-pre-window-conf)
-	 (setq org-agenda-pre-window-conf nil))))
+  (org-agenda--quit))
 
 (defun org-agenda-quit ()
   "Exit the agenda.
@@ -7218,31 +7193,38 @@ (defun org-agenda-quit ()
 When column view is active, exit column view instead of the
 agenda."
   (interactive)
-  (let ((org-agenda-last-indirect-window
-	 (and (eq org-indirect-buffer-display 'other-window)
-	      org-agenda-last-indirect-buffer
-	      (get-buffer-window org-agenda-last-indirect-buffer))))
-    (when org-agenda-last-indirect-window
-      (delete-window org-agenda-last-indirect-window)))
+  (org-agenda--quit org-agenda-sticky))
+
+(defun org-agenda--quit (&optional bury)
   (if org-agenda-columns-active
       (org-columns-quit)
-    (if org-agenda-sticky
-	(let ((buf (current-buffer)))
-	  (if (eq org-agenda-window-setup 'other-frame)
-	      (progn
-		(delete-frame))
-	    (and (not (eq org-agenda-window-setup 'current-window))
-		 (not (one-window-p))
-		 (delete-window)))
-	  (with-current-buffer buf
-	    (bury-buffer)
-	    ;; Maybe restore the pre-agenda window configuration.
-	    (and org-agenda-restore-windows-after-quit
-		 (not (eq org-agenda-window-setup 'other-frame))
-		 org-agenda-pre-window-conf
-		 (set-window-configuration org-agenda-pre-window-conf)
-		 (setq org-agenda-pre-window-conf nil))))
-      (org-agenda-Quit))))
+    (let ((buf (current-buffer))
+	  (wconf org-agenda-pre-window-conf)
+	  (org-agenda-last-indirect-window
+	   (and (eq org-indirect-buffer-display 'other-window)
+		org-agenda-last-indirect-buffer
+		(get-buffer-window org-agenda-last-indirect-buffer))))
+      (cond
+       ((eq org-agenda-window-setup 'other-frame)
+	(delete-frame))
+       ((and org-agenda-restore-windows-after-quit
+	     wconf)
+	;; Maybe restore the pre-agenda window configuration.  Reset
+	;; `org-agenda-pre-window-conf' before running
+	;; `set-window-configuration', which loses the current buffer.
+	(setq org-agenda-pre-window-conf nil)
+	(set-window-configuration wconf))
+       (t
+	(when org-agenda-last-indirect-window
+	  (delete-window org-agenda-last-indirect-window))
+	(and (not (eq org-agenda-window-setup 'current-window))
+	     (not (one-window-p))
+	     (delete-window))))
+      (if bury
+	  (bury-buffer buf)
+	(kill-buffer buf)
+	(setq org-agenda-archives-mode nil
+	      org-agenda-buffer nil)))))
 
 (defun org-agenda-exit ()
   "Exit the agenda, killing Org buffers loaded by the agenda.
-- 
2.2.1


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

* Re: [PATCH] Patches for agenda exiting commands
  2015-01-02 23:04 [PATCH] Patches for agenda exiting commands Kyle Meyer
@ 2015-01-03 11:25 ` Nicolas Goaziou
  2015-01-05  4:24   ` Kyle Meyer
  0 siblings, 1 reply; 4+ messages in thread
From: Nicolas Goaziou @ 2015-01-03 11:25 UTC (permalink / raw)
  To: Kyle Meyer; +Cc: Org-mode

Hello,

Kyle Meyer <kyle@kyleam.com> writes:

> I've attached a few patches related to the agenda exiting commands.

Thank you. I applied patches 1, 2 and 3.

> Subject: [PATCH 4/5] org-agenda: Track last indirect buffer
>
> * lisp/org-agenda.el (org-agenda-tree-to-indirect-buffer): Record last
>   indirect buffer for agenda.
> * lisp/org-agenda.el (org-agenda-quit): Delete window for
>   org-agenda-last-indirect-buffer, not org-last-indirect-buffer.
>
> If an indirect buffer for an Org subtree was present as a window,
> org-agenda-quit deleted this window regardless of whether it was created
> from the agenda.  Introduce a new variable,
> org-agenda-last-indirect-buffer, that is specific for the agenda (and
> perhaps a particular agenda buffer, if org-agenda-sticky is set).
>
> org-agenda-quit checked for indirect buffers while org-agenda-Quit did
> not.  There doesn't seem to be any reason for this difference in
> behavior, so make org-agenda-Quit treat windows for indirect buffers the
> same way as org-agenda-quit.

Nitpick: in commit messages, prefer the present tense.

> +(defvar org-agenda-last-indirect-buffer nil)

Please provide a docstring for this new variable.

> Subject: [PATCH 5/5] org-agenda: Fix issues with restoring windows
>
> * lisp/org-agenda.el (org-agenda-prepare-window): Update window
>   configuration even when agenda buffer exists in background.
> * lisp/org-agenda.el (org-agenda-Quit): Use buffer value for
>   org-agenda-pre-window-conf to allow for local values used with sticky
>   agenda buffers.
> * lisp/org-agenda.el (org-agenda-quit): Reset local, not global, value for
>   org-agenda-pre-window-conf.
>
> The pre-agenda window configuration was not being updated, resulting in
> a window configuration other than the one prior to the most recent
> agenda call being restored, in the following cases:
>
> - The user exited or buried the buffer without using q, Q, or x.
> - org-agenda-sticky was non-nil and the user buried the buffer with q.
>   This was because the global, not buffer-local, value for
>   org-agenda-pre-window-conf was not being reset.
>
> Also, when org-agenda-sticky was non-nil, pressing Q (org-agenda-Quit)
> restored the global, not the buffer-local, value for
> org-agenda-pre-window-conf.
>
> Along with these changes, merge the duplicated functionality in
> org-agenda-quit and org-agenda-Quit.

Present tense, please.

Also, the commit message lacks the creation of `org-agenda--quit'.

Regards,

-- 
Nicolas Goaziou

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

* Re: [PATCH] Patches for agenda exiting commands
  2015-01-03 11:25 ` Nicolas Goaziou
@ 2015-01-05  4:24   ` Kyle Meyer
  2015-01-05 11:50     ` Nicolas Goaziou
  0 siblings, 1 reply; 4+ messages in thread
From: Kyle Meyer @ 2015-01-05  4:24 UTC (permalink / raw)
  To: Org-mode

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

Nicolas Goaziou <mail@nicolasgoaziou.fr> wrote:
[...]
> Nitpick: in commit messages, prefer the present tense.

I've reworded the commit message for the remaining patches.

>> +(defvar org-agenda-last-indirect-buffer nil)
>
> Please provide a docstring for this new variable.
[...]
> Also, the commit message lacks the creation of `org-agenda--quit'.

I've added both of these.

Thanks for your comments.

--
Kyle


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: 0001-org-agenda-Track-last-indirect-buffer.patch --]
[-- Type: text/x-diff, Size: 3665 bytes --]

From fc3a2b526a77e574c6b076d626cd35583ad5ecdf Mon Sep 17 00:00:00 2001
From: Kyle Meyer <kyle@kyleam.com>
Date: Sun, 4 Jan 2015 22:18:40 -0500
Subject: [PATCH 1/2] org-agenda: Track last indirect buffer

* lisp/org-agenda.el (org-agenda-tree-to-indirect-buffer): Record last
  indirect buffer for agenda.
* lisp/org-agenda.el (org-agenda-quit): Delete window for
  org-agenda-last-indirect-buffer, not org-last-indirect-buffer.

Introduce a new variable, org-agenda-last-indirect-buffer, that is
specific for the agenda (and perhaps a particular agenda buffer, if
org-agenda-sticky is set).  This prevents org-agenda-quit from deleting
a window if it is displaying a buffer that was created through a
org-tree-to-indirect-buffer call outside of
org-agenda-tree-to-indirect-buffer.

Make org-agenda-Quit check for indirect buffer windows, like
org-agenda-quit does.
---
 lisp/org-agenda.el | 24 +++++++++++++++++-------
 1 file changed, 17 insertions(+), 7 deletions(-)

diff --git a/lisp/org-agenda.el b/lisp/org-agenda.el
index 2fbfacc..6e2e953 100644
--- a/lisp/org-agenda.el
+++ b/lisp/org-agenda.el
@@ -2078,6 +2078,8 @@ (defvar org-agenda-last-prefix-arg nil)
 (defvar org-agenda-this-buffer-name nil)
 (defvar org-agenda-doing-sticky-redo nil)
 (defvar org-agenda-this-buffer-is-sticky nil)
+(defvar org-agenda-last-indirect-buffer nil
+  "Last buffer loaded by `org-agenda-tree-to-indirect-buffer'.")
 
 (defconst org-agenda-local-vars
   '(org-agenda-this-buffer-name
@@ -2102,6 +2104,7 @@ (defconst org-agenda-local-vars
     org-agenda-effort-filter
     org-agenda-markers
     org-agenda-last-search-view-search-was-boolean
+    org-agenda-last-indirect-buffer
     org-agenda-filtered-by-category
     org-agenda-filter-form
     org-agenda-cycle-counter
@@ -7177,6 +7180,12 @@ (defun org-agenda-Quit ()
 Like `org-agenda-quit', but kill the buffer even when
 `org-agenda-sticky' is non-nil."
   (interactive)
+  (let ((org-agenda-last-indirect-window
+	 (and (eq org-indirect-buffer-display 'other-window)
+	      org-agenda-last-indirect-buffer
+	      (get-buffer-window org-agenda-last-indirect-buffer))))
+    (when org-agenda-last-indirect-window
+      (delete-window org-agenda-last-indirect-window)))
   (if org-agenda-columns-active
       (org-columns-quit)
     (let ((buf (current-buffer)))
@@ -7210,12 +7219,12 @@ (defun org-agenda-quit ()
 When column view is active, exit column view instead of the
 agenda."
   (interactive)
-  (if (and (eq org-indirect-buffer-display 'other-window)
-	   org-last-indirect-buffer)
-      (let ((org-last-indirect-window
-	     (get-buffer-window org-last-indirect-buffer)))
-	(if org-last-indirect-window
-	    (delete-window org-last-indirect-window))))
+  (let ((org-agenda-last-indirect-window
+	 (and (eq org-indirect-buffer-display 'other-window)
+	      org-agenda-last-indirect-buffer
+	      (get-buffer-window org-agenda-last-indirect-buffer))))
+    (when org-agenda-last-indirect-window
+      (delete-window org-agenda-last-indirect-window)))
   (if org-agenda-columns-active
       (org-columns-quit)
     (if org-agenda-sticky
@@ -8758,7 +8767,8 @@ (defun org-agenda-tree-to-indirect-buffer (arg)
 	  (and indirect-window (select-window indirect-window))
 	  (switch-to-buffer org-last-indirect-buffer :norecord)
 	  (fit-window-to-buffer indirect-window)))
-      (select-window (get-buffer-window agenda-buffer)))))
+      (select-window (get-buffer-window agenda-buffer))
+      (setq org-agenda-last-indirect-buffer org-last-indirect-buffer))))
 
 (defun org-agenda-do-tree-to-indirect-buffer (arg)
   "Same as `org-agenda-tree-to-indirect-buffer' without saving window."
-- 
2.2.1


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #3: 0002-org-agenda-Fix-issues-with-restoring-windows.patch --]
[-- Type: text/x-diff, Size: 5481 bytes --]

From f842617f9bacccdf2458a0c6b53f86814787cdc3 Mon Sep 17 00:00:00 2001
From: Kyle Meyer <kyle@kyleam.com>
Date: Sun, 4 Jan 2015 22:18:46 -0500
Subject: [PATCH 2/2] org-agenda: Fix issues with restoring windows

* lisp/org-agenda.el (org-agenda-prepare-window): Update window
  configuration even when agenda buffer exists in background.
* lisp/org-agenda.el (org-agenda-Quit): Use buffer value for
  org-agenda-pre-window-conf to allow for local values used with sticky
  agenda buffers.
* lisp/org-agenda.el (org-agenda-quit): Reset local, not global, value for
  org-agenda-pre-window-conf.
* lisp/org-agenda.el (org-agenda--quit): New function.

Update the pre-agenda window configuration on the next agenda call even
if org-agenda-pre-window-conf is non-nil (which occurs when the agenda
buffer is exited without q, Q, or X).  This prevents restoring a window
configuration that is not the one prior to the most recent agenda call.

Make org-agenda-Quit (Q) restore the buffer-local, not the global, value
for org-agenda-pre-window-conf so that it works correctly with sticky
agenda buffers.

Along with these changes, merge the duplicated functionality of
org-agenda-quit and org-agenda-Quit into a new function,
org-agenda--quit.
---
 lisp/org-agenda.el | 82 +++++++++++++++++++++---------------------------------
 1 file changed, 32 insertions(+), 50 deletions(-)

diff --git a/lisp/org-agenda.el b/lisp/org-agenda.el
index 6e2e953..8d5655f 100644
--- a/lisp/org-agenda.el
+++ b/lisp/org-agenda.el
@@ -3633,7 +3633,7 @@ (defun org-agenda-prepare-window (abuf filter-alist)
     (unless (equal (current-buffer) abuf)
       (org-pop-to-buffer-same-window abuf))
     (setq org-agenda-pre-window-conf
-	  (or org-agenda-pre-window-conf wconf))))
+	  (or wconf org-agenda-pre-window-conf))))
 
 (defun org-agenda-prepare (&optional name)
   (let ((filter-alist (if org-agenda-persistent-filter
@@ -7180,32 +7180,7 @@ (defun org-agenda-Quit ()
 Like `org-agenda-quit', but kill the buffer even when
 `org-agenda-sticky' is non-nil."
   (interactive)
-  (let ((org-agenda-last-indirect-window
-	 (and (eq org-indirect-buffer-display 'other-window)
-	      org-agenda-last-indirect-buffer
-	      (get-buffer-window org-agenda-last-indirect-buffer))))
-    (when org-agenda-last-indirect-window
-      (delete-window org-agenda-last-indirect-window)))
-  (if org-agenda-columns-active
-      (org-columns-quit)
-    (let ((buf (current-buffer)))
-      (if (eq org-agenda-window-setup 'other-frame)
-	  (progn
-	    (kill-buffer buf)
-	    (setq org-agenda-archives-mode nil)
-	    (delete-frame))
-	(and (not (eq org-agenda-window-setup 'current-window))
-	     (not (one-window-p))
-	     (delete-window))
-	(kill-buffer buf)
-	(setq org-agenda-archives-mode nil)))
-    (setq org-agenda-buffer nil)
-    ;; Maybe restore the pre-agenda window configuration.
-    (and org-agenda-restore-windows-after-quit
-	 (not (eq org-agenda-window-setup 'other-frame))
-	 org-agenda-pre-window-conf
-	 (set-window-configuration org-agenda-pre-window-conf)
-	 (setq org-agenda-pre-window-conf nil))))
+  (org-agenda--quit))
 
 (defun org-agenda-quit ()
   "Exit the agenda.
@@ -7219,31 +7194,38 @@ (defun org-agenda-quit ()
 When column view is active, exit column view instead of the
 agenda."
   (interactive)
-  (let ((org-agenda-last-indirect-window
-	 (and (eq org-indirect-buffer-display 'other-window)
-	      org-agenda-last-indirect-buffer
-	      (get-buffer-window org-agenda-last-indirect-buffer))))
-    (when org-agenda-last-indirect-window
-      (delete-window org-agenda-last-indirect-window)))
+  (org-agenda--quit org-agenda-sticky))
+
+(defun org-agenda--quit (&optional bury)
   (if org-agenda-columns-active
       (org-columns-quit)
-    (if org-agenda-sticky
-	(let ((buf (current-buffer)))
-	  (if (eq org-agenda-window-setup 'other-frame)
-	      (progn
-		(delete-frame))
-	    (and (not (eq org-agenda-window-setup 'current-window))
-		 (not (one-window-p))
-		 (delete-window)))
-	  (with-current-buffer buf
-	    (bury-buffer)
-	    ;; Maybe restore the pre-agenda window configuration.
-	    (and org-agenda-restore-windows-after-quit
-		 (not (eq org-agenda-window-setup 'other-frame))
-		 org-agenda-pre-window-conf
-		 (set-window-configuration org-agenda-pre-window-conf)
-		 (setq org-agenda-pre-window-conf nil))))
-      (org-agenda-Quit))))
+    (let ((buf (current-buffer))
+	  (wconf org-agenda-pre-window-conf)
+	  (org-agenda-last-indirect-window
+	   (and (eq org-indirect-buffer-display 'other-window)
+		org-agenda-last-indirect-buffer
+		(get-buffer-window org-agenda-last-indirect-buffer))))
+      (cond
+       ((eq org-agenda-window-setup 'other-frame)
+	(delete-frame))
+       ((and org-agenda-restore-windows-after-quit
+	     wconf)
+	;; Maybe restore the pre-agenda window configuration.  Reset
+	;; `org-agenda-pre-window-conf' before running
+	;; `set-window-configuration', which loses the current buffer.
+	(setq org-agenda-pre-window-conf nil)
+	(set-window-configuration wconf))
+       (t
+	(when org-agenda-last-indirect-window
+	  (delete-window org-agenda-last-indirect-window))
+	(and (not (eq org-agenda-window-setup 'current-window))
+	     (not (one-window-p))
+	     (delete-window))))
+      (if bury
+	  (bury-buffer buf)
+	(kill-buffer buf)
+	(setq org-agenda-archives-mode nil
+	      org-agenda-buffer nil)))))
 
 (defun org-agenda-exit ()
   "Exit the agenda, killing Org buffers loaded by the agenda.
-- 
2.2.1


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

* Re: [PATCH] Patches for agenda exiting commands
  2015-01-05  4:24   ` Kyle Meyer
@ 2015-01-05 11:50     ` Nicolas Goaziou
  0 siblings, 0 replies; 4+ messages in thread
From: Nicolas Goaziou @ 2015-01-05 11:50 UTC (permalink / raw)
  To: Kyle Meyer; +Cc: Org-mode

Kyle Meyer <kyle@kyleam.com> writes:

> I've reworded the commit message for the remaining patches.

Applied. Thank you.


Regards,

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

end of thread, other threads:[~2015-01-05 11:49 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2015-01-02 23:04 [PATCH] Patches for agenda exiting commands Kyle Meyer
2015-01-03 11:25 ` Nicolas Goaziou
2015-01-05  4:24   ` Kyle Meyer
2015-01-05 11:50     ` Nicolas Goaziou

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).