0

I'd like some kind of visual feedback in the mode-line, saying whether the current buffer is a file that is added to the org-agenda. Is there some way to do that?;)

3
  • Do you just mean "is a member of org-agenda-files" ?
    – phils
    Apr 6 at 10:04
  • @phils Yes, cause I find myself adding TODOs' all over the place and I'm constantly not sure if the file I add the TODO to, is part of the agenda, so that the TODO will be visible when I run org-agenda views Apr 6 at 11:05
  • Are the files necessarily *.org files?
    – phils
    Apr 7 at 1:06

1 Answer 1

1

I recommend always avoiding unnecessary dynamic evaluations in the mode line, so I suggest you do the look-up in find-file-hook. The simplest approach to that means that you won't automatically see mode line 'corrections' to existing buffers if you update org-agenda-files (you would need to revisit the file), but the benefit is that the mode line rendering is very cheap.

(require 'org)

(defvar-local my-org-agenda-file-p nil
  "Whether this buffer's file is a member of `org-agenda-files'.")

(defun my-org-agenda-file-check ()
  "Update `my-org-agenda-file-p'."
  (when (member buffer-file-name (org-agenda-files t))
    (setq my-org-agenda-file-p t)))

(add-hook 'find-file-hook #'my-org-agenda-file-check)

(add-to-list 'global-mode-string '(my-org-agenda-file-p "Agenda"))

I can't guess whether you want to pass the ARCHIVES argument to org-agenda-files, so you should check that yourself.

(org-agenda-files &optional UNRESTRICTED ARCHIVES)
2
  • Instead of the (mapcar #'expand-file-name org-agenda-files), it might be better to use (org-agenda-files) which expands the variable appropriately in all cases.
    – NickD
    Apr 6 at 16:21
  • Much better; thanks NickD.
    – phils
    Apr 7 at 0:38

Your Answer

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

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