From mboxrd@z Thu Jan 1 00:00:00 1970 From: Kyle Meyer Subject: Re: [PATCH] Patches for agenda exiting commands Date: Sun, 04 Jan 2015 23:24:17 -0500 Message-ID: <87tx05hn2m.fsf@kmlap.domain.org> References: <87iogog4xu.fsf@kmlap.domain.org> <87sifs6r7c.fsf@nicolasgoaziou.fr> Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" Return-path: Received: from eggs.gnu.org ([2001:4830:134:3::10]:60662) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Y7zAA-0003ij-1p for emacs-orgmode@gnu.org; Sun, 04 Jan 2015 23:21:07 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1Y7zA6-0002Hp-Pz for emacs-orgmode@gnu.org; Sun, 04 Jan 2015 23:21:05 -0500 Received: from mail-ig0-f179.google.com ([209.85.213.179]:44662) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Y7zA6-0002Hj-Jr for emacs-orgmode@gnu.org; Sun, 04 Jan 2015 23:21:02 -0500 Received: by mail-ig0-f179.google.com with SMTP id r2so1923577igi.0 for ; Sun, 04 Jan 2015 20:21:01 -0800 (PST) Received: from localhost (cpe-65-189-241-197.woh.res.rr.com. [65.189.241.197]) by mx.google.com with ESMTPSA id p137sm26152659ioe.29.2015.01.04.20.20.59 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sun, 04 Jan 2015 20:21:00 -0800 (PST) In-Reply-To: <87sifs6r7c.fsf@nicolasgoaziou.fr> (Nicolas Goaziou's message of "Sat, 03 Jan 2015 12:25:59 +0100") List-Id: "General discussions about Org-mode." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-orgmode-bounces+geo-emacs-orgmode=m.gmane.org@gnu.org Sender: emacs-orgmode-bounces+geo-emacs-orgmode=m.gmane.org@gnu.org To: Org-mode --=-=-= Content-Type: text/plain Nicolas Goaziou 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 --=-=-= Content-Type: text/x-diff Content-Disposition: attachment; filename=0001-org-agenda-Track-last-indirect-buffer.patch >From fc3a2b526a77e574c6b076d626cd35583ad5ecdf Mon Sep 17 00:00:00 2001 From: Kyle Meyer 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 --=-=-= Content-Type: text/x-diff Content-Disposition: attachment; filename=0002-org-agenda-Fix-issues-with-restoring-windows.patch >From f842617f9bacccdf2458a0c6b53f86814787cdc3 Mon Sep 17 00:00:00 2001 From: Kyle Meyer 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 --=-=-=--