emacs-orgmode
[Top][All Lists]
Advanced

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

Re: [Orgmode] firefox urls


From: Nick Dokos
Subject: Re: [Orgmode] firefox urls
Date: Tue, 20 May 2008 16:46:37 -0400

Daniel M German <address@hidden> wrote:

>  >> 
>  >> Hi Alan,
>  >> 
>  >> Did you download the file as I indicated in my previous message? It has
>  >> detailed instructions on how to get all the pieces working.
>  >> 
>  >> --dmg
> 
>  Richard> I followed the instructions but I cant get it working.
> 
>  Richard> Are the instructions for adding 2 bookmarklets lacking since
>  Richard> it only really describes remember protocol? (Step 2).
> 
>  Richard> Step 3 only mentioned the remember handler. Should there also be an
>  Richard> annotate handler?
> 
> 
> Start by doing remember first. Are you able to get the remember command
> line script (what I call the handler) working? Try it from the command
> line.
> 
> I suspect your javascript bookmarklet is not passing the info of the
> page correctly. I would double check that first.
> 
> --dmg
> 
> 
>  Richard> I dont think I did anything too silly and wonder if anyone else 
> managed
>  Richard> to install this properly? Currently when I click on the remember
>  Richard> bookmarklet the pane empties and emacs prompts me for a template 
> type
>  Richard> but then does not insert the link. It just inserts "about:blank" as 
> the
>  Richard> link.
> 

I think part of the problem is that the comments are inconsistent:

Step 1 (and Daniel, in the mail above) talks about the "remember"
script, while the script itself and Step 3 talk about the
"org-annotation-helper" script.

Here is an attempt at clarification: it's mostly minor edits but there
are enough of them that I thought I'd send out the whole thing rather
than a patch. It is still very much oriented towards Linux.

However, I have problems with how the remember template works, so the
description below is fuzzy, perhaps incomplete, perhaps wrong.

With this caveat, Richard, can you try these steps out and see if they
work/make sense? If this is deemed OK, then maybe it can replace the
comment section in org-annotation-helper.el, after the requisite additions/
corrections/deletions are made.

Regards,
Nick

---------------------------------------------------------------------------
[Debugging notes - skip ahead if not interested]

Assuming I have defined a remember template like this:

           (?w "* %u %c \n\n%i" "~/lib/org/bookmarks.org" "Web links")

when bzg/org-annotation-helper calls org-remember with argument ?w, I
expect this template to pop up in a *Remember* buffer. Instead, I get
asked which template I want to use (I have three more templates in
org-remember-templates). When I say "w" and force the choice, the
contents of the buffer are not what I expect: I get the time stamp from
%u, and the link from %c, but *not* the selection from %i. I uncommented
the echo in the script and the browser is passing the selection to the
script correctly. I also single-stepped through
bzg/org-annotation-helper, which sets the :region property of the link
to the selection like so:

        (org-store-link-props :type type
                              :link url
                              :region region
                              :description title)

but somehow that seems to get dropped on the floor afterwards. Maybe a
bug in org-remember? I 'm under the (possibly erroneous?) impression
that we should be going through the if-true path of the following code
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)
?--->   (progn
          (when (< (length org-remember-templates) 2)
            (error "No other template available"))
          (erase-buffer)
          (let ((annotation (plist-get org-store-link-plist :annotation))
                (initial (plist-get org-store-link-plist :initial)))
            (org-remember-apply-template))
          (message "Press C-c C-c to remember data"))
      (if (org-region-active-p)
          (org-do-remember (buffer-substring (point) (mark)))
        (org-do-remember))))))

but org-finish-function is nil in this case, so we fall through to the
org-do-remember at the end.

[end of debugging notes]
---------------------------------------------------------------------------

;; 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 dynamically.
;;
;; 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://<the web page url>::remember::<the title>::remember::<selection>
;;
;; The annotation:// url is similar but there is no <selection> associated
;; with it.
;;
;; The web page url and the  title will be url-hex-encoded. 
;;
;;
;; The bookmarklets:
;;
;;----------------------------------------------------------------------
;; javascript:location.href='remember://' + location.href + \ 
;;   '::remember::' + escape(document.title) + '::remember::' + 
escape(window.getSelection())
;;----------------------------------------------------------------------
;; javascript:location.href='annotation://' + location.href + '::remember::' +\
;;     escape(document.title) ;; 
;;----------------------------------------------------------------------
;;
;;
;; The handler:
;;
;;----------------------------------------------------------------------
;; #!/bin/sh
;; # org-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
;; 
;; # To test uncomment following line
;; #echo $1 >> /tmp/remember.out
;; 
;; emacsclient --eval "(progn (bzg/org-annotation-helper \"$1\" ) nil)"
;;----------------------------------------------------------------------
;; 
;;
;; To install:
;; 
;; Step 0: Install this module.
;;
;;  * Install this file and require it in your .emacs (or wherever you
;;    want to do it)
;;
;;    (require 'org-annotation-helper)
;;
;;
;; Step 1: Install the org-annotation-helper shell script.
;; 
;;  * Save the handler as a script, and make sure it is executable. In
;;    the following, we assume that it has been saved under the name
;;    "org-annotation-helper" in some directory in your $PATH.
;;
;;  * Try it: Make sure emacs is running and you have started its server
;;    mode (server-start).  Run this command from the command line:
;;
;;       org-annotation-helper 
'remember://http%3A//orgmode.org/::remember::Org-Mode%20Homepage::remember::Notes'
;;
;;    Emacs should now show a remember window. If you have set up a
;;    remember template for this case, e.g. a template similar to the
;;    one in Step 4 below, the remember window will show a link to the
;;    orgmode.org site with the name "Org-Mode Homepage", with "Notes"
;;    added as initial content (XXX - this doesn't work?). Otherwise,
;;    you can insert the link with org-insert-link (commonly bound to
;;    C-c C-l).
;;
;;
;; Step 2: add two bookmarklets to the browser.
;;
;; For Firefox:
;;
;;  * Right click on the bookmarks area of Firefox. 
;;  * Select "New Bookmark".
;;  * In the Location field, fill the javascript code above (the bookmarklet).
;;  * Make sure "Load this bookmark in the sidebar" is deselected.
;;
;;  Try it. You should have now a url that starts with "remember://"
;;  and your browser will not know what do to with it.
;;
;;
;; Step 3: Add the handler for the "remember://" URI.
;;
;; For Firefox:
;;
;; To add a protocol handler (eg: remember://) in Firefox, take the
;; following steps:
;;
;;  * Type in "about:config" in the location bar.
;;  * Right click and from the drop-down menu, select New --> String.
;;  * The Preference Name should be "network.protocol-handler.app.remember".
;;  * The Value should be the name of the executable shell script (see
;;    Step 1 above, where we called it "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.
;;
;; For Opera:
;;
;; Add the protocol in the Preferences->Advanced->Programs
;; dialog.
;;
;; 
;; Step 4: Configure a template.
;;
;; I personally  use the following template for this mode
;;
;;      (?w "* %u %c \n\n%i" "~/working/trunk/org/bookmarks.org" "Web links")
;;
;; %c will be replaced with the hyperlink to the page, displaying the
;;     title of the page.
;; %i will be replaced with the selected text from the browser.
;;
;; By default the new remember notes are placed in the bookmarks.org
;; file under the "Web links" section, but it can be easily overriden
;; with C-u C-c C-c.
;;
;; Step 5:
;;    Enjoy!





reply via email to

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