Hi all, Ever wanted to create a planner annotation or start remember directly from within an external web browser, say Firefox? Here's how I do it.
I've registered special protocol handlers in the browser, "remember://" and "annotation://". I've configured these handlers to call a script that passes the information to a running Emacs session using emacsclient/gnuclient. The remember/annotation handlers are invoked through bookmarklets (bookmarks which execute JavaScript code). The "remember://" protocol starts M-x remember with a planner link for the current website filled in, using the document title as the description of the link, just like planner-w3m does. The "annotation://" protocol handler works similar to `planner-annotation-as-kill': it puts a planner link in the kill ring. An example: [[http://www.emacswiki.org/cgi-bin/wiki/PlannerMode][EmacsWiki: PlannerMode]] I created this link by a simple click in my web browser, and of course a yank from within Emacs. I've put the bookmarklets on a toolbar in my browser for easy access. I'm using Opera myself, but I tested it to work with Firefox. Attached is an emacs-lisp file with the necessary lisp code and in the comments the necessary helper script and bookmarklet code. The file also contains some documentation. The helper script either needs a recent emacsclient that can evaluate lisp forms (Emacs 22+) or gnuclient. Of course you will need to have emacs-server or gnuserv running. In summary, to use all this: - make sure the lisp code is loaded by Emacs - extract the shell script from the comments and put it somewhere in your path (don't forget chmod +x) - register the protocols in your browser (see lisp file for details) - add the bookmarklets (see the lisp file) to your browser - click on the bookmarklets and enjoy :-) I'm using this for quite some time now, I hope you will find this useful too. Best, Geert
;;; gjk-planner-annotation-helper.el --- start remember from a web browser ;; Author: Geert Kloosterman <[EMAIL PROTECTED]> ;; Created: Sat Nov 19 22:33:18 2005 ;; Updated: Thu Oct 25 17:48:41 2007 ;; Keywords: planner remember ;;; Commentary: ;; We want to be able to pass a URL and document title directly from a ;; web browser to Emacs. ;; ;; We define a remember:// url handler in the browser and use a shell ;; script to handle the protocol. This script passes the information ;; to a running Emacs process (using emacsclient/gnuclient). We use ;; bookmarklets to create the remember:// urls dynamicly. ;; ;; The protocol types currently recognized are: ;; ;; remember:// start `remember' with the url and title filled in ;; annotation:// similar to `planner-annotation-as-kill'. ;; ;; The urls used internally will have the following form: ;; ;; remember://<the web page url>%1C<the title> ;; ;; The title will be url-hex-encoded. "%1C" is the (url-encoded) low ;; ascii value for the field separator. ;; ;; The bookmarklets: ;; ;; javascript:location.href='remember://' + location.href + '%1C' + escape(document.title) ;; javascript:location.href='annotation://' + location.href + '%1C' + escape(document.title) ;; The helper script: ;; ;; #!/bin/sh ;; # planner-annotation-helper -- pass a remember-url to emacs ;; # ;; # Author: Geert Kloosterman <[EMAIL PROTECTED]> ;; # Date: Sat Nov 19 22:33:18 2005 ;; ;; if [ -z "$1" ]; then ;; echo "$0: Error: no arguments given!" 1>&2 ;; exit 1 ;; fi ;; ;; # For years I've been using Martin Schwenke's dtemacs script to start ;; # Emacs. The script uses gnuclient to connect to Emacs and starts a ;; # new Emacs process when necessary. ;; # See http://www.meltin.net/hacks/emacs/ ;; # ;; # dtemacs -batch -eval "(progn (gjk/planner-annotation-helper \"$1\" ) \"\")" ;; ;; # As of Emacs 22 emacsclient will work too ;; emacsclient --eval "(progn (gjk/planner-annotation-helper \"$1\" ) nil)" ;; ;; # EOF ;; Adding a protocol handler ;; ------------------------- ;; ;; Firefox ;; ;; To add a protocol handler (eg: remember://) in Firefox, take the ;; following steps: ;; ;; - type in "about:config" in the location bar ;; - right click, select New --> String ;; - the name should be "network.protocol-handler.app.remember" ;; - the value should be the executable, eg. "planner-annotation-helper". ;; At least under Linux this does not need to be the full path to ;; the executable. ;; ;; See http://kb.mozillazine.org/Register_protocol for more details. ;; ;; Opera ;; ;; In Opera add the protocol in the Preferences->Advanced->Programs ;; dialog. ;;; Code: (autoload 'url-unhex-string "url") (defun gjk/planner-annotation-helper (urlstring) """Process an externally passed remember:// style url. URLSTRING consists of a protocol part and a url and title, separated by %1C. The protocol types currently recognized are: remember:// start `remember' with the url and title annotation:// similar to `planner-annotation-as-kill'. """ (let ((remember-annotation-functions nil)) ;; The `parse-url' functions break on the embedded url, ;; since our format is fixed we'll split the url ourselves. (if (string-match "^\\([^:]*\\):\\(/*\\)\\(.*\\)" urlstring) (let* ((proto (match-string 1 urlstring)) (url+title (match-string 3 urlstring)) (splitparts (split-string url+title "%1C")) (url (car splitparts)) (title (cadr splitparts)) plannerlink) (setq title (if (> (length title) 0) (url-unhex-string title))) (setq plannerlink (planner-make-link url title t)) (raise-frame) (cond ((equal proto "remember") (remember (concat "\n\n" plannerlink))) ((equal proto "annotation") (message "Copied '%s' to the kill-ring." plannerlink) (kill-new plannerlink)) (t (error "unrecognized planner-helper protocol")))) (error "could not parse argument")))) ;;; planner-annotation-helper.el ends here
_______________________________________________ Planner-el-discuss mailing list [email protected] https://mail.gna.org/listinfo/planner-el-discuss
