0

Setup

Cygwin Emacs, and I have a partially working setup with org-protocol. Org-protocol is a way to capture information from the browser and pass it to Emacs. I used a Windows 7 registry modification to add org-protocol to the list of known protocols and, to enable cygwin's bash to startup emacsclient to handle those requests. Partially working meaning that bookmarklet and emacs loading operations are successful except for the problem case below.

Problem

I select interesting text on the page, and invoke the bookmarklet, but some characters are not correctly escaped by using encodeURIComponent alone (namely, parentheses and the single quote). This wreaks havoc causing parse errors for bash. I don't know of a way to handle this potential quoting problem with bash alone, so I thought to modify the bookmarklet, to replace any problematic characters.

The code below works when invoked inside Chrome's JS console, but NOT when invoked as a bookmarklet. I also tried redo'ing it with (function(){...})() syntax with the same, failed result.

What solutions ( bash, bookmarklet, other? ) do I have?

Bookmarklet Code

javascript:location.href='org-protocol://capture://'+encodeURIComponent(location.href)+'/'+encodeURIComponent(document.title)+'/'+encodeURIComponent(window.getSelection()).replace(/'/g,"%27").replace(/\(/g,"%28").replace(/\)/g,"%29")

Registry Mod

Also, here is the command line invocation - in case there is some problem with my quoting scheme.

REGEDIT4

[HKEY_CLASSES_ROOT\org-protocol]
@="URL:Org Protocol"
"URL Protocol"=""
[HKEY_CLASSES_ROOT\org-protocol\shell]
[HKEY_CLASSES_ROOT\org-protocol\shell\open]
[HKEY_CLASSES_ROOT\org-protocol\shell\open\command]
@="\"cmd.exe\" \"/k\" \"C:\\cygwin\\bin\\bash.exe\" \"--login\" \"-c\" \"DISPLAY=:0 /usr/local/bin/emacsclient -c %1\""
assem
  • 2,077
  • 1
  • 19
  • 24
  • When you say it does not work, does it do nothing at all or not what you expect ? – tomdemuyt Sep 14 '12 at 14:58
  • @tomdemuyt: when I say does not work, I mean the punctuation causes bash parse errors. so the highlighted text is not correctly used in the invocation of emacs. – assem Sep 27 '12 at 13:29

0 Answers0