为 Org Capture Extension 定制 org-capture-template
Customized org-capture-template for Org Capture Extension
我正在使用很棒的 Org Capture Extension Firefox 插件直接将我的网络 link 捕获到我的 Emacs 文档中。
最小的组织捕获模板是:
(setq org-capture-templates `(
("L" "Protocol Link" entry (file+headline "~/web.org" "Links")
"* [[%:link][%:description]]\n")
;; ... your other templates
))
我用它来为文章添加书签,特别是很多文章都在
arxiv.org。问题是 arxiv 标题页包含 [] 个字符,例如:
[1606.04838] Optimization Methods for Large-Scale Machine Learning
这 不能 与模板中使用的 [[%:link][%:description]]
很好地混合以创建组织模式 link。例如捕获 returns:
** [[https://arxiv.org/abs/1606.04838][[1606.04838] Optimization Methods for Large-Scale Machine Learning]]
并且 Org-Mode link 已损坏 因为 "[1606.04838]" 中的括号字符串。
如何解决?
治疗方法是将link [%:description]
描述转换成不包含方括号[]的字符串。为此,我们可以定义一个函数,将 [ ] 字符转换为 (, ) 字符。
(defun transform-square-brackets-to-round-ones(string-to-transform)
"Transforms [ into ( and ] into ), other chars left unchanged."
(concat
(mapcar #'(lambda (c) (if (equal c ?[) ?\( (if (equal c ?]) ?\) c))) string-to-transform))
)
然后我们就可以把这个函数改成org-capture-template
了。 %(sexp) syntax 用于将 lisp 代码评估为模板:
%(sexp) Evaluate Elisp sexp and replace with the result.
For convenience, %:keyword (see below) placeholders
within the expression will be expanded prior to this.
The sexp must return a string.
修改后的org-capture-template
为:
(setq org-capture-templates '(
("L" "Protocol Link" entry (file+headline "~/web.org" "Links")
"* [[%:link][%(transform-square-brackets-to-round-ones \"%:description\")]]\n")
;; ... your other templates
))
然后当您单击 Firefox Org-Capture 按钮时,模板会正确扩展为
** (1606.04838) Optimization Methods for Large-Scale Machine Learning
具有良好的组织模式 link(请注意 [1606.04838] 已变成 (1606.04838))
我正在使用很棒的 Org Capture Extension Firefox 插件直接将我的网络 link 捕获到我的 Emacs 文档中。
最小的组织捕获模板是:
(setq org-capture-templates `(
("L" "Protocol Link" entry (file+headline "~/web.org" "Links")
"* [[%:link][%:description]]\n")
;; ... your other templates
))
我用它来为文章添加书签,特别是很多文章都在 arxiv.org。问题是 arxiv 标题页包含 [] 个字符,例如:
[1606.04838] Optimization Methods for Large-Scale Machine Learning
这 不能 与模板中使用的 [[%:link][%:description]]
很好地混合以创建组织模式 link。例如捕获 returns:
** [[https://arxiv.org/abs/1606.04838][[1606.04838] Optimization Methods for Large-Scale Machine Learning]]
并且 Org-Mode link 已损坏 因为 "[1606.04838]" 中的括号字符串。
如何解决?
治疗方法是将link [%:description]
描述转换成不包含方括号[]的字符串。为此,我们可以定义一个函数,将 [ ] 字符转换为 (, ) 字符。
(defun transform-square-brackets-to-round-ones(string-to-transform)
"Transforms [ into ( and ] into ), other chars left unchanged."
(concat
(mapcar #'(lambda (c) (if (equal c ?[) ?\( (if (equal c ?]) ?\) c))) string-to-transform))
)
然后我们就可以把这个函数改成org-capture-template
了。 %(sexp) syntax 用于将 lisp 代码评估为模板:
%(sexp) Evaluate Elisp sexp and replace with the result. For convenience, %:keyword (see below) placeholders within the expression will be expanded prior to this. The sexp must return a string.
修改后的org-capture-template
为:
(setq org-capture-templates '(
("L" "Protocol Link" entry (file+headline "~/web.org" "Links")
"* [[%:link][%(transform-square-brackets-to-round-ones \"%:description\")]]\n")
;; ... your other templates
))
然后当您单击 Firefox Org-Capture 按钮时,模板会正确扩展为
** (1606.04838) Optimization Methods for Large-Scale Machine Learning
具有良好的组织模式 link(请注意 [1606.04838] 已变成 (1606.04838))