Agenda: Fix problems with follow mode.
[org-mode.git] / contrib / lisp / org-browser-url.el
blob478f3731ef2a01e5da837acac24526525ae261c1
1 ;;; org-browser-url.el --- Bookmark from a browser into org links
3 ;; Author: Ross Patterson <me@rpatterson.net>
4 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
5 ;;
6 ;;; Commentary:
8 ;; Once a bookmarklet and a app handler are setup in your browser,
9 ;; the functions here support using the bookmarklet to add links to
10 ;; the org links ring.
12 ;; Much of this is taken from or modeled after
13 ;; org-annotation-helper.el
15 ;; Installation and Activation
16 ;; ---------------------------
18 ;; Step 1: Install this library on your path and enable it in your
19 ;; $HOME/.emacs:
21 ;; (require 'org-browser-url)
23 ;; Step 2: Install the handler script
25 ;; * Save the following script to an appropriate place and make sure
26 ;; it is executable:
28 ;; #!/bin/sh
29 ;; # org-browser-url-store - Store URLs in the org links ring
30 ;; emacsclient --eval "(let ((org-browser-url-args \"$*\"))\
31 ;; (call-interactively 'org-store-link))"
33 ;; * Make sure emacs is running with server mode started:
35 ;; (server-start)
37 ;; * Test the script from the command line
39 ;; $ org-browser-url-store \
40 ;; 'org-browser-url-store:///Link%20Description/http://foo.com'
42 ;; * Insert the link in an org-mode buffer with C-c C-l
44 ;; Step 3: Add the handler to your browser
46 ;; * For Firefox:
47 ;; - type in "about:config" in the location bar
48 ;; - right click, select "New", then "String"
49 ;; - enter the name:
50 ;; "network.protocol-handler.app.org-browser-url-store"
51 ;; - leave the value blank
53 ;; See http://kb.mozillazine.org/Register_protocol for more details.
55 ;; * For Opera add the protocol in the
56 ;; Preferences->Advanced->Programs dialog.
58 ;; Step 4: Add bookmarklet
60 ;; * Create a new bookmark with the following location:
62 ;; javascript:location.href='org-browser-url-store:///'+\
63 ;; escape(document.title)+'/'+location.href
65 ;; When you first use the bookmarklet, Firefox will prompt you for
66 ;; the script. Point it to the full path of the script.
68 ;;; Code:
70 (require 'org)
71 (require 'url)
73 (defun org-browser-url-store-link ()
74 "Store a browser URL as an org link from the bookmarklet"
75 (if (boundp 'org-browser-url-args)
76 (let* ((stored (url-generic-parse-url org-browser-url-args))
77 (path (split-string (aref stored 6) "/"))
78 (parsed (url-generic-parse-url
79 (mapconcat 'identity (cddr path) "/")))
80 (type (aref parsed 1))
81 (link (aset parsed 7 (aref stored 7)))
82 (link (url-recreate-url parsed))
83 (description (url-unhex-string (nth 1 path))))
84 (org-store-link-props
85 :type type :link link :description description))))
87 (add-hook 'org-store-link-functions 'org-browser-url-store-link)
89 (provide 'org-browser-url)