最近在用org-roam,怎么方便地连接还没有标注ID的headline?

比如在obsidian,在写一篇文章,想加个连接,直接[[]]写就可以,自动帮你找文件,找head,选择就好。 但是在org-roam,如果我想加另一个文件的headline做链接,这个headline如果之前有ID属性,是可以通过node find或node-insert找到的,但如果没有的话,还得先去另一个文件的headline,然后org-id-get-create创建一个id属性,再回到编辑文件才能加,太麻烦了。

1 个赞

org-roam-node-insert

1 个赞

如果你用 ivy 的话, 从 Kitchin 的 scimax-org.el 里 copy 两个函数就能做到在当前目录下的所有 org 文件的所有 headings 中进行补全搜索 (无论有没有 ID). 这两个函数自己小改一下就可以做到加任意 org heading 的 ID 链接 (之前没有 ID 的可以自动补). 如果不会改的话先作为一个补全搜索所有 heading 的函数也超好用 (比 org-refile 快很多):

(defun ivy-org-jump-to-heading-in-files (files &optional fontify)
  "Jump to org heading in FILES.
Optional FONTIFY colors the headlines. It might slow things down
a lot with large numbers of org-files or long org-files. This
function does not open the files."
  (let ((headlines '()))
    (cl-loop for file in files do
	  (when (file-exists-p file)
	    (with-temp-buffer
	      (insert-file-contents file)
	      (when fontify
		(org-mode)
		(font-lock-ensure))
	      (goto-char (point-min))
	      (while (re-search-forward org-heading-regexp nil t)
		(cl-pushnew (list
			     (format "%-80s (%s)"
				     (match-string 0)
				     (file-name-nondirectory file))
			     :file file
			     :position (match-beginning 0))
			    headlines)))))
    (ivy-read "Headline: "
	      (reverse headlines)
	      :action (lambda (candidate)
			(org-mark-ring-push)
			(find-file (plist-get (cdr candidate) :file))
			(goto-char (plist-get (cdr candidate) :position))
			(outline-show-entry)))))

(defun ivy-org-jump-to-heading-in-directory (&optional recursive)
  "Jump to heading in an org file in the current directory.
Use a prefix arg to make it RECURSIVE.
Use a double prefix to make it recursive and fontified."
  (interactive "P")
  (let ((fontify nil))
    (when (equal recursive '(16))
      (setq fontify t))
    (ivy-org-jump-to-heading-in-files
     (f-entries "."
		(lambda (f)
		  (and
		   (f-ext? f "org")
		   (not (s-contains? "#" f))
		   (not (string-equal "~" (substring f -1)))); 自己加的, 排除备份 org 文件
		  )
		recursive)
     fontify)))
2 个赞

使用 GitHub - toshism/org-super-links: Package to create links with auto backlinks 中 345 行 注释掉了。

(when (derived-mode-p 'org-mode)
	       (org-super-links-insert-backlink (car source-formatted-link) (cdr source-formatted-link)))

对于要插入任何 headline 链接都是 m-x org-super-links-quick-insert-inline-link ,会弹出搜索框,搜索相关headline,然后选中headline。如果headline 有id属性会直接插入,如果headline 没有id 属性,会自动生成并插入

2 个赞