From 92941e90f9ed7000682b3dd93ab132fca8acb90f Mon Sep 17 00:00:00 2001 From: rubikitch Date: Tue, 27 Oct 2015 03:53:58 +0900 Subject: [PATCH 1/7] Avoid floating close parens. --- subshell-proc.el | 27 +++++++++++---------------- 1 file changed, 11 insertions(+), 16 deletions(-) diff --git a/subshell-proc.el b/subshell-proc.el index 7f6605c..e79ca5a 100644 --- a/subshell-proc.el +++ b/subshell-proc.el @@ -7,12 +7,12 @@ ;; ;; ;;In elisp code ;; (defproc noir-server "lein" '("run") -;; "Run a noir server") +;; "Run a noir server") ;; ;; 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 ;; ;; @@ -21,29 +21,24 @@ (defmacro defproc (fn-name command command-args &optional docstring) "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)))) - )) - + (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) + (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)) - ))))) - + (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: ") From 0861705c863dfbe2f09b542b6025222e38bb9c8d Mon Sep 17 00:00:00 2001 From: rubikitch Date: Tue, 27 Oct 2015 03:55:31 +0900 Subject: [PATCH 2/7] Add `echo-test' example to prove `defproc' evaluates command-args at command-executing time. --- README.md | 2 ++ subshell-proc.el | 2 ++ 2 files changed, 4 insertions(+) diff --git a/README.md b/README.md index 41123b3..795a608 100644 --- a/README.md +++ b/README.md @@ -8,6 +8,8 @@ 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'") ``` While editing: diff --git a/subshell-proc.el b/subshell-proc.el index e79ca5a..9ac7114 100644 --- a/subshell-proc.el +++ b/subshell-proc.el @@ -8,6 +8,8 @@ ;; ;;In elisp code ;; (defproc noir-server "lein" '("run") ;; "Run a noir server") +;; (defproc echo-test "echo" `(,buffer-file-name) +;; "Print `buffer-file-name'") ;; ;; While editing: ;; M-x run-proc From 6bd676d83a0a077e8f4733d7f7ed22be044a35b4 Mon Sep 17 00:00:00 2001 From: rubikitch Date: Tue, 27 Oct 2015 03:58:56 +0900 Subject: [PATCH 3/7] Use lexical-binding instead of deprecated lexical-let. --- subshell-proc.el | 21 +++++++-------------- 1 file changed, 7 insertions(+), 14 deletions(-) diff --git a/subshell-proc.el b/subshell-proc.el index 9ac7114..6fa2733 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 @@ -18,9 +18,6 @@ ;; ;; -(require 'cl) - - (defmacro defproc (fn-name command command-args &optional docstring) "Defines an interactive function which creates a comint subprocess using command" `(defun ,fn-name (&rest extra-args) @@ -31,16 +28,12 @@ ,(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))))))) + (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))))) (defun run-proc (command &optional buffer-name) (interactive "MCommand to run: ") From 054f0e0996ef20c9feaed8384d593b2cefbefc63 Mon Sep 17 00:00:00 2001 From: rubikitch Date: Tue, 27 Oct 2015 03:59:56 +0900 Subject: [PATCH 4/7] defproc: Make command-args as optional --- subshell-proc.el | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/subshell-proc.el b/subshell-proc.el index 6fa2733..88646cf 100644 --- a/subshell-proc.el +++ b/subshell-proc.el @@ -18,7 +18,7 @@ ;; ;; -(defmacro defproc (fn-name command command-args &optional docstring) +(defmacro defproc (fn-name command &optional command-args docstring) "Defines an interactive function which creates a comint subprocess using command" `(defun ,fn-name (&rest extra-args) ,docstring @@ -27,7 +27,7 @@ (make-proc-run-fn ,command ,command-args ,(format "*%s*" (symbol-name fn-name)))))) -(defun make-proc-run-fn (command command-args &optional buffer-name) +(defun make-proc-run-fn (command &optional command-args buffer-name) (lambda (&rest extra-args) (let* ((buffer-name (or buffer-name (format "*%s*" command))) (buffer (get-buffer-create buffer-name))) From 44d3a54b9ec04c9d8ce8b9aca68e2bfe7364017b Mon Sep 17 00:00:00 2001 From: rubikitch Date: Tue, 27 Oct 2015 04:04:40 +0900 Subject: [PATCH 5/7] run-proc: use shell-file-name and shell-command-switch like start-process-shell-command. --- subshell-proc.el | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/subshell-proc.el b/subshell-proc.el index 88646cf..12e502b 100644 --- a/subshell-proc.el +++ b/subshell-proc.el @@ -37,8 +37,9 @@ (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) From 7436032db84560b5c12ba08cc09a26ab3724ad2b Mon Sep 17 00:00:00 2001 From: rubikitch Date: Tue, 27 Oct 2015 04:11:20 +0900 Subject: [PATCH 6/7] defproc: New arg `display-fn' --- subshell-proc.el | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/subshell-proc.el b/subshell-proc.el index 12e502b..11a25dc 100644 --- a/subshell-proc.el +++ b/subshell-proc.el @@ -18,20 +18,21 @@ ;; ;; -(defmacro defproc (fn-name command &optional command-args 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) ,docstring (interactive) (funcall (make-proc-run-fn ,command ,command-args - ,(format "*%s*" (symbol-name fn-name)))))) + ,(format "*%s*" (symbol-name fn-name)) + ,display-fn)))) -(defun make-proc-run-fn (command &optional command-args buffer-name) +(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))) - (pop-to-buffer buffer) + (funcall (or display-fn 'pop-to-buffer) buffer) (apply 'make-comint-in-buffer (append (list buffer-name buffer command nil) command-args))))) From 112a8c42bd30084850162779c5cfb5e1e07ead82 Mon Sep 17 00:00:00 2001 From: rubikitch Date: Tue, 27 Oct 2015 04:14:28 +0900 Subject: [PATCH 7/7] Add some examples --- README.md | 6 ++++++ subshell-proc.el | 6 ++++++ 2 files changed, 12 insertions(+) diff --git a/README.md b/README.md index 795a608..e46a256 100644 --- a/README.md +++ b/README.md @@ -10,6 +10,12 @@ from emacs comint.el in a slightly easier to use fashion. "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 11a25dc..fa2d381 100644 --- a/subshell-proc.el +++ b/subshell-proc.el @@ -10,6 +10,12 @@ ;; "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