From mboxrd@z Thu Jan 1 00:00:00 1970 From: Richard G Riley Subject: Re: org-annotation-helper Date: Sun, 31 Aug 2008 12:19:23 +0200 Message-ID: References: <17249.1220148863@gamaville.dokosmarshall.org> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Return-path: Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1KZk2H-0002rd-Up for emacs-orgmode@gnu.org; Sun, 31 Aug 2008 06:19:58 -0400 Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1KZk2D-0002qP-DV for emacs-orgmode@gnu.org; Sun, 31 Aug 2008 06:19:54 -0400 Received: from [199.232.76.173] (port=43300 helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1KZk2C-0002q0-8n for emacs-orgmode@gnu.org; Sun, 31 Aug 2008 06:19:52 -0400 Received: from fg-out-1718.google.com ([72.14.220.155]:7499) by monty-python.gnu.org with esmtp (Exim 4.60) (envelope-from ) id 1KZk2B-0006uQ-HG for emacs-orgmode@gnu.org; Sun, 31 Aug 2008 06:19:51 -0400 Received: by fg-out-1718.google.com with SMTP id l26so952887fgb.30 for ; Sun, 31 Aug 2008 03:19:50 -0700 (PDT) In-Reply-To: <17249.1220148863@gamaville.dokosmarshall.org> (Nick Dokos's message of "Sat, 30 Aug 2008 22:14:23 -0400") 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: nicholas.dokos@hp.com Cc: org-mode , Richard G Riley caveat : I do not know if this is optimal or even recommended but it now works for me. I have modified the code a little to remove hex from the actual link. I have "boxquoted" all code so you will need to remove that. firefox/iceweasel : To set up the bookmark link, simple create a new book mark called "remember" in firefox and make this the location code: ,---- | javascript:location.href='remember://%20'+location.href+'%1C'+escape(document.title)+'%1C'+escape(window.getSelection()) `---- This is as simple as right click on your bookmark toolbar and create new. Do *not* select "load this bookmark in the sidebar" - when I selected this then links and region did not pass to the protocol handler discussed in the comments below. I have no idea why and if someone could explain why this should be I would be grateful. Follow the instructions in the code to set up the shell script and the protocol registry to handle the protocol when you click on the remember bookmark. I would advise ignoring all "annotation" stuff and just concentrate getting remember working for now. The org-remember-template I now use is (note the addition of %:link which shows the physical http link) ,---- | ("Web-Link" ?w "* %c \n :PROPERTIES: \n :Entered: %U\n :END: \n\n - link: %:link\n - Quote:\n %:region\n - End Quote\n\n %?\n" "bookmarks.org" "Unfiled Clips") `---- Using linux with X, I also modified the remember shell script to use wmctl to bring emacs to the foreground. I also reformatted the location codes to be on a single line. ,---- | ;;; 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 <[EMAIL PROTECTED]> 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 | ;;# remember -- pass a remember-url to emacs | ;;# | ;;# Author: Geert Kloosterman | ;;# Date: Sat Nov 19 22:33:18 2005 | ;;# | ;;# modified 31 Aug 2008 rgr : added call to wmctrl to bring emacs to the foreground | ;;# | ;; | ;;if [ -z "$1" ]; then | ;; echo "$0: Error: no arguments given!" 1>&2 | ;; exit 1 | ;;fi | ;; | ;;# To test uncomment following line | ;;#echo $1 >> /tmp/remember.out | ;;wmctrl -a emacs22 | ;;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. "remember". | ;; 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 url (if (> (length url) 0) (url-unhex-string url))) | (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")))) | | (provide 'org-annotation-helper) `----