[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [O] capture template placeholders do not work
From: |
Allen Li |
Subject: |
Re: [O] capture template placeholders do not work |
Date: |
Thu, 12 Oct 2017 14:12:00 -0700 |
On Thu, Oct 12, 2017 at 6:24 AM, Kaushal Modi <address@hidden> 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