Skip to content

Instantly share code, notes, and snippets.

@iani
Created January 31, 2014 20:49
Show Gist options
  • Select an option

  • Save iani/8742837 to your computer and use it in GitHub Desktop.

Select an option

Save iani/8742837 to your computer and use it in GitHub Desktop.
Save/Load agenda file lists in emacs org-mode.
* Add, remove, save agenda file list
#+BEGIN_SRC emacs-lisp
(defvar org-agenda-list-save-path
"~/.emacs.d/savefile/org-agenda-list.el"
"Path to save the list of files belonging to the agenda.")
(defun org-agenda-save-file-list ()
"Save list of desktops from file in org-agenda-list-save-path"
(interactive)
(save-excursion
(let ((buf (find-file-noselect org-agenda-list-save-path)))
(set-buffer buf)
(erase-buffer)
(print (list 'quote org-agenda-files) buf)
(save-buffer)
(kill-buffer)
(message "org-agenda file list saved to: %s" org-agenda-list-save-path))))
(defun org-agenda-load-file-list ()
"Load list of desktops from file in org-agenda-list-save-path"
(interactive)
(save-excursion
(let ((buf (find-file-noselect org-agenda-list-save-path)))
(set-buffer buf)
(setq org-agenda-files (eval (read (buffer-string))))
(kill-buffer)
(message "org-agenda file list loaded from: %s" org-agenda-list-save-path))))
(defun org-agenda-remove-file (&optional select-from-list)
"Remove a file from org-agenda-files list.
If called without prefix argument, remove the file of the current buffer.
If called with prefix argument, then select a file from org-agenda-files list."
(interactive "P")
(let (path)
(if (select-from-list)
(let ((menu (grizzl-make-index org-agenda-files)))
(setq path (grizzl-completing-read "Choose an agenda file: " menu)))
(setq path (buffer-file-name (current-buffer))))
(setq org-agenda-files
(remove (buffer-file-name (current-buffer)) org-agenda-files)))
(org-agenda-save-file-list))
(defun org-agenda-open-file ()
"Open a file from the current agenda file list."
(interactive)
(let* ((menu (grizzl-make-index org-agenda-files))
(answer (grizzl-completing-read "Choose an agenda file: " menu)))
(find-file answer)))
(defun org-agenda-list-files ()
"List the paths that are currently in org-agenda-files"
(interactive)
(let ((menu (grizzl-make-index org-agenda-files)))
(grizzl-completing-read "These are currently the files in org-agenda-files. " menu)))
(defun org-agenda-list-menu ()
"Present menu with commands for loading, saving, adding and removing
files to org-agenda-files."
(interactive)
(let* ((menu (grizzl-make-index
'("org-agenda-save-file-list"
"org-agenda-load-file-list"
"org-agenda-list-files"
"org-agenda-open-file"
"org-agenda-file-to-front"
"org-agenda-remove-file")))
(command (grizzl-completing-read "Choose a command: " menu)))
(call-interactively (intern command))))
(global-set-key (kbd "H-a H-a") 'org-agenda-list-menu)
#+END_SRC
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment