From mboxrd@z Thu Jan 1 00:00:00 1970 From: John Rakestraw Subject: Re: firefox urls Date: Mon, 12 May 2008 11:33:21 -0400 Message-ID: <20080512113321.45188d4b@dhcp-296-6> References: Mime-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit Return-path: Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1Jva5R-0003TT-Dx for emacs-orgmode@gnu.org; Mon, 12 May 2008 11:37:13 -0400 Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1Jva5Q-0003Sx-PP for emacs-orgmode@gnu.org; Mon, 12 May 2008 11:37:13 -0400 Received: from [199.232.76.173] (port=47692 helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1Jva5Q-0003Sq-Mm for emacs-orgmode@gnu.org; Mon, 12 May 2008 11:37:12 -0400 Received: from relay03.pair.com ([209.68.5.17]:3263) by monty-python.gnu.org with smtp (Exim 4.60) (envelope-from ) id 1Jva5Q-0007og-BD for emacs-orgmode@gnu.org; Mon, 12 May 2008 11:37:12 -0400 In-Reply-To: List-Id: "General discussions about Org-mode." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: emacs-orgmode-bounces+geo-emacs-orgmode=m.gmane.org@gnu.org Errors-To: emacs-orgmode-bounces+geo-emacs-orgmode=m.gmane.org@gnu.org To: emacs-orgmode@gnu.org Richard G Riley wrote: > Are there any add-ons anything to yank urls from firefox/iceweasel > directly into a certain org-mode category? ouch. Your query reminds me that I promised long ago to write up my use of some code that Bastien adapted from a planner-mode extension. I'm in the midst of end-of-the-semester woes here (though I finally finished grading my finals late last night!), but here's a quick cut-and-paste of that code. It works very well for me. First, here's the template I use (apologies for formatting weirdness). You could add a function to semi-automate the category assignment -- ("web-clip" ?w "* %c \n :PROPERTIES: \n :Entered: %U \n :END: \n - ---->Quote from web page starts here\n - %:region\n - ---->Quote from web page ends here\n\n %?\n" "~/plans/webclips.org" "Unfiled Clips") Second, here's the code -- ;;; org-annotation-helper.el --- start remember from a web browser ;; ;; Author: bzg AT altern DOT org ;; Keywords: org remember ;; ;;; Commentary: ;; ;; [bzg:] This is an adapted version of the planner-mode extension the ;; was first posted by Geert Kloosterman on ;; the Planner mailing list. All comments below are his. ;; ;; 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' (org?) ;; ;; The urls used internally will have the following form: ;; ;; remember://%1C ;; ;; 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) + '%1C' + escape(window.getSelection()) ;; javascript:location.href='annotation://' + location.href + '%1C' + escape(document.title) ;; ;; The helper script: ;; ;; #!/bin/sh ;; # org-annotation-helper -- pass a remember-url to emacs ;; # ;; # Author: Geert Kloosterman ;; # 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 (bzg/org-annotation-helper \"$1\" ) \"\")" ;; ;; # As of Emacs 22 emacsclient will work too ;; emacsclient --eval "(progn (bzg/org-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. "org-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: (require 'url) (autoload 'url-unhex-string "url") (defun bzg/org-annotation-helper (info) (interactive) "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 `org-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 "^\\([^:]*\\):\\(/*\\)\\(.*\\)" info) (let* ((proto (match-string 1 info)) (url_title_region (match-string 3 info)) (splitparts (split-string url_title_region "%1C")) (url (car splitparts)) (type (if (string-match "^\\([a-z]+\\):" url) (match-string 1 url))) (title (cadr splitparts)) (region (url-unhex-string (caddr splitparts))) orglink) (setq title (if (> (length title) 0) (url-unhex-string title))) (setq orglink (org-make-link-string url title)) (org-store-link-props :type type :link url :region region :description title) (setq org-stored-links (cons (list url title) org-stored-links)) ;; FIXME can't access %a in the template -- how to set annotation? (raise-frame) (cond ((equal proto "remember") (kill-new orglink) (org-remember ?w)) ;; (yank)) I don't think I need this yank ((equal proto "annotation") (message "Copied '%s' to the kill-ring." orglink) (kill-new orglink)) (t (error "unrecognized org-helper protocol")))) (error "could not parse argument")))) ) -- John Rakestraw