emacs-orgmode
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Orgmode] Org Remember idea


From: John Rakestraw
Subject: Re: [Orgmode] Org Remember idea
Date: Tue, 6 Nov 2007 15:49:07 -0500

> I've started using Remember mode more and more, and it has given me an
> idea for new piece of functionality.
> 
> %c - insert clipboard/kill-ring at point
> 
> This is for 'auto' pasting links or snippets of text from my browser
> into an org file.
> 

I used planner mode for a while before switching to org mode, and still
occasionally look in on planner to see what they're doing. A couple of
weeks ago I stumbled on this in the list planner-el-discuss:

> 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.

I would really like to have something like this for org. The poster
actually included the lisp code, the browser protocols, and the script
that did all this. I know next to nothing about lisp so was unable to
do anything with it, but is it possible that it could be easy for
someone who knows this stuff to adapt it to org?

In hopes that someone will look at it, I've posted the code below.
Apologies for the length of the post.

--John

;;; gjk-planner-annotation-helper.el --- start remember from a web
browser

;; Author: Geert Kloosterman <address@hidden>
;; 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 <address@hidden>
;; # 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

Attachment: signature.asc
Description: PGP signature


reply via email to

[Prev in Thread] Current Thread [Next in Thread]