1

I'm trying to create a custom agenda to show todos for the current project logged via org-projectile. Something like this:

(setq org-agenda-custom-commands
            '(("p" "Current project"
         ((tags (concat "CATEGORY=\"" (projectile-project-name) "\""))))))

However, since this is called from the agenda dispatcher, projectile-project-name is -.

How can I create an agenda view for the current projectile project?


Additional details:

I have one projects.org file already added to org-agenda-files with headlines formatted like so:

* my-project
  :PROPERTIES:
  :CATEGORY: my-project
  :END:
** TODO some project-specific todo
3
  • I presume your project.org file(s) are all on org-agenda-files, so when you ask for the agenda, you get TODO items for every project? And you are interested in limiting that just to one project (the one returned by projectile-project-name at the current time) - is that correct?
    – NickD
    Aug 31, 2021 at 21:55
  • @NickD yes, that's exactly correct! I realize that keeping track of the project once I open the dispatcher might be tricky, so I'd also happily accept a function that I could bind to a key directly that would bring up the view.
    – Mathletics
    Sep 1, 2021 at 14:07
  • I think a function to bring up the view is the way to go: it can determine the current project easily at the time of the call and that's a necessary prerequisite.
    – NickD
    Sep 1, 2021 at 14:55

1 Answer 1

0

Assuming that you have a project.org file at the root of each project that contains the TODO items for that project, here's a simple function to do what I think you want:

(defun ndk/agenda-for-project ()
  (interactive)
  (let* ((project-name (projectile-project-name))
         (project-root (projectile-project-root))
         (org-agenda-files (list (concat project-root "project.org")))
         (org-agenda-custom-commands `(("p" ,project-name tags-todo))))
    (org-agenda-list "p")))

It basically let-binds org-agenda-files to a list of the single project.org file in the project's root and org-agenda-custom-comands to something that will show the TODO items; and then calls org-agenda-list with the p setting defined in the let-bound value of org-agenda-custom-commands. You can bind the function to a key of your choice e.g.

(global-set-key (kbd "<f12>") #'ndk/agenda-for-project)

The custom agenda command is just an example for testing: you can make it as complicated as you want. I use the backquote mechanism to pass calculated values into a basically constant list as an illustration of how to do similar things in more complicated situations: it does not buy us much with the simple custom command I used.

The restriction that the Org mode file is called project.org in every project can be relaxed a bit, but there needs to be some convention, so that the function could calculate it easily. But making it a constant is simple and not particularly restrictive IMO.

Lightly tested. Let me know how it works for you.

3
  • Thank you! This isn't quite working for me; I added details to the question for how my file is organized.
    – Mathletics
    Sep 2, 2021 at 15:10
  • So one file for all the projects: the projects are top-level headlines with the details of each project as second-level (or deeper) headlines, correct?
    – NickD
    Sep 2, 2021 at 16:33
  • I have tried changing the structure to what (I think) you use, but I have not been able to come up with a custom agenda that works with it (and I don't understand why what I have tried is not working). I'll keep plugging at it for a while longer and hope for success at some point - but not yet :-(
    – NickD
    Sep 6, 2021 at 14:24

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.