-
Notifications
You must be signed in to change notification settings - Fork 12
/
Copy pathscript.el
75 lines (69 loc) · 2.19 KB
/
script.el
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
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
(defvar script&shell-alist
'(("py" . "python")
("rb" . "ruby")
("lua" . "lua")
("php" . "php")
("pl" . "perl")
("sh" . "bash")
("java" . "javac")
("hs" . "hugs")
("js" . "node")
("coffee" . "coffee")
))
;;;###autoload
(defun run-current-file ()
"Execute or compile the current file.
For example, if the current buffer is the file x.pl,
then it'll call “perl x.pl” in a shell.
The file can be php, perl, python, bash, java.
File suffix is used to determine what program to run."
(interactive)
(let (ext-map file-name file-ext prog-name cmd-str
outputf status)
(setq ext-map script&shell-alist)
(setq
status
(catch 'status
(or (setq file-name (buffer-file-name))
(throw 'status "isn't a file!"))
(or (setq file-ext (file-name-extension file-name))
(throw 'status "no file ext name!"))
(or (setq prog-name (cdr (assoc file-ext ext-map)))
(throw 'status "how to do?"))
(setq cmd-str (concat prog-name " " file-name))
(setq outputf (if (equal (this-command-keys) [f5]) 'compile 'shell-command))
(and (funcall outputf cmd-str)
(throw 'status nil))))
(and status (message "%s" status))))
;;;###autoload
(defun x-shell (prog)
(let ((progstr (symbol-name prog)))
(eval
`(defun ,(concat-symbol prog '-shell)()
,(format "make a %s shell" prog)
(interactive)
(switch-to-buffer
(make-comint ,progstr
,(or
(cdr (assoc progstr script&shell-alist))
progstr)
nil "-i"))))))
;; (mapcar 'x-shell '(python lua))
;;;###autoload
(defun lua-shell ()
"make a lua shell"
(interactive)
(switch-to-buffer (make-comint "lua" "lua" nil "-i")))
;;;###autoload
(defun node.js ()
"make a node.js shell"
(interactive)
(switch-to-buffer (make-comint "node.js" "node" nil "-i")))
;;;###autoload
(defun coffee ()
"make a coffee-script shell"
(interactive)
(switch-to-buffer (make-comint "coffee" "coffee" nil "-i")))
;;;###autoload
(autoload 'run-ruby "inf-ruby"
"Run an inferior Ruby process" t)