From mboxrd@z Thu Jan 1 00:00:00 1970 From: =?UTF-8?Q?Philipp_M=C3=B6ller?= Subject: Re: %(SEXP) with %c in org-capture templates Date: Sat, 16 Jul 2011 00:38:09 +0200 Message-ID: References: Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable Return-path: Received: from eggs.gnu.org ([140.186.70.92]:44483) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Qhr1W-0008Nx-Ug for emacs-orgmode@gnu.org; Fri, 15 Jul 2011 18:38:20 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1Qhr1V-0006bL-AN for emacs-orgmode@gnu.org; Fri, 15 Jul 2011 18:38:18 -0400 Received: from mail-pv0-f169.google.com ([74.125.83.169]:47765) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Qhr1U-0006aj-Qo for emacs-orgmode@gnu.org; Fri, 15 Jul 2011 18:38:17 -0400 Received: by pvc12 with SMTP id 12so1837281pvc.0 for ; Fri, 15 Jul 2011 15:38:10 -0700 (PDT) In-Reply-To: List-Id: "General discussions about Org-mode." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-orgmode-bounces+geo-emacs-orgmode=m.gmane.org@gnu.org Sender: emacs-orgmode-bounces+geo-emacs-orgmode=m.gmane.org@gnu.org To: emacs-orgmode@gnu.org On 13 July 2011 01:46, Philipp M=C3=B6ller wro= te: > Hello all, > I want to define a capture template which pre-processes the head of the k= ill > ring with a sexp that takes a string as an argument: > > (setq org-capture-templates > =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 (quote > =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 (("l" "Link" entry (file+headline ""= "Links") > =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 "* \"%c\" %(get-page-tit= le \"%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) > =C2=A0 "Get title of web page, whose url can be found in the current line= " > =C2=A0 ;; Get title of web page, with the help of functions in url.el > =C2=A0 (with-current-buffer (url-retrieve-synchronously url) > =C2=A0=C2=A0=C2=A0 ;; find title by grep the html code > =C2=A0=C2=A0=C2=A0 (goto-char 0) > =C2=A0=C2=A0=C2=A0 (re-search-forward "\\([^<]*\\)" nil t = 1) > =C2=A0=C2=A0=C2=A0 (setq web_title_str (match-string 1)) > =C2=A0=C2=A0=C2=A0 ;; find charset by grep the html code > =C2=A0=C2=A0=C2=A0 (goto-char 0) > > =C2=A0=C2=A0=C2=A0 ;; find the charset, assume utf-8 otherwise > =C2=A0=C2=A0=C2=A0 (if (re-search-forward "charset=3D\\([-0-9a-zA-Z]*\\)"= nil t 1) > =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 (setq coding_charset (downcase= (match-string 1))) > =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 (setq coding_charset "utf-8") > =C2=A0=C2=A0=C2=A0 ;; decode the string of title. > =C2=A0=C2=A0=C2=A0 (setq web_title_str (decode-coding-string web_title_st= r (intern > > coding_charset))) > =C2=A0=C2=A0=C2=A0 ) > =C2=A0 (concat "[[" url "][" web_title_str "]]") > =C2=A0 )) > > 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 whe= n > called from the capture template. > Is the problem the way I escape the string or is this just not the way th= e > 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 >