* eshell/esh-var.el (eshell-variable-aliases-list): Fix doc typo.
[bpt/emacs.git] / lisp / eshell / esh-proc.el
index f510f4b..e77287c 100644 (file)
@@ -1,6 +1,6 @@
-;;; esh-proc.el --- process management
+;;; esh-proc.el --- process management  -*- lexical-binding:t -*-
 
-;; Copyright (C) 1999-201 Free Software Foundation, Inc.
+;; Copyright (C) 1999-2013 Free Software Foundation, Inc.
 
 ;; Author: John Wiegley <johnw@gnu.org>
 
@@ -25,9 +25,7 @@
 
 (provide 'esh-proc)
 
-(eval-when-compile
-  (require 'eshell)
-  (require 'esh-util))
+(require 'esh-cmd)
 
 (defgroup eshell-proc nil
   "When Eshell invokes external commands, it always does so
@@ -165,43 +163,38 @@ The signals which will cause this to happen are matched by
        (list-processes)))
 
 (defun eshell/kill (&rest args)
-  "Kill processes, buffers, symbol or files."
-  (let ((ptr args)
-       (signum 'SIGINT))
-    (while ptr
-      (if (or (eshell-processp (car ptr))
-             (and (stringp (car ptr))
-                  (string-match "^[A-Za-z/][A-Za-z0-9<>/]+$"
-                                (car ptr))))
-         ;; What about when $lisp-variable is possible here?
-         ;; It could very well name a process.
-         (setcar ptr (get-process (car ptr))))
-      (setq ptr (cdr ptr)))
+  "Kill processes.
+Usage: kill [-<signal>] <pid>|<process> ...
+Accepts PIDs and process objects."
+  ;; If the first argument starts with a dash, treat it as the signal
+  ;; specifier.
+  (let ((signum 'SIGINT))
+    (let ((arg (car args))
+          (case-fold-search nil))
+      (when (stringp arg)
+        (cond
+         ((string-match "\\`-[[:digit:]]+\\'" arg)
+          (setq signum (abs (string-to-number arg))))
+         ((string-match "\\`-\\([[:upper:]]+\\|[[:lower:]]+\\)\\'" arg)
+          (setq signum (abs (string-to-number arg)))))
+        (setq args (cdr args))))
     (while args
-      (let ((id (if (eshell-processp (car args))
-                   (process-id (car args))
-                 (car args))))
-       (when id
-         (cond
-          ((null id)
-           (error "kill: bad signal spec"))
-          ((and (numberp id) (= id 0))
-           (error "kill: bad signal spec `%d'" id))
-          ((and (stringp id)
-                (string-match "^-?[0-9]+$" id))
-           (setq signum (abs (string-to-number id))))
-          ((stringp id)
-           (let (case-fold-search)
-             (if (string-match "^-\\([A-Z]+[12]?\\)$" id)
-                 (setq signum
-                       (intern (concat "SIG" (match-string 1 id))))
-               (error "kill: bad signal spec `%s'" id))))
-          ((< id 0)
-           (setq signum (abs id)))
-          (t
-           (signal-process id signum)))))
-      (setq args (cdr args)))
-    nil))
+      (let ((arg (if (eshell-processp (car args))
+                     (process-id (car args))
+                   (car args))))
+        (when arg
+          (cond
+           ((null arg)
+            (error "kill: null pid.  Process may actually be a network connection."))
+           ((not (numberp arg))
+            (error "kill: invalid argument type: %s" (type-of arg)))
+           ((and (numberp arg)
+                 (<= arg 0))
+            (error "kill: bad pid: %d" arg))
+           (t
+            (signal-process arg signum)))))
+      (setq args (cdr args))))
+  nil)
 
 (defun eshell-read-process-name (prompt)
   "Read the name of a process from the minibuffer, using completion.