Mercurial > emacs
comparison lisp/eshell/esh-cmd.el @ 88155:d7ddb3e565de
sync with trunk
author | Henrik Enberg <henrik.enberg@telia.com> |
---|---|
date | Mon, 16 Jan 2006 00:03:54 +0000 |
parents | ea69593b3b09 |
children |
comparison
equal
deleted
inserted
replaced
88154:8ce476d3ba36 | 88155:d7ddb3e565de |
---|---|
1 ;;; esh-cmd.el --- command invocation | 1 ;;; esh-cmd.el --- command invocation |
2 | 2 |
3 ;; Copyright (C) 1999, 2000 Free Software Foundation | 3 ;; Copyright (C) 1999, 2000, 2002, 2003, 2004, |
4 ;; 2005 Free Software Foundation, Inc. | |
4 | 5 |
5 ;; Author: John Wiegley <johnw@gnu.org> | 6 ;; Author: John Wiegley <johnw@gnu.org> |
6 | 7 |
7 ;; This file is part of GNU Emacs. | 8 ;; This file is part of GNU Emacs. |
8 | 9 |
16 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | 17 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
17 ;; GNU General Public License for more details. | 18 ;; GNU General Public License for more details. |
18 | 19 |
19 ;; You should have received a copy of the GNU General Public License | 20 ;; You should have received a copy of the GNU General Public License |
20 ;; along with GNU Emacs; see the file COPYING. If not, write to the | 21 ;; along with GNU Emacs; see the file COPYING. If not, write to the |
21 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330, | 22 ;; Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, |
22 ;; Boston, MA 02111-1307, USA. | 23 ;; Boston, MA 02110-1301, USA. |
23 | 24 |
24 (provide 'esh-cmd) | 25 (provide 'esh-cmd) |
25 | 26 |
26 (eval-when-compile (require 'esh-maint)) | 27 (eval-when-compile (require 'esh-maint)) |
27 | 28 |
28 (defgroup eshell-cmd nil | 29 (defgroup eshell-cmd nil |
29 "Executing an Eshell command is as simple as typing it in and | 30 "Executing an Eshell command is as simple as typing it in and |
30 pressing <RET>. There are several different kinds of commands, | 31 pressing <RET>. There are several different kinds of commands, |
31 however." | 32 however." |
32 :tag "Command invocation" | 33 :tag "Command invocation" |
33 :link '(info-link "(eshell)Command invocation") | 34 ;; :link '(info-link "(eshell)Command invocation") |
34 :group 'eshell) | 35 :group 'eshell) |
35 | 36 |
36 ;;; Commentary: | 37 ;;; Commentary: |
37 | 38 |
38 ;;;_* Invoking external commands | 39 ;;;_* Invoking external commands |
450 "Run subcommand + Lisp form" | 451 "Run subcommand + Lisp form" |
451 (eshell-command-result-p "{(+ 1 2)}" "3\n")) | 452 (eshell-command-result-p "{(+ 1 2)}" "3\n")) |
452 | 453 |
453 (defun eshell-rewrite-named-command (terms) | 454 (defun eshell-rewrite-named-command (terms) |
454 "If no other rewriting rule transforms TERMS, assume a named command." | 455 "If no other rewriting rule transforms TERMS, assume a named command." |
455 (list (if eshell-in-pipeline-p | 456 (let ((sym (if eshell-in-pipeline-p |
456 'eshell-named-command* | 457 'eshell-named-command* |
457 'eshell-named-command) | 458 'eshell-named-command)) |
458 (car terms) | 459 (cmd (car terms)) |
459 (and (cdr terms) | 460 (args (cdr terms))) |
460 (append (list 'list) (cdr terms))))) | 461 (if args |
462 (list sym cmd (append (list 'list) (cdr terms))) | |
463 (list sym cmd)))) | |
461 | 464 |
462 (eshell-deftest cmd named-command | 465 (eshell-deftest cmd named-command |
463 "Execute named command" | 466 "Execute named command" |
464 (eshell-command-result-p "+ 1 2" "3\n")) | 467 (eshell-command-result-p "+ 1 2" "3\n")) |
465 | 468 |
755 ;; need to change them. Change them directly only if your intention | 758 ;; need to change them. Change them directly only if your intention |
756 ;; is to change the calling environment. | 759 ;; is to change the calling environment. |
757 | 760 |
758 (defmacro eshell-do-subjob (object) | 761 (defmacro eshell-do-subjob (object) |
759 "Evaluate a command OBJECT as a subjob. | 762 "Evaluate a command OBJECT as a subjob. |
760 We indicate thet the process was run in the background by returned it | 763 We indicate that the process was run in the background by returning it |
761 ensconced in a list." | 764 ensconced in a list." |
762 `(let ((eshell-current-subjob-p t)) | 765 `(let ((eshell-current-subjob-p t)) |
763 ,object)) | 766 ,object)) |
764 | 767 |
765 (defmacro eshell-commands (object &optional silent) | 768 (defmacro eshell-commands (object &optional silent) |
1004 (setq eshell-current-command command) | 1007 (setq eshell-current-command command) |
1005 (let ((delim (catch 'eshell-incomplete | 1008 (let ((delim (catch 'eshell-incomplete |
1006 (eshell-resume-eval)))) | 1009 (eshell-resume-eval)))) |
1007 ;; On systems that don't support async subprocesses, eshell-resume | 1010 ;; On systems that don't support async subprocesses, eshell-resume |
1008 ;; can return t. Don't treat that as an error. | 1011 ;; can return t. Don't treat that as an error. |
1012 (if (listp delim) | |
1013 (setq delim (car delim))) | |
1009 (if (and delim (not (eq delim t))) | 1014 (if (and delim (not (eq delim t))) |
1010 (error "Unmatched delimiter: %c" | 1015 (error "Unmatched delimiter: %c" delim))))) |
1011 (if (listp delim) | |
1012 (car delim) | |
1013 delim)))))) | |
1014 | 1016 |
1015 (defun eshell-resume-command (proc status) | 1017 (defun eshell-resume-command (proc status) |
1016 "Resume the current command when a process ends." | 1018 "Resume the current command when a process ends." |
1017 (when proc | 1019 (when proc |
1018 (unless (or (not (stringp status)) | 1020 (unless (or (not (stringp status)) |
1244 (cadr alias) "\""))) | 1246 (cadr alias) "\""))) |
1245 (unless program | 1247 (unless program |
1246 (setq program (eshell-search-path name)) | 1248 (setq program (eshell-search-path name)) |
1247 (let* ((esym (eshell-find-alias-function name)) | 1249 (let* ((esym (eshell-find-alias-function name)) |
1248 (sym (or esym (intern-soft name)))) | 1250 (sym (or esym (intern-soft name)))) |
1249 (if (and sym (fboundp sym) | 1251 (if (and (or esym (and sym (fboundp sym))) |
1250 (or esym eshell-prefer-lisp-functions | 1252 (or eshell-prefer-lisp-functions (not direct))) |
1251 (not program))) | |
1252 (let ((desc (let ((inhibit-redisplay t)) | 1253 (let ((desc (let ((inhibit-redisplay t)) |
1253 (save-window-excursion | 1254 (save-window-excursion |
1254 (prog1 | 1255 (prog1 |
1255 (describe-function sym) | 1256 (describe-function sym) |
1256 (message nil)))))) | 1257 (message nil)))))) |
1284 (defalias 'eshell-named-command* 'eshell-named-command) | 1285 (defalias 'eshell-named-command* 'eshell-named-command) |
1285 | 1286 |
1286 (defun eshell-find-alias-function (name) | 1287 (defun eshell-find-alias-function (name) |
1287 "Check whether a function called `eshell/NAME' exists." | 1288 "Check whether a function called `eshell/NAME' exists." |
1288 (let* ((sym (intern-soft (concat "eshell/" name))) | 1289 (let* ((sym (intern-soft (concat "eshell/" name))) |
1289 (file (symbol-file sym))) | 1290 (file (symbol-file sym 'defun))) |
1290 ;; If the function exists, but is defined in an eshell module | 1291 ;; If the function exists, but is defined in an eshell module |
1291 ;; that's not currently enabled, don't report it as found | 1292 ;; that's not currently enabled, don't report it as found |
1292 (if (and file | 1293 (if (and file |
1293 (string-match "\\(em\\|esh\\)-\\(.*\\)\\(\\.el\\)?\\'" file)) | 1294 (string-match "\\(em\\|esh\\)-\\(.*\\)\\(\\.el\\)?\\'" file)) |
1294 (let ((module-sym | 1295 (let ((module-sym |
1398 (unless (get object 'eshell-no-numeric-conversions) | 1399 (unless (get object 'eshell-no-numeric-conversions) |
1399 (while args | 1400 (while args |
1400 (let ((arg (car args))) | 1401 (let ((arg (car args))) |
1401 (if (and (stringp arg) | 1402 (if (and (stringp arg) |
1402 (> (length arg) 0) | 1403 (> (length arg) 0) |
1403 (get-text-property 0 'number arg)) | 1404 (not (text-property-not-all |
1405 0 (length arg) 'number t arg))) | |
1404 (setcar args (string-to-number arg)))) | 1406 (setcar args (string-to-number arg)))) |
1405 (setq args (cdr args)))) | 1407 (setq args (cdr args)))) |
1406 (eshell-apply object eshell-last-arguments)) | 1408 (eshell-apply object eshell-last-arguments)) |
1407 (setq eshell-last-arguments args | 1409 (setq eshell-last-arguments args |
1408 eshell-last-command-name "#<Lisp object>") | 1410 eshell-last-command-name "#<Lisp object>") |
1414 (eshell-print "\n")) | 1416 (eshell-print "\n")) |
1415 (eshell-close-handles 0 (list 'quote result))))) | 1417 (eshell-close-handles 0 (list 'quote result))))) |
1416 | 1418 |
1417 (defalias 'eshell-lisp-command* 'eshell-lisp-command) | 1419 (defalias 'eshell-lisp-command* 'eshell-lisp-command) |
1418 | 1420 |
1421 ;;; arch-tag: 8e4f3867-a0c5-441f-96ba-ddd142d94366 | |
1419 ;;; esh-cmd.el ends here | 1422 ;;; esh-cmd.el ends here |