如何自动添加到议程列表中的文件夹下的所有组织文件? [英] How to make all org-files under a folder added in agenda-list automatically?
问题描述
我使用 org-mode 来写笔记,使用 org-agenda 来组织所有笔记,尤其是搜索一些信息.按关键字或标签.
I am using org-mode to write notes and org-agenda to organize all notes, especially to search some info. by keyword or tag.
抄送可以通过输入的标签搜索一些文件,抄送按关键字搜索,org-agenda的这些功能很好用,但是,我需要添加组织- 手动将其归档到议程列表中.
C-c a m can search some files by tag inputed, C-c a s by keyword ,those functions from org-agenda are well to utilize, however, I need to add org-file into the agenda-list by hand.
我在.emacs中添加了一些代码,比如
I added some codes into .emacs, such as
(setq org-agenda-files (list "path/folder/*.org"))
或
(setq org-agenda-files (file-expand-wildcards "path/folder/*.org"))
但是,两者都未能将指定文件夹下的文件自动添加到议程列表中,因此我无法在这些组织文件中搜索关键字或标签,除非我打开一个组织文件并键入 Cc [ 将其添加到议程列表中.
but, both failed to add files under the folder specified into agenda-list automatically, so I can't search keyword or tag among those org-files, unless that I open a org-file and type C-c [ to add it into agenda-list.
如何使文件夹下的所有组织文件自动添加到议程中?
How can I make all org-files under a folder automatically added in agenda?
推荐答案
只要命名目录就足够了.例如,这对我很有效:
Just naming the directory should be enough. For example this works for me very well:
(setq org-agenda-files '("~/org"))
另请看org-agenda-text-search-extra-files
;它让你添加仅包含在文本搜索中的额外文件.典型值可能是,
Also take a look at org-agenda-text-search-extra-files
; it lets you
add extra files included only in text searches. A typical value might
be,
(setq org-agenda-text-search-extra-files
'(agenda-archives
"~/org/subdir/textfile1.txt"
"~/org/subdir/textfile1.txt"))
警告:如果在启动后将文件添加到目录中Emacs,不会被收录.
Caveat: If you add a file to the directory after you have started Emacs, it will not be included.
(2018 年)要在额外文件列表中包含具有特定扩展名的所有文件,您可以尝试使用我曾经写过的以下函数(此处可能提供更新的版本).
(2018) To include all files with a certain extension in the extra files list you can try the following function I wrote sometime back (a more recent version might be available here).
;; 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-lispdirectory-files-recursively
也提供了这个功能.但是,请注意在这些情况下文件名参数是(贪婪的)正则表达式.所以像 (directory-files-recursively "~/my-dir" "org")
这样的东西会给你所有的 Org 文件,包括备份文件(*.org~
).要仅包含 *.org
文件,您可以使用 (directory-files-recursively "~/my-dir" "org$")
.
(2019) As mentioned in the answer by @mingwei-zhang and the comment by @xiaobing, find-lisp-find-files
from find-lisp
and directory-files-recursively
also provides this functionality. However, please note in these cases the file name argument is a (greedy) regex. So something like (directory-files-recursively "~/my-dir" "org")
will give you all Org files including backup files (*.org~
). To include only *.org
files, you may use (directory-files-recursively "~/my-dir" "org$")
.
这篇关于如何自动添加到议程列表中的文件夹下的所有组织文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!