2

To get a process buffer an eshell buffer I thought I used to be able to run:

(get-buffer-process (current-buffer))

In Emacs 25 this no longer works. Specifically "GNU Emacs 25.1.50.2 (x86_64-unknown-linux-gnu, GTK+ Version 3.10.8) of 2015-11-30"

Here is what I do. I start an eshell with M-x eshell. Then with that as the only window or buffer around I run

M-x eval

Eval: (get-buffer-process (current-buffer))

And the result is nil.

I am using this in the code for realgud, an emacs front-end to various debuggers. It needs to interact with the debugger like see if the debugger is running or has terminated, send commands to it and run hooks when output appears.

How would I do this?

rocky
  • 888
  • 7
  • 26
  • 1
    Erm, what process are you expecting to find in an `eshell` buffer? I'm not an eshell user but, as far as I understand, one of the defining features of eshell is that there *isn't* an external process; and I can only presume this has always been the case. – phils May 29 '16 at 09:39
  • 1
    @phils You get the process of the program started in the `eshell`-buffer. But, that works fine for me with emacs 25.1.50. – Tobias May 29 '16 at 16:10
  • @Tobias Hmm. I am using GNU Emacs 25.1.50.2 (x86_64-unknown-linux-gnu, GTK+ Version 3.10.8) of 2015-11-30 and I am getting nil back. I'll revise the question to be more detailed about this. – rocky May 29 '16 at 20:06
  • 1
    Please see [that `eshell`-session](http://pastebin.com/mQhxBTHd). (Note: It is a link to pastebin.com.) The first `get-buffer-process` returns nil, so nothing is shown. The second `get-buffer-process` returns the started `xterm` which is shown in the eshell-buffer. Emacs-version is also shown in this buffer. – Tobias May 29 '16 at 21:34
  • 1
    @Tobias if you post your comment as an answer I'll accept it. This solves my problem or rather confusion. – rocky May 30 '16 at 00:53
  • @phils right. Sorry I meant eshell. I can't edit the question anymore. Of course I can delete that. So I will since it is no longer relevant. – rocky May 30 '16 at 09:57

1 Answers1

3

Eshell has not a process-id of its own. It is solely running on the base of emacs-lisp functions within emacs.

Nevertheless, you can start processes from an eshell buffer. The eshell buffer becomes the process-buffer for the started processes.

The following eshell session shows what is going on with processes in the eshell buffer.

Welcome to the Emacs shell

~ $ emacs-version 
GNU Emacs 24.5.1 (x86_64-unknown-cygwin, GTK+ Version 3.14.13)
 of 2015-06-23 on desktop-new
~ $ get-buffer-process (current-buffer)
~ $ /usr/bin/xterm &
[xterm<1>] 5168
~ $ get-buffer-process (current-buffer)
#<process xterm<1>>
~ $ /usr/local/bin/xpdf.exe &
[xpdf.exe] 6464
~ $ get-buffer-process (current-buffer)
#<process xpdf.exe>
~ $ process-buffer (get-process "xpdf.exe")
#<buffer *eshell*>
~ $ process-buffer (get-process "xterm<1>")
#<buffer *eshell*>
~ $ remove-if-not #'(lambda (proc) (equal (process-buffer proc) (current-buffer))) (process-list)
(#<process xpdf.exe> #<process xterm<1>>)

Note, that I have deleted some lines that may only cause confusion (e.g., font messages for the started processes).

Side note: It is rather interesting that both started background processes have the same eshell buffer as process buffer, i.e., the process of a process buffer is not unique. It looks like get-buffer-process gets only the last started process for the buffer.

Tobias
  • 32,569
  • 1
  • 34
  • 75