* capture template placeholders do not work
@ 2017-10-11 18:47 Carl Bolduc
2017-10-12 3:54 ` Allen Li
0 siblings, 1 reply; 6+ messages in thread
From: Carl Bolduc @ 2017-10-11 18:47 UTC (permalink / raw)
To: emacs-orgmode
Hi,
I want to use org-mode to store my bookmarks. I configured the following template:
("b" "Bookmark" entry (file+headline "~/org/bookmarks.org" "Bookmarks") "* %:url %:title %?\n”)
And I have the following bookmarklet in my browser:
javascript:location.href='org-protocol://capture?template=b'+'&url='+encodeURIComponent(window.location.href)+'&title='+encodeURIComponent(document.title)+'&body='+encodeURIComponent(window.getSelection());
When I click on my bookmarklet, Emacs opens a new capture buffer and here is what I see:
**
I get an empty entry, the %:url and %:title placeholders are not expanded to the values passed by the bookmarklet. How can I troubleshoot this?
I’m running emacs 25.3 with the emacs-25.3-mac-6.8 patch on macOS High Sierra with org-mode 9.1.1.
Thanks,
Carl
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: capture template placeholders do not work
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
0 siblings, 2 replies; 6+ messages in thread
From: Allen Li @ 2017-10-12 3:54 UTC (permalink / raw)
To: Carl Bolduc; +Cc: emacs-orgmode
On Wed, Oct 11, 2017 at 11:47 AM, Carl Bolduc <cbol@me.com> wrote:
> Hi,
>
> I want to use org-mode to store my bookmarks. I configured the following template:
> ("b" "Bookmark" entry (file+headline "~/org/bookmarks.org" "Bookmarks") "* %:url %:title %?\n”)
%:url and $:title are wrong, they should be %:link and %:description
respectively.
Check out the source code of org-protocol-do-capture.
The valid placeholders are
type
link
description
annotation
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: capture template placeholders do not work
2017-10-12 3:54 ` Allen Li
@ 2017-10-12 12:27 ` Carl Bolduc
2017-10-12 13:24 ` Kaushal Modi
1 sibling, 0 replies; 6+ messages in thread
From: Carl Bolduc @ 2017-10-12 12:27 UTC (permalink / raw)
To: Allen Li; +Cc: emacs-orgmode
> On Oct 11, 2017, at 11:54 PM, Allen Li <vianchielfaura@gmail.com> wrote:
>
> %:url and $:title are wrong, they should be %:link and %:description
> respectively.
oh! thank you, I modified the template and it works now. The manual is misleading:
"The template refers to the data through %:url and %:title placeholders."
http://orgmode.org/manual/_003ccode_003ecapture_003c_002fcode_003e-protocol.html#_003ccode_003ecapture_003c_002fcode_003e-protocol
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: capture template placeholders do not work
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
1 sibling, 1 reply; 6+ messages in thread
From: Kaushal Modi @ 2017-10-12 13:24 UTC (permalink / raw)
To: Allen Li, Carl Bolduc; +Cc: emacs-orgmode
[-- Attachment #1: Type: text/plain, Size: 2403 bytes --]
On Thu, Oct 12, 2017 at 12:07 AM Allen Li <vianchielfaura@gmail.com> wrote:
> %:url and $:title are wrong, they should be %:link and %:description
> respectively.
>
> Check out the source code of org-protocol-do-capture.
>
> The valid placeholders are
>
> type
> link
> description
> annotation
>
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)
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
[-- Attachment #2: Type: text/html, Size: 5476 bytes --]
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: capture template placeholders do not work
2017-10-12 13:24 ` Kaushal Modi
@ 2017-10-12 21:12 ` Allen Li
2017-10-12 22:43 ` Kaushal Modi
0 siblings, 1 reply; 6+ messages in thread
From: Allen Li @ 2017-10-12 21:12 UTC (permalink / raw)
To: Kaushal Modi; +Cc: emacs-orgmode, Carl Bolduc
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
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: capture template placeholders do not work
2017-10-12 21:12 ` Allen Li
@ 2017-10-12 22:43 ` Kaushal Modi
0 siblings, 0 replies; 6+ messages in thread
From: Kaushal Modi @ 2017-10-12 22:43 UTC (permalink / raw)
To: Allen Li; +Cc: emacs-orgmode, Carl Bolduc
[-- Attachment #1: Type: text/plain, Size: 761 bytes --]
On Thu, Oct 12, 2017 at 5:12 PM Allen Li <vianchielfaura@gmail.com> wrote:
> 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.
>
Thanks.
> I don't have any secret knowledge, I just dug through the source code
> and experimented with different inputs.
Of course :) It's a bit difficult skimming through the code as I don't have
org-protocol set up.
> The code and/or documentation could be clearer
>
Would you like to submit a patch for that?
--
Kaushal Modi
[-- Attachment #2: Type: text/html, Size: 1773 bytes --]
^ permalink raw reply [flat|nested] 6+ messages in thread
end of thread, other threads:[~2017-10-12 22:44 UTC | newest]
Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
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
2017-10-12 22:43 ` Kaushal Modi
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).