all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
* bug#26649: 26.0.50; buffer-command: Return the cmd that started a process in buffer
@ 2017-04-25  8:15 Tino Calancha
  2017-04-26 10:03 ` Eli Zaretskii
  2017-04-26 22:09 ` Juri Linkov
  0 siblings, 2 replies; 5+ messages in thread
From: Tino Calancha @ 2017-04-25  8:15 UTC (permalink / raw)
  To: 26649

Severity: wishlist

I define in my private customization a command `buffer-command', which
calls `process-command' on the process associated with the current
buffer.
Interactively, it shows in the echo area the command as the last column
of `list-processes' does.
Is anyone interested in adding this feature?
--8<-----------------------------cut here---------------start------------->8---
From 59ee6e113b7ff557ba5208b79ddf57a26b4578b2 Mon Sep 17 00:00:00 2001
From: Tino Calancha <tino.calancha@gmail.com>
Date: Tue, 25 Apr 2017 17:07:07 +0900
Subject: [PATCH] buffer-command: Return the cmd that started a process in
 buffer

* lisp/simple.el (buffer-command): Return command executed to
start a process in BUFFER (Bug#26649).
* doc/lispref/processes.texi (Process Information): Document new command.
* test/lisp/subr-tests.el (subr-tests--buffer-command): Add test
; * etc/NEWS: Add news entry.
---
 doc/lispref/processes.texi |  7 +++++++
 etc/NEWS                   |  4 ++++
 lisp/simple.el             | 18 ++++++++++++++++++
 test/lisp/subr-tests.el    | 11 +++++++++++
 4 files changed, 40 insertions(+)

diff --git a/doc/lispref/processes.texi b/doc/lispref/processes.texi
index 630853384e..b182842614 100644
--- a/doc/lispref/processes.texi
+++ b/doc/lispref/processes.texi
@@ -975,6 +975,13 @@ Process Information
 @end smallexample
 @end defun
 
+@deffn Command buffer-command &optional buffer
+This command calls @code{process-command} on the process associated
+with @var{buffer}.  @var{buffer} defaults to the current buffer.
+If @var{buffer} is not associated with a running process, then returns
+@code{nil}.
+@end deffn
+
 @defun process-contact process &optional key
 This function returns information about how a network, a serial, or a
 pipe connection was set up.  When @var{key} is @code{nil}, it returns
diff --git a/etc/NEWS b/etc/NEWS
index 9d4c72d6dc..87d6c93fa1 100644
--- a/etc/NEWS
+++ b/etc/NEWS
@@ -886,6 +886,10 @@ instead of its first.
 * Lisp Changes in Emacs 26.1
 
 +++
+** New command 'buffer-command' calls 'process-command' on the
+process associated with the current buffer.
+
++++
 ** Emacs now supports records for user-defined types, via the new
 functions 'make-record', 'record', and 'recordp'.  Records are now
 used internally to represent cl-defstruct and defclass instances, for
diff --git a/lisp/simple.el b/lisp/simple.el
index a58164a112..2aed47502e 100644
--- a/lisp/simple.el
+++ b/lisp/simple.el
@@ -3967,6 +3967,24 @@ list-processes
     (tabulated-list-print))
   (display-buffer buffer)
   nil)
+
+(defun buffer-command (&optional buffer)
+  "Return the command that was executed to start the process in BUFFER.
+Buffer defaults to the current buffer.
+This runs `process-command' on the process associated with BUFFER.
+If BUFFER is not associated with a process, then return nil."
+  (interactive)
+  (when (and buffer (not (buffer-live-p (get-buffer buffer))))
+    (error "Not a living buffer '%S'" buffer))
+  (let* ((buf (get-buffer (or buffer (current-buffer))))
+         (proc (get-buffer-process buf))
+	     (cmd (and proc (process-command proc))))
+    (cond ((null cmd)
+	       (message "No process in buffer '%s'" (buffer-name buf))
+           nil)
+          (t
+           (message "%s" (mapconcat #'identity cmd " "))
+           cmd))))
 \f
 ;;;; Prefix commands
 
diff --git a/test/lisp/subr-tests.el b/test/lisp/subr-tests.el
index 0d243cc5d8..f4e6640f9c 100644
--- a/test/lisp/subr-tests.el
+++ b/test/lisp/subr-tests.el
@@ -291,5 +291,16 @@ subr-test--frames-1
   (should-error (eval '(dolist "foo") t)
                 :type 'wrong-type-argument))
 
+(ert-deftest subr-tests--buffer-command ()
+  (let ((program (executable-find "sleep"))
+        (timeout "10") proc)
+    (with-temp-buffer
+      (should-not (buffer-command))
+      (when program
+        (setq proc
+              (start-process "sleep" (current-buffer) program timeout))
+        (set-process-query-on-exit-flag proc nil)
+        (should (equal (buffer-command) (list program timeout)))))))
+
 (provide 'subr-tests)
 ;;; subr-tests.el ends here
-- 
2.11.0

--8<-----------------------------cut here---------------end--------------->8---

In GNU Emacs 26.0.50 (build 1, x86_64-pc-linux-gnu, GTK+ Version 3.22.11)
 of 2017-04-25
Repository revision: 5b0fdefb4ca54b0d3dac3047ac1e4b380beb6ba7





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

* bug#26649: 26.0.50; buffer-command: Return the cmd that started a process in buffer
  2017-04-25  8:15 bug#26649: 26.0.50; buffer-command: Return the cmd that started a process in buffer Tino Calancha
@ 2017-04-26 10:03 ` Eli Zaretskii
  2017-04-26 22:09 ` Juri Linkov
  1 sibling, 0 replies; 5+ messages in thread
From: Eli Zaretskii @ 2017-04-26 10:03 UTC (permalink / raw)
  To: Tino Calancha; +Cc: 26649

> From: Tino Calancha <tino.calancha@gmail.com>
> Date: Tue, 25 Apr 2017 17:15:26 +0900
> 
> Severity: wishlist
> 
> I define in my private customization a command `buffer-command', which
> calls `process-command' on the process associated with the current
> buffer.
> Interactively, it shows in the echo area the command as the last column
> of `list-processes' does.
> Is anyone interested in adding this feature?

I don't have an opinion on this, perhaps others will offer theirs.  I
do have a few comments:

> Subject: [PATCH] buffer-command: Return the cmd that started a process in
>  buffer                          ^^^^^^

Not "return", "display".

> * lisp/simple.el (buffer-command): Return command executed to
> start a process in BUFFER (Bug#26649).

Likewise.  Also, we generally use just "new command" in these cases.

> * doc/lispref/processes.texi (Process Information): Document new command.

It is better to mention the name of the command.

> +@deffn Command buffer-command &optional buffer

I think it would be better to have the command's name start with
"process-", so something like process-command-in-buffer.

> +This command calls @code{process-command} on the process associated
> +with @var{buffer}.

This describes the implementation; it should instead describe the
effect of the command.

> +If @var{buffer} is not associated with a running process, then returns
> +@code{nil}.

The value returned by a command is not interesting, you should
describe the effect of invoking this command in a buffer that has n o
associated process.

> +(defun buffer-command (&optional buffer)
> +  "Return the command that was executed to start the process in BUFFER.

Same comment here: describe the effect, not the return value.  If the
returned value is important for non-interactive invocations, it should
be described in addition to the effect of an interactive invocation.

> +Buffer defaults to the current buffer.
   ^^^^^^
BUFFER

> +    (error "Not a living buffer '%S'" buffer))

"Not a live buffer '%S'"

> +    (cond ((null cmd)
> +	       (message "No process in buffer '%s'" (buffer-name buf))

It is better to say something like

  Buffer '%s' is not associated with any process

Btw, why %s here and %S in the error message?

> +          (t
> +           (message "%s" (mapconcat #'identity cmd " "))

What will this produce if some of the command-line arguments include
embedded whitespace?

> +(ert-deftest subr-tests--buffer-command ()
> +  (let ((program (executable-find "sleep"))
> +        (timeout "10") proc)

Instead of bypassing the test where 'sleep' doesn't exist, how about
if you use the Emacs executable instead?  That will always exist.

Thanks.





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

* bug#26649: 26.0.50; buffer-command: Return the cmd that started a process in buffer
  2017-04-25  8:15 bug#26649: 26.0.50; buffer-command: Return the cmd that started a process in buffer Tino Calancha
  2017-04-26 10:03 ` Eli Zaretskii
@ 2017-04-26 22:09 ` Juri Linkov
  2017-04-27  3:22   ` Tino Calancha
  1 sibling, 1 reply; 5+ messages in thread
From: Juri Linkov @ 2017-04-26 22:09 UTC (permalink / raw)
  To: Tino Calancha; +Cc: 26649

> Severity: wishlist
>
> I define in my private customization a command `buffer-command', which
> calls `process-command' on the process associated with the current
> buffer.
> Interactively, it shows in the echo area the command as the last column
> of `list-processes' does.
> Is anyone interested in adding this feature?

The command name ‘buffer-command’ is confusing.  At first I thought it
should read a command in the minibuffer like ‘shell-command’ and execute
it in the buffer's process.  But actually it just displays the same info
that is available in ‘list-processes’.





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

* bug#26649: 26.0.50; buffer-command: Return the cmd that started a process in buffer
  2017-04-26 22:09 ` Juri Linkov
@ 2017-04-27  3:22   ` Tino Calancha
  2017-05-03  8:25     ` Tino Calancha
  0 siblings, 1 reply; 5+ messages in thread
From: Tino Calancha @ 2017-04-27  3:22 UTC (permalink / raw)
  To: Juri Linkov; +Cc: 26649

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



On Thu, 27 Apr 2017, Juri Linkov wrote:

>> Severity: wishlist
>>
>> I define in my private customization a command `buffer-command', which
>> calls `process-command' on the process associated with the current
>> buffer.
>> Interactively, it shows in the echo area the command as the last column
>> of `list-processes' does.
>> Is anyone interested in adding this feature?
>
> The command name ‘buffer-command’ is confusing.  At first I thought it
> should read a command in the minibuffer like ‘shell-command’ and execute
> it in the buffer's process.  But actually it just displays the same info
> that is available in ‘list-processes’.
Yeah, this command seems very specific to my workflow.  It doesn't add
nothing to `list-process', so i agree it's worthless adding it into 
Emacs.

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

* bug#26649: 26.0.50; buffer-command: Return the cmd that started a process in buffer
  2017-04-27  3:22   ` Tino Calancha
@ 2017-05-03  8:25     ` Tino Calancha
  0 siblings, 0 replies; 5+ messages in thread
From: Tino Calancha @ 2017-05-03  8:25 UTC (permalink / raw)
  To: 26649-done

Tino Calancha <tino.calancha@gmail.com> writes:

> On Thu, 27 Apr 2017, Juri Linkov wrote:
>
>>> Severity: wishlist
>>>
>>> I define in my private customization a command `buffer-command', which
>>> calls `process-command' on the process associated with the current
>>> buffer.
>>> Interactively, it shows in the echo area the command as the last column
>>> of `list-processes' does.
>>> Is anyone interested in adding this feature?
>>
>> The command name ‘buffer-command’ is confusing.  At first I thought it
>> should read a command in the minibuffer like ‘shell-command’ and execute
>> it in the buffer's process.  But actually it just displays the same info
>> that is available in ‘list-processes’.
> Yeah, this command seems very specific to my workflow.  It doesn't add
> nothing to `list-process', so i agree it's worthless adding it into
> Emacs.
There is no general interest in this proposal, so i am closing the report.





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

end of thread, other threads:[~2017-05-03  8:25 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2017-04-25  8:15 bug#26649: 26.0.50; buffer-command: Return the cmd that started a process in buffer Tino Calancha
2017-04-26 10:03 ` Eli Zaretskii
2017-04-26 22:09 ` Juri Linkov
2017-04-27  3:22   ` Tino Calancha
2017-05-03  8:25     ` Tino Calancha

Code repositories for project(s) associated with this external index

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

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.