# HG changeset patch # User Atul Varma # Date 1269717572 25200 # Node ID 41bc597758727b086e3df8458c6f279bd885f15a # Parent c41c4896c97e86d9b5338a4ac3d555d9431f0d72 wow, haven't committed changes in a long time. diff -r c41c4896c97e -r 41bc59775872 my-enso-commands.py --- a/my-enso-commands.py Wed Aug 20 11:10:05 2008 -0700 +++ b/my-enso-commands.py Sat Mar 27 12:19:32 2010 -0700 @@ -58,10 +58,12 @@ import AppKit pb = AppKit.NSPasteboard.generalPasteboard() + typestr = pb.availableTypeFromArray_([AppKit.NSTIFFPboardType, + AppKit.NSPICTPboardType]) tiffbytes = None - if pb.availableTypeFromArray_([AppKit.NSTIFFPboardType]): + if typestr == AppKit.NSTIFFPboardType: tiffbytes = pb.dataForType_(AppKit.NSTIFFPboardType).bytes() - elif pb.availableTypeFromArray_([AppKit.NSPICTPboardType]): + elif typestr == AppKit.NSPICTPboardType: img = AppKit.NSImage.alloc().initWithPasteboard_(pb) tiffbytes = img.TIFFRepresentation().bytes() @@ -74,6 +76,7 @@ import Image datafile = _get_clipboard_img_datafile() + if datafile: img = Image.open(datafile) return func(ensoapi, img) @@ -353,7 +356,7 @@ webbrowser.open( self._url_template % {"query" : query} ) -cmd_wiki = WebSearchCmd("http://en.wikipedia.org/wiki/%(query)s") +cmd_wiki = WebSearchCmd("http://en.wikipedia.org/wiki/Special:Search?search=%(query)s") cmd_wowhead = WebSearchCmd("http://www.wowhead.com/?search=%(query)s") cmd_amaz = WebSearchCmd("http://www.amazon.com/exec/obidos/search-handle-url/index%%3Dblended%%26field-keywords%%3D%(query)s%%26store-name%%3Dall-product-search") cmd_yp = WebSearchCmd("http://local.google.com/local?sc=1&q=%(query)s&near=2418+washington+94115&btnG=Google+Search") @@ -636,6 +639,18 @@ os.remove(source_name) os.remove(output_name) +def cmd_wow_firefox(ensoapi): + popen = subprocess.Popen(["/Users/varmaa/bin/wow-firefox"]) + +def cmd_work_firefox(ensoapi): + popen = subprocess.Popen(["/Users/varmaa/bin/work-firefox"]) + +def cmd_mozpics_firefox(ensoapi): + popen = subprocess.Popen(["/Users/varmaa/bin/mozpics-firefox"]) + +def cmd_firefox(ensoapi): + popen = subprocess.Popen(["/Users/varmaa/bin/personal-firefox"]) + def cmd_nosetest(ensoapi): """ runs nosetests on the selected region of python code. @@ -684,6 +699,49 @@ os.remove(source_name) os.remove(output_name) +def cmd_markdown_to_html(ensoapi): + """ + Converts the plaintext markdown selection to plaintext + HTML source. + """ + + import markdown2 + text = ensoapi.get_selection().get("text", "") + html = markdown2.markdown(text) + ensoapi.set_selection({"text": html}) + +def cmd_unquote(ensoapi): + """ + Removes a '<' at the beginning of every line. + """ + + text = ensoapi.get_selection().get("text", "") + lines = ["%s\n" % line[2:] + for line in text.splitlines() + if line.startswith("> ")] + ensoapi.set_selection({"text": ''.join(lines)}) + +def cmd_quote(ensoapi): + """ + Puts a '>' at the beginning of every line. + """ + + text = ensoapi.get_selection().get("text", "") + lines = ["> %s\n" % line + for line in text.splitlines()] + ensoapi.set_selection({"text": ''.join(lines)}) + +def cmd_markdown(ensoapi): + """ + Converts the plaintext markdown selection to rich text. + """ + + import markdown2 + text = ensoapi.get_selection().get("text", "") + html = markdown2.markdown(text) + ensoapi.set_selection({"html": html, + "text": text}) + def cmd_insert_html(ensoapi): ensoapi.set_selection( {"html":"hi

there

"} ) @@ -787,9 +845,7 @@ ensoapi.set_selection({"text" : HTML_TEMPLATE}) HTML_TEMPLATE = """\ - - + - + """