unofficial mirror of bug-gnu-emacs@gnu.org 
 help / color / mirror / code / Atom feed
* bug#33037: 27.0.50; [PATCH] Support program switches in 'comint-run' command
@ 2018-10-14  4:42 Phil Sainty
  2019-07-11 15:33 ` Lars Ingebrigtsen
  0 siblings, 1 reply; 2+ messages in thread
From: Phil Sainty @ 2018-10-14  4:42 UTC (permalink / raw)
  To: 33037

[-- Attachment #1: Type: text/plain, Size: 1508 bytes --]

This patch enables arguments to be passed to the specified program when
invoking `comint-run'.

Interactively, a prefix argument C-u will make the command prompt for
the switches (as a string) after prompting for the program.  The
switches are processed with `split-string-and-unquote'.

I think this is a sensible enhancement, but not necessarily the best
user interface.  Other possibilities which occur are:

1. Do not require a prefix arg, and simply make this the default
   prompting behaviour.

2. Do not require a separate prompt, and instead parse the program
   and its switches out of a single string.

Either of those would mean that the user doesn't need to bother with
(or remember to use) a prefix argument to enable something which is
arguably important enough to happen by default.

Option (2) is an issue when PROGRAM contains spaces, as the user would
now need to quote that value, which is not currently necessary.  Maybe
the benefits make that a worthwhile change, though?  (i.e. greater ease
of use for the 'normal' use-cases where the path to the program does
not contain spaces).

I suppose option (3) might be "all of the above", with a user option
to select the preferred prompting behaviour, but that might be overkill.

...all of which reminds me that I've been meaning to write a similar
patch to allow switches to be specified for the `term' and `ansi-term'
commands, and a consistent approach in all cases would seem sensible;
so that's something else to keep in mind.


-Phil

[-- Attachment #2: 0001-Support-program-switches-in-comint-run-command.patch --]
[-- Type: text/x-patch, Size: 2917 bytes --]

From 3adc0be13880472e74b6015c6948046a25acdb9b Mon Sep 17 00:00:00 2001
From: Phil Sainty <psainty@orcon.net.nz>
Date: Sun, 14 Oct 2018 15:54:05 +1300
Subject: [PATCH] Support program switches in 'comint-run' command

* lisp/comint.el (comint-run): Add optional SWITCHES argument.
With prefix argument C-u, prompt for SWITCHES.

* etc/NEWS:
* doc/emacs/misc.texi: Describe new behaviour.
---
 doc/emacs/misc.texi |  3 ++-
 etc/NEWS            |  4 ++++
 lisp/comint.el      | 16 ++++++++++++----
 3 files changed, 18 insertions(+), 5 deletions(-)

diff --git a/doc/emacs/misc.texi b/doc/emacs/misc.texi
index 236cb07..fe397f7 100644
--- a/doc/emacs/misc.texi
+++ b/doc/emacs/misc.texi
@@ -1088,7 +1088,8 @@ Shell Mode
 @findex comint-run
   You can use @kbd{M-x comint-run} to execute any program of your choice
 in a subprocess using unmodified Comint mode---without the
-specializations of Shell mode.
+specializations of Shell mode.  To pass arguments to the program, use
+@kbd{C-u M-x comint-run}
 
 @node Shell Prompts
 @subsection Shell Prompts
diff --git a/etc/NEWS b/etc/NEWS
index 946a823..d2b8bdb 100644
--- a/etc/NEWS
+++ b/etc/NEWS
@@ -366,6 +366,10 @@ better emulate 'M-.' in both Bash and zsh, since the former counts
 from the beginning of the arguments, while the latter counts from the
 end.
 
++++
+*** 'comint-run' can now accept a list of switches to pass to the program.
+'C-u M-x comint-run' will prompt for the switches interactively.
+
 ** SQL
 
 *** Installation of 'sql-indent' from ELPA is strongly encouraged.
diff --git a/lisp/comint.el b/lisp/comint.el
index 5928804..5be763e 100644
--- a/lisp/comint.el
+++ b/lisp/comint.el
@@ -759,16 +759,24 @@ make-comint
   (apply #'make-comint-in-buffer name nil program startfile switches))
 
 ;;;###autoload
-(defun comint-run (program)
-  "Run PROGRAM in a Comint buffer and switch to it.
+(defun comint-run (program &optional switches)
+  "Run PROGRAM in a Comint buffer and switch to that buffer.
+
+If SWITCHES are supplied, they are passed to PROGRAM.  With prefix argument
+\\[universal-argument] prompt for SWITCHES as well as PROGRAM.
+
 The buffer name is made by surrounding the file name of PROGRAM with `*'s.
 The file name is used to make a symbol name, such as `comint-sh-hook', and any
 hooks on this symbol are run in the buffer.
+
 See `make-comint' and `comint-exec'."
   (declare (interactive-only make-comint))
-  (interactive "sRun program: ")
+  (interactive
+   (list (read-string "Run program: ")
+         (and (consp current-prefix-arg)
+              (split-string-and-unquote (read-string "Switches: ")))))
   (let ((name (file-name-nondirectory program)))
-    (switch-to-buffer (make-comint name program))
+    (switch-to-buffer (apply #'make-comint name program nil switches))
     (run-hooks (intern-soft (concat "comint-" name "-hook")))))
 
 (defun comint-exec (buffer name command startfile switches)
-- 
2.8.3


^ permalink raw reply related	[flat|nested] 2+ messages in thread

* bug#33037: 27.0.50; [PATCH] Support program switches in 'comint-run' command
  2018-10-14  4:42 bug#33037: 27.0.50; [PATCH] Support program switches in 'comint-run' command Phil Sainty
@ 2019-07-11 15:33 ` Lars Ingebrigtsen
  0 siblings, 0 replies; 2+ messages in thread
From: Lars Ingebrigtsen @ 2019-07-11 15:33 UTC (permalink / raw)
  To: Phil Sainty; +Cc: 33037

Phil Sainty <psainty@orcon.net.nz> writes:

> This patch enables arguments to be passed to the specified program when
> invoking `comint-run'.
>
> Interactively, a prefix argument C-u will make the command prompt for
> the switches (as a string) after prompting for the program.  The
> switches are processed with `split-string-and-unquote'.
>
> I think this is a sensible enhancement, but not necessarily the best
> user interface.  Other possibilities which occur are:
>
> 1. Do not require a prefix arg, and simply make this the default
>    prompting behaviour.
>
> 2. Do not require a separate prompt, and instead parse the program
>    and its switches out of a single string.

I think your patch makes sense as it is, so I've applied it to the Emacs
trunk now.

-- 
(domestic pets only, the antidote for overdose, milk.)
   bloggy blog: http://lars.ingebrigtsen.no





^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2019-07-11 15:33 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-10-14  4:42 bug#33037: 27.0.50; [PATCH] Support program switches in 'comint-run' command Phil Sainty
2019-07-11 15:33 ` Lars Ingebrigtsen

Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).