Last active
January 19, 2016 00:06
-
-
Save Nalisarc/3e6f1272592cfc2f1b98 to your computer and use it in GitHub Desktop.
A little Script that automatically opens files in emacs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
"""AutoEmacs Document""" | |
#expiremental version | |
# imports | |
import sys | |
import os | |
import psutil | |
import subprocess | |
from argparse import ArgumentParser | |
# constants | |
xlaunch_config = #"Enter your xlaunch config file" | |
script = ['xterm', '-display', ':0', '-e', 'emacs-w32'] | |
# internal functions & classes | |
def xlaunch_check(): | |
# checks if an instance of Xlaunch is running | |
xlaunch_state = [] | |
for p in psutil.process_iter(): #list all running process | |
try: | |
if p.name() == 'xlaunch.exe':# once xlaunch is found make an object | |
xlaunch_state.append(p) | |
except psutil.Error: # if xlaunch is not found return false | |
return False | |
return xlaunch_state != [] #double checks that xlaunch is running | |
def xlaunch_run(run): | |
if run == False: | |
os.startfile(xlaunch_config) | |
return 0 #Launched | |
else: | |
return 1 #Already Running | |
def emacs_run(script): | |
subprocess.Popen(script, shell=True) | |
return 0#Launched Sucessfully | |
def sysarg(): | |
try: | |
f = sys.argv[1] | |
il = f.split() | |
l = il[0].split('\\') | |
return l[(len(l) - 1)] | |
except IndexError: | |
return 'Errno 200' | |
def main(script): | |
f = sysarg() | |
xlaunch_running = xlaunch_check() | |
xlaunch_run(xlaunch_running) | |
if f != 'Errno 200': | |
script.append(f) | |
else: | |
pass | |
emacs_run(script) | |
return 0 | |
if __name__ == '__main__': | |
status = main(script) | |
sys.exit(status) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I'll add in argparsers in a later version. Maybe make a full fledged installer