Viv*_*odo 9 emacs elisp org-mode
该org-mode具有Capture-Refile-Archive的机制.我经常用它来记笔记和记录.我也想用它来建立我自己的词汇.例如,当我在阅读一些英文文本时遇到一些新单词时,我想简单地键入C-c c v e以将单词记录到我的词汇表文件中Word-List-EN.org.我也希望这些单词被分类为Letters,例如,cashew将被记录到条目中/C/CA.我想键入C-c c v E以将我的世界语单词记录到某个文件中vortaro.org.如何配置org-capture-templates实现这个?我阅读了组织信息,但仍然没有任何线索.手册说我可以使用类似的东西(function function-finding-location).但我必须定义自己的function-finding-location.希望elisp大师可以帮助我!
小智 5
我认为 pmr 是正确的,即选择文件位置作为模板一部分的功能对于您的需求来说太早了。
与 org capture refile 工作流集成的一种方法是使用标准的 org capture 模板系统将您的新词归档到 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)))))
Run Code Online (Sandbox Code Playgroud)
我在获取 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")
)
)
Run Code Online (Sandbox Code Playgroud)