Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,14 @@ from emacs comint.el in a slightly easier to use fashion.
;;In elisp code
(defproc "noir-server" "lein" '("run")
"Run a noir server")
(defproc echo-test "echo" `(,buffer-file-name)
"Print `buffer-file-name'")
(defproc echo-test2 "echo" `(,buffer-file-name)
"Print `buffer-file-name' without selecting *echo* buffer."
'display-buffer)
(defproc xeyes "xeyes" nil
"Run xeyes without popping up *xeyes* buffer"
'ignore)
```

While editing:
Expand Down
60 changes: 29 additions & 31 deletions subshell-proc.el
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
;;; subshell-proc.el --- Functions for working with comints
;;; subshell-proc.el --- Functions for working with comints -*- lexical-binding: -*-
;; Author: Andrew Mains
;; URL: https://github.com/andrewmains12/subshell-proc
;; Version: 0.2
Expand All @@ -7,48 +7,46 @@
;;
;; ;;In elisp code
;; (defproc noir-server "lein" '("run")
;; "Run a noir server")
;; "Run a noir server")
;; (defproc echo-test "echo" `(,buffer-file-name)
;; "Print `buffer-file-name'")
;; (defproc echo-test2 "echo" `(,buffer-file-name)
;; "Print `buffer-file-name' without selecting *echo* buffer."
;; 'display-buffer)
;; (defproc xeyes "xeyes" nil
;; "Run xeyes without popping up *xeyes* buffer"
;; 'ignore)
;;
;; While editing:
;; M-x run-proc
;; M-x run-proc
;; bash
;; will bring up a comint running bash
;; will bring up a comint running bash
;;
;;

(require 'cl)


(defmacro defproc (fn-name command command-args &optional docstring)
(defmacro defproc (fn-name command &optional command-args docstring display-fn)
"Defines an interactive function which creates a comint subprocess using command"
`(defun ,fn-name (&rest extra-args)
`(defun ,fn-name (&rest extra-args)
,docstring
(interactive)
(funcall
(make-proc-run-fn ,command ,command-args
,(format "*%s*" (symbol-name fn-name))))
))


(defun make-proc-run-fn (command command-args &optional buffer-name)
(lexical-let ((buffer-name buffer-name)
(command command)
(command-args command-args)
)
(function (lambda (&rest extra-args)
(let* ((buffer-name (or buffer-name (format "*%s*" command)))
(buffer (get-buffer-create buffer-name))
)
(pop-to-buffer buffer)
(apply 'make-comint-in-buffer
(append (list buffer-name buffer command nil) command-args))
)))))

(funcall
(make-proc-run-fn ,command ,command-args
,(format "*%s*" (symbol-name fn-name))
,display-fn))))

(defun make-proc-run-fn (command &optional command-args buffer-name display-fn)
(lambda (&rest extra-args)
(let* ((buffer-name (or buffer-name (format "*%s*" command)))
(buffer (get-buffer-create buffer-name)))
(funcall (or display-fn 'pop-to-buffer) buffer)
(apply 'make-comint-in-buffer
(append (list buffer-name buffer command nil) command-args)))))

(defun run-proc (command &optional buffer-name)
(interactive "MCommand to run: ")
(let ((command-list (split-string command)))
(funcall (make-proc-run-fn (car command-list) (cdr command-list) buffer-name))))
(funcall (make-proc-run-fn shell-file-name
(list shell-command-switch command)
buffer-name)))

(provide 'subshell-proc)

Expand Down