diff --git a/README.md b/README.md index 41123b3..e46a256 100644 --- a/README.md +++ b/README.md @@ -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: diff --git a/subshell-proc.el b/subshell-proc.el index 7f6605c..fa2d381 100644 --- a/subshell-proc.el +++ b/subshell-proc.el @@ -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 @@ -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)