From mboxrd@z Thu Jan 1 00:00:00 1970 From: =?UTF-8?Q?Philipp_M=C3=B6ller?= Subject: %(SEXP) with %c in org-capture templates Date: Wed, 13 Jul 2011 01:46:59 +0200 Message-ID: Mime-Version: 1.0 Content-Type: multipart/alternative; boundary=bcaec5314c797b1f5204a7e7eacc Return-path: Received: from eggs.gnu.org ([140.186.70.92]:45481) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1QgmfS-0001av-QO for emacs-orgmode@gnu.org; Tue, 12 Jul 2011 19:47:11 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1QgmfO-0006N6-QW for emacs-orgmode@gnu.org; Tue, 12 Jul 2011 19:47:06 -0400 Received: from mail-pz0-f41.google.com ([209.85.210.41]:43097) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1QgmfO-0006N2-Ct for emacs-orgmode@gnu.org; Tue, 12 Jul 2011 19:47:02 -0400 Received: by pzk4 with SMTP id 4so5121294pzk.0 for ; Tue, 12 Jul 2011 16:47:00 -0700 (PDT) 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 --bcaec5314c797b1f5204a7e7eacc Content-Type: text/plain; charset=UTF-8 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 "\\([^<]*\\)" 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? Regards, Philipp --bcaec5314c797b1f5204a7e7eacc Content-Type: text/html; charset=UTF-8 Content-Transfer-Encoding: quoted-printable Hello all,
I want to define a capture template which pre-processes the h= ead of the kill 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-title \"%c\")"))))

;; throws Bad url
(ge= t-page-title "foo-bar")
;; works as expected
(get-page-titl= e "http:= //orgmode.org/manual/Template-expansion.html")

(defun get-page-title (url)
=C2=A0 "Get title of web page, whos= e 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 "<title&= gt;\\([^<]*\\)</title>" 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 gr= ep the html code
=C2=A0=C2=A0=C2=A0 (goto-char 0)

=C2=A0=C2=A0=C2=A0 ;; find the char= set, assume utf-8 otherwise
=C2=A0=C2=A0=C2=A0 (if (re-search-forward &q= uot;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 (se= tq web_title_str (decode-coding-string web_title_str (intern
=C2=A0=C2= =A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0= =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2= =A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0= =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2= =A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 coding_charset)))
= =C2=A0=C2=A0=C2=A0 )
=C2=A0 (concat "[[" url "][" we= b_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 when called from the capture template.
Is the problem th= e way I escape the string or is this just not the way the sexp in capture a= re supposed to be used?

Regards,
Philipp
--bcaec5314c797b1f5204a7e7eacc--