-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathnom.py
More file actions
executable file
·29 lines (24 loc) · 925 Bytes
/
Copy pathnom.py
File metadata and controls
executable file
·29 lines (24 loc) · 925 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
#!/usr/bin/env python
import re, os, os.path, sys, tempfile
import subprocess
# This script dumps its stdin into an Emacs buffer (using emacsclient).
# cat foo | nom # creates a buffer called *nom*
# cat foo | nom python # creates a buffer called *nom* in python-mode
# cat foo | nom python yo # creates a buffer called *nom-yo* in python-mode
esc = re.compile(r'["\\]')
q = lambda s: esc.sub(lambda m: '\\'+m.group(0), s)
if __name__ == '__main__':
fd, fname = tempfile.mkstemp()
subprocess.Popen(["dd"], stdout=fd).wait()
os.close(fd)
name = ""
mode = ""
if len(sys.argv) > 1:
mode = "(" + sys.argv[1] + "-mode)"
if len(sys.argv) > 2:
name = "-" + sys.argv[2]
ff = """(progn
(switch-to-buffer (generate-new-buffer "*nom%s*"))
(insert-file-contents "%s")%s)""" % (q(name), q(fname), mode)
subprocess.Popen(['emacsclient', '-n', '-e', ff]).wait()
os.unlink(fname)