Want more features on Pastebin? Sign Up, it's FREE!
Guest

Untitled

By: a guest on Feb 20th, 2012  |  syntax: Python  |  size: 1.51 KB  |  views: 28  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. #! /usr/bin/env python
  2. # -*- coding: utf-8 -*-
  3. #==============================================================================#
  4. #   DESCRIPTION:  open text file with emacsclient and register the it into the
  5. #                 recently-used-files list (~/.recently-used.xbel)
  6. #
  7. #       OPTIONS:  ---
  8. #  REQUIREMENTS:  ---
  9. #         NOTES:  http://www.pygtk.org/docs/pygtk/class-gtkrecentmanager.html
  10. #        AUTHOR:  Wenping Guo (ybyygu)
  11. #         EMAIL:  ybyygu@gmail.com
  12. #       LICENCE:  GPL version 2 or upper
  13. #       CREATED:  Wed Sep  1 12:59:29 2010
  14. #       UPDATED:  Wed Sep  1 22:09:50 2010
  15. #==============================================================================#
  16.  
  17. __VERSION__ = "0.2.r7"
  18.  
  19. import os
  20. import sys
  21. import subprocess
  22. import urllib
  23.  
  24. import gtk
  25. import pygtk
  26. pygtk.require('2.0')
  27.  
  28. from guts import get_mime_type
  29.  
  30. if len(sys.argv) == 1:
  31.     print("%s: open file using emacsclient and register it into .recently-used.xbel" % (__file__))
  32.     sys.exit(0)
  33.  
  34. path = os.path.abspath(sys.argv[1])
  35.  
  36. #args = ["emacsclient", "-n", "-c", "-a gvim"]
  37. #args = ["emacsclient", "-n", "-c"]
  38. args = ["emacsclient", "-c"]
  39.  
  40. args.extend(sys.argv[1:])
  41. subprocess.Popen(args)
  42.  
  43. if not os.path.exists(path):
  44.     mime_type = "text/plain"
  45. else:    
  46.     mime_type = get_mime_type(path)
  47. uri = "file://" + urllib.quote(path.encode('utf-8'))
  48.  
  49. manager = gtk.recent_manager_get_default()
  50. manager.add_full(uri, recent_data={"mime_type":mime_type, "app_name":"emacsclient", "app_exec": "/usr/bin/emacsclient"})
clone this paste RAW Paste Data