emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
From: "Philipp Möller" <bootsarehax@googlemail.com>
To: emacs-orgmode@gnu.org
Subject: %(SEXP) with %c in org-capture templates
Date: Wed, 13 Jul 2011 01:46:59 +0200	[thread overview]
Message-ID: <CAC5Jocgz2mSzxVkMbt1vhFx3Fi0brz26x3tQzW=6i3ewMwDikA@mail.gmail.com> (raw)

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

Regards,
Philipp

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

             reply	other threads:[~2011-07-12 23:47 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-07-12 23:46 Philipp Möller [this message]
2011-07-15 22:38 ` %(SEXP) with %c in org-capture templates Philipp Möller
2011-07-24 16:48   ` Bastien
2011-07-25 13:49     ` Philipp Möller
2011-07-25 21:09       ` Bastien

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.orgmode.org/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to='CAC5Jocgz2mSzxVkMbt1vhFx3Fi0brz26x3tQzW=6i3ewMwDikA@mail.gmail.com' \
    --to=bootsarehax@googlemail.com \
    --cc=emacs-orgmode@gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

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).