emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
From: Allen Li <vianchielfaura@gmail.com>
To: Kaushal Modi <kaushal.modi@gmail.com>
Cc: emacs-orgmode@gnu.org, Carl Bolduc <cbol@me.com>
Subject: Re: capture template placeholders do not work
Date: Thu, 12 Oct 2017 14:12:00 -0700	[thread overview]
Message-ID: <CAJr1M6d7EVU+RnH8aiy2Ocmr4Q1jDcKFRjDstyN25i5vtPvjAA@mail.gmail.com> (raw)
In-Reply-To: <CAFyQvY3iz9n-ADj3Jsf6oH3D5MFkCT=Z6+B8CngozNWULVVGVg@mail.gmail.com>

On Thu, Oct 12, 2017 at 6:24 AM, Kaushal Modi <kaushal.modi@gmail.com> wrote:
>
> I don't use org-protocol, but I'd just like to understand how you derived
> that.
>
> Source code:
>
> (defun org-protocol-do-capture (info)
>   "Perform the actual capture based on INFO."
>   (let* ((temp-parts (org-protocol-parse-parameters info))
> (parts
>   (cond
>    ((and (listp info) (symbolp (car info))) info)
>    ((= (length (car temp-parts)) 1) ;; First parameter is exactly one
> character long
>     (org-protocol-assign-parameters temp-parts '(:template :url :title
> :body)))
>    (t
>     (org-protocol-assign-parameters temp-parts '(:url :title :body)))))
> (template (or (plist-get parts :template)
>        org-protocol-default-template-key))
> (url (and (plist-get parts :url) (org-protocol-sanitize-uri (plist-get parts
> :url))))
> (type (and url (if (string-match "^\\([a-z]+\\):" url)
>     (match-string 1 url))))
> (title (or (plist-get parts :title) ""))
> (region (or (plist-get parts :body) ""))
> (orglink (if url
>       (org-make-link-string
>        url (if (string-match "[^[:space:]]" title) title url))
>     title))
> (org-capture-link-is-already-stored t)) ;; avoid call to org-store-link
>     (setq org-stored-links
>   (cons (list url title) org-stored-links))
>     (org-store-link-props :type type
>   :link url
>   :description title
>   :annotation orglink
>   :initial region
>   :query parts)
>     (raise-frame)
>     (funcall 'org-capture nil template)))
>
> From that, we have:
>
> (org-store-link-props :type type
>   :link url
>   :description title
>   :annotation orglink
>   :initial region
>   :query parts)

org-store-link-props basically shoves everything into
org-store-link-plist (with some pre-processing).  The plist keys are
what's used as keywords for %:

The :initlal is special; it gets mapped to %i, and :query is a list
not a string, so you can't use %:query although you can access it from
Emacs Lisp embedded in the template.

I don't have any secret knowledge, I just dug through the source code
and experimented with different inputs.  The code and/or documentation
could be clearer

>
> but that is an internal call.. :link key gets its value from let-bound url
> and :description gets its value from let-bound title.
>
> And further up, url gets assigned value from a plist with key :url:
>
>  (url (and (plist-get parts :url) (org-protocol-sanitize-uri (plist-get
> parts :url))))
>
> and title gets assigned value from a plist with key :title.
>
> So that seems to match the documented: "The template refers to the data
> through %:url and %:title placeholders.".
>
> So I am surprised why %:link and %:description worked..
>
> I didn't dig deeper as to where the connection with org-protocol and
> org-capture happens.
> --
>
> Kaushal Modi

  reply	other threads:[~2017-10-12 21:12 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-10-11 18:47 capture template placeholders do not work Carl Bolduc
2017-10-12  3:54 ` Allen Li
2017-10-12 12:27   ` Carl Bolduc
2017-10-12 13:24   ` Kaushal Modi
2017-10-12 21:12     ` Allen Li [this message]
2017-10-12 22:43       ` Kaushal Modi

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=CAJr1M6d7EVU+RnH8aiy2Ocmr4Q1jDcKFRjDstyN25i5vtPvjAA@mail.gmail.com \
    --to=vianchielfaura@gmail.com \
    --cc=cbol@me.com \
    --cc=emacs-orgmode@gnu.org \
    --cc=kaushal.modi@gmail.com \
    /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).