emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
From: John Rakestraw <lists@johnrakestraw.com>
To: emacs-orgmode@gnu.org
Subject: Re: Org Remember idea
Date: Tue, 6 Nov 2007 15:49:07 -0500	[thread overview]
Message-ID: <20071106154907.5d68b019@dhcp-296-6> (raw)
In-Reply-To: <3d6808890711060842p3ef89421xc03f0ee87257327@mail.gmail.com>


[-- Attachment #1.1: Type: text/plain, Size: 6009 bytes --]

> 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 <g.j.kloosterman@gmail.com>
;; 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 <g.j.kloosterman@gmail.com>
;; # 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 #1.2: signature.asc --]
[-- Type: application/pgp-signature, Size: 189 bytes --]

[-- Attachment #2: Type: text/plain, Size: 204 bytes --]

_______________________________________________
Emacs-orgmode mailing list
Remember: use `Reply All' to send replies to the list.
Emacs-orgmode@gnu.org
http://lists.gnu.org/mailman/listinfo/emacs-orgmode

  parent reply	other threads:[~2007-11-06 19:49 UTC|newest]

Thread overview: 19+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2007-11-06 16:42 Org Remember idea Tim O'Callaghan
2007-11-06 18:38 ` Leo
2007-11-06 18:39 ` Carsten Dominik
2007-11-06 19:42   ` Tim O'Callaghan
2007-11-06 19:43     ` Tim O'Callaghan
2007-11-06 19:43       ` Tim O'Callaghan
2007-11-06 20:49 ` John Rakestraw [this message]
2007-11-07  2:22   ` Bastien
2007-11-07  2:59     ` John Rakestraw
2007-11-07 12:29       ` Bastien
2007-11-07 21:17         ` John Rakestraw
2007-11-08  3:57           ` Bastien
2007-11-09  3:27             ` John Rakestraw
2007-11-08  4:59           ` Bastien
2007-11-09  3:30             ` John Rakestraw
2008-01-14 11:35         ` Adam Spiers
2007-11-06 22:42 ` Adam Spiers
2007-11-07  8:43 ` Carsten Dominik
2007-11-09  5:56 ` Dmitri Minaev

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.orgmode.org/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20071106154907.5d68b019@dhcp-296-6 \
    --to=lists@johnrakestraw.com \
    --cc=emacs-orgmode@gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).