On 13 July 2011 01:46, Philipp Möller <bootsare...@googlemail.com> wrote: > Hello all, > I want to define a capture template which pre-processes the head of the kill > ring with a sexp that takes a string as an argument: > > (setq org-capture-templates > (quote > (("l" "Link" entry (file+headline "" "Links") > "* \"%c\" %(get-page-title \"%c\")")))) > > ;; throws Bad url > (get-page-title "foo-bar") > ;; works as expected > (get-page-title "http://orgmode.org/manual/Template-expansion.html") > > (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 "]]") > )) > > Please just ignore that I'm trying to parse XML with a regexp here. > > get-page-title works when called from code but always returns bad url when > called from the capture template. > Is the problem the way I escape the string or is this just not the way the > sexp in capture are supposed to be used?
Hi, nevermind. I figured out that the expansion order of %s and s expressions is the problem and also the reason for the with the correct URL. The solution is to use %(get-page-title (current-kill 0)). Can this be added to the documentation or is it supposed to be obvious from the order of available template expansions? Regards, Philipp > Regards, > Philipp >