Org-mode:如何嵌入info文件的链接

16

我使用 org-mode 维护一份日记(内部博客,包含需要记住的想法),有时,当我学习 Emacs 时,我会将学到的技巧与信息文件引用存储下来。

目前,我的做法是这样的。我打开所需的信息文件,按下 c 来复制当前节点名称,然后按下 < s TAB - 这是一个 易模板,可以展开成一个 src-block。然后我添加 lisp 表达式并粘贴节点名称,最终链接看起来像这样:

#+begin_src emacs-lisp
(info "(org) Properties and Columns")
#+end_src
当我需要查看info文件时,我会将光标放在lisp sexp之后,然后按下C-x C-e(eval-last-sexp)。
这个过程很繁琐且不雅观。在org-mode中嵌入链接以链接到info文件的最佳方法是什么? 编辑: 我已经发现如何添加到info节点的链接。 Org-mode手册上的External links描述了使用链接的等效方法。
[[info:org#Tags]]
[[elisp:(info "(org) Tags")]]

对于第一种变体,我不确定如何将(org) Tags自动转换为org#Tags。我该如何进一步简化这个过程?

3个回答

15

您可以像处理其他支持的链接一样进行操作(请参见手册中的"处理链接"部分)。在info文件中,您可以使用M-x org-store-link(按照手册建议将其绑定为C-c l)进行储存,然后在您的org文件中使用C-c C-l插入链接。这时,您只需从已储存的链接列表中选择链接到您的info文件即可。


1

应该可行的步骤: - 转到所需的信息节点,然后只按“c”(节点名称将成为剪贴板中的条目) - 在您的org源文件中,转到您需要插入链接的位置,按C-c,C-l - 按Tab键,然后从提示的缓冲区中选择elisp:(或任何其他类型的链接)。现在你的迷你缓冲区里说elisp: - 在“:”之后输入此上下文(info “^”),让^成为您的节点名称,然后通过C-y粘贴回来 - 按Ret,然后会要求您填写一些描述。现在您已经完成了它,但仍然不知道发生了什么。 - M-x,visibility-mode,然后手动编写内容,我们现在得出结论,在上下文中必须替换每个空格的出现次数为“%20”。 例如==>自己做,自己看 - 切换回您的可见性模式 祝好运


1

org-store-link在访问Info页面时会提示“无法链接到未访问文件的缓冲区”,因为Info将buffer-name设置为*info*,而buffer-file-name设置为nil。为了解决这个问题,社区提供了一个示例来添加到man页面的链接(http://orgmode.org/manual/Adding-hyperlink-types.html),可以稍作修改:

;; Modified version of contrib/lisp/org-man.el; see
;; (http://orgmode.org/manual/Adding-hyperlink-types.html#Adding-hyperlink-types)
(require 'org)

(org-add-link-type "info" 'org-info-open)
(add-hook 'org-store-link-functions 'org-info-store-link)

(defcustom org-info-command 'info
  "The Emacs command to be used to display an info page."
  :group 'org-link
  :type '(choice (const info)))

(defun org-info-open (path)
  "Visit the infopage on PATH.
   PATH should be a topic that can be thrown at the info command."
  (funcall org-info-command path))

(defun org-info-store-link ()
  "Store a link to an info page."
  (when (memq major-mode '(Info-mode))
    ;; This is a info page, we do make this link
    (let* ((page (org-info-get-page-name))
           (link (concat "info:" page))
           (description (format "Infopage for %s" page)))
      (org-store-link-props
       :type "info"
       :link link
       :description description))))

(defun org-info-get-page-name ()
  "Extract the page name from Info in a hackish way."
  ;; This works for `Info-mode'.
  ;; Hackity-hack: copy the node name into the kill ring.
  (Info-copy-current-node-name)
  ;; Just return the kill.
  (current-kill 0))

(provide 'org-info)

重要的部分在最后:由于信息节点名称不是直接可访问的(我很难找到),我们可以通过调用Info-copy-current-node-name将其放入kill-ring中来解决此问题,然后返回kill-ring中的第一条目录(应该是刚插入的节点名称)。

2
请注意,这些信息在2013年是正确的,但至少从2017年以来已经不再正确。org-store-link现在可以正确处理Info文件,无需外部辅助功能。 - Trey
5
如果您在2017年之后阅读此内容并且 org-store-link 看起来仍然无法正确处理 Info 缓冲区,请确保 'ol-infoorg-modules 中。至少在2021年,Doom Emacs默认情况下会省略它,可以通过 (after! org (add-to-list 'org-modules 'ol-info)) 来解决。 - Chris Hunt

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接