【问题标题】:How to use org-mode "capture-refile" mechanism to build my own vocabulary?如何使用 org-mode “capture-refile” 机制来构建自己的词汇表?
【发布时间】:2012-11-25 12:00:02
【问题描述】:

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高手能帮帮我!

【问题讨论】:

  • 应该/C/CA 是树的标题还是你的意思是一个斜线来表示一个子级别?
  • 我看到的主要问题是:org-capture 在您调用它时决定位置。这意味着您无法选择该位置,因为您还没有插入单词(有意义,不是吗?)。因此,您可能应该有一个自定义重新文件而不是捕获。只需将捕获的单词发送到正确的文件 (english.org),然后使用您的自定义重新文件。
  • 是的,/C/CA 表示第二个子级别,CAC 下的条目。

标签: emacs elisp org-mode


【解决方案1】:

我认为 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)))))

【讨论】:

  • 看来vocab.org一开始就不应该为空。
【解决方案2】:

我在为类似的东西获取 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")
    )
)

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-06-22
    • 1970-01-01
    • 2018-02-04
    相关资源
    最近更新 更多