#+name: org-id-remap-org-id-open-advice
#+begin_src emacs-lisp :noweb yes
((lambda (search-option)
(lambda (oldfn link _ &optional _nlv)
(let ((org-link-search-must-match-exact-headline t)
(wcnf (current-window-configuration))
(found t)
(nlv (or _nlv 1))
links)
(funcall log "[%d]remap id: %S..."
nlv link)
(add-hook
'org-execute-file-search-functions
search-option)
(cond
(;; 先看看有没有 remap 为 id 的,以免每次
;; 都得让 org-id-find 遍历所有 Org 文件。
<<@([[id:org-id-remap.el::remap-id-link]])>>)
(;; 原 `org-id-open'.
(ignore-errors
(funcall oldfn link _)
(funcall log "[%d]no remap need"
nlv)
t))
(;; 最后找 http-link.
<<@([[id:org-id-remap.el::remap-http-link]])>>)
(;; not remap found.
t
(set-window-configuration wcnf)
(setq found nil)))
(remove-hook
'org-execute-file-search-functions
search-option)
(unless found
(error
"Cannot find entry with ID \"%s\""
link)))))
<<@([[id:org-id-remap.el::drawer-searcher]])>>)
#+end_src