Skip to content

Instantly share code, notes, and snippets.

@Nalisarc
Last active January 19, 2016 00:06
Show Gist options
  • Save Nalisarc/3e6f1272592cfc2f1b98 to your computer and use it in GitHub Desktop.
Save Nalisarc/3e6f1272592cfc2f1b98 to your computer and use it in GitHub Desktop.
A little Script that automatically opens files in emacs
"""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)
@Nalisarc
Copy link
Author

I'll add in argparsers in a later version. Maybe make a full fledged installer

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment