org mode 如何搜索标题直接插入链接

插入一个标题链接(比如要引用某个概念), 现在我是这样做的:

  • 当前内容添加 bookmark, 这样方便一会儿跳转回来
  • 搜索标题, 用 consult-org-heading 或者 consult-outline, 跳转
  • 执行 org-super-links-store-link, 保存 link
  • 通过前面添加的 bookmark, 跳转回到原位置
  • 执行 org-super-links-insert-link

但如果能直接集成为一步, 不用跳转就好了, 即直接:

  • 搜索标题, 用 consult-org-heading 或者 consult-outline, 不跳转, 按个什么键, 直接对搜索到的标题执行 org-super-links-store-link, 再在当前文本执行 org-super-links-insert-link, 那就太方便了.

有什么办法么?

1 个赞

虽然我没试过,但我觉得你可以将多个步骤压缩成 emacs 里的「宏」,用命令来调用。

可以考虑添加embark命令

把你上面的所有步骤写个函数

用 embark 应该是最方便的,详见 关于 embark ,大家有什么小技巧或者 hack 吗?

3 个赞

看上去这篇文章可能对你有帮助:

(defun my/org-insert-link-and-ref ()
  "effectively duplicates the org-insert-link function and adds a ref (a link to the file the
   linked-entry is pasted into) in the linked-entries property drawer."
  (interactive)
  (let* ((buf (current-buffer))
         (current-heading-id (org-id-get-create))
         (current-heading (format "%s" (org-get-heading t t t t)))
         (heading-of-inserted-link (format "%s" (cadr (car org-stored-links))))
         (id-of-inserted-link (substring-no-properties (car (car org-stored-links))))
         (file-of-inserted-link (car (org-id-find (cadr (split-string id-of-inserted-link "id:")))))
         (buffer-of-inserted-link (org-find-base-buffer-visiting file-of-inserted-link))
         (marker-to-inserted-link (org-find-exact-headline-in-buffer heading-of-inserted-link buffer-of-inserted-link))
         (marker-to-current-link (org-find-exact-headline-in-buffer current-heading buf)))
    (with-current-buffer (get-buffer-create buffer-of-inserted-link)
      ;; check the REFS for existence/enries
      (if (org-entry-get marker-to-inserted-link "REFS")
          ;; check if the id has already been inserted (avoid placing the same ref)
          (if (not (string-match-p current-heading-id (format "%s" (org-entry-get marker-to-inserted-link "REFS"))))
              ;; if there's no ref already in the property, append it
              (org-entry-put marker-to-inserted-link "REFS"
                             (format "%s //// [[id:%s][%s]]"
                                     (org-entry-get marker-to-inserted-link "REFS") current-heading-id current-heading)))
             ;; else, place the ref
            (org-entry-put marker-to-inserted-link "REFS"
                           (format "[[id:%s][%s]]" current-heading-id current-heading)))
        (save-buffer))
      (insert (format "[[id:%s][%s]]" id-of-inserted-link heading-of-inserted-link))))

我说个简单的,假设你用的是 gui 版,那么直接 make-frame 去找你想要的 node,找到以后复制链接然后 frame 一关瞬间回到原来的 frame,粘贴即可

这套操作我太常用了, 因此 make-frame 和关 frame 都有快捷键。很多时候你找 node 的时候又逛到其他地方去了,再 make-frame 即可。总之最后所有打开的 frame 自然保存了你的整个检索过程,不用特意去书签记录。搞完之后关关关就好了,同时也能顺便回顾一下自己刚才都干了啥