emacs - 使用 sexp 进行组织模式捕获

标签 emacs org-mode

我正在尝试创建一个捕获模板,该模板将 URL 转换为带有 <title> 的组织模式链接。作为链接名称。

我的转换函数如下所示:

(defun get-page-title (url)
  "Get title of web page, whose url can be found in the current line"
  ;; Get title of web page, with the help of functions in url.el
  (with-current-buffer (url-retrieve-synchronously url)
    ;; find title by grep the html code
    (goto-char 0)
    (re-search-forward "<title>\\([^<]*\\)</title>" nil t 1)
    (setq web_title_str (match-string 1))
    ;; find charset by grep the html code
    (goto-char 0)

    ;; find the charset, assume utf-8 otherwise
    (if (re-search-forward "charset=\\([-0-9a-zA-Z]*\\)" nil t 1)
        (setq coding_charset (downcase (match-string 1)))
      (setq coding_charset "utf-8")
    ;; decode the string of title.
    (setq web_title_str (decode-coding-string web_title_str (intern
                                                             coding_charset)))
    )
  (concat "[[" url "][" web_title_str "]]")
  ))

当从普通的 emacs lisp 代码调用时,它返回正确的结果。但是当用在这个org-capture-template它只返回 bad url .
setq org-capture-templates
    (quote
     (("l" "Link" entry (file+headline "" "Links")
       "* \"%c\" %(get-page-title \"%c\")"))))

展开的顺序不同吗?我需要以不同的方式转义字符串吗?魔法?
第一%c只是他们调试字符串,确实被打印为“url”。

请不要费心指出使用正则表达式解析 XML 是错误的方法。克苏鲁 已经困扰着我,这不会让它变得更糟。

最佳答案

问题是模板参数的展开顺序。简单的%在评估 sexp 后扩展模板。原始错误消息仍然包含一个模板,因此被扩展到剪贴板的内容中,因此错误消息不包含最初传递给 get-page-title 的字符串。 .

解决方案是从 sexp 中访问 kill ring:

%(get-page-title (current-kill 0))

编辑 此行为现​​在记录在 org-mode 中。

关于emacs - 使用 sexp 进行组织模式捕获,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6681407/

相关文章:

emacs - 如何将值固定在模型线的右侧?

emacs - org-mode: native 字体化代码块

emacs - 如何区分 org-babel 代码块中的方案方言?

emacs - 在Emacs组织模式下,如何将显示范围缩小到两个单独文件中的两个子树?

emacs - 如何为组织模式议程中的 SCHEDULED 项目启用警告日?

python - Pymacs 不在 Emacs24 Carbon 上启动

emacs - 在 emacs 的字符串中突出显示 ""

javascript - 如何在 emacs 的 js2 模式下 trim 尾随空格

emacs - 能不能让emacs有类似010编辑器文件格式分析的功能?

emacs - 永久对 Org 模式表中的列求和