From mboxrd@z Thu Jan 1 00:00:00 1970 From: Daniel M German Subject: Re: firefox urls Date: Tue, 20 May 2008 14:49:39 -0700 Message-ID: <87skwcbq8c.fsf@uvic.ca> References: <20080512113321.45188d4b@dhcp-296-6> <87k5hxa5ia.fsf@uvic.ca> <871w44wlgz.fsf@uvic.ca> <7bef1f890805171827w40525d0fi95b7e9d31400ac96@mail.gmail.com> <87wslsgoai.fsf@uvic.ca> <3ziqx86h7a.fsf@richardriley.net> <877idodh9w.fsf@uvic.ca> <19851.1211316397@alphaville.zko.hp.com> Reply-To: dmg@uvic.ca 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 1JyZil-0006cq-B1 for emacs-orgmode@gnu.org; Tue, 20 May 2008 17:50:11 -0400 Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1JyZig-0006aP-S5 for emacs-orgmode@gnu.org; Tue, 20 May 2008 17:50:10 -0400 Received: from [199.232.76.173] (port=44151 helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1JyZig-0006aH-Kt for emacs-orgmode@gnu.org; Tue, 20 May 2008 17:50:06 -0400 Received: from tungsten.cs.uvic.ca ([142.104.68.122]:46174 helo=mn.cs.uvic.ca) by monty-python.gnu.org with esmtp (Exim 4.60) (envelope-from ) id 1JyZig-0007Yk-Az for emacs-orgmode@gnu.org; Tue, 20 May 2008 17:50:06 -0400 In-Reply-To: <19851.1211316397@alphaville.zko.hp.com> (Nick Dokos's message of "Tue, 20 May 2008 16:46:37 -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: emacs-orgmode@gnu.org Thanks Nick, Nick> Step 1 (and Daniel, in the mail above) talks about the "remember" Nick> script, while the script itself and Step 3 talk about the Nick> "org-annotation-helper" script. I agree. The nomenclature is not the best. Nick> Here is an attempt at clarification: it's mostly minor edits but there Nick> are enough of them that I thought I'd send out the whole thing rather Nick> than a patch. It is still very much oriented towards Linux. it works also under OS X. Nick> However, I have problems with how the remember template works, so the Nick> description below is fuzzy, perhaps incomplete, perhaps wrong. Perhaps the solution is to split the command line script and the elisp into different files. And provide a shortcut create to the boorkmarklet via a web page. Nick> With this caveat, Richard, can you try these steps out and see if they Nick> work/make sense? If this is deemed OK, then maybe it can replace the Nick> comment section in org-annotation-helper.el, after the requisite additions/ Nick> corrections/deletions are made. Nick> Regards, Nick> Nick Nick> --------------------------------------------------------------------------- Nick> [Debugging notes - skip ahead if not interested] Nick> Assuming I have defined a remember template like this: (?w "* %u %c \n\n%i" "~/lib/org/bookmarks.org" "Web links") Nick> when bzg/org-annotation-helper calls org-remember with argument ?w, I Nick> expect this template to pop up in a *Remember* buffer. Instead, I get Nick> asked which template I want to use (I have three more templates in Nick> org-remember-templates). When I say "w" and force the choice, the Nick> contents of the buffer are not what I expect: I get the time stamp from Nick> %u, and the link from %c, but *not* the selection from %i. I uncommented Nick> the echo in the script and the browser is passing the selection to the Nick> script correctly. I also single-stepped through Nick> bzg/org-annotation-helper, which sets the :region property of the link Nick> to the selection like so: Nick> (org-store-link-props :type type Nick> :link url Nick> :region region Nick> :description title) Nick> but somehow that seems to get dropped on the floor afterwards. Maybe a Nick> bug in org-remember? I 'm under the (possibly erroneous?) impression Nick> that we should be going through the if-true path of the following code Nick> in org-remember (as shown by the arrow): ... ;; `org-select-remember-template' (setq org-select-template-temp-major-mode major-mode) (setq org-select-template-original-buffer (current-buffer)) (if (eq org-finish-function 'org-remember-finalize) Nick> ?---> (progn Nick> (when (< (length org-remember-templates) 2) Nick> (error "No other template available")) Nick> (erase-buffer) Nick> (let ((annotation (plist-get org-store-link-plist :annotation)) Nick> (initial (plist-get org-store-link-plist :initial))) Nick> (org-remember-apply-template)) Nick> (message "Press C-c C-c to remember data")) (if (org-region-active-p) Nick> (org-do-remember (buffer-substring (point) (mark))) Nick> (org-do-remember)))))) Nick> but org-finish-function is nil in this case, so we fall through to the Nick> org-do-remember at the end. Nick> [end of debugging notes] Nick> --------------------------------------------------------------------------- Nick> ;; We want to be able to pass a URL and document title directly from a Nick> ;; web browser to Emacs. Nick> ;; Nick> ;; We define a remember:// url handler in the browser and use a shell Nick> ;; script to handle the protocol. This script passes the information Nick> ;; to a running Emacs process (using emacsclient/gnuclient). We use Nick> ;; bookmarklets to create the remember:// urls dynamically. Nick> ;; Nick> ;; The protocol types currently recognized are: Nick> ;; Nick> ;; remember:// start `remember' with the url and title filled in Nick> ;; annotation:// similar to `planner-annotation-as-kill' (org?) Nick> ;; Nick> ;; The urls used internally will have the following form: Nick> ;; Nick> ;; remember://::remember::::remember:: Nick> ;; Nick> ;; The annotation:// url is similar but there is no associated Nick> ;; with it. Nick> ;; Nick> ;; The web page url and the title will be url-hex-encoded. Nick> ;; Nick> ;; Nick> ;; The bookmarklets: Nick> ;; Nick> ;;---------------------------------------------------------------------- Nick> ;; javascript:location.href='remember://' + location.href + \ Nick> ;; '::remember::' + escape(document.title) + '::remember::' + escape(window.getSelection()) Nick> ;;---------------------------------------------------------------------- Nick> ;; javascript:location.href='annotation://' + location.href + '::remember::' +\ Nick> ;; escape(document.title) ;; Nick> ;;---------------------------------------------------------------------- Nick> ;; Nick> ;; Nick> ;; The handler: Nick> ;; Nick> ;;---------------------------------------------------------------------- Nick> ;; #!/bin/sh Nick> ;; # org-annotation-helper -- pass a remember-url to emacs Nick> ;; # Nick> ;; # Author: Geert Kloosterman Nick> ;; # Date: Sat Nov 19 22:33:18 2005 Nick> ;; Nick> ;; if [ -z "$1" ]; then Nick> ;; echo "$0: Error: no arguments given!" 1>&2 Nick> ;; exit 1 Nick> ;; fi Nick> ;; Nick> ;; # To test uncomment following line Nick> ;; #echo $1 >> /tmp/remember.out Nick> ;; Nick> ;; emacsclient --eval "(progn (bzg/org-annotation-helper \"$1\" ) nil)" Nick> ;;---------------------------------------------------------------------- Nick> ;; Nick> ;; Nick> ;; To install: Nick> ;; Nick> ;; Step 0: Install this module. Nick> ;; Nick> ;; * Install this file and require it in your .emacs (or wherever you Nick> ;; want to do it) Nick> ;; Nick> ;; (require 'org-annotation-helper) Nick> ;; Nick> ;; Nick> ;; Step 1: Install the org-annotation-helper shell script. Nick> ;; Nick> ;; * Save the handler as a script, and make sure it is executable. In Nick> ;; the following, we assume that it has been saved under the name Nick> ;; "org-annotation-helper" in some directory in your $PATH. Nick> ;; Nick> ;; * Try it: Make sure emacs is running and you have started its server Nick> ;; mode (server-start). Run this command from the command line: Nick> ;; Nick> ;; org-annotation-helper 'remember://http%3A//orgmode.org/::remember::Org-Mode%20Homepage::remember::Notes' Nick> ;; Nick> ;; Emacs should now show a remember window. If you have set up a Nick> ;; remember template for this case, e.g. a template similar to the Nick> ;; one in Step 4 below, the remember window will show a link to the Nick> ;; orgmode.org site with the name "Org-Mode Homepage", with "Notes" Nick> ;; added as initial content (XXX - this doesn't work?). Otherwise, Nick> ;; you can insert the link with org-insert-link (commonly bound to Nick> ;; C-c C-l). Nick> ;; Nick> ;; Nick> ;; Step 2: add two bookmarklets to the browser. Nick> ;; Nick> ;; For Firefox: Nick> ;; Nick> ;; * Right click on the bookmarks area of Firefox. Nick> ;; * Select "New Bookmark". Nick> ;; * In the Location field, fill the javascript code above (the bookmarklet). Nick> ;; * Make sure "Load this bookmark in the sidebar" is deselected. Nick> ;; Nick> ;; Try it. You should have now a url that starts with "remember://" Nick> ;; and your browser will not know what do to with it. Nick> ;; Nick> ;; Nick> ;; Step 3: Add the handler for the "remember://" URI. Nick> ;; Nick> ;; For Firefox: Nick> ;; Nick> ;; To add a protocol handler (eg: remember://) in Firefox, take the Nick> ;; following steps: Nick> ;; Nick> ;; * Type in "about:config" in the location bar. Nick> ;; * Right click and from the drop-down menu, select New --> String. Nick> ;; * The Preference Name should be "network.protocol-handler.app.remember". Nick> ;; * The Value should be the name of the executable shell script (see Nick> ;; Step 1 above, where we called it "org-annotation-helper"). At Nick> ;; least under Linux, this does not need to be the full path to the Nick> ;; executable. Nick> ;; Nick> ;; See http://kb.mozillazine.org/Register_protocol for more details. Nick> ;; Nick> ;; For Opera: Nick> ;; Nick> ;; Add the protocol in the Preferences->Advanced->Programs Nick> ;; dialog. Nick> ;; Nick> ;; Nick> ;; Step 4: Configure a template. Nick> ;; Nick> ;; I personally use the following template for this mode Nick> ;; Nick> ;; (?w "* %u %c \n\n%i" "~/working/trunk/org/bookmarks.org" "Web links") Nick> ;; Nick> ;; %c will be replaced with the hyperlink to the page, displaying the Nick> ;; title of the page. Nick> ;; %i will be replaced with the selected text from the browser. Nick> ;; Nick> ;; By default the new remember notes are placed in the bookmarks.org Nick> ;; file under the "Web links" section, but it can be easily overriden Nick> ;; with C-u C-c C-c. Nick> ;; Nick> ;; Step 5: Nick> ;; Enjoy! -- -- Daniel M. German http://turingmachine.org/ http://silvernegative.com/ dmg (at) uvic (dot) ca replace (at) with @ and (dot) with .