I am using emacs with org-mode on OSX. Since I have a lot of .org files added to my agenda and it would be good for clean-up purpose if I could cycle through them and maybe also remove them if not needed.

For this, I tried using org-cycle-agenda-files

It only goes to the file that is at the top of the agenda list and does not cycle through remaining files.

Is there some configuration change that I can do to fix it?

On evaluation of expression

(org-agenda-files t)

I can see the list of my agenda files

("~/work/pubsub/onCall/File4OnCall.org" "~/work/pubsub/tasks/DocumentExistingAlarms/DocumentExistingAlarms.org" "~/work/pubsub/tasks/1739_alarmCBOpen/TaskAnalysis.org" 
"~/work/docs/workNotes/OfficsTasks.org" "~/work/docs/workNotes/GeneralTodos.org" "~/work/pubsub/documents/notes/general/CodeLooks.org" "~/work/pubsub/documents/notes/general/Tasks2Do.org" ...)
  • If you prefer this forum over the other one, then delete the other thread so that we are not spinning our wheels in two locations.
    – lawlist
    Jan 20, 2017 at 15:30
  • Sure, here keeping your latest comment Jan 20, 2017 at 15:41
  • By @lawlist : In that case, the only real thing you can do is copy the entire source code for org-cycle-agenda-files to your scratch buffer and starting putting in some messages with values to see why it is not working. You should be using at least the version of org-mode that comes with Emacs 25.1, but I suppose you can debug an older version if you really want to Jan 20, 2017 at 15:41
  • org-cycle-agenda-files (C-,) is working for me (org 9.0.3.) Jan 20, 2017 at 16:30
  • For Debian Stretch users experiencing this bug, see #870459.
    – user16560
    Aug 2, 2017 at 8:23

1 Answer 1


The function org-cycle-agenda-files is broken in org-mode version 8.2.10 (which ships with Emacs 25.1). Here is a working function:

(when (version= org-version "8.2.10")
  (defun org-cycle-agenda-files ()
    "Cycle through the files in `org-agenda-files'.
If the current buffer visits an agenda file, find the next one in the list.
If the current buffer does not, find the first agenda file."
    (let* ((fs (org-agenda-files t))
           (files (append fs (list (car fs))))
           (tcf (if buffer-file-name (file-truename buffer-file-name)))
      (unless files (user-error "No agenda files"))
      (catch 'exit
        (while (setq file (pop files))
          (if (equal (file-truename file) tcf)
              (when (car files)
                (find-file (car files))
                (throw 'exit t))))
        (find-file (car fs)))
      (if (buffer-base-buffer) (org-pop-to-buffer-same-window (buffer-base-buffer))))))

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.