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.

up vote 8 down vote accepted

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

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

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:

http://debbugs.gnu.org/cgi/bugreport.cgi?archive=yes&bug=22734

24.5; do not leave opened org-agenda-files on org-agenda-list, etc.

Your Answer

 
discard

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

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