阅读法律条文时,文中经常会引用到其他条款,搜索了一圈,没找到能方便跳转的包。自己写了个不太完美的,如有更好的,麻烦各位告知下。
效果如下:
(defvar lld-search-radio-regexp "^[》]*第\\([一二三四五六七八九十百千万]+条\\)")
(defvar lld-search-radio-match-string-begin "^[[:blank:]]*")
(defvar lld-search-radio-match-string "")
(defun lld-reg-search-radio-advice (fn link &rest arg)
(let* ((type (org-element-property :type link))
(end (org-element-property :end link))
(eol (save-excursion
(goto-char end)
(move-end-of-line 1)
(point))))
(when (equal type "radio")
(setq lld-search-radio-match-string "")
(save-excursion
(save-restriction
(narrow-to-region end eol)
(when (re-search-forward lld-search-radio-regexp eol t)
(setq lld-search-radio-match-string (concat "第" (match-string 1))))))))
(apply fn link arg))
(defun lld-radio-goto-match-advice (fn target)
(let ((str target)
(old (point))
origin)
(funcall fn target)
(setq origin (point))
(when (not (= origin old))
(save-restriction
(org-narrow-to-subtree)
(unless (re-search-forward (concat lld-search-radio-match-string-begin
lld-search-radio-match-string)
nil t)
(goto-char origin))))))
(advice-add 'org-link-open :around 'lld-reg-search-radio-advice)
(advice-add 'org-link--search-radio-target :around 'lld-radio-goto-match-advice)
使用时只需要把某个法律放到org-mode的一个headline下,然后在此 headline 下创建一个 Radio Targets 。比如:<<<民法典>>>。保存后,revert-buffer
就能跳转了。