org-mode
具有Capture-Refile-Archive
机制。我经常用它来记笔记和记录。我也想用它来建立我自己的词汇。例如,当我在阅读一些英文文本时遇到一些新单词时,我只想输入C-c c v e
将单词记录到我的词汇表文件Word-List-EN.org
中。我还希望将单词分类为字母,例如,cashew
将被记录到条目/C/CA
中。我想输入C-c c v E
将我的世界语单词记录到像vortaro.org
这样的文件中。如何配置org-capture-templates
来实现这个?我阅读了组织信息,但仍然没有任何线索。手册说我可以使用像(function function-finding-location)
这样的东西。但我必须定义自己的function-finding-location
。希望elisp大师可以帮助我!
答案 0 :(得分:4)
我认为pmr是正确的,因为选择文件位置作为模板的一部分的功能发生得太早,无法满足您的需求。
与org捕获refile工作流集成的一种方法是使用标准组织捕获模板系统将新单词存入vocab缓冲区,然后使用自定义elisp函数作为钩子,可能进入org-capture-before-finalize -hook,将新定义存档到正确的位置。
我编写了以下函数作为提示输入单词和定义的示例,并将其插入到正确位置的组织缓冲区中。如果它符合您的需求,您可以将其绑定到您选择的键,或者将其用作钩子方法的起点。
;;
;; remove extra spaces between stars and the headline text
;;
(defun tidy-headlines ()
(interactive)
(save-excursion
(goto-char (point-min))
(while (re-search-forward "^\\*+\\([[:space:]][[:space:]]+\\)" (point-max) t)
(replace-match " " nil nil nil 1))))
;;
;; function for storing things in vocab files like cashew /C/CA/Cashew
;;
(defun insert-vocab-word (vocab-word definition)
"prompts for a word then opens a vocab file and puts the word in place"
(interactive "sWord: \nsDefinition: ")
(find-file "~/org/vocab.org")
(tidy-headlines)
(goto-char (point-min))
(let* ((first-char (upcase (substring vocab-word 0 1)))
(first-two-chars (upcase (substring vocab-word 0 2))))
(while (and (re-search-forward "^\\* " (point-max) t)
(string< (buffer-substring-no-properties (point) (+ 1 (point))) first-char)))
(if (string= (buffer-substring-no-properties (point) (+ 1 (point))) first-char)
(let* ((end-of-subtree (save-excursion (org-end-of-subtree) (point))))
(while (and (re-search-forward "^\\*\\* " end-of-subtree t)
(string< (buffer-substring-no-properties (point) (+ 2 (point))) first-two-chars)))
(if (string= (buffer-substring-no-properties (point) (+ 2 (point))) first-two-chars)
(let* ((end-of-subtree2 (save-excursion (org-end-of-subtree) (point))))
(while (and (re-search-forward "^\\*\\*\\* " end-of-subtree2 t)
(string< (word-at-point) vocab-word)))
(if (string< vocab-word (word-at-point))
(progn
(beginning-of-line)
(org-insert-heading t))
(org-insert-heading-after-current))
(insert vocab-word)
(org-insert-subheading t)
(insert definition))
(progn
(if (string< first-two-chars (buffer-substring-no-properties (point) (+ 2 (point))))
(progn
(beginning-of-line)
(org-insert-heading t))
(org-insert-heading-after-current))
(insert first-two-chars)
(org-insert-subheading t)
(insert vocab-word)
(org-insert-subheading t)
(insert definition))))
(progn
(org-insert-heading-after-current)
(insert first-char)
(org-insert-subheading t)
(insert first-two-chars)
(org-insert-subheading t)
(insert vocab-word)
(org-insert-subheading t)
(insert definition)))))
答案 1 :(得分:1)
我遇到了类似的类似org-capture的巨大问题,但是org-remember工作得很好。这是我的相关.emacs位:
(require 'org-install)
(setq org-directory "~/.orgfiles/")
(setq org-default-notes-file (expand-file-name "~/.orgfiles/notes.org"))
(setq remember-annotation-functions '(org-remember-annotation))
(setq remember-handler-functions '(org-remember-handler))
(add-hook 'remember-mode-hook 'org-remember-apply-template)
(setq org-agenda-files '("~/.orgfiles"))
(global-set-key "\C-cl" 'org-store-link)
(global-set-key "\C-cc" 'org-remember)
(global-set-key "\C-ca" 'org-agenda)
(global-set-key "\C-cb" 'org-iswitchb)
(setq org-remember-templates
'(("Todo" ?t "* TODO %^{Brief Description} %^g\n%? Added: %U" "~/.orgfiles/TODO.org" "Tasks")
("Idea" ?i "* %^{Brief Description} %^g\n%? Added: %U" "~/.orgfiles/Idea.org" "Ideas")
("Study" ?s "* %^{Brief Description} %^g\n%? Added: %U" "~/.orgfiles/Study.org" "Study")
("Receipt" ?r "** %^{Brief Description} %U %^g\n%?" "~/.orgfiles/Receipt.org")
)
)