emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
* %(SEXP) with %c in org-capture templates
@ 2011-07-12 23:46 Philipp Möller
  2011-07-15 22:38 ` Philipp Möller
  0 siblings, 1 reply; 5+ messages in thread
From: Philipp Möller @ 2011-07-12 23:46 UTC (permalink / raw)
  To: emacs-orgmode

[-- Attachment #1: Type: text/plain, Size: 1561 bytes --]

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
       (("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

  (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?


[-- Attachment #2: Type: text/html, Size: 2135 bytes --]

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2011-07-25 21:09 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2011-07-12 23:46 %(SEXP) with %c in org-capture templates Philipp Möller
2011-07-15 22:38 ` Philipp Möller
2011-07-24 16:48   ` Bastien
2011-07-25 13:49     ` Philipp Möller
2011-07-25 21:09       ` Bastien

Code repositories for project(s) associated with this public inbox


This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).