annotate lisp/eshell/esh-proc.el @ 106636:6c68929f170b

* emacs.texi (Top): Update node listing. * abbrevs.texi (Saving Abbrevs): Abbrev file should be in .emacs.d. * basic.texi (Moving Point): M-r is now move-to-window-line-top-bottom. * cmdargs.texi (Initial Options): * xresources.texi (Resources): Document inhibit-x-resources. * custom.texi (Specifying File Variables): Note that minor modes are enabled unconditionally. * display.texi (Scrolling): Briefly document the old recenter command, and document recenter-positions. * files.texi (Visiting): * buffers.texi (Buffers): Max buffer size is now 512 MB. * frames.texi (Cut/Paste Other App): Document save-interprogram-paste-before-kill. * killing.texi (Kill Options): New node.
author Chong Yidong <cyd@stupidchicken.com>
date Fri, 25 Dec 2009 20:00:32 +0000
parents 16b061d2742d
children 1d1d5d9bd884
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
38414
67b464da13ec Some fixes to follow coding conventions.
Pavel Janík <Pavel@Janik.cz>
parents: 37658
diff changeset
1 ;;; esh-proc.el --- process management
29876
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
2
74509
f7702c5f335d Update copyright years.
Glenn Morris <rgm@gnu.org>
parents: 68648
diff changeset
3 ;; Copyright (C) 1999, 2000, 2001, 2002, 2003, 2004,
100908
a9dc0e7c3f2b Add 2009 to copyright years.
Glenn Morris <rgm@gnu.org>
parents: 100055
diff changeset
4 ;; 2005, 2006, 2007, 2008, 2009 Free Software Foundation, Inc.
29876
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
5
32526
8e57189d61b4 Add author information.
Gerd Moellmann <gerd@gnu.org>
parents: 31241
diff changeset
6 ;; Author: John Wiegley <johnw@gnu.org>
8e57189d61b4 Add author information.
Gerd Moellmann <gerd@gnu.org>
parents: 31241
diff changeset
7
29876
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
8 ;; This file is part of GNU Emacs.
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
9
94661
b5b0801a7637 Switch to recommended form of GPLv3 permissions notice.
Glenn Morris <rgm@gnu.org>
parents: 93975
diff changeset
10 ;; GNU Emacs is free software: you can redistribute it and/or modify
29876
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
11 ;; it under the terms of the GNU General Public License as published by
94661
b5b0801a7637 Switch to recommended form of GPLv3 permissions notice.
Glenn Morris <rgm@gnu.org>
parents: 93975
diff changeset
12 ;; the Free Software Foundation, either version 3 of the License, or
b5b0801a7637 Switch to recommended form of GPLv3 permissions notice.
Glenn Morris <rgm@gnu.org>
parents: 93975
diff changeset
13 ;; (at your option) any later version.
29876
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
14
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
15 ;; GNU Emacs is distributed in the hope that it will be useful,
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
16 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
17 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
18 ;; GNU General Public License for more details.
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
19
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
20 ;; You should have received a copy of the GNU General Public License
94661
b5b0801a7637 Switch to recommended form of GPLv3 permissions notice.
Glenn Morris <rgm@gnu.org>
parents: 93975
diff changeset
21 ;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
29876
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
22
87087
d8ed6bf7f010 Require individual files if needed when compiling, rather than
Glenn Morris <rgm@gnu.org>
parents: 79345
diff changeset
23 ;;; Commentary:
d8ed6bf7f010 Require individual files if needed when compiling, rather than
Glenn Morris <rgm@gnu.org>
parents: 79345
diff changeset
24
101347
d1ba3386e97a Comment (header format fix).
Glenn Morris <rgm@gnu.org>
parents: 100908
diff changeset
25 ;;; Code:
d1ba3386e97a Comment (header format fix).
Glenn Morris <rgm@gnu.org>
parents: 100908
diff changeset
26
29876
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
27 (provide 'esh-proc)
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
28
87087
d8ed6bf7f010 Require individual files if needed when compiling, rather than
Glenn Morris <rgm@gnu.org>
parents: 79345
diff changeset
29 (eval-when-compile
d8ed6bf7f010 Require individual files if needed when compiling, rather than
Glenn Morris <rgm@gnu.org>
parents: 79345
diff changeset
30 (require 'eshell)
d8ed6bf7f010 Require individual files if needed when compiling, rather than
Glenn Morris <rgm@gnu.org>
parents: 79345
diff changeset
31 (require 'esh-util))
29876
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
32
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
33 (defgroup eshell-proc nil
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
34 "When Eshell invokes external commands, it always does so
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
35 asynchronously, so that Emacs isn't tied up waiting for the process to
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
36 finish."
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
37 :tag "Process management"
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
38 :group 'eshell)
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
39
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
40 ;;; User Variables:
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
41
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
42 (defcustom eshell-proc-load-hook '(eshell-proc-initialize)
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
43 "*A hook that gets run when `eshell-proc' is loaded."
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
44 :type 'hook
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
45 :group 'eshell-proc)
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
46
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
47 (defcustom eshell-process-wait-seconds 0
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
48 "*The number of seconds to delay waiting for a synchronous process."
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
49 :type 'integer
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
50 :group 'eshell-proc)
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
51
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
52 (defcustom eshell-process-wait-milliseconds 50
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
53 "*The number of milliseconds to delay waiting for a synchronous process."
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
54 :type 'integer
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
55 :group 'eshell-proc)
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
56
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
57 (defcustom eshell-done-messages-in-minibuffer t
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
58 "*If non-nil, subjob \"Done\" messages will display in minibuffer."
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
59 :type 'boolean
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
60 :group 'eshell-proc)
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
61
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
62 (defcustom eshell-delete-exited-processes t
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
63 "*If nil, process entries will stick around until `jobs' is run.
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
64 This variable sets the buffer-local value of `delete-exited-processes'
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
65 in Eshell buffers.
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
66
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
67 This variable causes Eshell to mimic the behavior of bash when set to
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
68 nil. It allows the user to view the exit status of a completed subjob
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
69 \(process) at their leisure, because the process entry remains in
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
70 memory until the user examines it using \\[list-processes].
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
71
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
72 Otherwise, if `eshell-done-messages-in-minibuffer' is nil, and this
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
73 variable is set to t, the only indication the user will have that a
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
74 subjob is done is that it will no longer appear in the
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
75 \\[list-processes\\] display.
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
76
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
77 Note that Eshell will have to be restarted for a change in this
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
78 variable's value to take effect."
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
79 :type 'boolean
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
80 :group 'eshell-proc)
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
81
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
82 (defcustom eshell-reset-signals
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
83 "^\\(interrupt\\|killed\\|quit\\|stopped\\)"
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
84 "*If a termination signal matches this regexp, the terminal will be reset."
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
85 :type 'regexp
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
86 :group 'eshell-proc)
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
87
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
88 (defcustom eshell-exec-hook nil
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
89 "*Called each time a process is exec'd by `eshell-gather-process-output'.
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
90 It is passed one argument, which is the process that was just started.
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
91 It is useful for things that must be done each time a process is
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
92 executed in a eshell mode buffer (e.g., `process-kill-without-query').
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
93 In contrast, `eshell-mode-hook' is only executed once when the buffer
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
94 is created."
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
95 :type 'hook
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
96 :group 'eshell-proc)
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
97
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
98 (defcustom eshell-kill-hook '(eshell-reset-after-proc)
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
99 "*Called when a process run by `eshell-gather-process-output' has ended.
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
100 It is passed two arguments: the process that was just ended, and the
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
101 termination status (as a string). Note that the first argument may be
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
102 nil, in which case the user attempted to send a signal, but there was
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
103 no relevant process. This can be used for displaying help
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
104 information, for example."
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
105 :type 'hook
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
106 :group 'eshell-proc)
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
107
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
108 ;;; Internal Variables:
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
109
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
110 (defvar eshell-current-subjob-p nil)
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
111
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
112 (defvar eshell-process-list nil
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
113 "A list of the current status of subprocesses.")
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
114
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
115 ;;; Functions:
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
116
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
117 (defun eshell-proc-initialize ()
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
118 "Initialize the process handling code."
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
119 (make-local-variable 'eshell-process-list)
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
120 (define-key eshell-command-map [(meta ?i)] 'eshell-insert-process)
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
121 (define-key eshell-command-map [(control ?c)] 'eshell-interrupt-process)
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
122 (define-key eshell-command-map [(control ?k)] 'eshell-kill-process)
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
123 (define-key eshell-command-map [(control ?d)] 'eshell-send-eof-to-process)
37658
f9277090a94a Disable `eshell-stop-process' and `eshell-continue-process', since
John Wiegley <johnw@newartisans.com>
parents: 32526
diff changeset
124 ; (define-key eshell-command-map [(control ?q)] 'eshell-continue-process)
29876
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
125 (define-key eshell-command-map [(control ?s)] 'list-processes)
37658
f9277090a94a Disable `eshell-stop-process' and `eshell-continue-process', since
John Wiegley <johnw@newartisans.com>
parents: 32526
diff changeset
126 ; (define-key eshell-command-map [(control ?z)] 'eshell-stop-process)
29876
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
127 (define-key eshell-command-map [(control ?\\)] 'eshell-quit-process))
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
128
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
129 (defun eshell-reset-after-proc (proc status)
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
130 "Reset the command input location after a process terminates.
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
131 The signals which will cause this to happen are matched by
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
132 `eshell-reset-signals'."
31241
3099993cba0f See ChangeLog
John Wiegley <johnw@newartisans.com>
parents: 29934
diff changeset
133 (if (and (stringp status)
3099993cba0f See ChangeLog
John Wiegley <johnw@newartisans.com>
parents: 29934
diff changeset
134 (string-match eshell-reset-signals status))
29876
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
135 (eshell-reset)))
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
136
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
137 (defun eshell-wait-for-process (&rest procs)
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
138 "Wait until PROC has successfully completed."
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
139 (while procs
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
140 (let ((proc (car procs)))
31241
3099993cba0f See ChangeLog
John Wiegley <johnw@newartisans.com>
parents: 29934
diff changeset
141 (when (eshell-processp proc)
29876
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
142 ;; NYI: If the process gets stopped here, that's bad.
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
143 (while (assq proc eshell-process-list)
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
144 (if (input-pending-p)
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
145 (discard-input))
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
146 (sit-for eshell-process-wait-seconds
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
147 eshell-process-wait-milliseconds))))
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
148 (setq procs (cdr procs))))
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
149
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
150 (defalias 'eshell/wait 'eshell-wait-for-process)
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
151
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
152 (defun eshell/jobs (&rest args)
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
153 "List processes, if there are any."
31241
3099993cba0f See ChangeLog
John Wiegley <johnw@newartisans.com>
parents: 29934
diff changeset
154 (and (fboundp 'process-list)
3099993cba0f See ChangeLog
John Wiegley <johnw@newartisans.com>
parents: 29934
diff changeset
155 (process-list)
29876
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
156 (list-processes)))
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
157
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
158 (defun eshell/kill (&rest args)
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
159 "Kill processes, buffers, symbol or files."
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
160 (let ((ptr args)
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
161 (signum 'SIGINT))
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
162 (while ptr
31241
3099993cba0f See ChangeLog
John Wiegley <johnw@newartisans.com>
parents: 29934
diff changeset
163 (if (or (eshell-processp (car ptr))
29876
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
164 (and (stringp (car ptr))
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
165 (string-match "^[A-Za-z/][A-Za-z0-9<>/]+$"
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
166 (car ptr))))
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
167 ;; What about when $lisp-variable is possible here?
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
168 ;; It could very well name a process.
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
169 (setcar ptr (get-process (car ptr))))
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
170 (setq ptr (cdr ptr)))
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
171 (while args
31241
3099993cba0f See ChangeLog
John Wiegley <johnw@newartisans.com>
parents: 29934
diff changeset
172 (let ((id (if (eshell-processp (car args))
29876
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
173 (process-id (car args))
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
174 (car args))))
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
175 (when id
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
176 (cond
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
177 ((null id)
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
178 (error "kill: bad signal spec"))
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
179 ((and (numberp id) (= id 0))
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
180 (error "kill: bad signal spec `%d'" id))
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
181 ((and (stringp id)
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
182 (string-match "^-?[0-9]+$" id))
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
183 (setq signum (abs (string-to-number id))))
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
184 ((stringp id)
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
185 (let (case-fold-search)
76798
95e8e1e8d4de (eshell/kill): Tweak regexp to recognize SIGUSR1 and SIGUSR2.
Chong Yidong <cyd@stupidchicken.com>
parents: 75346
diff changeset
186 (if (string-match "^-\\([A-Z]+[12]?\\)$" id)
29876
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
187 (setq signum
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
188 (intern (concat "SIG" (match-string 1 id))))
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
189 (error "kill: bad signal spec `%s'" id))))
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
190 ((< id 0)
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
191 (setq signum (abs id)))
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
192 (t
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
193 (signal-process id signum)))))
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
194 (setq args (cdr args)))
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
195 nil))
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
196
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
197 (defun eshell-read-process-name (prompt)
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
198 "Read the name of a process from the minibuffer, using completion.
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
199 The prompt will be set to PROMPT."
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
200 (completing-read prompt
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
201 (mapcar
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
202 (function
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
203 (lambda (proc)
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
204 (cons (process-name proc) t)))
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
205 (process-list)) nil t))
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
206
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
207 (defun eshell-insert-process (process)
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
208 "Insert the name of PROCESS into the current buffer at point."
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
209 (interactive
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
210 (list (get-process
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
211 (eshell-read-process-name "Name of process: "))))
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
212 (insert-and-inherit "#<process " (process-name process) ">"))
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
213
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
214 (defsubst eshell-record-process-object (object)
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
215 "Record OBJECT as now running."
31241
3099993cba0f See ChangeLog
John Wiegley <johnw@newartisans.com>
parents: 29934
diff changeset
216 (if (and (eshell-processp object)
29876
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
217 eshell-current-subjob-p)
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
218 (eshell-interactive-print
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
219 (format "[%s] %d\n" (process-name object) (process-id object))))
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
220 (setq eshell-process-list
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
221 (cons (list object eshell-current-handles
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
222 eshell-current-subjob-p nil nil)
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
223 eshell-process-list)))
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
224
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
225 (defun eshell-remove-process-entry (entry)
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
226 "Record the process ENTRY as fully completed."
31241
3099993cba0f See ChangeLog
John Wiegley <johnw@newartisans.com>
parents: 29934
diff changeset
227 (if (and (eshell-processp (car entry))
29876
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
228 (nth 2 entry)
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
229 eshell-done-messages-in-minibuffer)
65596
e188ae94d98b Correct my previous breakage of parens.
Deepak Goel <deego@gnufans.org>
parents: 65588
diff changeset
230 (message "[%s]+ Done %s" (process-name (car entry))
e188ae94d98b Correct my previous breakage of parens.
Deepak Goel <deego@gnufans.org>
parents: 65588
diff changeset
231 (process-command (car entry))))
29876
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
232 (setq eshell-process-list
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
233 (delq entry eshell-process-list)))
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
234
31241
3099993cba0f See ChangeLog
John Wiegley <johnw@newartisans.com>
parents: 29934
diff changeset
235 (defvar eshell-scratch-buffer " *eshell-scratch*"
3099993cba0f See ChangeLog
John Wiegley <johnw@newartisans.com>
parents: 29934
diff changeset
236 "Scratch buffer for holding Eshell's input/output.")
3099993cba0f See ChangeLog
John Wiegley <johnw@newartisans.com>
parents: 29934
diff changeset
237 (defvar eshell-last-sync-output-start nil
3099993cba0f See ChangeLog
John Wiegley <johnw@newartisans.com>
parents: 29934
diff changeset
238 "A marker that tracks the beginning of output of the last subprocess.
3099993cba0f See ChangeLog
John Wiegley <johnw@newartisans.com>
parents: 29934
diff changeset
239 Used only on systems which do not support async subprocesses.")
3099993cba0f See ChangeLog
John Wiegley <johnw@newartisans.com>
parents: 29934
diff changeset
240
100055
40edc7692997 (eshell-needs-pipe): New variable.
Glenn Morris <rgm@gnu.org>
parents: 99920
diff changeset
241 (defvar eshell-needs-pipe '("bc")
40edc7692997 (eshell-needs-pipe): New variable.
Glenn Morris <rgm@gnu.org>
parents: 99920
diff changeset
242 "List of commands which need `process-connection-type' to be nil.
40edc7692997 (eshell-needs-pipe): New variable.
Glenn Morris <rgm@gnu.org>
parents: 99920
diff changeset
243 Currently only affects commands in pipelines, and not those at
40edc7692997 (eshell-needs-pipe): New variable.
Glenn Morris <rgm@gnu.org>
parents: 99920
diff changeset
244 the front. If an element contains a directory part it must match
40edc7692997 (eshell-needs-pipe): New variable.
Glenn Morris <rgm@gnu.org>
parents: 99920
diff changeset
245 the full name of a command, otherwise just the nondirectory part must match.")
40edc7692997 (eshell-needs-pipe): New variable.
Glenn Morris <rgm@gnu.org>
parents: 99920
diff changeset
246
40edc7692997 (eshell-needs-pipe): New variable.
Glenn Morris <rgm@gnu.org>
parents: 99920
diff changeset
247 (defun eshell-needs-pipe-p (command)
40edc7692997 (eshell-needs-pipe): New variable.
Glenn Morris <rgm@gnu.org>
parents: 99920
diff changeset
248 "Return non-nil if COMMAND needs `process-connection-type' to be nil.
40edc7692997 (eshell-needs-pipe): New variable.
Glenn Morris <rgm@gnu.org>
parents: 99920
diff changeset
249 See `eshell-needs-pipe'."
40edc7692997 (eshell-needs-pipe): New variable.
Glenn Morris <rgm@gnu.org>
parents: 99920
diff changeset
250 (and eshell-in-pipeline-p
40edc7692997 (eshell-needs-pipe): New variable.
Glenn Morris <rgm@gnu.org>
parents: 99920
diff changeset
251 (not (eq eshell-in-pipeline-p 'first))
40edc7692997 (eshell-needs-pipe): New variable.
Glenn Morris <rgm@gnu.org>
parents: 99920
diff changeset
252 ;; FIXME should this return non-nil for anything that is
40edc7692997 (eshell-needs-pipe): New variable.
Glenn Morris <rgm@gnu.org>
parents: 99920
diff changeset
253 ;; neither 'first nor 'last? See bug#1388 discussion.
40edc7692997 (eshell-needs-pipe): New variable.
Glenn Morris <rgm@gnu.org>
parents: 99920
diff changeset
254 (catch 'found
40edc7692997 (eshell-needs-pipe): New variable.
Glenn Morris <rgm@gnu.org>
parents: 99920
diff changeset
255 (dolist (exe eshell-needs-pipe)
40edc7692997 (eshell-needs-pipe): New variable.
Glenn Morris <rgm@gnu.org>
parents: 99920
diff changeset
256 (if (string-equal exe (if (string-match "/" exe)
40edc7692997 (eshell-needs-pipe): New variable.
Glenn Morris <rgm@gnu.org>
parents: 99920
diff changeset
257 command
40edc7692997 (eshell-needs-pipe): New variable.
Glenn Morris <rgm@gnu.org>
parents: 99920
diff changeset
258 (file-name-nondirectory command)))
40edc7692997 (eshell-needs-pipe): New variable.
Glenn Morris <rgm@gnu.org>
parents: 99920
diff changeset
259 (throw 'found t))))))
40edc7692997 (eshell-needs-pipe): New variable.
Glenn Morris <rgm@gnu.org>
parents: 99920
diff changeset
260
29876
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
261 (defun eshell-gather-process-output (command args)
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
262 "Gather the output from COMMAND + ARGS."
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
263 (unless (and (file-executable-p command)
106219
16b061d2742d Improve handling of processes on remote hosts.
Michael Albinus <michael.albinus@gmx.de>
parents: 101347
diff changeset
264 (file-regular-p (file-truename command)))
29876
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
265 (error "%s: not an executable file" command))
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
266 (let* ((delete-exited-processes
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
267 (if eshell-current-subjob-p
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
268 eshell-delete-exited-processes
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
269 delete-exited-processes))
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
270 (process-environment (eshell-environment-variables))
31241
3099993cba0f See ChangeLog
John Wiegley <johnw@newartisans.com>
parents: 29934
diff changeset
271 proc decoding encoding changed)
3099993cba0f See ChangeLog
John Wiegley <johnw@newartisans.com>
parents: 29934
diff changeset
272 (cond
106219
16b061d2742d Improve handling of processes on remote hosts.
Michael Albinus <michael.albinus@gmx.de>
parents: 101347
diff changeset
273 ((fboundp 'start-file-process)
31241
3099993cba0f See ChangeLog
John Wiegley <johnw@newartisans.com>
parents: 29934
diff changeset
274 (setq proc
100055
40edc7692997 (eshell-needs-pipe): New variable.
Glenn Morris <rgm@gnu.org>
parents: 99920
diff changeset
275 (let ((process-connection-type
40edc7692997 (eshell-needs-pipe): New variable.
Glenn Morris <rgm@gnu.org>
parents: 99920
diff changeset
276 (unless (eshell-needs-pipe-p command)
106219
16b061d2742d Improve handling of processes on remote hosts.
Michael Albinus <michael.albinus@gmx.de>
parents: 101347
diff changeset
277 process-connection-type))
16b061d2742d Improve handling of processes on remote hosts.
Michael Albinus <michael.albinus@gmx.de>
parents: 101347
diff changeset
278 (command (or (file-remote-p command 'localname) command)))
16b061d2742d Improve handling of processes on remote hosts.
Michael Albinus <michael.albinus@gmx.de>
parents: 101347
diff changeset
279 (apply 'start-file-process
100055
40edc7692997 (eshell-needs-pipe): New variable.
Glenn Morris <rgm@gnu.org>
parents: 99920
diff changeset
280 (file-name-nondirectory command) nil
40edc7692997 (eshell-needs-pipe): New variable.
Glenn Morris <rgm@gnu.org>
parents: 99920
diff changeset
281 ;; `start-process' can't deal with relative filenames.
40edc7692997 (eshell-needs-pipe): New variable.
Glenn Morris <rgm@gnu.org>
parents: 99920
diff changeset
282 (append (list (expand-file-name command)) args))))
31241
3099993cba0f See ChangeLog
John Wiegley <johnw@newartisans.com>
parents: 29934
diff changeset
283 (eshell-record-process-object proc)
3099993cba0f See ChangeLog
John Wiegley <johnw@newartisans.com>
parents: 29934
diff changeset
284 (set-process-buffer proc (current-buffer))
3099993cba0f See ChangeLog
John Wiegley <johnw@newartisans.com>
parents: 29934
diff changeset
285 (if (eshell-interactive-output-p)
3099993cba0f See ChangeLog
John Wiegley <johnw@newartisans.com>
parents: 29934
diff changeset
286 (set-process-filter proc 'eshell-output-filter)
3099993cba0f See ChangeLog
John Wiegley <johnw@newartisans.com>
parents: 29934
diff changeset
287 (set-process-filter proc 'eshell-insertion-filter))
3099993cba0f See ChangeLog
John Wiegley <johnw@newartisans.com>
parents: 29934
diff changeset
288 (set-process-sentinel proc 'eshell-sentinel)
3099993cba0f See ChangeLog
John Wiegley <johnw@newartisans.com>
parents: 29934
diff changeset
289 (run-hook-with-args 'eshell-exec-hook proc)
3099993cba0f See ChangeLog
John Wiegley <johnw@newartisans.com>
parents: 29934
diff changeset
290 (when (fboundp 'process-coding-system)
3099993cba0f See ChangeLog
John Wiegley <johnw@newartisans.com>
parents: 29934
diff changeset
291 (let ((coding-systems (process-coding-system proc)))
3099993cba0f See ChangeLog
John Wiegley <johnw@newartisans.com>
parents: 29934
diff changeset
292 (setq decoding (car coding-systems)
3099993cba0f See ChangeLog
John Wiegley <johnw@newartisans.com>
parents: 29934
diff changeset
293 encoding (cdr coding-systems)))
3099993cba0f See ChangeLog
John Wiegley <johnw@newartisans.com>
parents: 29934
diff changeset
294 ;; If start-process decided to use some coding system for
3099993cba0f See ChangeLog
John Wiegley <johnw@newartisans.com>
parents: 29934
diff changeset
295 ;; decoding data sent from the process and the coding system
3099993cba0f See ChangeLog
John Wiegley <johnw@newartisans.com>
parents: 29934
diff changeset
296 ;; doesn't specify EOL conversion, we had better convert CRLF
3099993cba0f See ChangeLog
John Wiegley <johnw@newartisans.com>
parents: 29934
diff changeset
297 ;; to LF.
3099993cba0f See ChangeLog
John Wiegley <johnw@newartisans.com>
parents: 29934
diff changeset
298 (if (vectorp (coding-system-eol-type decoding))
3099993cba0f See ChangeLog
John Wiegley <johnw@newartisans.com>
parents: 29934
diff changeset
299 (setq decoding (coding-system-change-eol-conversion decoding 'dos)
3099993cba0f See ChangeLog
John Wiegley <johnw@newartisans.com>
parents: 29934
diff changeset
300 changed t))
3099993cba0f See ChangeLog
John Wiegley <johnw@newartisans.com>
parents: 29934
diff changeset
301 ;; Even if start-process left the coding system for encoding
3099993cba0f See ChangeLog
John Wiegley <johnw@newartisans.com>
parents: 29934
diff changeset
302 ;; data sent from the process undecided, we had better use the
3099993cba0f See ChangeLog
John Wiegley <johnw@newartisans.com>
parents: 29934
diff changeset
303 ;; same one as what we use for decoding. But, we should
3099993cba0f See ChangeLog
John Wiegley <johnw@newartisans.com>
parents: 29934
diff changeset
304 ;; suppress EOL conversion.
3099993cba0f See ChangeLog
John Wiegley <johnw@newartisans.com>
parents: 29934
diff changeset
305 (if (and decoding (not encoding))
3099993cba0f See ChangeLog
John Wiegley <johnw@newartisans.com>
parents: 29934
diff changeset
306 (setq encoding (coding-system-change-eol-conversion decoding 'unix)
3099993cba0f See ChangeLog
John Wiegley <johnw@newartisans.com>
parents: 29934
diff changeset
307 changed t))
3099993cba0f See ChangeLog
John Wiegley <johnw@newartisans.com>
parents: 29934
diff changeset
308 (if changed
3099993cba0f See ChangeLog
John Wiegley <johnw@newartisans.com>
parents: 29934
diff changeset
309 (set-process-coding-system proc decoding encoding))))
3099993cba0f See ChangeLog
John Wiegley <johnw@newartisans.com>
parents: 29934
diff changeset
310 (t
3099993cba0f See ChangeLog
John Wiegley <johnw@newartisans.com>
parents: 29934
diff changeset
311 ;; No async subprocesses...
3099993cba0f See ChangeLog
John Wiegley <johnw@newartisans.com>
parents: 29934
diff changeset
312 (let ((oldbuf (current-buffer))
3099993cba0f See ChangeLog
John Wiegley <johnw@newartisans.com>
parents: 29934
diff changeset
313 (interact-p (eshell-interactive-output-p))
3099993cba0f See ChangeLog
John Wiegley <johnw@newartisans.com>
parents: 29934
diff changeset
314 lbeg lend line proc-buf exit-status)
3099993cba0f See ChangeLog
John Wiegley <johnw@newartisans.com>
parents: 29934
diff changeset
315 (and (not (markerp eshell-last-sync-output-start))
3099993cba0f See ChangeLog
John Wiegley <johnw@newartisans.com>
parents: 29934
diff changeset
316 (setq eshell-last-sync-output-start (point-marker)))
3099993cba0f See ChangeLog
John Wiegley <johnw@newartisans.com>
parents: 29934
diff changeset
317 (setq proc-buf
3099993cba0f See ChangeLog
John Wiegley <johnw@newartisans.com>
parents: 29934
diff changeset
318 (set-buffer (get-buffer-create eshell-scratch-buffer)))
3099993cba0f See ChangeLog
John Wiegley <johnw@newartisans.com>
parents: 29934
diff changeset
319 (erase-buffer)
3099993cba0f See ChangeLog
John Wiegley <johnw@newartisans.com>
parents: 29934
diff changeset
320 (set-buffer oldbuf)
3099993cba0f See ChangeLog
John Wiegley <johnw@newartisans.com>
parents: 29934
diff changeset
321 (run-hook-with-args 'eshell-exec-hook command)
3099993cba0f See ChangeLog
John Wiegley <johnw@newartisans.com>
parents: 29934
diff changeset
322 (setq exit-status
3099993cba0f See ChangeLog
John Wiegley <johnw@newartisans.com>
parents: 29934
diff changeset
323 (apply 'call-process-region
3099993cba0f See ChangeLog
John Wiegley <johnw@newartisans.com>
parents: 29934
diff changeset
324 (append (list eshell-last-sync-output-start (point)
3099993cba0f See ChangeLog
John Wiegley <johnw@newartisans.com>
parents: 29934
diff changeset
325 command t
3099993cba0f See ChangeLog
John Wiegley <johnw@newartisans.com>
parents: 29934
diff changeset
326 eshell-scratch-buffer nil)
3099993cba0f See ChangeLog
John Wiegley <johnw@newartisans.com>
parents: 29934
diff changeset
327 args)))
3099993cba0f See ChangeLog
John Wiegley <johnw@newartisans.com>
parents: 29934
diff changeset
328 ;; When in a pipeline, record the place where the output of
3099993cba0f See ChangeLog
John Wiegley <johnw@newartisans.com>
parents: 29934
diff changeset
329 ;; this process will begin.
3099993cba0f See ChangeLog
John Wiegley <johnw@newartisans.com>
parents: 29934
diff changeset
330 (and eshell-in-pipeline-p
3099993cba0f See ChangeLog
John Wiegley <johnw@newartisans.com>
parents: 29934
diff changeset
331 (set-marker eshell-last-sync-output-start (point)))
3099993cba0f See ChangeLog
John Wiegley <johnw@newartisans.com>
parents: 29934
diff changeset
332 ;; Simulate the effect of the process filter.
3099993cba0f See ChangeLog
John Wiegley <johnw@newartisans.com>
parents: 29934
diff changeset
333 (when (numberp exit-status)
3099993cba0f See ChangeLog
John Wiegley <johnw@newartisans.com>
parents: 29934
diff changeset
334 (set-buffer proc-buf)
3099993cba0f See ChangeLog
John Wiegley <johnw@newartisans.com>
parents: 29934
diff changeset
335 (goto-char (point-min))
3099993cba0f See ChangeLog
John Wiegley <johnw@newartisans.com>
parents: 29934
diff changeset
336 (setq lbeg (point))
3099993cba0f See ChangeLog
John Wiegley <johnw@newartisans.com>
parents: 29934
diff changeset
337 (while (eq 0 (forward-line 1))
3099993cba0f See ChangeLog
John Wiegley <johnw@newartisans.com>
parents: 29934
diff changeset
338 (setq lend (point)
3099993cba0f See ChangeLog
John Wiegley <johnw@newartisans.com>
parents: 29934
diff changeset
339 line (buffer-substring-no-properties lbeg lend))
3099993cba0f See ChangeLog
John Wiegley <johnw@newartisans.com>
parents: 29934
diff changeset
340 (set-buffer oldbuf)
3099993cba0f See ChangeLog
John Wiegley <johnw@newartisans.com>
parents: 29934
diff changeset
341 (if interact-p
3099993cba0f See ChangeLog
John Wiegley <johnw@newartisans.com>
parents: 29934
diff changeset
342 (eshell-output-filter nil line)
3099993cba0f See ChangeLog
John Wiegley <johnw@newartisans.com>
parents: 29934
diff changeset
343 (eshell-output-object line))
3099993cba0f See ChangeLog
John Wiegley <johnw@newartisans.com>
parents: 29934
diff changeset
344 (setq lbeg lend)
3099993cba0f See ChangeLog
John Wiegley <johnw@newartisans.com>
parents: 29934
diff changeset
345 (set-buffer proc-buf))
3099993cba0f See ChangeLog
John Wiegley <johnw@newartisans.com>
parents: 29934
diff changeset
346 (set-buffer oldbuf))
3099993cba0f See ChangeLog
John Wiegley <johnw@newartisans.com>
parents: 29934
diff changeset
347 (eshell-update-markers eshell-last-output-end)
3099993cba0f See ChangeLog
John Wiegley <johnw@newartisans.com>
parents: 29934
diff changeset
348 ;; Simulate the effect of eshell-sentinel.
3099993cba0f See ChangeLog
John Wiegley <johnw@newartisans.com>
parents: 29934
diff changeset
349 (eshell-close-handles (if (numberp exit-status) exit-status -1))
3099993cba0f See ChangeLog
John Wiegley <johnw@newartisans.com>
parents: 29934
diff changeset
350 (run-hook-with-args 'eshell-kill-hook command exit-status)
3099993cba0f See ChangeLog
John Wiegley <johnw@newartisans.com>
parents: 29934
diff changeset
351 (or eshell-in-pipeline-p
3099993cba0f See ChangeLog
John Wiegley <johnw@newartisans.com>
parents: 29934
diff changeset
352 (setq eshell-last-sync-output-start nil))
3099993cba0f See ChangeLog
John Wiegley <johnw@newartisans.com>
parents: 29934
diff changeset
353 (if (not (numberp exit-status))
3099993cba0f See ChangeLog
John Wiegley <johnw@newartisans.com>
parents: 29934
diff changeset
354 (error "%s: external command failed: %s" command exit-status))
3099993cba0f See ChangeLog
John Wiegley <johnw@newartisans.com>
parents: 29934
diff changeset
355 (setq proc t))))
29876
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
356 proc))
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
357
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
358 (defun eshell-insertion-filter (proc string)
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
359 "Insert a string into the eshell buffer, or a process/file/buffer.
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
360 PROC is the process for which we're inserting output. STRING is the
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
361 output."
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
362 (when (buffer-live-p (process-buffer proc))
79345
5339903c5abe Johan Bockg? <bojohan at gnu.org>
Glenn Morris <rgm@gnu.org>
parents: 78220
diff changeset
363 (with-current-buffer (process-buffer proc)
5339903c5abe Johan Bockg? <bojohan at gnu.org>
Glenn Morris <rgm@gnu.org>
parents: 78220
diff changeset
364 (let ((entry (assq proc eshell-process-list)))
5339903c5abe Johan Bockg? <bojohan at gnu.org>
Glenn Morris <rgm@gnu.org>
parents: 78220
diff changeset
365 (when entry
5339903c5abe Johan Bockg? <bojohan at gnu.org>
Glenn Morris <rgm@gnu.org>
parents: 78220
diff changeset
366 (setcar (nthcdr 3 entry)
5339903c5abe Johan Bockg? <bojohan at gnu.org>
Glenn Morris <rgm@gnu.org>
parents: 78220
diff changeset
367 (concat (nth 3 entry) string))
5339903c5abe Johan Bockg? <bojohan at gnu.org>
Glenn Morris <rgm@gnu.org>
parents: 78220
diff changeset
368 (unless (nth 4 entry) ; already being handled?
5339903c5abe Johan Bockg? <bojohan at gnu.org>
Glenn Morris <rgm@gnu.org>
parents: 78220
diff changeset
369 (while (nth 3 entry)
5339903c5abe Johan Bockg? <bojohan at gnu.org>
Glenn Morris <rgm@gnu.org>
parents: 78220
diff changeset
370 (let ((data (nth 3 entry)))
5339903c5abe Johan Bockg? <bojohan at gnu.org>
Glenn Morris <rgm@gnu.org>
parents: 78220
diff changeset
371 (setcar (nthcdr 3 entry) nil)
5339903c5abe Johan Bockg? <bojohan at gnu.org>
Glenn Morris <rgm@gnu.org>
parents: 78220
diff changeset
372 (setcar (nthcdr 4 entry) t)
5339903c5abe Johan Bockg? <bojohan at gnu.org>
Glenn Morris <rgm@gnu.org>
parents: 78220
diff changeset
373 (eshell-output-object data nil (cadr entry))
5339903c5abe Johan Bockg? <bojohan at gnu.org>
Glenn Morris <rgm@gnu.org>
parents: 78220
diff changeset
374 (setcar (nthcdr 4 entry) nil)))))))))
29876
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
375
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
376 (defun eshell-sentinel (proc string)
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
377 "Generic sentinel for command processes. Reports only signals.
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
378 PROC is the process that's exiting. STRING is the exit message."
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
379 (when (buffer-live-p (process-buffer proc))
79345
5339903c5abe Johan Bockg? <bojohan at gnu.org>
Glenn Morris <rgm@gnu.org>
parents: 78220
diff changeset
380 (with-current-buffer (process-buffer proc)
5339903c5abe Johan Bockg? <bojohan at gnu.org>
Glenn Morris <rgm@gnu.org>
parents: 78220
diff changeset
381 (unwind-protect
5339903c5abe Johan Bockg? <bojohan at gnu.org>
Glenn Morris <rgm@gnu.org>
parents: 78220
diff changeset
382 (let* ((entry (assq proc eshell-process-list)))
5339903c5abe Johan Bockg? <bojohan at gnu.org>
Glenn Morris <rgm@gnu.org>
parents: 78220
diff changeset
383 ; (if (not entry)
5339903c5abe Johan Bockg? <bojohan at gnu.org>
Glenn Morris <rgm@gnu.org>
parents: 78220
diff changeset
384 ; (error "Sentinel called for unowned process `%s'"
5339903c5abe Johan Bockg? <bojohan at gnu.org>
Glenn Morris <rgm@gnu.org>
parents: 78220
diff changeset
385 ; (process-name proc))
5339903c5abe Johan Bockg? <bojohan at gnu.org>
Glenn Morris <rgm@gnu.org>
parents: 78220
diff changeset
386 (when entry
5339903c5abe Johan Bockg? <bojohan at gnu.org>
Glenn Morris <rgm@gnu.org>
parents: 78220
diff changeset
387 (unwind-protect
5339903c5abe Johan Bockg? <bojohan at gnu.org>
Glenn Morris <rgm@gnu.org>
parents: 78220
diff changeset
388 (progn
5339903c5abe Johan Bockg? <bojohan at gnu.org>
Glenn Morris <rgm@gnu.org>
parents: 78220
diff changeset
389 (unless (string= string "run")
5339903c5abe Johan Bockg? <bojohan at gnu.org>
Glenn Morris <rgm@gnu.org>
parents: 78220
diff changeset
390 (unless (string-match "^\\(finished\\|exited\\)" string)
5339903c5abe Johan Bockg? <bojohan at gnu.org>
Glenn Morris <rgm@gnu.org>
parents: 78220
diff changeset
391 (eshell-insertion-filter proc string))
5339903c5abe Johan Bockg? <bojohan at gnu.org>
Glenn Morris <rgm@gnu.org>
parents: 78220
diff changeset
392 (eshell-close-handles (process-exit-status proc) 'nil
5339903c5abe Johan Bockg? <bojohan at gnu.org>
Glenn Morris <rgm@gnu.org>
parents: 78220
diff changeset
393 (cadr entry))))
5339903c5abe Johan Bockg? <bojohan at gnu.org>
Glenn Morris <rgm@gnu.org>
parents: 78220
diff changeset
394 (eshell-remove-process-entry entry))))
5339903c5abe Johan Bockg? <bojohan at gnu.org>
Glenn Morris <rgm@gnu.org>
parents: 78220
diff changeset
395 (run-hook-with-args 'eshell-kill-hook proc string)))))
29876
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
396
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
397 (defun eshell-process-interact (func &optional all query)
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
398 "Interact with a process, using PROMPT if more than one, via FUNC.
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
399 If ALL is non-nil, background processes will be interacted with as well.
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
400 If QUERY is non-nil, query the user with QUERY before calling FUNC."
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
401 (let (defunct result)
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
402 (eshell-for entry eshell-process-list
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
403 (if (and (memq (process-status (car entry))
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
404 '(run stop open closed))
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
405 (or all
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
406 (not (nth 2 entry)))
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
407 (or (not query)
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
408 (y-or-n-p (format query (process-name (car entry))))))
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
409 (setq result (funcall func (car entry))))
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
410 (unless (memq (process-status (car entry))
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
411 '(run stop open closed))
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
412 (setq defunct (cons entry defunct))))
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
413 ;; clean up the process list; this can get dirty if an error
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
414 ;; occurred that brought the user into the debugger, and then they
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
415 ;; quit, so that the sentinel was never called.
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
416 (eshell-for d defunct
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
417 (eshell-remove-process-entry d))
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
418 result))
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
419
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
420 (defcustom eshell-kill-process-wait-time 5
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
421 "*Seconds to wait between sending termination signals to a subprocess."
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
422 :type 'integer
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
423 :group 'eshell-proc)
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
424
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
425 (defcustom eshell-kill-process-signals '(SIGINT SIGQUIT SIGKILL)
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
426 "*Signals used to kill processes when an Eshell buffer exits.
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
427 Eshell calls each of these signals in order when an Eshell buffer is
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
428 killed; if the process is still alive afterwards, Eshell waits a
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
429 number of seconds defined by `eshell-kill-process-wait-time', and
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
430 tries the next signal in the list."
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
431 :type '(repeat symbol)
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
432 :group 'eshell-proc)
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
433
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
434 (defcustom eshell-kill-processes-on-exit nil
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
435 "*If non-nil, kill active processes when exiting an Eshell buffer.
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
436 Emacs will only kill processes owned by that Eshell buffer.
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
437
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
438 If nil, ownership of background and foreground processes reverts to
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
439 Emacs itself, and will die only if the user exits Emacs, calls
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
440 `kill-process', or terminates the processes externally.
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
441
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
442 If `ask', Emacs prompts the user before killing any processes.
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
443
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
444 If `every', it prompts once for every process.
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
445
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
446 If t, it kills all buffer-owned processes without asking.
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
447
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
448 Processes are first sent SIGHUP, then SIGINT, then SIGQUIT, then
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
449 SIGKILL. The variable `eshell-kill-process-wait-time' specifies how
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
450 long to delay between signals."
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
451 :type '(choice (const :tag "Kill all, don't ask" t)
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
452 (const :tag "Ask before killing" ask)
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
453 (const :tag "Ask for each process" every)
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
454 (const :tag "Don't kill subprocesses" nil))
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
455 :group 'eshell-proc)
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
456
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
457 (defun eshell-round-robin-kill (&optional query)
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
458 "Kill current process by trying various signals in sequence.
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
459 See the variable `eshell-kill-processes-on-exit'."
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
460 (let ((sigs eshell-kill-process-signals))
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
461 (while sigs
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
462 (eshell-process-interact
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
463 (function
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
464 (lambda (proc)
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
465 (signal-process (process-id proc) (car sigs)))) t query)
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
466 (setq query nil)
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
467 (if (not eshell-process-list)
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
468 (setq sigs nil)
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
469 (sleep-for eshell-kill-process-wait-time)
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
470 (setq sigs (cdr sigs))))))
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
471
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
472 (defun eshell-query-kill-processes ()
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
473 "Kill processes belonging to the current Eshell buffer, possibly w/ query."
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
474 (when (and eshell-kill-processes-on-exit
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
475 eshell-process-list)
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
476 (save-window-excursion
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
477 (list-processes)
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
478 (if (or (not (eq eshell-kill-processes-on-exit 'ask))
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
479 (y-or-n-p (format "Kill processes owned by `%s'? "
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
480 (buffer-name))))
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
481 (eshell-round-robin-kill
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
482 (if (eq eshell-kill-processes-on-exit 'every)
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
483 "Kill Eshell child process `%s'? ")))
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
484 (let ((buf (get-buffer "*Process List*")))
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
485 (if (and buf (buffer-live-p buf))
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
486 (kill-buffer buf)))
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
487 (message nil))))
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
488
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
489 (custom-add-option 'eshell-exit-hook 'eshell-query-kill-processes)
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
490
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
491 (defun eshell-interrupt-process ()
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
492 "Interrupt a process."
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
493 (interactive)
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
494 (unless (eshell-process-interact 'interrupt-process)
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
495 (run-hook-with-args 'eshell-kill-hook nil "interrupt")))
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
496
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
497 (defun eshell-kill-process ()
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
498 "Kill a process."
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
499 (interactive)
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
500 (unless (eshell-process-interact 'kill-process)
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
501 (run-hook-with-args 'eshell-kill-hook nil "killed")))
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
502
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
503 (defun eshell-quit-process ()
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
504 "Send quit signal to process."
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
505 (interactive)
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
506 (unless (eshell-process-interact 'quit-process)
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
507 (run-hook-with-args 'eshell-kill-hook nil "quit")))
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
508
37658
f9277090a94a Disable `eshell-stop-process' and `eshell-continue-process', since
John Wiegley <johnw@newartisans.com>
parents: 32526
diff changeset
509 ;(defun eshell-stop-process ()
f9277090a94a Disable `eshell-stop-process' and `eshell-continue-process', since
John Wiegley <johnw@newartisans.com>
parents: 32526
diff changeset
510 ; "Send STOP signal to process."
f9277090a94a Disable `eshell-stop-process' and `eshell-continue-process', since
John Wiegley <johnw@newartisans.com>
parents: 32526
diff changeset
511 ; (interactive)
f9277090a94a Disable `eshell-stop-process' and `eshell-continue-process', since
John Wiegley <johnw@newartisans.com>
parents: 32526
diff changeset
512 ; (unless (eshell-process-interact 'stop-process)
f9277090a94a Disable `eshell-stop-process' and `eshell-continue-process', since
John Wiegley <johnw@newartisans.com>
parents: 32526
diff changeset
513 ; (run-hook-with-args 'eshell-kill-hook nil "stopped")))
29876
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
514
37658
f9277090a94a Disable `eshell-stop-process' and `eshell-continue-process', since
John Wiegley <johnw@newartisans.com>
parents: 32526
diff changeset
515 ;(defun eshell-continue-process ()
f9277090a94a Disable `eshell-stop-process' and `eshell-continue-process', since
John Wiegley <johnw@newartisans.com>
parents: 32526
diff changeset
516 ; "Send CONTINUE signal to process."
f9277090a94a Disable `eshell-stop-process' and `eshell-continue-process', since
John Wiegley <johnw@newartisans.com>
parents: 32526
diff changeset
517 ; (interactive)
f9277090a94a Disable `eshell-stop-process' and `eshell-continue-process', since
John Wiegley <johnw@newartisans.com>
parents: 32526
diff changeset
518 ; (unless (eshell-process-interact 'continue-process)
f9277090a94a Disable `eshell-stop-process' and `eshell-continue-process', since
John Wiegley <johnw@newartisans.com>
parents: 32526
diff changeset
519 ; ;; jww (1999-09-17): this signal is not dealt with yet. For
f9277090a94a Disable `eshell-stop-process' and `eshell-continue-process', since
John Wiegley <johnw@newartisans.com>
parents: 32526
diff changeset
520 ; ;; example, `eshell-reset' will be called, and so will
f9277090a94a Disable `eshell-stop-process' and `eshell-continue-process', since
John Wiegley <johnw@newartisans.com>
parents: 32526
diff changeset
521 ; ;; `eshell-resume-eval'.
f9277090a94a Disable `eshell-stop-process' and `eshell-continue-process', since
John Wiegley <johnw@newartisans.com>
parents: 32526
diff changeset
522 ; (run-hook-with-args 'eshell-kill-hook nil "continue")))
29876
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
523
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
524 (defun eshell-send-eof-to-process ()
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
525 "Send EOF to process."
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
526 (interactive)
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
527 (eshell-send-input nil nil t)
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
528 (eshell-process-interact 'process-send-eof))
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
529
93975
1e3a407766b9 Fix up comment convention on the arch-tag lines.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 87649
diff changeset
530 ;; arch-tag: ac477a3e-ee4d-4b44-8ec6-212010e607bb
29876
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
531 ;;; esh-proc.el ends here