I came across this flow of execution while trying to export a ghost org-file to pdf, meaning that the file is 'created' through #'find-file but not saved. While export the following backtrace is noted: ``` Debugger entered--entering a function: * org-check-agenda-file("/home/akash/Desktop/test.org") org-agenda-prepare-buffers(("/home/akash/Desktop/test.org")) org-map-entries((lambda nil (org-set-tags (delete "attached" (org-get-tags)))) "attached") custom/org-export-remove-attached-tag(latex) org-export-as(latex nil nil nil (:output-file "org-exports/test/test.tex")) org-export-to-file(latex "org-exports/test/test.tex" nil nil nil nil nil org-latex-compile) org-latex-export-to-pdf(nil nil nil nil) org-export-dispatch(nil) funcall-interactively(org-export-dispatch nil) command-execute(org-export-dispatch) ``` I have provisions to call #'org-map-entries before export this triggers #'org-agenda-prepare-buffers which finally calls #'org-check-agenda-files This asks the user what to do with a non existent file Non-existent agenda file %s. [R]emove from list or [A]bort? *Problem* I think this should not be called unless the file is part of 'org-agenda-files I have resorted to advicing the function as follows: ``` ;; Advice-Patch ;; if #'org-map-entries is called then #'org-check-agenda-file is executed through #'org-agenda-prepare-buffers ;; issue: neither functions is relevant to non-agenda files, causes bug asking user for extra input ;; Non-existent agenda file %s. [R]emove from list or [A]bort? ;; see : https://github.com/bzg/org-mode/blob/ec5d76bce1434a54a9a529dbe250b09dc3c132c0/lisp/org.el#L15340 ;; Possible solution: Do not call #'org-agenda-prepare-buffers for non-agenda files => ~exist 'org-agenda-files (defun my-org-agenda-prepare-buffers-advice (orig-func &rest args) "Advice function to modify `org-agenda-prepare-buffers'. It filters the FILES argument to ensure only agenda files are processed." (let ((files (if (listp (car args)) (car args) nil))) (when files (setq files (seq-filter #'(lambda (file) (member file org-agenda-files)) files))) (apply orig-func (list files)))) (advice-add 'org-agenda-prepare-buffers :around #'my-org-agenda-prepare-buffers-advice) ``` I don't know if this is a bug or something peculiar to my use case. Leaving the solution for others to see and possibly advice further. First posted on reddit r/emacs. https://www.reddit.com/r/emacs/comments/1bnhz24/bug_nonexistent_agenda_file_s/