A being the set of all the .org files I use for schedules, I restrained agenda searches to A like this :

(setq org-agenda-files (quote ("../file_1.org"

It is useful to be able to see all the tasks stored in these files in an agenda view. However, I would also like to be able to have an agenda view showing only the content of a specific subset of A. This specific subset being different according to the project I'm working on.

For example, let's say I would like to switch between org-agenda-list for file_1.org and file_2.org and org-agenda-list for file_5.org.

  • 1
    How about let-binding org-agenda-files when you call org-agenda or when you expressly call one of the three main functions, i.e., org-agenda-list, org-tags-view and/or org-search-view? E.g., (let ((org-agenda-files '("../file_1.org" "../file_2.org"))) ...)
    – lawlist
    Commented Nov 20, 2021 at 23:21
  • @lawlist thanks for your answer, but unfortunately my Emacs knowledge is not advanced enough to be able to understand it. How and where am I supposed to put (let ((org-agenda-files '("../file_1.org" "../file_2.org"))) ...)?
    – crocefisso
    Commented Nov 20, 2021 at 23:28
  • The question is a bit too general for me to be able to write up a global solution, but perhaps another forum participant can come up with one. It might be helpful for you to state how it is that call a particular agenda command, and that way the answer can be specific to your needs and also tested to ensure that it works before someone posts an answer.
    – lawlist
    Commented Nov 20, 2021 at 23:32
  • 1
    To build the agenda buffer I do C-c a a. Which corresponds to M-x org-agenda-week-view
    – crocefisso
    Commented Nov 20, 2021 at 23:47
  • 1
    When you have time, go ahead and give this a try: (defun my-function (&optional iso-week) "Doc-string for this function." (interactive "P") (let ((org-agenda-files '("../file_1.org" "../file_2.org"))) (org-agenda-week-view iso-week))) Inasmuch as I use a highly modified older version of org-mode, I don't really have a way of testing this proposed function without setting everything up again from scratch.
    – lawlist
    Commented Nov 21, 2021 at 4:07

2 Answers 2


I think the most idiomatic way to do this is to set org-agenda-custom-commands with an agenda let-binding org-agenda-files. Something like:

(setq org-agenda-custom-commands
      '(("o" "crocefisso" agenda ""
           '("../file_1.org" "../file_2.org"))))))

(Untested, since I don't have your setup here, but take a look at the variable's docstring and the manual and, if you are not familiar with the variable, you may want to use the customize interface to set it).

  • Marvelous! On top of that, it solves the issue of going back to D with f and b. Thanks!
    – crocefisso
    Commented Nov 21, 2021 at 16:35
  • 1
    @crocefisso Indeed, let-binding for the agenda is unusually tricky. Since an agenda can have multiple blocks, and each can have a different set of variables set, they are stored in the agenda buffer as text properties, everything else is actively cleared. That's why your attempt worked for the "first view" but not for subsequent ones.
    – gusbrs
    Commented Nov 21, 2021 at 18:29

Thanks to lawlist suggestions I managed to find a solution. But first I had to learn how to deal with functions and key binding in Emacs Lisp (I hope my code is compliant with conventions).

Note that this solution works even if file_1.org, file_2.org and file_5.org don't belong to A.

So here is the code to put in the .emacs config file:

Code for file_1.org and file_2.org, key bound with C-c n

(defun file_1_and_2()
  "lauch org-agenda for file_1.org and file_2.org."
  (let ((org-agenda-files '("../file_1.org" "../file_2.org"))) (org-agenda))
(global-set-key (kbd "C-c n") 'file_1_and_2)

Code for file_5.org, key bound with C-c s.

(defun file_5()
  "lauch org-agenda for file_5.org."
  (let ((org-agenda-files '("../file_5.org"))) (org-agenda))
(global-set-key (kbd "C-c s") 'file_5)

The only drawback, is that when I navigate in the Agenda buffer with f (org-agenda-later) and b (org-agenda-earlier), the view goes back to show searches related to A. If someone has an idea of how to prevent that, I'm interested.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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