更新
locate 符号化;基于 org-exec 的构建。
1 locate 符号化
动机:上个版本中,我们已经裁掉了 org-noweb-expand-link
展开远程资源的特性,转而把展开远程资源的特性支持借由 org-id-remap
实现。现在,我们仿照 org-exec, 利用 link-open-conf 扩展 org-noweb-expand-link
的 locate
函数,以使其支持展开远程资源,无需依赖 org-id-remap
.
从 locate
=> (locate (make-symbol "locate"))
#+name: 2025-08-03-16-19
#+begin_src emacs-lisp :eval no
(locate (make-symbol "locate"))
expand features log
babel-variables
org-element-expanders post-process
#+end_src
提供一个命令以便导出 locate
: (org-noweb-expand-link 'locate)
.
#+name: 2025-08-03-16-20
#+begin_src emacs-lisp :eval no
;; 如空,提供一个接口查询特性说明。
((null link)
(when-let*
((f (completing-read
"Describe feature: "
features))
(f (seq-position
features
f #'string=))
(f (nth f features))
(_ (functionp f)))
(describe-function f)))
;; 按 Org 元素类型设置元素展开函数。
;; (type expander &optional feature-name)
((eq link 'set-expander)
(when-let* ((type (car conf))
(expander (cadr conf)))
(setf (alist-get
type org-element-expanders)
expander)
(when-let*
((f (caddr conf))
(_ (symbolp expander))
(f (make-symbol (symbol-name f))))
(!def f expander)
(setq features
(append features `(,f))))))
;; 添加展开后处理函数。
;; (post-process &optional feature-name)
((eq link 'add-post-process)
(when-let* ((proc (car conf)))
(push proc post-process)
(when-let*
((f (cadr conf))
(_ (symbolp proc))
(f (make-symbol (symbol-name f))))
(!def f proc)
(setq features
(append features `(,f))))))
;; 添加 Babel Variable.
;; (variable)
((eq link 'add-babel-var)
(when (car conf)
(setq
babel-variables
(append babel-variables `(,(car conf))))))
;; export log function
((eq link 'log) log)
((eq link 'locate) locate)
((eq link 'features) features)
((eq link 'version) nil)
#+end_src
映射表:
注:由于这里使用了 org-id-remap 表项覆盖 (2) 特性,所以,想要构建这个版本,需要先将 org-id-remap 升级到支持该特性的版本。
#+name: 2025-08-03-16-39
#+begin_src emacs-lisp :eval no
(org-id-remap
"map-table-base"
"https://emacs-china.org/t/org-tangle/29663::2025-07-26-15-13")
#+end_src
#+name: 2025-08-03-16-38
#+header: :depend (org-sbe "2025-08-03-16-39" ":eval yes")
#+begin_src emacs-lisp :eval no
<<@([[id:map-table-base]])>>
nil nil
"org-noweb-expand-link::private"
"ec:org-tangle/29663::2025-08-03-16-19"
"org-noweb-expand-link::cmd-set"
"ec:org-tangle/29663::2025-08-03-16-20"
#+end_src
2 基于 org-exec 的构建
构建入口:
#+name: 2025-08-03-16-42
#+header: :var tangle="no" load="no"
#+begin_src emacs-lisp :results silent :noweb yes :eval no
(org-id-remap 'reset)
(org-id-remap
"build-script"
"https://emacs-china.org/t/org-id-remap/29814::2025-08-03-11-27"
"build-target"
"https://emacs-china.org/t/org-tangle/29663::2025-07-26-11-26"
"map-table"
"https://emacs-china.org/t/org-tangle/29663::2025-08-03-16-38")
(org-id-remap t)
(org-exec "[[id:build-script]]" nil
:eval "yes"
'target "[[id:build-target]]"
'map-table ''("[[id:map-table]]")
'tangle (or tangle "~/org/org-noweb-expand-link.el")
'load (or load "yes"))
#+end_src