14

Generating today's agenda in Org-Mode (C-c a a) opens the files in org-agenda-files. I don't want Emacs to open these extra buffers.

Is there an easy way to tell Emacs not to open these buffers? (or what is the same, to automatically close them if they weren't open before calling the agenda?).

UPDATE:

This is a more compact version of the solution provided by @lawlist:

(require 'dash)

(defun my-org-keep-quiet (orig-fun &rest args)
  (let ((buffers-pre (-filter #'get-file-buffer (org-agenda-files))))
    (apply orig-fun args)
    (let* ((buffers-post (-filter #'get-file-buffer (org-agenda-files)))
           (buffers-new  (-difference buffers-post buffers-pre)))
      (mapcar (lambda (file) (kill-buffer (get-file-buffer file))) buffers-new))))

(advice-add 'org-agenda-list :around #'my-org-keep-quiet)
(advice-add 'org-search-view :around #'my-org-keep-quiet)
(advice-add 'org-tags-view   :around #'my-org-keep-quiet)

Regrettably, this still is not perfect, as now clicking on an event in the agenda does not open the corresponding org file.

11

You want org-agenda-exit, conveniently bound to x by default in the agenda view

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.

I found this using describe-mode.

  • Sane answer here. – YoungFrog Aug 10 '16 at 13:08
  • 1
    Appreciate the pointer to describe-mode. – Matt Sep 11 '18 at 16:43
4

The org-agenda-files buffer(s) should not be killed until after the search functions have finished. The three (3) most common search functions used to generate an *Org Agenda* buffer are: org-agenda-list; org-search-view; and org-tags-view. org-agenda-files is both a variable and a function -- two different, but related, animals.

(defvar opened-org-agenda-files nil)

(defun opened-org-agenda-files ()
  (let ((files (org-agenda-files)))
    (setq opened-org-agenda-files nil)
    (mapcar
      (lambda (x)
        (when (get-file-buffer x)
          (push x opened-org-agenda-files)))
      files)))

(defun kill-org-agenda-files ()
  (let ((files (org-agenda-files)))
    (mapcar
      (lambda (x)
        (when
            (and
              (get-file-buffer x)
              (not (member x opened-org-agenda-files)))
          (kill-buffer (get-file-buffer x))))
      files)))

(defadvice org-agenda-list (around opened-org-agenda-list-around activate)
  (opened-org-agenda-files)
  ad-do-it
  (kill-org-agenda-files))

(defadvice org-search-view (around org-search-view-around activate)
  (opened-org-agenda-files)
  ad-do-it
  (kill-org-agenda-files))

(defadvice org-tags-view (around org-tags-view-around activate)
  (opened-org-agenda-files)
  ad-do-it
  (kill-org-agenda-files))
  • That's good. The only problem is that I wouldn't like to kill a buffer that was open before creating the agenda. Thus, it seems that the right solution requires creating an "around" advice. – scaramouche Dec 26 '14 at 4:27
  • @scaramouche -- In my initial testing, the revised draft appears to do what it is that you are seeking -- it incorporates the around with advice. – lawlist Dec 26 '14 at 5:21
  • Now there's another problem: pressing enter in an event in the agenda does not open the corresponding file. Maybe there's no nice way of implementing this. – scaramouche Dec 26 '14 at 16:54
  • Yes, that makes sense (now that I think about it) because the *Org-Agenda* buffer is just a copy and paste from the org-agenda-files [kind of, it is actually pushed into a list and then reorganized and inserted into the *Org-Agenda* buffer]. When editing, a user jumps back to the original org-agenda-files to make the edit, which the editing functions assume is already open. If you really have to have the org-agenda-files closed when not in use, then you'll need to revise the editing functions to open the file needed and then close it again when done. There may also be other issues – lawlist Dec 26 '14 at 17:46
1

After you have opened the agenda, just exit it by pressing x in the agenda's buffer at any time. If you use q to quite the agenda it will keep all the buffers open.

  • 3
    Your answer is escentially a duplicate of user2699 that was posted on February 19, 2016. – lawlist Aug 9 '16 at 21:01

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.