只需命名目录就足够了。例如,这对我很有用:
(setq org-agenda-files '("~/org"))
也看看org-agenda-text-search-extra-files
; 它允许您添加仅包含在文本搜索中的额外文件。一个典型的值可能是,
(setq org-agenda-text-search-extra-files
'(agenda-archives
"~/org/subdir/textfile1.txt"
"~/org/subdir/textfile1.txt"))
警告:如果您在启动 Emacs 后将文件添加到目录中,则不会包含该文件。
编辑:(2018)要将具有特定扩展名的所有文件包含在额外文件列表中,您可以尝试以下我写过的函数(此处可能提供更新的版本)。
;; recursively find .org files in provided directory
;; modified from an Emacs Lisp Intro example
(defun sa-find-org-file-recursively (&optional directory filext)
"Return .org and .org_archive files recursively from DIRECTORY.
If FILEXT is provided, return files with extension FILEXT instead."
(interactive "DDirectory: ")
(let* (org-file-list
(case-fold-search t) ; filesystems are case sensitive
(file-name-regex "^[^.#].*") ; exclude dot, autosave, and backupfiles
(filext (or filext "org$\\\|org_archive"))
(fileregex (format "%s\\.\\(%s$\\)" file-name-regex filext))
(cur-dir-list (directory-files directory t file-name-regex)))
;; loop over directory listing
(dolist (file-or-dir cur-dir-list org-file-list) ; returns org-file-list
(cond
((file-regular-p file-or-dir) ; regular files
(if (string-match fileregex file-or-dir) ; org files
(add-to-list 'org-file-list file-or-dir)))
((file-directory-p file-or-dir)
(dolist (org-file (sa-find-org-file-recursively file-or-dir filext)
org-file-list) ; add files found to result
(add-to-list 'org-file-list org-file)))))))
你可以像这样使用它:
(setq org-agenda-text-search-extra-files
(append (sa-find-org-file-recursively "~/org/dir1/" "txt")
(sa-find-org-file-recursively "~/org/dir2/" "tex")))
编辑:(2019)正如@mingwei-zhang 的回答和@xiaobing 的评论中提到的,find-lisp-find-files
来自find-lisp
并且directory-files-recursively
也提供了这个功能。但是,请注意在这些情况下,文件名参数是(贪婪的)正则表达式。所以类似的东西(directory-files-recursively "~/my-dir" "org")
会给你所有的组织文件,包括备份文件(*.org~
)。要仅包含*.org
文件,您可以使用(directory-files-recursively "~/my-dir" "org$")
.