3

looking for a little help with my function. I'm trying to create a loop-while that'll return a list of files back to org-agenda-files. It's just not working though and i keep getting errors. Any ideas how I can get this to work? Any using a loop-while could be completely wrong, i'm just looking for something that'll work.

(setq org-gtd-task-files '("next.org" "coding.org" "personal.org"))
(setq org-gtd-folder '"~/.org/gtd/")

(push (format "%s%s" org-gtd-folder (loop-while org-gtd-task-files (pop org-gtd-task-files))) org-agenda-files)

Another method I tried was:

 (let ((files org-gtd-task-files)
       (dir org-gtd-folder))
   (loop-while files
     (setq org-agenda-files (list (format "%s%s" org-gtd-folder (prog1 (car org-gtd-task-files) (setq org-gtd-task-files (cdr org-gtd-task-files)))))))
   (org-agenda nil "t")
   (print org-agenda-files))
Drew
  • 75,699
  • 9
  • 109
  • 225

1 Answers1

6

Without looking up any of the Org variables or functions you refer to, here's a guess at what you're trying to do. They both do the same thing: iterate over a list of file names, expanding them in directory org-gtd-folder, and setting the value of variable org-agenda-files to the resulting list of absolute file names.

;; Use `mapcar'
(setq org-agenda-files
      (mapcar (lambda (f) (expand-file-name file org-gtd-folder))
              org-gtd-task-files))

;; Use `dolist'
(dolist (file  org-agenda-files)
  (push (expand-file-name file org-gtd-folder) org-agenda-files)
  org-agenda-files)

See the Elisp manual, nodes Iteration and Mapping Functions.

One other thing: Don't use format or concat etc. for file-name manipulations. Use the file-name manipulation functions that Emacs Lisp provides. In this case, expand-file-name. See the Elisp manual, node File Names.

Drew
  • 75,699
  • 9
  • 109
  • 225
  • mapcar worked perfectly, and actually one of the functions i've been trying to figure out, your example helps a bunch! thanks! – Nick Martin Jul 25 '20 at 21:56