I am trying to create a capture template that converts a url into an org-mode link with <title> as the link name.
My conversion function looks like this:
(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 "]]") ))
When called from normal emacs lisp code, it returns the correct result. But when used in this org-capture-template it returns only bad url .
setq org-capture-templates (quote (("l" "Link" entry (file+headline "" "Links") "* \"%c\" %(get-page-title \"%c\")"))))
Is the extension order different? Do I need to avoid the string differently? Magic? The first %c is just them for debugging the string and is actually printed as "url".
Please don’t even bother pointing out that parsing XML using regular expression is the wrong approach. Cthulhu already haunting me, and this will not worsen the situation.
emacs org-mode
pmr
source share