求教【smart note】如何orgmode中快速插入headline链接

如Kinney所言,如果你愿意用文件组织笔记,现在有很多方案。

不过,我个人也是倾向用heading组织笔记,快速插入链接的最简单的方法是用 helm-org 的Action。实际上,helm-org自带插入链接功能,只不过插入的通过标题名匹配的链接,如果修改heading名称,链接就会失效。因此,用id链接是更稳健的方案。演示效果: helm-org-link

注意看最下面的mini-buffer,显示插入的是id链接

首先,确保 helm-org 已安装

然后配置:

   (defun yuchen/helm-org-run-marked-heading-id-link ()
     (interactive)
     (with-helm-alive-p
       (helm-exit-and-execute-action
        'yuchen/helm-org-marked-heading-id-link)))

   (defun yuchen/helm-org-marked-heading-id-link (marker)
     (let* ((victims (with-helm-buffer (helm-marked-candidates)))
            (buffer (marker-buffer marker))
            (filename (buffer-file-name buffer))
            (rfloc (list nil filename nil marker)))
       (when (and (= 1 (length victims))
                  (equal (helm-get-selection) (car victims)))
         ;; No candidates are marked; we are refiling the entry at point
         ;; to the selected heading
         (setq victims (list marker)))
       (when (and victims buffer filename rfloc)
         (cl-loop for victim in victims
                  ;; do (org-with-point-at victim
                  ;;      (org-refile nil nil rfloc))

                  do (with-current-buffer (marker-buffer victim)
         (let ((heading-id (save-excursion (goto-char (marker-position victim))
                                           (org-id-get-create)
                                           ))
               (heading-name
                (save-excursion
                  (goto-char (marker-position victim))
                  (org-entry-get nil "ITEM"))
                )
               )
           (with-helm-current-buffer
             (org-insert-link
              nil (concat "id:" heading-id) heading-name)
             (insert " ")
             )))
   ))))

添加到现有action-list

(add-to-list 'helm-org-headings-actions '(“Insert id link(s) C-H-l” . yuchen/helm-org-marked-heading-id-link) t)

绑定快捷键

(define-key helm-org-headings-map (kbd “C-H-l”) 'yuchen/helm-org-run-marked-heading-id-link)

5 个赞