10

有机制org-modeCapture-Refile-Archive我经常用它来做笔记和日志。我也想用它来建立我自己的词汇量。例如,当我在阅读一些英文文本时遇到一些生词,我想简单地键入C-c c v e将这个词记录到我的词汇文件Word-List-EN.org中。我还希望将单词分类为 Letters,例如cashew将记录到 entry 中/C/CA。我想输入C-c c v E以将我的世界语单词记录到某个文件中,例如vortaro.org. 如何配置org-capture-templates来实现这个?我阅读了组织信息,但仍然没有任何线索。手册说我可以使用类似(function function-finding-location). 但我必须定义我自己的function-finding-location. 希望elisp高手能帮帮我!

4

2 回答 2

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)))))
于 2012-12-11T07:02:43.957 回答
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")
    )
)
于 2012-12-04T09:09:06.280 回答