Я пытаюсь создать шаблон захвата, который преобразует 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
, он возвращает только неверный URL
.
setq org-capture-templates
(quote
(("l" "Link" entry (file+headline "" "Links")
"* \"%c\" %(get-page-title \"%c\")"))))
Отличается ли порядок раскрытия? Нужно ли мне экранировать строку по-другому? Магия?
Первый % c
предназначен только для отладки строки и действительно печатается как «url».
Пожалуйста, даже не обращайте внимания на то, что синтаксический анализ XML с помощью регулярного выражения - неправильный подход. Ктулху уже преследует меня, и от этого не станет хуже.