>From 6caca7a57427efb67d5d1fdaf25232a46c96b2ba Mon Sep 17 00:00:00 2001 From: Nicolas Goaziou Date: Tue, 4 Jul 2017 14:48:41 +0200 Subject: [PATCH] org.texi: Document Org Protocol * doc/org.texi (Protocols): Document feature. --- doc/org.texi | 208 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 200 insertions(+), 8 deletions(-) diff --git a/doc/org.texi b/doc/org.texi index 176e7c259..e73c9c06a 100644 --- a/doc/org.texi +++ b/doc/org.texi @@ -499,6 +499,12 @@ Capture templates * Template expansion:: Filling in information about time and context * Templates in contexts:: Only show a template in a specific context +Protocols for external access + +* @code{store-link} protocol:: Store a link, push URL to kill-ring +* @code{capture} protocol:: Fill a buffer with external information +* @code{open-source} protocol:: Edit published contents + Archiving * Moving subtrees:: Moving a tree to an archive file @@ -7515,16 +7521,202 @@ For more information, including how to read atom feeds, see @node Protocols @section Protocols for external access @cindex protocols, for external access address@hidden emacsserver -You can set up Org for handling protocol calls from outside applications that -are passed to Emacs through the @file{emacsserver}. For example, you can +Org protocol in a mean to trigger custom actions in Emacs from external +applications. Any application that supports calling external programs with +an URL as argument may be used with this functionality. For example, you can configure bookmarks in your web browser to send a link to the current page to -Org and create a note from it using capture (@pxref{Capture}). Or you -could create a bookmark that will tell Emacs to open the local source file of -a remote website you are looking at with the browser. See address@hidden://orgmode.org/worg/org-contrib/org-protocol.php} for detailed -documentation and setup instructions. +Org and create a note from it using capture (@pxref{Capture}). You can also +create a bookmark that tells Emacs to open the local source file of a remote +website you are browsing. + address@hidden Org protocol, set-up address@hidden Installing Org protocol +In order to use Org protocol from an application, you need to register address@hidden://} as a valid scheme-handler. External calls are passed +to Emacs through the @code{emacsclient} command, so you also need to ensure +an Emacs server is running. More precisely, when the application calls + address@hidden +emacsclient org-protocol://PROTOCOL?key1=var1&key2=var2 address@hidden example + address@hidden +Emacs calls the handler associated to @samp{PROTOCOL} with argument address@hidden(:key1 var1 :key2 var2)}. + address@hidden protocol, new protocol address@hidden defining new protocols +Org protocol comes with three predefined protocols, detailed in the following +sections. Configure @code{org-protocol-protocol-alist} to define your own. + address@hidden +* @code{store-link} protocol:: Store a link, push URL to kill-ring +* @code{capture} protocol:: Fill a buffer with external information +* @code{open-source} protocol:: Edit published contents address@hidden menu + address@hidden @code{store-link} protocol address@hidden @code{store-link} protocol address@hidden store-link protocol address@hidden protocol, store-link + +Using @code{store-link} handler, you can copy links, insertable through address@hidden org-insert-link} or yanking thereafter. More precisely, the command + address@hidden +emacsclient org-protocol://store-link?url=URL&title=TITLE address@hidden example + address@hidden +stores the following link: + address@hidden +[[URL][TITLE]] address@hidden example + +In addition, @samp{URL} is pushed on the kill-ring for yanking. You need to +encode @samp{URL} and @samp{TITLE} if they contain slashes, and probably +quote those for the shell. + +To use this feature from a browser, add a bookmark with an arbitrary name, +e.g., @samp{Org: store-link} and enter this as @emph{Location}: + address@hidden +javascript:location.href='org-protocol://store-link?url='+ + encodeURIComponent(location.href); address@hidden example + address@hidden @code{capture} protocol address@hidden @code{capture} protocol address@hidden capture protocol address@hidden protocol, capture + address@hidden capture, %:url placeholder address@hidden %:url template expansion in capture address@hidden capture, %:title placeholder address@hidden %:title template expansion in capture +Activating @code{capture} handler pops up a @samp{Capture} buffer and fills +the capture template associated to the @samp{X} key with them. The template +refers to the data through @code{%:url} and @code{%:title} placeholders. +Moreover, any selected text in the browser is appended to the body of the +entry. + address@hidden +emacsclient org-protocol://capture?template=X?url=URL?title=TITLE?body=BODY address@hidden example + +To use this feature, add a bookmark with an arbitrary name, e.g. address@hidden: capture} and enter this as @samp{Location}: + address@hidden +javascript:location.href='org-protocol://template=x'+ + '&url='+encodeURIComponent(window.location.href)+ + '&title='+encodeURIComponent(document.title)+ + '&body='+encodeURIComponent(window.getSelection()); address@hidden example + address@hidden org-protocol-default-template-key +The result depends on the capture template used, which is set in the bookmark +itself, as in the example above, or in address@hidden + address@hidden @code{open-source} protocol address@hidden @code{open-source} protocol address@hidden open-source protocol address@hidden protocol, open-source + +The @code{open-source} handler is designed to help with editing local sources +when reading a document. To that effect, you can use a bookmark with the +following location: + address@hidden +javascript:location.href='org-protocol://open-source?&url='+ + encodeURIComponent(location.href) address@hidden example + address@hidden protocol, open-source, :base-url property address@hidden :base-url property in open-source protocol address@hidden protocol, open-source, :working-directory property address@hidden :working-directory property in open-source protocol address@hidden protocol, open-source, :online-suffix property address@hidden :online-suffix property in open-source protocol address@hidden protocol, open-source, :working-suffix property address@hidden :working-suffix property in open-source protocol address@hidden org-protocol-project-alist +The variable @code{org-protocol-project-alist} maps URLs to local file names, +by stripping URL parameters from the end and replacing the @code{:base-url} +with @code{:working-diretory} and @code{:online-suffix} with address@hidden:working-suffix}. For example, assuming you own a local copy of address@hidden://orgmode.org/worg/} contents at @file{/home/user/worg}, you can +set @code{org-protocol-project-alist} to the following + address@hidden +(setq org-protocol-project-alist + '(("Worg" + :base-url "http://orgmode.org/worg/" + :working-directory "/home/user/worg/" + :online-suffix ".html" + :working-suffix ".org"))) address@hidden lisp + address@hidden +If you are now browsing address@hidden://orgmode.org/worg/org-contrib/org-protocol.html} and find a typo +or have an idea about how to enhance the documentation, simply click the +bookmark and start editing. + address@hidden handle rewritten URL in open-source protocol address@hidden protocol, open-source rewritten URL +However, such mapping may not yield the desired results. Suppose you +maintain an online store located at @url{http://example.com/}. The local +sources reside in @file{/home/user/example/}. It is common practice to serve +all products in such a store through one file and rewrite URLs that do not +match an existing file on the server. That way, a request to address@hidden://example.com/print/posters.html} might be rewritten on the server +to something like address@hidden://example.com/shop/products.php/posters.html.php}. The address@hidden handler probably cannot find a file named address@hidden/home/user/example/print/posters.html.php} and fails. + address@hidden protocol, open-source, :rewrites property address@hidden :rewrites property in open-source protocol +Such an entry in @code{org-protocol-project-alist} may hold an additional +property @code{:rewrites}. This property is a list of cons cells, each of +which maps a regular expression to a path relative to the address@hidden:working-directory}. + +Now map the URL to the path @file{/home/user/example/products.php} by adding address@hidden:rewrites} rules like this: + address@hidden +(setq org-protocol-project-alist + '(("example.com" + :base-url "http://example.com/" + :working-directory "/home/user/example/" + :online-suffix ".php" + :working-suffix ".php" + :rewrites (("example.com/print/" . "products.php") + ("example.com/$" . "index.php"))))) address@hidden lisp + address@hidden +Since @samp{example.com/$} is used as a regular expression, it maps address@hidden://example.com/}, @url{https://example.com}, address@hidden://www.example.com/} and similar to address@hidden/home/user/example/index.php}. + +The @code{:rewrites} rules are searched as a last resort if and only if no +existing file name is matched. + address@hidden protocol, open-source, set-up mapping address@hidden set-up mappings in open-source protocol address@hidden org-protocol-create address@hidden org-protocol-create-for-org +Two functions can help you filling @code{org-protocol-project-alist} with +valid contents: @code{org-protocol-create} and address@hidden The latter is of use if you're editing +an Org file that is part of a publishing project. @node Refile and copy @section Refile and copy -- 2.13.2