Re: [O] capture template placeholders do not work

2017-10-12 Thread Kaushal Modi
On Thu, Oct 12, 2017 at 5:12 PM Allen Li  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


Re: [O] capture template placeholders do not work

2017-10-12 Thread Allen Li
On Thu, Oct 12, 2017 at 6:24 AM, Kaushal Modi  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



Re: [O] capture template placeholders do not work

2017-10-12 Thread Kaushal Modi
On Thu, Oct 12, 2017 at 12:07 AM Allen Li  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


Re: [O] capture template placeholders do not work

2017-10-12 Thread Carl Bolduc

> On Oct 11, 2017, at 11:54 PM, Allen Li  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





Re: [O] capture template placeholders do not work

2017-10-11 Thread Allen Li
On Wed, Oct 11, 2017 at 11:47 AM, Carl Bolduc  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



[O] capture template placeholders do not work

2017-10-11 Thread Carl Bolduc
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