#! /usr/bin/env python # -*- coding: utf-8 -*- #==============================================================================# # DESCRIPTION: open text file with emacsclient and register the it into the # recently-used-files list (~/.recently-used.xbel) # # OPTIONS: --- # REQUIREMENTS: --- # NOTES: http://www.pygtk.org/docs/pygtk/class-gtkrecentmanager.html # AUTHOR: Wenping Guo (ybyygu) # EMAIL: ybyygu@gmail.com # LICENCE: GPL version 2 or upper # CREATED: Wed Sep 1 12:59:29 2010 # UPDATED: Wed Sep 1 22:09:50 2010 #==============================================================================# __VERSION__ = "0.2.r7" import os import sys import subprocess import urllib import gtk import pygtk pygtk.require('2.0') from guts import get_mime_type if len(sys.argv) == 1: print("%s: open file using emacsclient and register it into .recently-used.xbel" % (__file__)) sys.exit(0) path = os.path.abspath(sys.argv[1]) #args = ["emacsclient", "-n", "-c", "-a gvim"] #args = ["emacsclient", "-n", "-c"] args = ["emacsclient", "-c"] args.extend(sys.argv[1:]) subprocess.Popen(args) if not os.path.exists(path): mime_type = "text/plain" else: mime_type = get_mime_type(path) uri = "file://" + urllib.quote(path.encode('utf-8')) manager = gtk.recent_manager_get_default() manager.add_full(uri, recent_data={"mime_type":mime_type, "app_name":"emacsclient", "app_exec": "/usr/bin/emacsclient"})