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


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.


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.

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

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)
      (lambda (x)
        (when (get-file-buffer x)
          (push x opened-org-agenda-files)))

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

(defadvice org-agenda-list (around opened-org-agenda-list-around activate)

(defadvice org-search-view (around org-search-view-around activate)

(defadvice org-tags-view (around org-tags-view-around activate)
| improve this answer | |
  • 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

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.

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

I switched to new org-mode workflow.

Previously I use:

  • NOTE.org as main storage for free form notes edited by hand with key binding to quick access to this file
  • TODO.org for org-remember or (lambda () (interactive) (org-capture nil "t"))

TODO.org I visit only via C-c a a. But NOTE.org become unmaintainable with size greater then 1 MiB of plain text.

So I split this file by main easy distinguished topics, like LEARNING.org, PURCHASES.org, emacs-python.org, linux.org, vps.org, ...

Instead of maintaining list of possible names I have specified directory:

(setq org-agenda-file-regexp "\\`[^.#].*[^_]\\.org\\'"
      org-agenda-files (list org-directory))

I happy with this setup because I can quickly find necessary topic via switching to buffer (by IDO via meaningful file name) and searching (by C-s) in limited space.

All schedules available via C-c a a across all .org files.

But now I have a lot of opened unused .org files after C-c a a which I should kill when they are appear during buffer switches.

I think that bug report should be submitted:


24.5; do not leave opened org-agenda-files on org-agenda-list, etc.
| improve this answer | |

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.