annotate lisp/eshell/esh-cmd.el @ 112438:11f1b4757236

* image.c (x_create_bitmap_from_xpm_data): Add cast to fix type clash when calling XpmCreatePixmapFromData.
author Paul Eggert <eggert@cs.ucla.edu>
date Sat, 22 Jan 2011 20:33:12 -0800
parents ef719132ddfa
children
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: 38007
diff changeset
1 ;;; esh-cmd.el --- command invocation
29873
b0bbf97625c2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
2
95619
45dbb3c749a6 Remove unnecessary eval-when-compiles and eval-and-compiles.
Glenn Morris <rgm@gnu.org>
parents: 94661
diff changeset
3 ;; Copyright (C) 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007,
112218
376148b31b5e Add 2011 to FSF/AIST copyright years.
Glenn Morris <rgm@gnu.org>
parents: 106815
diff changeset
4 ;; 2008, 2009, 2010, 2011 Free Software Foundation, Inc.
29873
b0bbf97625c2 *** 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
29873
b0bbf97625c2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
8 ;; This file is part of GNU Emacs.
b0bbf97625c2 *** 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
29873
b0bbf97625c2 *** 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.
29873
b0bbf97625c2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
14
b0bbf97625c2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
15 ;; GNU Emacs is distributed in the hope that it will be useful,
b0bbf97625c2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
16 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
b0bbf97625c2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
17 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
b0bbf97625c2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
18 ;; GNU General Public License for more details.
b0bbf97625c2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
19
b0bbf97625c2 *** 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/>.
29873
b0bbf97625c2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
22
b0bbf97625c2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
23 ;;; Commentary:
b0bbf97625c2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
24
b0bbf97625c2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
25 ;;;_* Invoking external commands
b0bbf97625c2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
26 ;;
b0bbf97625c2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
27 ;; External commands cause processes to be created, by loading
b0bbf97625c2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
28 ;; external executables into memory. This is what most normal shells
b0bbf97625c2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
29 ;; do, most of the time. For more information, see [External commands].
b0bbf97625c2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
30 ;;
b0bbf97625c2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
31 ;;;_* Invoking Lisp functions
b0bbf97625c2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
32 ;;
b0bbf97625c2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
33 ;; A Lisp function can be invoked using Lisp syntax, or command shell
b0bbf97625c2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
34 ;; syntax. For example, to run `dired' to edit the current directory:
b0bbf97625c2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
35 ;;
b0bbf97625c2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
36 ;; /tmp $ (dired ".")
b0bbf97625c2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
37 ;;
b0bbf97625c2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
38 ;; Or:
b0bbf97625c2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
39 ;;
b0bbf97625c2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
40 ;; /tmp $ dired .
b0bbf97625c2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
41 ;;
b0bbf97625c2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
42 ;; The latter form is preferable, but the former is more precise,
b0bbf97625c2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
43 ;; since it involves no translations. See [Argument parsing], to
b0bbf97625c2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
44 ;; learn more about how arguments are transformed before passing them
b0bbf97625c2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
45 ;; to commands.
b0bbf97625c2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
46 ;;
b0bbf97625c2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
47 ;; Ordinarily, if 'dired' were also available as an external command,
b0bbf97625c2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
48 ;; the external version would be called in preference to any Lisp
b0bbf97625c2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
49 ;; function of the same name. To change this behavior so that Lisp
b0bbf97625c2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
50 ;; functions always take precedence, set
b0bbf97625c2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
51 ;; `eshell-prefer-lisp-functions' to t.
b0bbf97625c2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
52
b0bbf97625c2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
53 ;;;_* Alias functions
b0bbf97625c2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
54 ;;
b0bbf97625c2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
55 ;; Whenever a command is specified using a simple name, such as 'ls',
b0bbf97625c2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
56 ;; Eshell will first look for a Lisp function of the name `eshell/ls'.
b0bbf97625c2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
57 ;; If it exists, it will be called in preference to any other command
b0bbf97625c2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
58 ;; which might have matched the name 'ls' (such as command aliases,
b0bbf97625c2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
59 ;; external commands, Lisp functions of that name, etc).
b0bbf97625c2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
60 ;;
b0bbf97625c2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
61 ;; This is the most flexible mechanism for creating new commands,
b0bbf97625c2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
62 ;; since it does not pollute the global namespace, yet allows you to
b0bbf97625c2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
63 ;; use all of Lisp's facilities to define that piece of functionality.
b0bbf97625c2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
64 ;; Most of Eshell's "builtin" commands are defined as alias functions.
b0bbf97625c2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
65 ;;
b0bbf97625c2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
66 ;;;_* Lisp arguments
b0bbf97625c2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
67 ;;
b0bbf97625c2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
68 ;; It is possible to invoke a Lisp form as an argument. This can be
b0bbf97625c2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
69 ;; done either by specifying the form as you might in Lisp, or by
b0bbf97625c2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
70 ;; using the '$' character to introduce a value-interpolation:
b0bbf97625c2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
71 ;;
b0bbf97625c2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
72 ;; echo (+ 1 2)
b0bbf97625c2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
73 ;;
b0bbf97625c2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
74 ;; Or
b0bbf97625c2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
75 ;;
b0bbf97625c2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
76 ;; echo $(+ 1 2)
b0bbf97625c2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
77 ;;
b0bbf97625c2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
78 ;; The two forms are equivalent. The second is required only if the
b0bbf97625c2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
79 ;; form being interpolated is within a string, or is a subexpression
b0bbf97625c2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
80 ;; of a larger argument:
b0bbf97625c2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
81 ;;
b0bbf97625c2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
82 ;; echo x$(+ 1 2) "String $(+ 1 2)"
b0bbf97625c2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
83 ;;
b0bbf97625c2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
84 ;; To pass a Lisp symbol as a argument, use the alternate quoting
b0bbf97625c2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
85 ;; syntax, since the single quote character is far too overused in
b0bbf97625c2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
86 ;; shell syntax:
b0bbf97625c2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
87 ;;
b0bbf97625c2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
88 ;; echo #'lisp-symbol
b0bbf97625c2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
89 ;;
b0bbf97625c2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
90 ;; Backquote can also be used:
b0bbf97625c2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
91 ;;
b0bbf97625c2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
92 ;; echo `(list ,lisp-symbol)
b0bbf97625c2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
93 ;;
b0bbf97625c2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
94 ;; Lisp arguments are identified using the following regexp:
b0bbf97625c2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
95
87079
c1197dc2780b Require individual files if needed when compiling, rather than
Glenn Morris <rgm@gnu.org>
parents: 86202
diff changeset
96 ;;;_* Command hooks
c1197dc2780b Require individual files if needed when compiling, rather than
Glenn Morris <rgm@gnu.org>
parents: 86202
diff changeset
97 ;;
c1197dc2780b Require individual files if needed when compiling, rather than
Glenn Morris <rgm@gnu.org>
parents: 86202
diff changeset
98 ;; There are several hooks involved with command execution, which can
c1197dc2780b Require individual files if needed when compiling, rather than
Glenn Morris <rgm@gnu.org>
parents: 86202
diff changeset
99 ;; be used either to change or augment Eshell's behavior.
c1197dc2780b Require individual files if needed when compiling, rather than
Glenn Morris <rgm@gnu.org>
parents: 86202
diff changeset
100
c1197dc2780b Require individual files if needed when compiling, rather than
Glenn Morris <rgm@gnu.org>
parents: 86202
diff changeset
101
c1197dc2780b Require individual files if needed when compiling, rather than
Glenn Morris <rgm@gnu.org>
parents: 86202
diff changeset
102 ;;; Code:
c1197dc2780b Require individual files if needed when compiling, rather than
Glenn Morris <rgm@gnu.org>
parents: 86202
diff changeset
103
c1197dc2780b Require individual files if needed when compiling, rather than
Glenn Morris <rgm@gnu.org>
parents: 86202
diff changeset
104 (require 'esh-util)
c1197dc2780b Require individual files if needed when compiling, rather than
Glenn Morris <rgm@gnu.org>
parents: 86202
diff changeset
105 (unless (featurep 'xemacs)
c1197dc2780b Require individual files if needed when compiling, rather than
Glenn Morris <rgm@gnu.org>
parents: 86202
diff changeset
106 (require 'eldoc))
c1197dc2780b Require individual files if needed when compiling, rather than
Glenn Morris <rgm@gnu.org>
parents: 86202
diff changeset
107 (require 'esh-arg)
c1197dc2780b Require individual files if needed when compiling, rather than
Glenn Morris <rgm@gnu.org>
parents: 86202
diff changeset
108 (require 'esh-proc)
c1197dc2780b Require individual files if needed when compiling, rather than
Glenn Morris <rgm@gnu.org>
parents: 86202
diff changeset
109 (require 'esh-ext)
c1197dc2780b Require individual files if needed when compiling, rather than
Glenn Morris <rgm@gnu.org>
parents: 86202
diff changeset
110
c1197dc2780b Require individual files if needed when compiling, rather than
Glenn Morris <rgm@gnu.org>
parents: 86202
diff changeset
111 (eval-when-compile
98564
f79ec7c34dc5 Sven Joachim <svenjoac at gmx.de>
Glenn Morris <rgm@gnu.org>
parents: 97483
diff changeset
112 (require 'cl)
87079
c1197dc2780b Require individual files if needed when compiling, rather than
Glenn Morris <rgm@gnu.org>
parents: 86202
diff changeset
113 (require 'pcomplete))
c1197dc2780b Require individual files if needed when compiling, rather than
Glenn Morris <rgm@gnu.org>
parents: 86202
diff changeset
114
c1197dc2780b Require individual files if needed when compiling, rather than
Glenn Morris <rgm@gnu.org>
parents: 86202
diff changeset
115
c1197dc2780b Require individual files if needed when compiling, rather than
Glenn Morris <rgm@gnu.org>
parents: 86202
diff changeset
116 (defgroup eshell-cmd nil
c1197dc2780b Require individual files if needed when compiling, rather than
Glenn Morris <rgm@gnu.org>
parents: 86202
diff changeset
117 "Executing an Eshell command is as simple as typing it in and
c1197dc2780b Require individual files if needed when compiling, rather than
Glenn Morris <rgm@gnu.org>
parents: 86202
diff changeset
118 pressing <RET>. There are several different kinds of commands,
c1197dc2780b Require individual files if needed when compiling, rather than
Glenn Morris <rgm@gnu.org>
parents: 86202
diff changeset
119 however."
c1197dc2780b Require individual files if needed when compiling, rather than
Glenn Morris <rgm@gnu.org>
parents: 86202
diff changeset
120 :tag "Command invocation"
c1197dc2780b Require individual files if needed when compiling, rather than
Glenn Morris <rgm@gnu.org>
parents: 86202
diff changeset
121 ;; :link '(info-link "(eshell)Command invocation")
c1197dc2780b Require individual files if needed when compiling, rather than
Glenn Morris <rgm@gnu.org>
parents: 86202
diff changeset
122 :group 'eshell)
c1197dc2780b Require individual files if needed when compiling, rather than
Glenn Morris <rgm@gnu.org>
parents: 86202
diff changeset
123
c1197dc2780b Require individual files if needed when compiling, rather than
Glenn Morris <rgm@gnu.org>
parents: 86202
diff changeset
124 (defcustom eshell-prefer-lisp-functions nil
110580
f57f72bb4757 Cosmetic doc fixes for eshell.
Glenn Morris <rgm@gnu.org>
parents: 106815
diff changeset
125 "If non-nil, prefer Lisp functions to external commands."
87079
c1197dc2780b Require individual files if needed when compiling, rather than
Glenn Morris <rgm@gnu.org>
parents: 86202
diff changeset
126 :type 'boolean
c1197dc2780b Require individual files if needed when compiling, rather than
Glenn Morris <rgm@gnu.org>
parents: 86202
diff changeset
127 :group 'eshell-cmd)
c1197dc2780b Require individual files if needed when compiling, rather than
Glenn Morris <rgm@gnu.org>
parents: 86202
diff changeset
128
29873
b0bbf97625c2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
129 (defcustom eshell-lisp-regexp "\\([(`]\\|#'\\)"
110580
f57f72bb4757 Cosmetic doc fixes for eshell.
Glenn Morris <rgm@gnu.org>
parents: 106815
diff changeset
130 "A regexp which, if matched at beginning of an argument, means Lisp.
29873
b0bbf97625c2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
131 Such arguments will be passed to `read', and then evaluated."
b0bbf97625c2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
132 :type 'regexp
b0bbf97625c2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
133 :group 'eshell-cmd)
b0bbf97625c2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
134
b0bbf97625c2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
135 (defcustom eshell-pre-command-hook nil
110580
f57f72bb4757 Cosmetic doc fixes for eshell.
Glenn Morris <rgm@gnu.org>
parents: 106815
diff changeset
136 "A hook run before each interactive command is invoked."
29873
b0bbf97625c2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
137 :type 'hook
b0bbf97625c2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
138 :group 'eshell-cmd)
b0bbf97625c2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
139
b0bbf97625c2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
140 (defcustom eshell-post-command-hook nil
110580
f57f72bb4757 Cosmetic doc fixes for eshell.
Glenn Morris <rgm@gnu.org>
parents: 106815
diff changeset
141 "A hook run after each interactive command is invoked."
29873
b0bbf97625c2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
142 :type 'hook
b0bbf97625c2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
143 :group 'eshell-cmd)
b0bbf97625c2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
144
b0bbf97625c2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
145 (defcustom eshell-prepare-command-hook nil
110580
f57f72bb4757 Cosmetic doc fixes for eshell.
Glenn Morris <rgm@gnu.org>
parents: 106815
diff changeset
146 "A set of functions called to prepare a named command.
29873
b0bbf97625c2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
147 The command name and its argument are in `eshell-last-command-name'
b0bbf97625c2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
148 and `eshell-last-arguments'. The functions on this hook can change
b0bbf97625c2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
149 the value of these symbols if necessary.
b0bbf97625c2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
150
b0bbf97625c2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
151 To prevent a command from executing at all, set
b0bbf97625c2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
152 `eshell-last-command-name' to nil."
b0bbf97625c2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
153 :type 'hook
b0bbf97625c2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
154 :group 'eshell-cmd)
b0bbf97625c2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
155
b0bbf97625c2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
156 (defcustom eshell-named-command-hook nil
110580
f57f72bb4757 Cosmetic doc fixes for eshell.
Glenn Morris <rgm@gnu.org>
parents: 106815
diff changeset
157 "A set of functions called before a named command is invoked.
29873
b0bbf97625c2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
158 Each function will be passed the command name and arguments that were
b0bbf97625c2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
159 passed to `eshell-named-command'.
b0bbf97625c2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
160
b0bbf97625c2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
161 If any of the functions returns a non-nil value, the named command
b0bbf97625c2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
162 will not be invoked, and that value will be returned from
b0bbf97625c2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
163 `eshell-named-command'.
b0bbf97625c2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
164
b0bbf97625c2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
165 In order to substitute an alternate command form for execution, the
b0bbf97625c2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
166 hook function should throw it using the tag `eshell-replace-command'.
b0bbf97625c2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
167 For example:
b0bbf97625c2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
168
b0bbf97625c2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
169 (add-hook 'eshell-named-command-hook 'subst-with-cd)
b0bbf97625c2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
170 (defun subst-with-cd (command args)
b0bbf97625c2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
171 (throw 'eshell-replace-command
b0bbf97625c2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
172 (eshell-parse-command \"cd\" args)))
b0bbf97625c2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
173
b0bbf97625c2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
174 Although useless, the above code will cause any non-glob, non-Lisp
b0bbf97625c2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
175 command (i.e., 'ls' as opposed to '*ls' or '(ls)') to be replaced by a
b0bbf97625c2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
176 call to `cd' using the arguments that were passed to the function."
b0bbf97625c2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
177 :type 'hook
b0bbf97625c2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
178 :group 'eshell-cmd)
b0bbf97625c2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
179
b0bbf97625c2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
180 (defcustom eshell-pre-rewrite-command-hook
b0bbf97625c2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
181 '(eshell-no-command-conversion
b0bbf97625c2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
182 eshell-subcommand-arg-values)
110580
f57f72bb4757 Cosmetic doc fixes for eshell.
Glenn Morris <rgm@gnu.org>
parents: 106815
diff changeset
183 "A hook run before command rewriting begins.
29873
b0bbf97625c2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
184 The terms of the command to be rewritten is passed as arguments, and
b0bbf97625c2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
185 may be modified in place. Any return value is ignored."
b0bbf97625c2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
186 :type 'hook
b0bbf97625c2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
187 :group 'eshell-cmd)
b0bbf97625c2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
188
b0bbf97625c2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
189 (defcustom eshell-rewrite-command-hook
b0bbf97625c2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
190 '(eshell-rewrite-for-command
b0bbf97625c2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
191 eshell-rewrite-while-command
b0bbf97625c2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
192 eshell-rewrite-if-command
b0bbf97625c2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
193 eshell-rewrite-sexp-command
b0bbf97625c2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
194 eshell-rewrite-initial-subcommand
b0bbf97625c2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
195 eshell-rewrite-named-command)
110580
f57f72bb4757 Cosmetic doc fixes for eshell.
Glenn Morris <rgm@gnu.org>
parents: 106815
diff changeset
196 "A set of functions used to rewrite the command argument.
29873
b0bbf97625c2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
197 Once parsing of a command line is completed, the next step is to
b0bbf97625c2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
198 rewrite the initial argument into something runnable.
b0bbf97625c2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
199
b0bbf97625c2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
200 A module may wish to associate special behavior with certain argument
b0bbf97625c2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
201 syntaxes at the beginning of a command line. They are welcome to do
b0bbf97625c2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
202 so by adding a function to this hook. The first function to return a
b0bbf97625c2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
203 substitute command form is the one used. Each function is passed the
b0bbf97625c2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
204 command's full argument list, which is a list of sexps (typically
b0bbf97625c2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
205 forms or strings)."
b0bbf97625c2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
206 :type 'hook
b0bbf97625c2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
207 :group 'eshell-cmd)
b0bbf97625c2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
208
b0bbf97625c2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
209 (defcustom eshell-post-rewrite-command-hook nil
110580
f57f72bb4757 Cosmetic doc fixes for eshell.
Glenn Morris <rgm@gnu.org>
parents: 106815
diff changeset
210 "A hook run after command rewriting is finished.
29873
b0bbf97625c2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
211 Each function is passed the symbol containing the rewritten command,
b0bbf97625c2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
212 which may be modified directly. Any return value is ignored."
b0bbf97625c2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
213 :type 'hook
b0bbf97625c2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
214 :group 'eshell-cmd)
b0bbf97625c2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
215
79116
1af9837978fa (eshell-complex-commands): Add "ls".
Chong Yidong <cyd@stupidchicken.com>
parents: 78220
diff changeset
216 (defcustom eshell-complex-commands '("ls")
110580
f57f72bb4757 Cosmetic doc fixes for eshell.
Glenn Morris <rgm@gnu.org>
parents: 106815
diff changeset
217 "A list of commands names or functions, that determine complexity.
33020
e21feeab77fb See ChangeLog
John Wiegley <johnw@newartisans.com>
parents: 32526
diff changeset
218 That is, if a command is defined by a function named eshell/NAME,
e21feeab77fb See ChangeLog
John Wiegley <johnw@newartisans.com>
parents: 32526
diff changeset
219 and NAME is part of this list, it is invoked as a complex command.
e21feeab77fb See ChangeLog
John Wiegley <johnw@newartisans.com>
parents: 32526
diff changeset
220 Complex commands are always correct, but run much slower. If a
e21feeab77fb See ChangeLog
John Wiegley <johnw@newartisans.com>
parents: 32526
diff changeset
221 command works fine without being part of this list, then it doesn't
e21feeab77fb See ChangeLog
John Wiegley <johnw@newartisans.com>
parents: 32526
diff changeset
222 need to be.
e21feeab77fb See ChangeLog
John Wiegley <johnw@newartisans.com>
parents: 32526
diff changeset
223
e21feeab77fb See ChangeLog
John Wiegley <johnw@newartisans.com>
parents: 32526
diff changeset
224 If an entry is a function, it will be called with the name, and should
e21feeab77fb See ChangeLog
John Wiegley <johnw@newartisans.com>
parents: 32526
diff changeset
225 return non-nil if the command is complex."
e21feeab77fb See ChangeLog
John Wiegley <johnw@newartisans.com>
parents: 32526
diff changeset
226 :type '(repeat :tag "Commands"
e21feeab77fb See ChangeLog
John Wiegley <johnw@newartisans.com>
parents: 32526
diff changeset
227 (choice (string :tag "Name")
e21feeab77fb See ChangeLog
John Wiegley <johnw@newartisans.com>
parents: 32526
diff changeset
228 (function :tag "Predicate")))
e21feeab77fb See ChangeLog
John Wiegley <johnw@newartisans.com>
parents: 32526
diff changeset
229 :group 'eshell-cmd)
e21feeab77fb See ChangeLog
John Wiegley <johnw@newartisans.com>
parents: 32526
diff changeset
230
29873
b0bbf97625c2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
231 ;;; User Variables:
b0bbf97625c2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
232
b0bbf97625c2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
233 (defcustom eshell-cmd-load-hook '(eshell-cmd-initialize)
110580
f57f72bb4757 Cosmetic doc fixes for eshell.
Glenn Morris <rgm@gnu.org>
parents: 106815
diff changeset
234 "A hook that gets run when `eshell-cmd' is loaded."
29873
b0bbf97625c2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
235 :type 'hook
b0bbf97625c2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
236 :group 'eshell-cmd)
b0bbf97625c2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
237
b0bbf97625c2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
238 (defcustom eshell-debug-command nil
110580
f57f72bb4757 Cosmetic doc fixes for eshell.
Glenn Morris <rgm@gnu.org>
parents: 106815
diff changeset
239 "If non-nil, enable debugging code. SSLLOOWW.
29873
b0bbf97625c2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
240 This option is only useful for reporting bugs. If you enable it, you
b0bbf97625c2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
241 will have to visit the file 'eshell-cmd.el' and run the command
b0bbf97625c2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
242 \\[eval-buffer]."
b0bbf97625c2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
243 :type 'boolean
b0bbf97625c2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
244 :group 'eshell-cmd)
b0bbf97625c2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
245
b0bbf97625c2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
246 (defcustom eshell-deferrable-commands
b0bbf97625c2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
247 '(eshell-named-command
b0bbf97625c2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
248 eshell-lisp-command
b0bbf97625c2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
249 eshell-process-identity)
110580
f57f72bb4757 Cosmetic doc fixes for eshell.
Glenn Morris <rgm@gnu.org>
parents: 106815
diff changeset
250 "A list of functions which might return an ansychronous process.
29873
b0bbf97625c2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
251 If they return a process object, execution of the calling Eshell
b0bbf97625c2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
252 command will wait for completion (in the background) before finishing
b0bbf97625c2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
253 the command."
b0bbf97625c2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
254 :type '(repeat function)
b0bbf97625c2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
255 :group 'eshell-cmd)
b0bbf97625c2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
256
b0bbf97625c2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
257 (defcustom eshell-subcommand-bindings
b0bbf97625c2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
258 '((eshell-in-subcommand-p t)
b0bbf97625c2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
259 (default-directory default-directory)
b0bbf97625c2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
260 (process-environment (eshell-copy-environment)))
110580
f57f72bb4757 Cosmetic doc fixes for eshell.
Glenn Morris <rgm@gnu.org>
parents: 106815
diff changeset
261 "A list of `let' bindings for subcommand environments."
29873
b0bbf97625c2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
262 :type 'sexp
b0bbf97625c2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
263 :group 'eshell-cmd)
b0bbf97625c2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
264
b0bbf97625c2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
265 (put 'risky-local-variable 'eshell-subcommand-bindings t)
b0bbf97625c2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
266
b0bbf97625c2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
267 (defvar eshell-ensure-newline-p nil
b0bbf97625c2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
268 "If non-nil, ensure that a newline is emitted after a Lisp form.
b0bbf97625c2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
269 This can be changed by Lisp forms that are evaluated from the Eshell
b0bbf97625c2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
270 command line.")
b0bbf97625c2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
271
b0bbf97625c2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
272 ;;; Internal Variables:
b0bbf97625c2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
273
b0bbf97625c2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
274 (defvar eshell-current-command nil)
b0bbf97625c2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
275 (defvar eshell-command-name nil)
b0bbf97625c2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
276 (defvar eshell-command-arguments nil)
99824
df01f003c105 (eshell-in-pipeline-p): Add doc-string.
Glenn Morris <rgm@gnu.org>
parents: 98564
diff changeset
277 (defvar eshell-in-pipeline-p nil
df01f003c105 (eshell-in-pipeline-p): Add doc-string.
Glenn Morris <rgm@gnu.org>
parents: 98564
diff changeset
278 "Internal Eshell variable, non-nil inside a pipeline.
df01f003c105 (eshell-in-pipeline-p): Add doc-string.
Glenn Morris <rgm@gnu.org>
parents: 98564
diff changeset
279 Has the value 'first, 'last for the first/last commands in the pipeline,
df01f003c105 (eshell-in-pipeline-p): Add doc-string.
Glenn Morris <rgm@gnu.org>
parents: 98564
diff changeset
280 otherwise t.")
29873
b0bbf97625c2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
281 (defvar eshell-in-subcommand-p nil)
b0bbf97625c2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
282 (defvar eshell-last-arguments nil)
b0bbf97625c2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
283 (defvar eshell-last-command-name nil)
b0bbf97625c2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
284 (defvar eshell-last-async-proc nil
b0bbf97625c2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
285 "When this foreground process completes, resume command evaluation.")
b0bbf97625c2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
286
b0bbf97625c2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
287 ;;; Functions:
b0bbf97625c2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
288
b0bbf97625c2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
289 (defsubst eshell-interactive-process ()
b0bbf97625c2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
290 "Return currently running command process, if non-Lisp."
b0bbf97625c2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
291 eshell-last-async-proc)
b0bbf97625c2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
292
b0bbf97625c2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
293 (defun eshell-cmd-initialize ()
b0bbf97625c2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
294 "Initialize the Eshell command processing module."
b0bbf97625c2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
295 (set (make-local-variable 'eshell-current-command) nil)
b0bbf97625c2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
296 (set (make-local-variable 'eshell-command-name) nil)
b0bbf97625c2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
297 (set (make-local-variable 'eshell-command-arguments) nil)
b0bbf97625c2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
298 (set (make-local-variable 'eshell-last-arguments) nil)
b0bbf97625c2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
299 (set (make-local-variable 'eshell-last-command-name) nil)
b0bbf97625c2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
300 (set (make-local-variable 'eshell-last-async-proc) nil)
b0bbf97625c2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
301
b0bbf97625c2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
302 (add-hook 'eshell-kill-hook 'eshell-resume-command nil t)
b0bbf97625c2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
303
b0bbf97625c2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
304 ;; make sure that if a command is over, and no process is being
b0bbf97625c2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
305 ;; waited for, that `eshell-current-command' is set to nil. This
b0bbf97625c2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
306 ;; situation can occur, for example, if a Lisp function results in
b0bbf97625c2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
307 ;; `debug' being called, and the user then types \\[top-level]
b0bbf97625c2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
308 (add-hook 'eshell-post-command-hook
b0bbf97625c2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
309 (function
b0bbf97625c2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
310 (lambda ()
b0bbf97625c2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
311 (setq eshell-current-command nil
b0bbf97625c2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
312 eshell-last-async-proc nil))) nil t)
b0bbf97625c2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
313
b0bbf97625c2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
314 (add-hook 'eshell-parse-argument-hook
b0bbf97625c2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
315 'eshell-parse-subcommand-argument nil t)
b0bbf97625c2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
316 (add-hook 'eshell-parse-argument-hook
b0bbf97625c2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
317 'eshell-parse-lisp-argument nil t)
b0bbf97625c2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
318
b0bbf97625c2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
319 (when (eshell-using-module 'eshell-cmpl)
b0bbf97625c2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
320 (add-hook 'pcomplete-try-first-hook
b0bbf97625c2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
321 'eshell-complete-lisp-symbols nil t)))
b0bbf97625c2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
322
b0bbf97625c2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
323 (eshell-deftest var last-result-var
b0bbf97625c2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
324 "\"last result\" variable"
b0bbf97625c2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
325 (eshell-command-result-p "+ 1 2; + $$ 2" "3\n5\n"))
b0bbf97625c2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
326
b0bbf97625c2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
327 (eshell-deftest var last-result-var2
b0bbf97625c2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
328 "\"last result\" variable"
b0bbf97625c2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
329 (eshell-command-result-p "+ 1 2; + $$ $$" "3\n6\n"))
b0bbf97625c2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
330
b0bbf97625c2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
331 (eshell-deftest var last-arg-var
b0bbf97625c2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
332 "\"last arg\" variable"
b0bbf97625c2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
333 (eshell-command-result-p "+ 1 2; + $_ 4" "3\n6\n"))
b0bbf97625c2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
334
b0bbf97625c2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
335 (defun eshell-complete-lisp-symbols ()
b0bbf97625c2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
336 "If there is a user reference, complete it."
b0bbf97625c2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
337 (let ((arg (pcomplete-actual-arg)))
b0bbf97625c2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
338 (when (string-match (concat "\\`" eshell-lisp-regexp) arg)
b0bbf97625c2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
339 (setq pcomplete-stub (substring arg (match-end 0))
b0bbf97625c2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
340 pcomplete-last-completion-raw t)
b0bbf97625c2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
341 (throw 'pcomplete-completions
b0bbf97625c2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
342 (all-completions pcomplete-stub obarray 'boundp)))))
b0bbf97625c2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
343
b0bbf97625c2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
344 ;; Command parsing
b0bbf97625c2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
345
b0bbf97625c2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
346 (defun eshell-parse-command (command &optional args top-level)
b0bbf97625c2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
347 "Parse the COMMAND, adding ARGS if given.
b0bbf97625c2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
348 COMMAND can either be a string, or a cons cell demarcating a buffer
b0bbf97625c2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
349 region. TOP-LEVEL, if non-nil, means that the outermost command (the
b0bbf97625c2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
350 user's input command) is being parsed, and that pre and post command
b0bbf97625c2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
351 hooks should be run before and after the command."
b0bbf97625c2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
352 (let* (sep-terms
b0bbf97625c2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
353 (terms
b0bbf97625c2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
354 (append
b0bbf97625c2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
355 (if (consp command)
b0bbf97625c2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
356 (eshell-parse-arguments (car command) (cdr command))
b0bbf97625c2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
357 (let ((here (point))
111686
e8049570c647 * lisp/eshell/: Use with-silent-modifications.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 110580
diff changeset
358 (inhibit-point-motion-hooks t))
e8049570c647 * lisp/eshell/: Use with-silent-modifications.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 110580
diff changeset
359 (with-silent-modifications
e8049570c647 * lisp/eshell/: Use with-silent-modifications.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 110580
diff changeset
360 ;; FIXME: Why not use a temporary buffer and avoid this
e8049570c647 * lisp/eshell/: Use with-silent-modifications.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 110580
diff changeset
361 ;; "insert&delete" business? --Stef
e8049570c647 * lisp/eshell/: Use with-silent-modifications.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 110580
diff changeset
362 (insert command)
e8049570c647 * lisp/eshell/: Use with-silent-modifications.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 110580
diff changeset
363 (prog1
e8049570c647 * lisp/eshell/: Use with-silent-modifications.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 110580
diff changeset
364 (eshell-parse-arguments here (point))
e8049570c647 * lisp/eshell/: Use with-silent-modifications.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 110580
diff changeset
365 (delete-region here (point))))))
29873
b0bbf97625c2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
366 args))
b0bbf97625c2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
367 (commands
b0bbf97625c2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
368 (mapcar
b0bbf97625c2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
369 (function
b0bbf97625c2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
370 (lambda (cmd)
b0bbf97625c2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
371 (if (or (not (car sep-terms))
b0bbf97625c2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
372 (string= (car sep-terms) ";"))
b0bbf97625c2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
373 (setq cmd
b0bbf97625c2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
374 (eshell-parse-pipeline cmd (not (car sep-terms))))
b0bbf97625c2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
375 (setq cmd
b0bbf97625c2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
376 (list 'eshell-do-subjob
b0bbf97625c2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
377 (list 'list (eshell-parse-pipeline cmd)))))
b0bbf97625c2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
378 (setq sep-terms (cdr sep-terms))
b0bbf97625c2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
379 (if eshell-in-pipeline-p
b0bbf97625c2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
380 cmd
b0bbf97625c2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
381 (list 'eshell-trap-errors cmd))))
b0bbf97625c2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
382 (eshell-separate-commands terms "[&;]" nil 'sep-terms))))
b0bbf97625c2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
383 (let ((cmd commands))
b0bbf97625c2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
384 (while cmd
b0bbf97625c2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
385 (if (cdr cmd)
b0bbf97625c2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
386 (setcar cmd (list 'eshell-commands (car cmd))))
b0bbf97625c2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
387 (setq cmd (cdr cmd))))
b0bbf97625c2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
388 (setq commands
b0bbf97625c2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
389 (append (list 'progn)
b0bbf97625c2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
390 (if top-level
b0bbf97625c2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
391 (list '(run-hooks 'eshell-pre-command-hook)))
b0bbf97625c2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
392 (if (not top-level)
b0bbf97625c2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
393 commands
b0bbf97625c2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
394 (list
b0bbf97625c2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
395 (list 'catch (quote 'top-level)
b0bbf97625c2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
396 (append (list 'progn) commands))
b0bbf97625c2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
397 '(run-hooks 'eshell-post-command-hook)))))
b0bbf97625c2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
398 (if top-level
b0bbf97625c2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
399 (list 'eshell-commands commands)
b0bbf97625c2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
400 commands)))
b0bbf97625c2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
401
87079
c1197dc2780b Require individual files if needed when compiling, rather than
Glenn Morris <rgm@gnu.org>
parents: 86202
diff changeset
402 (defun eshell-debug-command (tag subform)
c1197dc2780b Require individual files if needed when compiling, rather than
Glenn Morris <rgm@gnu.org>
parents: 86202
diff changeset
403 "Output a debugging message to '*eshell last cmd*'."
c1197dc2780b Require individual files if needed when compiling, rather than
Glenn Morris <rgm@gnu.org>
parents: 86202
diff changeset
404 (let ((buf (get-buffer-create "*eshell last cmd*"))
c1197dc2780b Require individual files if needed when compiling, rather than
Glenn Morris <rgm@gnu.org>
parents: 86202
diff changeset
405 (text (eshell-stringify eshell-current-command)))
96274
b0ac9927a5c0 (eshell-manipulate): Check eshell-debug-command is bound before using it.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 95619
diff changeset
406 (with-current-buffer buf
87079
c1197dc2780b Require individual files if needed when compiling, rather than
Glenn Morris <rgm@gnu.org>
parents: 86202
diff changeset
407 (if (not tag)
c1197dc2780b Require individual files if needed when compiling, rather than
Glenn Morris <rgm@gnu.org>
parents: 86202
diff changeset
408 (erase-buffer)
c1197dc2780b Require individual files if needed when compiling, rather than
Glenn Morris <rgm@gnu.org>
parents: 86202
diff changeset
409 (insert "\n\C-l\n" tag "\n\n" text
c1197dc2780b Require individual files if needed when compiling, rather than
Glenn Morris <rgm@gnu.org>
parents: 86202
diff changeset
410 (if subform
c1197dc2780b Require individual files if needed when compiling, rather than
Glenn Morris <rgm@gnu.org>
parents: 86202
diff changeset
411 (concat "\n\n" (eshell-stringify subform)) ""))))))
c1197dc2780b Require individual files if needed when compiling, rather than
Glenn Morris <rgm@gnu.org>
parents: 86202
diff changeset
412
29873
b0bbf97625c2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
413 (defun eshell-debug-show-parsed-args (terms)
b0bbf97625c2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
414 "Display parsed arguments in the debug buffer."
b0bbf97625c2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
415 (ignore
b0bbf97625c2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
416 (if eshell-debug-command
b0bbf97625c2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
417 (eshell-debug-command "parsed arguments" terms))))
b0bbf97625c2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
418
b0bbf97625c2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
419 (defun eshell-no-command-conversion (terms)
b0bbf97625c2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
420 "Don't convert the command argument."
b0bbf97625c2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
421 (ignore
b0bbf97625c2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
422 (if (and (listp (car terms))
b0bbf97625c2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
423 (eq (caar terms) 'eshell-convert))
b0bbf97625c2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
424 (setcar terms (cadr (car terms))))))
b0bbf97625c2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
425
b0bbf97625c2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
426 (defun eshell-subcommand-arg-values (terms)
b0bbf97625c2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
427 "Convert subcommand arguments {x} to ${x}, in order to take their values."
b0bbf97625c2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
428 (setq terms (cdr terms)) ; skip command argument
b0bbf97625c2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
429 (while terms
b0bbf97625c2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
430 (if (and (listp (car terms))
b0bbf97625c2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
431 (eq (caar terms) 'eshell-as-subcommand))
b0bbf97625c2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
432 (setcar terms (list 'eshell-convert
b0bbf97625c2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
433 (list 'eshell-command-to-value
b0bbf97625c2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
434 (car terms)))))
b0bbf97625c2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
435 (setq terms (cdr terms))))
b0bbf97625c2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
436
b0bbf97625c2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
437 (defun eshell-rewrite-sexp-command (terms)
b0bbf97625c2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
438 "Rewrite a sexp in initial position, such as '(+ 1 2)'."
b0bbf97625c2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
439 ;; this occurs when a Lisp expression is in first position
b0bbf97625c2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
440 (if (and (listp (car terms))
b0bbf97625c2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
441 (eq (caar terms) 'eshell-command-to-value))
b0bbf97625c2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
442 (car (cdar terms))))
b0bbf97625c2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
443
b0bbf97625c2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
444 (eshell-deftest cmd lisp-command
b0bbf97625c2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
445 "Evaluate Lisp command"
b0bbf97625c2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
446 (eshell-command-result-p "(+ 1 2)" "3"))
b0bbf97625c2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
447
b0bbf97625c2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
448 (eshell-deftest cmd lisp-command-args
b0bbf97625c2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
449 "Evaluate Lisp command (ignore args)"
b0bbf97625c2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
450 (eshell-command-result-p "(+ 1 2) 3" "3"))
b0bbf97625c2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
451
b0bbf97625c2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
452 (defun eshell-rewrite-initial-subcommand (terms)
b0bbf97625c2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
453 "Rewrite a subcommand in initial position, such as '{+ 1 2}'."
b0bbf97625c2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
454 (if (and (listp (car terms))
b0bbf97625c2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
455 (eq (caar terms) 'eshell-as-subcommand))
b0bbf97625c2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
456 (car terms)))
b0bbf97625c2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
457
b0bbf97625c2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
458 (eshell-deftest cmd subcommand
b0bbf97625c2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
459 "Run subcommand"
b0bbf97625c2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
460 (eshell-command-result-p "{+ 1 2}" "3\n"))
b0bbf97625c2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
461
b0bbf97625c2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
462 (eshell-deftest cmd subcommand-args
b0bbf97625c2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
463 "Run subcommand (ignore args)"
b0bbf97625c2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
464 (eshell-command-result-p "{+ 1 2} 3" "3\n"))
b0bbf97625c2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
465
b0bbf97625c2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
466 (eshell-deftest cmd subcommand-lisp
b0bbf97625c2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
467 "Run subcommand + Lisp form"
b0bbf97625c2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
468 (eshell-command-result-p "{(+ 1 2)}" "3\n"))
b0bbf97625c2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
469
b0bbf97625c2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
470 (defun eshell-rewrite-named-command (terms)
b0bbf97625c2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
471 "If no other rewriting rule transforms TERMS, assume a named command."
65167
2980740e3f1c (eshell-rewrite-named-command): Changed the code around a bit so that
John Wiegley <johnw@newartisans.com>
parents: 64701
diff changeset
472 (let ((sym (if eshell-in-pipeline-p
2980740e3f1c (eshell-rewrite-named-command): Changed the code around a bit so that
John Wiegley <johnw@newartisans.com>
parents: 64701
diff changeset
473 'eshell-named-command*
2980740e3f1c (eshell-rewrite-named-command): Changed the code around a bit so that
John Wiegley <johnw@newartisans.com>
parents: 64701
diff changeset
474 'eshell-named-command))
2980740e3f1c (eshell-rewrite-named-command): Changed the code around a bit so that
John Wiegley <johnw@newartisans.com>
parents: 64701
diff changeset
475 (cmd (car terms))
2980740e3f1c (eshell-rewrite-named-command): Changed the code around a bit so that
John Wiegley <johnw@newartisans.com>
parents: 64701
diff changeset
476 (args (cdr terms)))
2980740e3f1c (eshell-rewrite-named-command): Changed the code around a bit so that
John Wiegley <johnw@newartisans.com>
parents: 64701
diff changeset
477 (if args
2980740e3f1c (eshell-rewrite-named-command): Changed the code around a bit so that
John Wiegley <johnw@newartisans.com>
parents: 64701
diff changeset
478 (list sym cmd (append (list 'list) (cdr terms)))
2980740e3f1c (eshell-rewrite-named-command): Changed the code around a bit so that
John Wiegley <johnw@newartisans.com>
parents: 64701
diff changeset
479 (list sym cmd))))
29873
b0bbf97625c2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
480
b0bbf97625c2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
481 (eshell-deftest cmd named-command
b0bbf97625c2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
482 "Execute named command"
b0bbf97625c2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
483 (eshell-command-result-p "+ 1 2" "3\n"))
b0bbf97625c2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
484
95619
45dbb3c749a6 Remove unnecessary eval-when-compiles and eval-and-compiles.
Glenn Morris <rgm@gnu.org>
parents: 94661
diff changeset
485 (defvar eshell-command-body)
45dbb3c749a6 Remove unnecessary eval-when-compiles and eval-and-compiles.
Glenn Morris <rgm@gnu.org>
parents: 94661
diff changeset
486 (defvar eshell-test-body)
29873
b0bbf97625c2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
487
b0bbf97625c2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
488 (defsubst eshell-invokify-arg (arg &optional share-output silent)
b0bbf97625c2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
489 "Change ARG so it can be invoked from a structured command.
b0bbf97625c2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
490
b0bbf97625c2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
491 SHARE-OUTPUT, if non-nil, means this invocation should share the
b0bbf97625c2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
492 current output stream, which is separately redirectable. SILENT
b0bbf97625c2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
493 means the user and/or any redirections shouldn't see any output
b0bbf97625c2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
494 from this command. If both SHARE-OUTPUT and SILENT are non-nil,
b0bbf97625c2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
495 the second is ignored."
b0bbf97625c2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
496 ;; something that begins with `eshell-convert' means that it
b0bbf97625c2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
497 ;; intends to return a Lisp value. We want to get past this,
b0bbf97625c2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
498 ;; but if it's not _actually_ a value interpolation -- in which
b0bbf97625c2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
499 ;; we leave it alone. In fact, the only time we muck with it
b0bbf97625c2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
500 ;; is in the case of a {subcommand} that has been turned into
b0bbf97625c2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
501 ;; the interpolation, ${subcommand}, by the parser because it
b0bbf97625c2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
502 ;; didn't know better.
b0bbf97625c2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
503 (if (and (listp arg)
b0bbf97625c2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
504 (eq (car arg) 'eshell-convert)
b0bbf97625c2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
505 (eq (car (cadr arg)) 'eshell-command-to-value))
b0bbf97625c2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
506 (if share-output
b0bbf97625c2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
507 (cadr (cadr arg))
b0bbf97625c2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
508 (list 'eshell-commands (cadr (cadr arg))
b0bbf97625c2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
509 silent))
b0bbf97625c2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
510 arg))
b0bbf97625c2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
511
b0bbf97625c2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
512 (defun eshell-rewrite-for-command (terms)
b0bbf97625c2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
513 "Rewrite a `for' command into its equivalent Eshell command form.
b0bbf97625c2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
514 Because the implementation of `for' relies upon conditional evaluation
75512
aee02f0a570b (eshell-rewrite-for-command): Fix typo in docstring.
Juanma Barranquero <lekktu@gmail.com>
parents: 75346
diff changeset
515 of its argument (i.e., use of a Lisp special form), it must be
29873
b0bbf97625c2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
516 implemented via rewriting, rather than as a function."
b0bbf97625c2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
517 (if (and (stringp (car terms))
b0bbf97625c2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
518 (string= (car terms) "for")
b0bbf97625c2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
519 (stringp (nth 2 terms))
b0bbf97625c2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
520 (string= (nth 2 terms) "in"))
b0bbf97625c2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
521 (let ((body (car (last terms))))
b0bbf97625c2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
522 (setcdr (last terms 2) nil)
b0bbf97625c2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
523 (list
b0bbf97625c2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
524 'let (list (list 'for-items
b0bbf97625c2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
525 (append
b0bbf97625c2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
526 (list 'append)
b0bbf97625c2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
527 (mapcar
b0bbf97625c2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
528 (function
b0bbf97625c2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
529 (lambda (elem)
b0bbf97625c2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
530 (if (listp elem)
b0bbf97625c2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
531 elem
b0bbf97625c2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
532 (list 'list elem))))
29875
19baeeb660f1 (eshell-rewrite-for-command): Use cdr and
Gerd Moellmann <gerd@gnu.org>
parents: 29873
diff changeset
533 (cdr (cddr terms)))))
29873
b0bbf97625c2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
534 (list 'eshell-command-body
b0bbf97625c2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
535 (list 'quote (list nil)))
b0bbf97625c2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
536 (list 'eshell-test-body
b0bbf97625c2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
537 (list 'quote (list nil))))
b0bbf97625c2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
538 (list
b0bbf97625c2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
539 'progn
b0bbf97625c2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
540 (list
b0bbf97625c2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
541 'while (list 'car (list 'symbol-value
b0bbf97625c2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
542 (list 'quote 'for-items)))
b0bbf97625c2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
543 (list
b0bbf97625c2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
544 'progn
b0bbf97625c2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
545 (list 'let
b0bbf97625c2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
546 (list (list (intern (cadr terms))
b0bbf97625c2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
547 (list 'car
b0bbf97625c2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
548 (list 'symbol-value
b0bbf97625c2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
549 (list 'quote 'for-items)))))
33020
e21feeab77fb See ChangeLog
John Wiegley <johnw@newartisans.com>
parents: 32526
diff changeset
550 (list 'eshell-protect
e21feeab77fb See ChangeLog
John Wiegley <johnw@newartisans.com>
parents: 32526
diff changeset
551 (eshell-invokify-arg body t)))
29873
b0bbf97625c2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
552 (list 'setcar 'for-items
b0bbf97625c2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
553 (list 'cadr
b0bbf97625c2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
554 (list 'symbol-value
b0bbf97625c2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
555 (list 'quote 'for-items))))
b0bbf97625c2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
556 (list 'setcdr 'for-items
b0bbf97625c2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
557 (list 'cddr
b0bbf97625c2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
558 (list 'symbol-value
b0bbf97625c2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
559 (list 'quote 'for-items))))))
b0bbf97625c2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
560 (list 'eshell-close-handles
b0bbf97625c2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
561 'eshell-last-command-status
b0bbf97625c2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
562 (list 'list (quote 'quote)
b0bbf97625c2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
563 'eshell-last-command-result)))))))
b0bbf97625c2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
564
b0bbf97625c2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
565 (defun eshell-structure-basic-command (func names keyword test body
b0bbf97625c2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
566 &optional else vocal-test)
b0bbf97625c2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
567 "With TERMS, KEYWORD, and two NAMES, structure a basic command.
b0bbf97625c2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
568 The first of NAMES should be the positive form, and the second the
b0bbf97625c2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
569 negative. It's not likely that users should ever need to call this
b0bbf97625c2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
570 function.
b0bbf97625c2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
571
b0bbf97625c2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
572 If VOCAL-TEST is non-nil, it means output from the test should be
b0bbf97625c2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
573 shown, as well as output from the body."
b0bbf97625c2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
574 ;; If the test form begins with `eshell-convert', it means
b0bbf97625c2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
575 ;; something data-wise will be returned, and we should let
b0bbf97625c2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
576 ;; that determine the truth of the statement.
b0bbf97625c2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
577 (unless (eq (car test) 'eshell-convert)
b0bbf97625c2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
578 (setq test
b0bbf97625c2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
579 (list 'progn test
b0bbf97625c2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
580 (list 'eshell-exit-success-p))))
b0bbf97625c2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
581
b0bbf97625c2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
582 ;; should we reverse the sense of the test? This depends
b0bbf97625c2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
583 ;; on the `names' parameter. If it's the symbol nil, yes.
b0bbf97625c2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
584 ;; Otherwise, it can be a pair of strings; if the keyword
b0bbf97625c2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
585 ;; we're using matches the second member of that pair (a
b0bbf97625c2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
586 ;; list), we should reverse it.
b0bbf97625c2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
587 (if (or (eq names nil)
b0bbf97625c2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
588 (and (listp names)
b0bbf97625c2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
589 (string= keyword (cadr names))))
b0bbf97625c2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
590 (setq test (list 'not test)))
b0bbf97625c2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
591
b0bbf97625c2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
592 ;; finally, create the form that represents this structured
b0bbf97625c2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
593 ;; command
b0bbf97625c2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
594 (list
b0bbf97625c2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
595 'let (list (list 'eshell-command-body
b0bbf97625c2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
596 (list 'quote (list nil)))
b0bbf97625c2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
597 (list 'eshell-test-body
b0bbf97625c2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
598 (list 'quote (list nil))))
b0bbf97625c2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
599 (list func test body else)
b0bbf97625c2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
600 (list 'eshell-close-handles
b0bbf97625c2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
601 'eshell-last-command-status
b0bbf97625c2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
602 (list 'list (quote 'quote)
b0bbf97625c2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
603 'eshell-last-command-result))))
b0bbf97625c2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
604
b0bbf97625c2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
605 (defun eshell-rewrite-while-command (terms)
b0bbf97625c2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
606 "Rewrite a `while' command into its equivalent Eshell command form.
b0bbf97625c2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
607 Because the implementation of `while' relies upon conditional
b0bbf97625c2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
608 evaluation of its argument (i.e., use of a Lisp special form), it
b0bbf97625c2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
609 must be implemented via rewriting, rather than as a function."
b0bbf97625c2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
610 (if (and (stringp (car terms))
b0bbf97625c2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
611 (member (car terms) '("while" "until")))
b0bbf97625c2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
612 (eshell-structure-basic-command
b0bbf97625c2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
613 'while '("while" "until") (car terms)
b0bbf97625c2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
614 (eshell-invokify-arg (cadr terms) nil t)
33020
e21feeab77fb See ChangeLog
John Wiegley <johnw@newartisans.com>
parents: 32526
diff changeset
615 (list 'eshell-protect
29873
b0bbf97625c2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
616 (eshell-invokify-arg (car (last terms)) t)))))
b0bbf97625c2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
617
b0bbf97625c2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
618 (defun eshell-rewrite-if-command (terms)
b0bbf97625c2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
619 "Rewrite an `if' command into its equivalent Eshell command form.
b0bbf97625c2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
620 Because the implementation of `if' relies upon conditional
b0bbf97625c2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
621 evaluation of its argument (i.e., use of a Lisp special form), it
b0bbf97625c2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
622 must be implemented via rewriting, rather than as a function."
b0bbf97625c2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
623 (if (and (stringp (car terms))
b0bbf97625c2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
624 (member (car terms) '("if" "unless")))
b0bbf97625c2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
625 (eshell-structure-basic-command
b0bbf97625c2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
626 'if '("if" "unless") (car terms)
b0bbf97625c2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
627 (eshell-invokify-arg (cadr terms) nil t)
33020
e21feeab77fb See ChangeLog
John Wiegley <johnw@newartisans.com>
parents: 32526
diff changeset
628 (list 'eshell-protect
e21feeab77fb See ChangeLog
John Wiegley <johnw@newartisans.com>
parents: 32526
diff changeset
629 (eshell-invokify-arg
38007
fa54203d014a (eshell-exit-success-p): Use a string-match to test if the last
John Wiegley <johnw@newartisans.com>
parents: 37817
diff changeset
630 (if (= (length terms) 4)
fa54203d014a (eshell-exit-success-p): Use a string-match to test if the last
John Wiegley <johnw@newartisans.com>
parents: 37817
diff changeset
631 (car (last terms 2))
33020
e21feeab77fb See ChangeLog
John Wiegley <johnw@newartisans.com>
parents: 32526
diff changeset
632 (car (last terms))) t))
38007
fa54203d014a (eshell-exit-success-p): Use a string-match to test if the last
John Wiegley <johnw@newartisans.com>
parents: 37817
diff changeset
633 (if (= (length terms) 4)
33020
e21feeab77fb See ChangeLog
John Wiegley <johnw@newartisans.com>
parents: 32526
diff changeset
634 (list 'eshell-protect
e21feeab77fb See ChangeLog
John Wiegley <johnw@newartisans.com>
parents: 32526
diff changeset
635 (eshell-invokify-arg
e21feeab77fb See ChangeLog
John Wiegley <johnw@newartisans.com>
parents: 32526
diff changeset
636 (car (last terms)))) t))))
29873
b0bbf97625c2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
637
b0bbf97625c2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
638 (defun eshell-exit-success-p ()
b0bbf97625c2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
639 "Return non-nil if the last command was \"successful\".
b0bbf97625c2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
640 For a bit of Lisp code, this means a return value of non-nil.
b0bbf97625c2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
641 For an external command, it means an exit code of 0."
38007
fa54203d014a (eshell-exit-success-p): Use a string-match to test if the last
John Wiegley <johnw@newartisans.com>
parents: 37817
diff changeset
642 (if (save-match-data
fa54203d014a (eshell-exit-success-p): Use a string-match to test if the last
John Wiegley <johnw@newartisans.com>
parents: 37817
diff changeset
643 (string-match "#<\\(Lisp object\\|function .*\\)>"
fa54203d014a (eshell-exit-success-p): Use a string-match to test if the last
John Wiegley <johnw@newartisans.com>
parents: 37817
diff changeset
644 eshell-last-command-name))
29873
b0bbf97625c2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
645 eshell-last-command-result
b0bbf97625c2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
646 (= eshell-last-command-status 0)))
b0bbf97625c2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
647
b0bbf97625c2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
648 (defun eshell-parse-pipeline (terms &optional final-p)
b0bbf97625c2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
649 "Parse a pipeline from TERMS, return the appropriate Lisp forms."
b0bbf97625c2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
650 (let* (sep-terms
b0bbf97625c2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
651 (bigpieces (eshell-separate-commands terms "\\(&&\\|||\\)"
b0bbf97625c2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
652 nil 'sep-terms))
b0bbf97625c2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
653 (bp bigpieces)
b0bbf97625c2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
654 (results (list t))
b0bbf97625c2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
655 final)
b0bbf97625c2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
656 (while bp
b0bbf97625c2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
657 (let ((subterms (car bp)))
b0bbf97625c2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
658 (let* ((pieces (eshell-separate-commands subterms "|"))
b0bbf97625c2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
659 (p pieces))
b0bbf97625c2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
660 (while p
b0bbf97625c2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
661 (let ((cmd (car p)))
b0bbf97625c2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
662 (run-hook-with-args 'eshell-pre-rewrite-command-hook cmd)
b0bbf97625c2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
663 (setq cmd (run-hook-with-args-until-success
b0bbf97625c2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
664 'eshell-rewrite-command-hook cmd))
b0bbf97625c2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
665 (run-hook-with-args 'eshell-post-rewrite-command-hook 'cmd)
b0bbf97625c2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
666 (setcar p cmd))
b0bbf97625c2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
667 (setq p (cdr p)))
b0bbf97625c2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
668 (nconc results
b0bbf97625c2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
669 (list
b0bbf97625c2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
670 (if (<= (length pieces) 1)
b0bbf97625c2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
671 (car pieces)
b0bbf97625c2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
672 (assert (not eshell-in-pipeline-p))
b0bbf97625c2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
673 (list 'eshell-execute-pipeline
b0bbf97625c2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
674 (list 'quote pieces))))))
b0bbf97625c2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
675 (setq bp (cdr bp))))
b0bbf97625c2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
676 ;; `results' might be empty; this happens in the case of
b0bbf97625c2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
677 ;; multi-line input
b0bbf97625c2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
678 (setq results (cdr results)
b0bbf97625c2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
679 results (nreverse results)
b0bbf97625c2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
680 final (car results)
b0bbf97625c2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
681 results (cdr results)
b0bbf97625c2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
682 sep-terms (nreverse sep-terms))
b0bbf97625c2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
683 (while results
b0bbf97625c2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
684 (assert (car sep-terms))
b0bbf97625c2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
685 (setq final (eshell-structure-basic-command
b0bbf97625c2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
686 'if (string= (car sep-terms) "&&") "if"
33020
e21feeab77fb See ChangeLog
John Wiegley <johnw@newartisans.com>
parents: 32526
diff changeset
687 (list 'eshell-protect (car results))
e21feeab77fb See ChangeLog
John Wiegley <johnw@newartisans.com>
parents: 32526
diff changeset
688 (list 'eshell-protect final)
29873
b0bbf97625c2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
689 nil t)
b0bbf97625c2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
690 results (cdr results)
b0bbf97625c2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
691 sep-terms (cdr sep-terms)))
b0bbf97625c2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
692 final))
b0bbf97625c2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
693
b0bbf97625c2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
694 (defun eshell-parse-subcommand-argument ()
b0bbf97625c2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
695 "Parse a subcommand argument of the form '{command}'."
b0bbf97625c2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
696 (if (and (not eshell-current-argument)
b0bbf97625c2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
697 (not eshell-current-quoted)
b0bbf97625c2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
698 (eq (char-after) ?\{)
b0bbf97625c2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
699 (or (= (point-max) (1+ (point)))
b0bbf97625c2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
700 (not (eq (char-after (1+ (point))) ?\}))))
b0bbf97625c2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
701 (let ((end (eshell-find-delimiter ?\{ ?\})))
b0bbf97625c2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
702 (if (not end)
b0bbf97625c2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
703 (throw 'eshell-incomplete ?\{)
b0bbf97625c2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
704 (when (eshell-arg-delimiter (1+ end))
b0bbf97625c2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
705 (prog1
b0bbf97625c2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
706 (list 'eshell-as-subcommand
b0bbf97625c2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
707 (eshell-parse-command (cons (1+ (point)) end)))
b0bbf97625c2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
708 (goto-char (1+ end))))))))
b0bbf97625c2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
709
b0bbf97625c2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
710 (defun eshell-parse-lisp-argument ()
b0bbf97625c2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
711 "Parse a Lisp expression which is specified as an argument."
b0bbf97625c2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
712 (if (and (not eshell-current-argument)
b0bbf97625c2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
713 (not eshell-current-quoted)
b0bbf97625c2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
714 (looking-at eshell-lisp-regexp))
b0bbf97625c2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
715 (let* ((here (point))
b0bbf97625c2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
716 (obj
b0bbf97625c2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
717 (condition-case err
b0bbf97625c2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
718 (read (current-buffer))
b0bbf97625c2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
719 (end-of-file
b0bbf97625c2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
720 (throw 'eshell-incomplete ?\()))))
b0bbf97625c2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
721 (if (eshell-arg-delimiter)
b0bbf97625c2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
722 (list 'eshell-command-to-value
b0bbf97625c2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
723 (list 'eshell-lisp-command (list 'quote obj)))
b0bbf97625c2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
724 (ignore (goto-char here))))))
b0bbf97625c2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
725
33020
e21feeab77fb See ChangeLog
John Wiegley <johnw@newartisans.com>
parents: 32526
diff changeset
726 (defun eshell-separate-commands (terms separator &optional
e21feeab77fb See ChangeLog
John Wiegley <johnw@newartisans.com>
parents: 32526
diff changeset
727 reversed last-terms-sym)
29873
b0bbf97625c2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
728 "Separate TERMS using SEPARATOR.
b0bbf97625c2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
729 If REVERSED is non-nil, the list of separated term groups will be
49477
ea69593b3b09 (eshell-separate-commands): Fix typo.
Juanma Barranquero <lekktu@gmail.com>
parents: 48211
diff changeset
730 returned in reverse order. If LAST-TERMS-SYM is a symbol, its value
29873
b0bbf97625c2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
731 will be set to a list of all the separator operators found (or '(list
b0bbf97625c2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
732 nil)' if none)."
b0bbf97625c2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
733 (let ((sub-terms (list t))
b0bbf97625c2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
734 (eshell-sep-terms (list t))
b0bbf97625c2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
735 subchains)
b0bbf97625c2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
736 (while terms
b0bbf97625c2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
737 (if (and (consp (car terms))
b0bbf97625c2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
738 (eq (caar terms) 'eshell-operator)
b0bbf97625c2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
739 (string-match (concat "^" separator "$")
b0bbf97625c2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
740 (nth 1 (car terms))))
b0bbf97625c2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
741 (progn
b0bbf97625c2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
742 (nconc eshell-sep-terms (list (nth 1 (car terms))))
b0bbf97625c2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
743 (setq subchains (cons (cdr sub-terms) subchains)
b0bbf97625c2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
744 sub-terms (list t)))
b0bbf97625c2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
745 (nconc sub-terms (list (car terms))))
b0bbf97625c2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
746 (setq terms (cdr terms)))
b0bbf97625c2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
747 (if (> (length sub-terms) 1)
b0bbf97625c2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
748 (setq subchains (cons (cdr sub-terms) subchains)))
b0bbf97625c2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
749 (if reversed
b0bbf97625c2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
750 (progn
b0bbf97625c2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
751 (if last-terms-sym
b0bbf97625c2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
752 (set last-terms-sym (reverse (cdr eshell-sep-terms))))
b0bbf97625c2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
753 subchains) ; already reversed
b0bbf97625c2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
754 (if last-terms-sym
b0bbf97625c2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
755 (set last-terms-sym (cdr eshell-sep-terms)))
b0bbf97625c2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
756 (nreverse subchains))))
b0bbf97625c2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
757
b0bbf97625c2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
758 ;;_* Command evaluation macros
b0bbf97625c2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
759 ;;
b0bbf97625c2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
760 ;; The structure of the following macros is very important to
b0bbf97625c2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
761 ;; `eshell-do-eval' [Iterative evaluation]:
b0bbf97625c2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
762 ;;
b0bbf97625c2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
763 ;; @ Don't use forms that conditionally evaluate their arguments, such
b0bbf97625c2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
764 ;; as `setq', `if', `while', `let*', etc. The only special forms
b0bbf97625c2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
765 ;; that can be used are `let', `condition-case' and
b0bbf97625c2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
766 ;; `unwind-protect'.
b0bbf97625c2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
767 ;;
b0bbf97625c2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
768 ;; @ The main body of a `let' can contain only one form. Use `progn'
b0bbf97625c2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
769 ;; if necessary.
b0bbf97625c2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
770 ;;
b0bbf97625c2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
771 ;; @ The two `special' variables are `eshell-current-handles' and
b0bbf97625c2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
772 ;; `eshell-current-subjob-p'. Bind them locally with a `let' if you
b0bbf97625c2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
773 ;; need to change them. Change them directly only if your intention
b0bbf97625c2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
774 ;; is to change the calling environment.
b0bbf97625c2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
775
b0bbf97625c2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
776 (defmacro eshell-do-subjob (object)
b0bbf97625c2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
777 "Evaluate a command OBJECT as a subjob.
62789
74e26c83386f (eshell-eval-command): If the return value of `eshell-resume-eval' is
John Wiegley <johnw@newartisans.com>
parents: 59121
diff changeset
778 We indicate that the process was run in the background by returning it
29873
b0bbf97625c2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
779 ensconced in a list."
b0bbf97625c2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
780 `(let ((eshell-current-subjob-p t))
b0bbf97625c2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
781 ,object))
b0bbf97625c2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
782
b0bbf97625c2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
783 (defmacro eshell-commands (object &optional silent)
b0bbf97625c2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
784 "Place a valid set of handles, and context, around command OBJECT."
b0bbf97625c2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
785 `(let ((eshell-current-handles
b0bbf97625c2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
786 (eshell-create-handles ,(not silent) 'append))
b0bbf97625c2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
787 eshell-current-subjob-p)
b0bbf97625c2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
788 ,object))
b0bbf97625c2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
789
b0bbf97625c2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
790 (defmacro eshell-trap-errors (object)
b0bbf97625c2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
791 "Trap any errors that occur, so they are not entirely fatal.
b0bbf97625c2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
792 Also, the variable `eshell-this-command-hook' is available for the
b0bbf97625c2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
793 duration of OBJECT's evaluation. Note that functions should be added
b0bbf97625c2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
794 to this hook using `nconc', and *not* `add-hook'.
b0bbf97625c2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
795
b0bbf97625c2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
796 Someday, when Scheme will become the dominant Emacs language, all of
b0bbf97625c2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
797 this grossness will be made to disappear by using `call/cc'..."
b0bbf97625c2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
798 `(let ((eshell-this-command-hook (list 'ignore)))
b0bbf97625c2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
799 (eshell-condition-case err
b0bbf97625c2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
800 (prog1
b0bbf97625c2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
801 ,object
b0bbf97625c2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
802 (run-hooks 'eshell-this-command-hook))
b0bbf97625c2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
803 (error
b0bbf97625c2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
804 (run-hooks 'eshell-this-command-hook)
b0bbf97625c2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
805 (eshell-errorn (error-message-string err))
b0bbf97625c2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
806 (eshell-close-handles 1)))))
b0bbf97625c2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
807
31241
3099993cba0f See ChangeLog
John Wiegley <johnw@newartisans.com>
parents: 30272
diff changeset
808 (defmacro eshell-copy-handles (object)
3099993cba0f See ChangeLog
John Wiegley <johnw@newartisans.com>
parents: 30272
diff changeset
809 "Duplicate current I/O handles, so OBJECT works with its own copy."
3099993cba0f See ChangeLog
John Wiegley <johnw@newartisans.com>
parents: 30272
diff changeset
810 `(let ((eshell-current-handles
3099993cba0f See ChangeLog
John Wiegley <johnw@newartisans.com>
parents: 30272
diff changeset
811 (eshell-create-handles
3099993cba0f See ChangeLog
John Wiegley <johnw@newartisans.com>
parents: 30272
diff changeset
812 (car (aref eshell-current-handles
3099993cba0f See ChangeLog
John Wiegley <johnw@newartisans.com>
parents: 30272
diff changeset
813 eshell-output-handle)) nil
3099993cba0f See ChangeLog
John Wiegley <johnw@newartisans.com>
parents: 30272
diff changeset
814 (car (aref eshell-current-handles
3099993cba0f See ChangeLog
John Wiegley <johnw@newartisans.com>
parents: 30272
diff changeset
815 eshell-error-handle)) nil)))
3099993cba0f See ChangeLog
John Wiegley <johnw@newartisans.com>
parents: 30272
diff changeset
816 ,object))
3099993cba0f See ChangeLog
John Wiegley <johnw@newartisans.com>
parents: 30272
diff changeset
817
29873
b0bbf97625c2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
818 (defmacro eshell-protect (object)
b0bbf97625c2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
819 "Protect I/O handles, so they aren't get closed after eval'ing OBJECT."
b0bbf97625c2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
820 `(progn
b0bbf97625c2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
821 (eshell-protect-handles eshell-current-handles)
b0bbf97625c2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
822 ,object))
b0bbf97625c2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
823
99824
df01f003c105 (eshell-in-pipeline-p): Add doc-string.
Glenn Morris <rgm@gnu.org>
parents: 98564
diff changeset
824 (defmacro eshell-do-pipelines (pipeline &optional notfirst)
df01f003c105 (eshell-in-pipeline-p): Add doc-string.
Glenn Morris <rgm@gnu.org>
parents: 98564
diff changeset
825 "Execute the commands in PIPELINE, connecting each to one another.
df01f003c105 (eshell-in-pipeline-p): Add doc-string.
Glenn Morris <rgm@gnu.org>
parents: 98564
diff changeset
826 This macro calls itself recursively, with NOTFIRST non-nil."
29873
b0bbf97625c2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
827 (when (setq pipeline (cadr pipeline))
31241
3099993cba0f See ChangeLog
John Wiegley <johnw@newartisans.com>
parents: 30272
diff changeset
828 `(eshell-copy-handles
3099993cba0f See ChangeLog
John Wiegley <johnw@newartisans.com>
parents: 30272
diff changeset
829 (progn
3099993cba0f See ChangeLog
John Wiegley <johnw@newartisans.com>
parents: 30272
diff changeset
830 ,(when (cdr pipeline)
3099993cba0f See ChangeLog
John Wiegley <johnw@newartisans.com>
parents: 30272
diff changeset
831 `(let (nextproc)
3099993cba0f See ChangeLog
John Wiegley <johnw@newartisans.com>
parents: 30272
diff changeset
832 (progn
3099993cba0f See ChangeLog
John Wiegley <johnw@newartisans.com>
parents: 30272
diff changeset
833 (set 'nextproc
99824
df01f003c105 (eshell-in-pipeline-p): Add doc-string.
Glenn Morris <rgm@gnu.org>
parents: 98564
diff changeset
834 (eshell-do-pipelines (quote ,(cdr pipeline)) t))
31241
3099993cba0f See ChangeLog
John Wiegley <johnw@newartisans.com>
parents: 30272
diff changeset
835 (eshell-set-output-handle ,eshell-output-handle
3099993cba0f See ChangeLog
John Wiegley <johnw@newartisans.com>
parents: 30272
diff changeset
836 'append nextproc)
3099993cba0f See ChangeLog
John Wiegley <johnw@newartisans.com>
parents: 30272
diff changeset
837 (eshell-set-output-handle ,eshell-error-handle
3099993cba0f See ChangeLog
John Wiegley <johnw@newartisans.com>
parents: 30272
diff changeset
838 'append nextproc)
3099993cba0f See ChangeLog
John Wiegley <johnw@newartisans.com>
parents: 30272
diff changeset
839 (set 'tailproc (or tailproc nextproc)))))
3099993cba0f See ChangeLog
John Wiegley <johnw@newartisans.com>
parents: 30272
diff changeset
840 ,(let ((head (car pipeline)))
3099993cba0f See ChangeLog
John Wiegley <johnw@newartisans.com>
parents: 30272
diff changeset
841 (if (memq (car head) '(let progn))
3099993cba0f See ChangeLog
John Wiegley <johnw@newartisans.com>
parents: 30272
diff changeset
842 (setq head (car (last head))))
3099993cba0f See ChangeLog
John Wiegley <johnw@newartisans.com>
parents: 30272
diff changeset
843 (when (memq (car head) eshell-deferrable-commands)
3099993cba0f See ChangeLog
John Wiegley <johnw@newartisans.com>
parents: 30272
diff changeset
844 (ignore
3099993cba0f See ChangeLog
John Wiegley <johnw@newartisans.com>
parents: 30272
diff changeset
845 (setcar head
3099993cba0f See ChangeLog
John Wiegley <johnw@newartisans.com>
parents: 30272
diff changeset
846 (intern-soft
3099993cba0f See ChangeLog
John Wiegley <johnw@newartisans.com>
parents: 30272
diff changeset
847 (concat (symbol-name (car head)) "*"))))))
99824
df01f003c105 (eshell-in-pipeline-p): Add doc-string.
Glenn Morris <rgm@gnu.org>
parents: 98564
diff changeset
848 ;; First and last elements in a pipeline may need special treatment.
df01f003c105 (eshell-in-pipeline-p): Add doc-string.
Glenn Morris <rgm@gnu.org>
parents: 98564
diff changeset
849 ;; (Currently only eshell-ls-files uses 'last.)
df01f003c105 (eshell-in-pipeline-p): Add doc-string.
Glenn Morris <rgm@gnu.org>
parents: 98564
diff changeset
850 ;; Affects process-connection-type in eshell-gather-process-output.
df01f003c105 (eshell-in-pipeline-p): Add doc-string.
Glenn Morris <rgm@gnu.org>
parents: 98564
diff changeset
851 (let ((eshell-in-pipeline-p
df01f003c105 (eshell-in-pipeline-p): Add doc-string.
Glenn Morris <rgm@gnu.org>
parents: 98564
diff changeset
852 ,(cond ((not notfirst) (quote 'first))
df01f003c105 (eshell-in-pipeline-p): Add doc-string.
Glenn Morris <rgm@gnu.org>
parents: 98564
diff changeset
853 ((cdr pipeline) t)
df01f003c105 (eshell-in-pipeline-p): Add doc-string.
Glenn Morris <rgm@gnu.org>
parents: 98564
diff changeset
854 (t (quote 'last)))))
97483
3c44de892298 (eshell-do-pipelines): Indicate the last command in a pipeline.
Glenn Morris <rgm@gnu.org>
parents: 97442
diff changeset
855 ,(car pipeline))))))
31241
3099993cba0f See ChangeLog
John Wiegley <johnw@newartisans.com>
parents: 30272
diff changeset
856
3099993cba0f See ChangeLog
John Wiegley <johnw@newartisans.com>
parents: 30272
diff changeset
857 (defmacro eshell-do-pipelines-synchronously (pipeline)
3099993cba0f See ChangeLog
John Wiegley <johnw@newartisans.com>
parents: 30272
diff changeset
858 "Execute the commands in PIPELINE in sequence synchronously.
3099993cba0f See ChangeLog
John Wiegley <johnw@newartisans.com>
parents: 30272
diff changeset
859 Output of each command is passed as input to the next one in the pipeline.
3099993cba0f See ChangeLog
John Wiegley <johnw@newartisans.com>
parents: 30272
diff changeset
860 This is used on systems where `start-process' is not supported."
3099993cba0f See ChangeLog
John Wiegley <johnw@newartisans.com>
parents: 30272
diff changeset
861 (when (setq pipeline (cadr pipeline))
3099993cba0f See ChangeLog
John Wiegley <johnw@newartisans.com>
parents: 30272
diff changeset
862 `(let (result)
29873
b0bbf97625c2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
863 (progn
b0bbf97625c2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
864 ,(when (cdr pipeline)
31241
3099993cba0f See ChangeLog
John Wiegley <johnw@newartisans.com>
parents: 30272
diff changeset
865 `(let (output-marker)
29873
b0bbf97625c2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
866 (progn
31241
3099993cba0f See ChangeLog
John Wiegley <johnw@newartisans.com>
parents: 30272
diff changeset
867 (set 'output-marker ,(point-marker))
29873
b0bbf97625c2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
868 (eshell-set-output-handle ,eshell-output-handle
31241
3099993cba0f See ChangeLog
John Wiegley <johnw@newartisans.com>
parents: 30272
diff changeset
869 'append output-marker)
29873
b0bbf97625c2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
870 (eshell-set-output-handle ,eshell-error-handle
31241
3099993cba0f See ChangeLog
John Wiegley <johnw@newartisans.com>
parents: 30272
diff changeset
871 'append output-marker))))
29873
b0bbf97625c2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
872 ,(let ((head (car pipeline)))
b0bbf97625c2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
873 (if (memq (car head) '(let progn))
b0bbf97625c2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
874 (setq head (car (last head))))
31241
3099993cba0f See ChangeLog
John Wiegley <johnw@newartisans.com>
parents: 30272
diff changeset
875 ;;; FIXME: is deferrable significant here?
29873
b0bbf97625c2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
876 (when (memq (car head) eshell-deferrable-commands)
b0bbf97625c2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
877 (ignore
b0bbf97625c2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
878 (setcar head
b0bbf97625c2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
879 (intern-soft
b0bbf97625c2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
880 (concat (symbol-name (car head)) "*"))))))
31241
3099993cba0f See ChangeLog
John Wiegley <johnw@newartisans.com>
parents: 30272
diff changeset
881 ;; The last process in the pipe should get its handles
3099993cba0f See ChangeLog
John Wiegley <johnw@newartisans.com>
parents: 30272
diff changeset
882 ;; redirected as we found them before running the pipe.
3099993cba0f See ChangeLog
John Wiegley <johnw@newartisans.com>
parents: 30272
diff changeset
883 ,(if (null (cdr pipeline))
3099993cba0f See ChangeLog
John Wiegley <johnw@newartisans.com>
parents: 30272
diff changeset
884 `(progn
3099993cba0f See ChangeLog
John Wiegley <johnw@newartisans.com>
parents: 30272
diff changeset
885 (set 'eshell-current-handles tail-handles)
3099993cba0f See ChangeLog
John Wiegley <johnw@newartisans.com>
parents: 30272
diff changeset
886 (set 'eshell-in-pipeline-p nil)))
3099993cba0f See ChangeLog
John Wiegley <johnw@newartisans.com>
parents: 30272
diff changeset
887 (set 'result ,(car pipeline))
3099993cba0f See ChangeLog
John Wiegley <johnw@newartisans.com>
parents: 30272
diff changeset
888 ;; tailproc gets the result of the last successful process in
3099993cba0f See ChangeLog
John Wiegley <johnw@newartisans.com>
parents: 30272
diff changeset
889 ;; the pipeline.
3099993cba0f See ChangeLog
John Wiegley <johnw@newartisans.com>
parents: 30272
diff changeset
890 (set 'tailproc (or result tailproc))
3099993cba0f See ChangeLog
John Wiegley <johnw@newartisans.com>
parents: 30272
diff changeset
891 ,(if (cdr pipeline)
3099993cba0f See ChangeLog
John Wiegley <johnw@newartisans.com>
parents: 30272
diff changeset
892 `(eshell-do-pipelines-synchronously (quote ,(cdr pipeline))))
3099993cba0f See ChangeLog
John Wiegley <johnw@newartisans.com>
parents: 30272
diff changeset
893 result))))
29873
b0bbf97625c2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
894
b0bbf97625c2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
895 (defalias 'eshell-process-identity 'identity)
b0bbf97625c2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
896
b0bbf97625c2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
897 (defmacro eshell-execute-pipeline (pipeline)
b0bbf97625c2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
898 "Execute the commands in PIPELINE, connecting each to one another."
b0bbf97625c2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
899 `(let ((eshell-in-pipeline-p t) tailproc)
b0bbf97625c2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
900 (progn
31241
3099993cba0f See ChangeLog
John Wiegley <johnw@newartisans.com>
parents: 30272
diff changeset
901 ,(if (fboundp 'start-process)
3099993cba0f See ChangeLog
John Wiegley <johnw@newartisans.com>
parents: 30272
diff changeset
902 `(eshell-do-pipelines ,pipeline)
3099993cba0f See ChangeLog
John Wiegley <johnw@newartisans.com>
parents: 30272
diff changeset
903 `(let ((tail-handles (eshell-create-handles
3099993cba0f See ChangeLog
John Wiegley <johnw@newartisans.com>
parents: 30272
diff changeset
904 (car (aref eshell-current-handles
3099993cba0f See ChangeLog
John Wiegley <johnw@newartisans.com>
parents: 30272
diff changeset
905 ,eshell-output-handle)) nil
3099993cba0f See ChangeLog
John Wiegley <johnw@newartisans.com>
parents: 30272
diff changeset
906 (car (aref eshell-current-handles
3099993cba0f See ChangeLog
John Wiegley <johnw@newartisans.com>
parents: 30272
diff changeset
907 ,eshell-error-handle)) nil)))
3099993cba0f See ChangeLog
John Wiegley <johnw@newartisans.com>
parents: 30272
diff changeset
908 (eshell-do-pipelines-synchronously ,pipeline)))
29873
b0bbf97625c2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
909 (eshell-process-identity tailproc))))
b0bbf97625c2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
910
b0bbf97625c2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
911 (defmacro eshell-as-subcommand (command)
b0bbf97625c2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
912 "Execute COMMAND using a temp buffer.
b0bbf97625c2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
913 This is used so that certain Lisp commands, such as `cd', when
b0bbf97625c2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
914 executed in a subshell, do not disturb the environment of the main
b0bbf97625c2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
915 Eshell buffer."
b0bbf97625c2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
916 `(let ,eshell-subcommand-bindings
b0bbf97625c2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
917 ,command))
b0bbf97625c2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
918
b0bbf97625c2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
919 (defmacro eshell-do-command-to-value (object)
b0bbf97625c2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
920 "Run a subcommand prepared by `eshell-command-to-value'.
b0bbf97625c2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
921 This avoids the need to use `let*'."
b0bbf97625c2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
922 `(let ((eshell-current-handles
b0bbf97625c2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
923 (eshell-create-handles value 'overwrite)))
b0bbf97625c2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
924 (progn
b0bbf97625c2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
925 ,object
b0bbf97625c2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
926 (symbol-value value))))
b0bbf97625c2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
927
b0bbf97625c2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
928 (defmacro eshell-command-to-value (object)
b0bbf97625c2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
929 "Run OBJECT synchronously, returning its result as a string.
b0bbf97625c2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
930 Returns a string comprising the output from the command."
b0bbf97625c2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
931 `(let ((value (make-symbol "eshell-temp")))
b0bbf97625c2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
932 (eshell-do-command-to-value ,object)))
b0bbf97625c2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
933
b0bbf97625c2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
934 ;;;_* Iterative evaluation
b0bbf97625c2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
935 ;;
b0bbf97625c2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
936 ;; Eshell runs all of its external commands asynchronously, so that
b0bbf97625c2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
937 ;; Emacs is not blocked while the operation is being performed.
b0bbf97625c2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
938 ;; However, this introduces certain synchronization difficulties,
b0bbf97625c2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
939 ;; since the Lisp code, once it returns, will not "go back" to finish
b0bbf97625c2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
940 ;; executing the commands which haven't yet been started.
b0bbf97625c2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
941 ;;
b0bbf97625c2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
942 ;; What Eshell does to work around this problem (basically, the lack
b0bbf97625c2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
943 ;; of threads in Lisp), is that it evaluates the command sequence
b0bbf97625c2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
944 ;; iteratively. Whenever an asynchronous process is begun, evaluation
b0bbf97625c2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
945 ;; terminates and control is given back to Emacs. When that process
b0bbf97625c2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
946 ;; finishes, it will resume the evaluation using the remainder of the
b0bbf97625c2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
947 ;; command tree.
b0bbf97625c2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
948
b0bbf97625c2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
949 (defun eshell/eshell-debug (&rest args)
b0bbf97625c2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
950 "A command for toggling certain debug variables."
b0bbf97625c2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
951 (ignore
b0bbf97625c2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
952 (cond
b0bbf97625c2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
953 ((not args)
b0bbf97625c2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
954 (if eshell-handle-errors
b0bbf97625c2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
955 (eshell-print "errors\n"))
b0bbf97625c2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
956 (if eshell-debug-command
b0bbf97625c2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
957 (eshell-print "commands\n")))
b0bbf97625c2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
958 ((or (string= (car args) "-h")
b0bbf97625c2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
959 (string= (car args) "--help"))
b0bbf97625c2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
960 (eshell-print "usage: eshell-debug [kinds]
b0bbf97625c2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
961
b0bbf97625c2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
962 This command is used to aid in debugging problems related to Eshell
b0bbf97625c2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
963 itself. It is not useful for anything else. The recognized `kinds'
b0bbf97625c2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
964 at the moment are:
b0bbf97625c2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
965
b0bbf97625c2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
966 errors stops Eshell from trapping errors
b0bbf97625c2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
967 commands shows command execution progress in `*eshell last cmd*'
b0bbf97625c2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
968 "))
b0bbf97625c2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
969 (t
b0bbf97625c2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
970 (while args
b0bbf97625c2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
971 (cond
b0bbf97625c2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
972 ((string= (car args) "errors")
b0bbf97625c2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
973 (setq eshell-handle-errors (not eshell-handle-errors)))
b0bbf97625c2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
974 ((string= (car args) "commands")
b0bbf97625c2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
975 (setq eshell-debug-command (not eshell-debug-command))))
b0bbf97625c2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
976 (setq args (cdr args)))))))
b0bbf97625c2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
977
b0bbf97625c2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
978 (defun pcomplete/eshell-mode/eshell-debug ()
b0bbf97625c2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
979 "Completion for the `debug' command."
b0bbf97625c2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
980 (while (pcomplete-here '("errors" "commands"))))
b0bbf97625c2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
981
33020
e21feeab77fb See ChangeLog
John Wiegley <johnw@newartisans.com>
parents: 32526
diff changeset
982 (defun eshell-invoke-directly (command input)
e21feeab77fb See ChangeLog
John Wiegley <johnw@newartisans.com>
parents: 32526
diff changeset
983 (let ((base (cadr (nth 2 (nth 2 (cadr command))))) name)
e21feeab77fb See ChangeLog
John Wiegley <johnw@newartisans.com>
parents: 32526
diff changeset
984 (if (and (eq (car base) 'eshell-trap-errors)
e21feeab77fb See ChangeLog
John Wiegley <johnw@newartisans.com>
parents: 32526
diff changeset
985 (eq (car (cadr base)) 'eshell-named-command))
e21feeab77fb See ChangeLog
John Wiegley <johnw@newartisans.com>
parents: 32526
diff changeset
986 (setq name (cadr (cadr base))))
e21feeab77fb See ChangeLog
John Wiegley <johnw@newartisans.com>
parents: 32526
diff changeset
987 (and name (stringp name)
e21feeab77fb See ChangeLog
John Wiegley <johnw@newartisans.com>
parents: 32526
diff changeset
988 (not (member name eshell-complex-commands))
e21feeab77fb See ChangeLog
John Wiegley <johnw@newartisans.com>
parents: 32526
diff changeset
989 (catch 'simple
e21feeab77fb See ChangeLog
John Wiegley <johnw@newartisans.com>
parents: 32526
diff changeset
990 (progn
e21feeab77fb See ChangeLog
John Wiegley <johnw@newartisans.com>
parents: 32526
diff changeset
991 (eshell-for pred eshell-complex-commands
e21feeab77fb See ChangeLog
John Wiegley <johnw@newartisans.com>
parents: 32526
diff changeset
992 (if (and (functionp pred)
e21feeab77fb See ChangeLog
John Wiegley <johnw@newartisans.com>
parents: 32526
diff changeset
993 (funcall pred name))
e21feeab77fb See ChangeLog
John Wiegley <johnw@newartisans.com>
parents: 32526
diff changeset
994 (throw 'simple nil)))
e21feeab77fb See ChangeLog
John Wiegley <johnw@newartisans.com>
parents: 32526
diff changeset
995 t))
e21feeab77fb See ChangeLog
John Wiegley <johnw@newartisans.com>
parents: 32526
diff changeset
996 (fboundp (intern-soft (concat "eshell/" name))))))
e21feeab77fb See ChangeLog
John Wiegley <johnw@newartisans.com>
parents: 32526
diff changeset
997
29873
b0bbf97625c2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
998 (defun eshell-eval-command (command &optional input)
b0bbf97625c2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
999 "Evaluate the given COMMAND iteratively."
b0bbf97625c2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
1000 (if eshell-current-command
b0bbf97625c2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
1001 ;; we can just stick the new command at the end of the current
b0bbf97625c2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
1002 ;; one, and everything will happen as it should
b0bbf97625c2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
1003 (setcdr (last (cdr eshell-current-command))
b0bbf97625c2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
1004 (list (list 'let '((here (and (eobp) (point))))
b0bbf97625c2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
1005 (and input
b0bbf97625c2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
1006 (list 'insert-and-inherit
b0bbf97625c2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
1007 (concat input "\n")))
b0bbf97625c2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
1008 '(if here
b0bbf97625c2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
1009 (eshell-update-markers here))
b0bbf97625c2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
1010 (list 'eshell-do-eval
b0bbf97625c2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
1011 (list 'quote command)))))
b0bbf97625c2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
1012 (and eshell-debug-command
96274
b0ac9927a5c0 (eshell-manipulate): Check eshell-debug-command is bound before using it.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 95619
diff changeset
1013 (with-current-buffer (get-buffer-create "*eshell last cmd*")
b0ac9927a5c0 (eshell-manipulate): Check eshell-debug-command is bound before using it.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 95619
diff changeset
1014 (erase-buffer)
b0ac9927a5c0 (eshell-manipulate): Check eshell-debug-command is bound before using it.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 95619
diff changeset
1015 (insert "command: \"" input "\"\n")))
29873
b0bbf97625c2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
1016 (setq eshell-current-command command)
31241
3099993cba0f See ChangeLog
John Wiegley <johnw@newartisans.com>
parents: 30272
diff changeset
1017 (let ((delim (catch 'eshell-incomplete
3099993cba0f See ChangeLog
John Wiegley <johnw@newartisans.com>
parents: 30272
diff changeset
1018 (eshell-resume-eval))))
42971
a4e7fd8ad209 (eshell-eval-command): If eshell-resume-eval
Eli Zaretskii <eliz@gnu.org>
parents: 38414
diff changeset
1019 ;; On systems that don't support async subprocesses, eshell-resume
a4e7fd8ad209 (eshell-eval-command): If eshell-resume-eval
Eli Zaretskii <eliz@gnu.org>
parents: 38414
diff changeset
1020 ;; can return t. Don't treat that as an error.
62789
74e26c83386f (eshell-eval-command): If the return value of `eshell-resume-eval' is
John Wiegley <johnw@newartisans.com>
parents: 59121
diff changeset
1021 (if (listp delim)
74e26c83386f (eshell-eval-command): If the return value of `eshell-resume-eval' is
John Wiegley <johnw@newartisans.com>
parents: 59121
diff changeset
1022 (setq delim (car delim)))
42971
a4e7fd8ad209 (eshell-eval-command): If eshell-resume-eval
Eli Zaretskii <eliz@gnu.org>
parents: 38414
diff changeset
1023 (if (and delim (not (eq delim t)))
62789
74e26c83386f (eshell-eval-command): If the return value of `eshell-resume-eval' is
John Wiegley <johnw@newartisans.com>
parents: 59121
diff changeset
1024 (error "Unmatched delimiter: %c" delim)))))
29873
b0bbf97625c2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
1025
b0bbf97625c2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
1026 (defun eshell-resume-command (proc status)
b0bbf97625c2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
1027 "Resume the current command when a process ends."
b0bbf97625c2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
1028 (when proc
31241
3099993cba0f See ChangeLog
John Wiegley <johnw@newartisans.com>
parents: 30272
diff changeset
1029 (unless (or (not (stringp status))
3099993cba0f See ChangeLog
John Wiegley <johnw@newartisans.com>
parents: 30272
diff changeset
1030 (string= "stopped" status)
29873
b0bbf97625c2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
1031 (string-match eshell-reset-signals status))
b0bbf97625c2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
1032 (if (eq proc (eshell-interactive-process))
b0bbf97625c2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
1033 (eshell-resume-eval)))))
b0bbf97625c2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
1034
b0bbf97625c2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
1035 (defun eshell-resume-eval ()
b0bbf97625c2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
1036 "Destructively evaluate a form which may need to be deferred."
b0bbf97625c2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
1037 (eshell-condition-case err
b0bbf97625c2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
1038 (progn
b0bbf97625c2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
1039 (setq eshell-last-async-proc nil)
b0bbf97625c2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
1040 (when eshell-current-command
b0bbf97625c2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
1041 (let* (retval
b0bbf97625c2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
1042 (proc (catch 'eshell-defer
b0bbf97625c2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
1043 (ignore
b0bbf97625c2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
1044 (setq retval
b0bbf97625c2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
1045 (eshell-do-eval
b0bbf97625c2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
1046 eshell-current-command))))))
31241
3099993cba0f See ChangeLog
John Wiegley <johnw@newartisans.com>
parents: 30272
diff changeset
1047 (if (eshell-processp proc)
29873
b0bbf97625c2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
1048 (ignore (setq eshell-last-async-proc proc))
b0bbf97625c2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
1049 (cadr retval)))))
b0bbf97625c2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
1050 (error
b0bbf97625c2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
1051 (error (error-message-string err)))))
b0bbf97625c2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
1052
b0bbf97625c2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
1053 (defmacro eshell-manipulate (tag &rest commands)
b0bbf97625c2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
1054 "Manipulate a COMMAND form, with TAG as a debug identifier."
96274
b0ac9927a5c0 (eshell-manipulate): Check eshell-debug-command is bound before using it.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 95619
diff changeset
1055 ;; Check `bound'ness since at compile time the code until here has not
b0ac9927a5c0 (eshell-manipulate): Check eshell-debug-command is bound before using it.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 95619
diff changeset
1056 ;; executed yet.
b0ac9927a5c0 (eshell-manipulate): Check eshell-debug-command is bound before using it.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 95619
diff changeset
1057 (if (not (and (boundp 'eshell-debug-command) eshell-debug-command))
29873
b0bbf97625c2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
1058 `(progn ,@commands)
b0bbf97625c2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
1059 `(progn
b0bbf97625c2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
1060 (eshell-debug-command ,(eval tag) form)
b0bbf97625c2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
1061 ,@commands
b0bbf97625c2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
1062 (eshell-debug-command ,(concat "done " (eval tag)) form))))
b0bbf97625c2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
1063
b0bbf97625c2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
1064 (put 'eshell-manipulate 'lisp-indent-function 1)
b0bbf97625c2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
1065
b0bbf97625c2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
1066 ;; eshell-lookup-function, eshell-functionp, and eshell-macrop taken
b0bbf97625c2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
1067 ;; from edebug
b0bbf97625c2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
1068
b0bbf97625c2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
1069 (defsubst eshell-lookup-function (object)
b0bbf97625c2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
1070 "Return the ultimate function definition of OBJECT."
b0bbf97625c2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
1071 (while (and (symbolp object) (fboundp object))
b0bbf97625c2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
1072 (setq object (symbol-function object)))
b0bbf97625c2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
1073 object)
b0bbf97625c2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
1074
b0bbf97625c2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
1075 (defconst function-p-func
48211
e23f9344f37d (function-p-func): Avoid `xemacs-p'.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 43335
diff changeset
1076 (if (fboundp 'compiled-function-p)
29873
b0bbf97625c2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
1077 'compiled-function-p
b0bbf97625c2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
1078 'byte-code-function-p))
b0bbf97625c2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
1079
b0bbf97625c2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
1080 (defsubst eshell-functionp (object)
b0bbf97625c2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
1081 "Returns the function named by OBJECT, or nil if it is not a function."
b0bbf97625c2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
1082 (setq object (eshell-lookup-function object))
b0bbf97625c2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
1083 (if (or (subrp object)
b0bbf97625c2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
1084 (funcall function-p-func object)
b0bbf97625c2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
1085 (and (listp object)
b0bbf97625c2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
1086 (eq (car object) 'lambda)
b0bbf97625c2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
1087 (listp (car (cdr object)))))
b0bbf97625c2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
1088 object))
b0bbf97625c2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
1089
b0bbf97625c2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
1090 (defsubst eshell-macrop (object)
b0bbf97625c2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
1091 "Return t if OBJECT is a macro or nil otherwise."
b0bbf97625c2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
1092 (setq object (eshell-lookup-function object))
b0bbf97625c2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
1093 (if (and (listp object)
b0bbf97625c2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
1094 (eq 'macro (car object))
b0bbf97625c2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
1095 (eshell-functionp (cdr object)))
b0bbf97625c2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
1096 t))
b0bbf97625c2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
1097
b0bbf97625c2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
1098 (defun eshell-do-eval (form &optional synchronous-p)
b0bbf97625c2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
1099 "Evaluate form, simplifying it as we go.
b0bbf97625c2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
1100 Unless SYNCHRONOUS-P is non-nil, throws `eshell-defer' if it needs to
b0bbf97625c2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
1101 be finished later after the completion of an asynchronous subprocess."
b0bbf97625c2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
1102 (cond
b0bbf97625c2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
1103 ((not (listp form))
b0bbf97625c2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
1104 (list 'quote (eval form)))
b0bbf97625c2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
1105 ((memq (car form) '(quote function))
b0bbf97625c2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
1106 form)
b0bbf97625c2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
1107 (t
b0bbf97625c2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
1108 ;; skip past the call to `eshell-do-eval'
b0bbf97625c2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
1109 (when (eq (car form) 'eshell-do-eval)
b0bbf97625c2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
1110 (setq form (cadr (cadr form))))
b0bbf97625c2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
1111 ;; expand any macros directly into the form. This is done so that
b0bbf97625c2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
1112 ;; we can modify any `let' forms to evaluate only once.
b0bbf97625c2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
1113 (if (eshell-macrop (car form))
b0bbf97625c2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
1114 (let ((exp (eshell-copy-tree (macroexpand form))))
b0bbf97625c2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
1115 (eshell-manipulate (format "expanding macro `%s'"
b0bbf97625c2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
1116 (symbol-name (car form)))
b0bbf97625c2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
1117 (setcar form (car exp))
b0bbf97625c2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
1118 (setcdr form (cdr exp)))))
b0bbf97625c2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
1119 (let ((args (cdr form)))
b0bbf97625c2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
1120 (cond
b0bbf97625c2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
1121 ((eq (car form) 'while)
b0bbf97625c2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
1122 ;; `eshell-copy-tree' is needed here so that the test argument
b0bbf97625c2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
1123 ;; doesn't get modified and thus always yield the same result.
b0bbf97625c2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
1124 (when (car eshell-command-body)
b0bbf97625c2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
1125 (assert (not synchronous-p))
b0bbf97625c2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
1126 (eshell-do-eval (car eshell-command-body))
31241
3099993cba0f See ChangeLog
John Wiegley <johnw@newartisans.com>
parents: 30272
diff changeset
1127 (setcar eshell-command-body nil)
3099993cba0f See ChangeLog
John Wiegley <johnw@newartisans.com>
parents: 30272
diff changeset
1128 (setcar eshell-test-body nil))
29873
b0bbf97625c2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
1129 (unless (car eshell-test-body)
b0bbf97625c2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
1130 (setcar eshell-test-body (eshell-copy-tree (car args))))
31241
3099993cba0f See ChangeLog
John Wiegley <johnw@newartisans.com>
parents: 30272
diff changeset
1131 (while (cadr (eshell-do-eval (car eshell-test-body)))
3099993cba0f See ChangeLog
John Wiegley <johnw@newartisans.com>
parents: 30272
diff changeset
1132 (setcar eshell-command-body (eshell-copy-tree (cadr args)))
3099993cba0f See ChangeLog
John Wiegley <johnw@newartisans.com>
parents: 30272
diff changeset
1133 (eshell-do-eval (car eshell-command-body) synchronous-p)
3099993cba0f See ChangeLog
John Wiegley <johnw@newartisans.com>
parents: 30272
diff changeset
1134 (setcar eshell-command-body nil)
3099993cba0f See ChangeLog
John Wiegley <johnw@newartisans.com>
parents: 30272
diff changeset
1135 (setcar eshell-test-body (eshell-copy-tree (car args))))
29873
b0bbf97625c2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
1136 (setcar eshell-command-body nil))
b0bbf97625c2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
1137 ((eq (car form) 'if)
b0bbf97625c2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
1138 ;; `eshell-copy-tree' is needed here so that the test argument
b0bbf97625c2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
1139 ;; doesn't get modified and thus always yield the same result.
31241
3099993cba0f See ChangeLog
John Wiegley <johnw@newartisans.com>
parents: 30272
diff changeset
1140 (if (car eshell-command-body)
3099993cba0f See ChangeLog
John Wiegley <johnw@newartisans.com>
parents: 30272
diff changeset
1141 (progn
3099993cba0f See ChangeLog
John Wiegley <johnw@newartisans.com>
parents: 30272
diff changeset
1142 (assert (not synchronous-p))
3099993cba0f See ChangeLog
John Wiegley <johnw@newartisans.com>
parents: 30272
diff changeset
1143 (eshell-do-eval (car eshell-command-body)))
3099993cba0f See ChangeLog
John Wiegley <johnw@newartisans.com>
parents: 30272
diff changeset
1144 (unless (car eshell-test-body)
3099993cba0f See ChangeLog
John Wiegley <johnw@newartisans.com>
parents: 30272
diff changeset
1145 (setcar eshell-test-body (eshell-copy-tree (car args))))
3099993cba0f See ChangeLog
John Wiegley <johnw@newartisans.com>
parents: 30272
diff changeset
1146 (if (cadr (eshell-do-eval (car eshell-test-body)))
3099993cba0f See ChangeLog
John Wiegley <johnw@newartisans.com>
parents: 30272
diff changeset
1147 (setcar eshell-command-body (eshell-copy-tree (cadr args)))
3099993cba0f See ChangeLog
John Wiegley <johnw@newartisans.com>
parents: 30272
diff changeset
1148 (setcar eshell-command-body (eshell-copy-tree (car (cddr args)))))
3099993cba0f See ChangeLog
John Wiegley <johnw@newartisans.com>
parents: 30272
diff changeset
1149 (eshell-do-eval (car eshell-command-body) synchronous-p))
3099993cba0f See ChangeLog
John Wiegley <johnw@newartisans.com>
parents: 30272
diff changeset
1150 (setcar eshell-command-body nil)
3099993cba0f See ChangeLog
John Wiegley <johnw@newartisans.com>
parents: 30272
diff changeset
1151 (setcar eshell-test-body nil))
29873
b0bbf97625c2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
1152 ((eq (car form) 'setcar)
b0bbf97625c2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
1153 (setcar (cdr args) (eshell-do-eval (cadr args) synchronous-p))
b0bbf97625c2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
1154 (eval form))
b0bbf97625c2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
1155 ((eq (car form) 'setcdr)
b0bbf97625c2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
1156 (setcar (cdr args) (eshell-do-eval (cadr args) synchronous-p))
b0bbf97625c2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
1157 (eval form))
b0bbf97625c2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
1158 ((memq (car form) '(let catch condition-case unwind-protect))
b0bbf97625c2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
1159 ;; `let', `condition-case' and `unwind-protect' have to be
b0bbf97625c2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
1160 ;; handled specially, because we only want to call
b0bbf97625c2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
1161 ;; `eshell-do-eval' on their first form.
b0bbf97625c2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
1162 ;;
b0bbf97625c2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
1163 ;; NOTE: This requires obedience by all forms which this
b0bbf97625c2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
1164 ;; function might encounter, that they do not contain
b0bbf97625c2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
1165 ;; other special forms.
b0bbf97625c2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
1166 (if (and (eq (car form) 'let)
b0bbf97625c2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
1167 (not (eq (car (cadr args)) 'eshell-do-eval)))
b0bbf97625c2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
1168 (eshell-manipulate "evaluating let args"
b0bbf97625c2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
1169 (eshell-for letarg (car args)
b0bbf97625c2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
1170 (if (and (listp letarg)
b0bbf97625c2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
1171 (not (eq (cadr letarg) 'quote)))
b0bbf97625c2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
1172 (setcdr letarg
b0bbf97625c2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
1173 (list (eshell-do-eval
b0bbf97625c2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
1174 (cadr letarg) synchronous-p)))))))
b0bbf97625c2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
1175 (unless (eq (car form) 'unwind-protect)
b0bbf97625c2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
1176 (setq args (cdr args)))
b0bbf97625c2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
1177 (unless (eq (caar args) 'eshell-do-eval)
b0bbf97625c2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
1178 (eshell-manipulate "handling special form"
b0bbf97625c2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
1179 (setcar args (list 'eshell-do-eval
b0bbf97625c2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
1180 (list 'quote (car args))
b0bbf97625c2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
1181 synchronous-p))))
b0bbf97625c2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
1182 (eval form))
b0bbf97625c2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
1183 (t
b0bbf97625c2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
1184 (if (and args (not (memq (car form) '(run-hooks))))
b0bbf97625c2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
1185 (eshell-manipulate
b0bbf97625c2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
1186 (format "evaluating arguments to `%s'"
b0bbf97625c2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
1187 (symbol-name (car form)))
b0bbf97625c2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
1188 (while args
b0bbf97625c2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
1189 (setcar args (eshell-do-eval (car args) synchronous-p))
b0bbf97625c2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
1190 (setq args (cdr args)))))
b0bbf97625c2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
1191 (cond
b0bbf97625c2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
1192 ((eq (car form) 'progn)
b0bbf97625c2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
1193 (car (last form)))
b0bbf97625c2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
1194 ((eq (car form) 'prog1)
b0bbf97625c2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
1195 (cadr form))
b0bbf97625c2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
1196 (t
33020
e21feeab77fb See ChangeLog
John Wiegley <johnw@newartisans.com>
parents: 32526
diff changeset
1197 ;; If a command desire to replace its execution form with
e21feeab77fb See ChangeLog
John Wiegley <johnw@newartisans.com>
parents: 32526
diff changeset
1198 ;; another command form, all it needs to do is throw the new
e21feeab77fb See ChangeLog
John Wiegley <johnw@newartisans.com>
parents: 32526
diff changeset
1199 ;; form using the exception tag `eshell-replace-command'.
e21feeab77fb See ChangeLog
John Wiegley <johnw@newartisans.com>
parents: 32526
diff changeset
1200 ;; For example, let's say that the form currently being
e21feeab77fb See ChangeLog
John Wiegley <johnw@newartisans.com>
parents: 32526
diff changeset
1201 ;; eval'd is:
e21feeab77fb See ChangeLog
John Wiegley <johnw@newartisans.com>
parents: 32526
diff changeset
1202 ;;
e21feeab77fb See ChangeLog
John Wiegley <johnw@newartisans.com>
parents: 32526
diff changeset
1203 ;; (eshell-named-command "hello")
e21feeab77fb See ChangeLog
John Wiegley <johnw@newartisans.com>
parents: 32526
diff changeset
1204 ;;
e21feeab77fb See ChangeLog
John Wiegley <johnw@newartisans.com>
parents: 32526
diff changeset
1205 ;; Now, let's assume the 'hello' command is an Eshell alias,
e21feeab77fb See ChangeLog
John Wiegley <johnw@newartisans.com>
parents: 32526
diff changeset
1206 ;; the definition of which yields the command:
e21feeab77fb See ChangeLog
John Wiegley <johnw@newartisans.com>
parents: 32526
diff changeset
1207 ;;
e21feeab77fb See ChangeLog
John Wiegley <johnw@newartisans.com>
parents: 32526
diff changeset
1208 ;; (eshell-named-command "echo" (list "Hello" "world"))
e21feeab77fb See ChangeLog
John Wiegley <johnw@newartisans.com>
parents: 32526
diff changeset
1209 ;;
e21feeab77fb See ChangeLog
John Wiegley <johnw@newartisans.com>
parents: 32526
diff changeset
1210 ;; What the alias code would like to do is simply substitute
e21feeab77fb See ChangeLog
John Wiegley <johnw@newartisans.com>
parents: 32526
diff changeset
1211 ;; the alias form for the original form. To accomplish
e21feeab77fb See ChangeLog
John Wiegley <johnw@newartisans.com>
parents: 32526
diff changeset
1212 ;; this, all it needs to do is to throw the substitution
e21feeab77fb See ChangeLog
John Wiegley <johnw@newartisans.com>
parents: 32526
diff changeset
1213 ;; form with the `eshell-replace-command' tag, and the form
e21feeab77fb See ChangeLog
John Wiegley <johnw@newartisans.com>
parents: 32526
diff changeset
1214 ;; will be replaced within the current command, and
e21feeab77fb See ChangeLog
John Wiegley <johnw@newartisans.com>
parents: 32526
diff changeset
1215 ;; execution will then resume (iteratively) as before.
e21feeab77fb See ChangeLog
John Wiegley <johnw@newartisans.com>
parents: 32526
diff changeset
1216 ;; Thus, aliases can even contain references to asynchronous
e21feeab77fb See ChangeLog
John Wiegley <johnw@newartisans.com>
parents: 32526
diff changeset
1217 ;; sub-commands, and things will still work out as they
e21feeab77fb See ChangeLog
John Wiegley <johnw@newartisans.com>
parents: 32526
diff changeset
1218 ;; should.
29873
b0bbf97625c2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
1219 (let (result new-form)
b0bbf97625c2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
1220 (if (setq new-form
b0bbf97625c2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
1221 (catch 'eshell-replace-command
b0bbf97625c2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
1222 (ignore
b0bbf97625c2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
1223 (setq result (eval form)))))
b0bbf97625c2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
1224 (progn
b0bbf97625c2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
1225 (eshell-manipulate "substituting replacement form"
b0bbf97625c2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
1226 (setcar form (car new-form))
b0bbf97625c2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
1227 (setcdr form (cdr new-form)))
b0bbf97625c2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
1228 (eshell-do-eval form synchronous-p))
b0bbf97625c2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
1229 (if (and (memq (car form) eshell-deferrable-commands)
b0bbf97625c2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
1230 (not eshell-current-subjob-p)
b0bbf97625c2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
1231 result
31241
3099993cba0f See ChangeLog
John Wiegley <johnw@newartisans.com>
parents: 30272
diff changeset
1232 (eshell-processp result))
29873
b0bbf97625c2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
1233 (if synchronous-p
b0bbf97625c2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
1234 (eshell/wait result)
b0bbf97625c2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
1235 (eshell-manipulate "inserting ignore form"
b0bbf97625c2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
1236 (setcar form 'ignore)
b0bbf97625c2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
1237 (setcdr form nil))
b0bbf97625c2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
1238 (throw 'eshell-defer result))
b0bbf97625c2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
1239 (list 'quote result))))))))))))
b0bbf97625c2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
1240
b0bbf97625c2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
1241 ;; command invocation
b0bbf97625c2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
1242
b0bbf97625c2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
1243 (defun eshell/which (command &rest names)
b0bbf97625c2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
1244 "Identify the COMMAND, and where it is located."
b0bbf97625c2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
1245 (eshell-for name (cons command names)
b0bbf97625c2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
1246 (let (program alias direct)
37817
431f430082e9 (eshell/which): Use `eshell-explicit-command-char' instead of ?*.
John Wiegley <johnw@newartisans.com>
parents: 37665
diff changeset
1247 (if (eq (aref name 0) eshell-explicit-command-char)
29873
b0bbf97625c2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
1248 (setq name (substring name 1)
b0bbf97625c2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
1249 direct t))
b0bbf97625c2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
1250 (if (and (not direct)
b0bbf97625c2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
1251 (eshell-using-module 'eshell-alias)
b0bbf97625c2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
1252 (setq alias
b0bbf97625c2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
1253 (funcall (symbol-function 'eshell-lookup-alias)
b0bbf97625c2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
1254 name)))
b0bbf97625c2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
1255 (setq program
b0bbf97625c2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
1256 (concat name " is an alias, defined as \""
b0bbf97625c2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
1257 (cadr alias) "\"")))
b0bbf97625c2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
1258 (unless program
b0bbf97625c2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
1259 (setq program (eshell-search-path name))
b0bbf97625c2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
1260 (let* ((esym (eshell-find-alias-function name))
b0bbf97625c2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
1261 (sym (or esym (intern-soft name))))
55968
db23082093f5 2004-06-06 Emilio C. Lopes <eclig@gmx.net>
John Wiegley <johnw@newartisans.com>
parents: 54568
diff changeset
1262 (if (and (or esym (and sym (fboundp sym)))
db23082093f5 2004-06-06 Emilio C. Lopes <eclig@gmx.net>
John Wiegley <johnw@newartisans.com>
parents: 54568
diff changeset
1263 (or eshell-prefer-lisp-functions (not direct)))
29873
b0bbf97625c2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
1264 (let ((desc (let ((inhibit-redisplay t))
b0bbf97625c2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
1265 (save-window-excursion
b0bbf97625c2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
1266 (prog1
b0bbf97625c2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
1267 (describe-function sym)
b0bbf97625c2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
1268 (message nil))))))
97442
5be4c494e1d5 (eshell/which): Handle the case where no description is found.
Glenn Morris <rgm@gnu.org>
parents: 96274
diff changeset
1269 (setq desc (if desc (substring desc 0
5be4c494e1d5 (eshell/which): Handle the case where no description is found.
Glenn Morris <rgm@gnu.org>
parents: 96274
diff changeset
1270 (1- (or (string-match "\n" desc)
5be4c494e1d5 (eshell/which): Handle the case where no description is found.
Glenn Morris <rgm@gnu.org>
parents: 96274
diff changeset
1271 (length desc))))
5be4c494e1d5 (eshell/which): Handle the case where no description is found.
Glenn Morris <rgm@gnu.org>
parents: 96274
diff changeset
1272 ;; This should not happen.
5be4c494e1d5 (eshell/which): Handle the case where no description is found.
Glenn Morris <rgm@gnu.org>
parents: 96274
diff changeset
1273 (format "%s is defined, \
5be4c494e1d5 (eshell/which): Handle the case where no description is found.
Glenn Morris <rgm@gnu.org>
parents: 96274
diff changeset
1274 but no documentation was found" name)))
31241
3099993cba0f See ChangeLog
John Wiegley <johnw@newartisans.com>
parents: 30272
diff changeset
1275 (if (buffer-live-p (get-buffer "*Help*"))
3099993cba0f See ChangeLog
John Wiegley <johnw@newartisans.com>
parents: 30272
diff changeset
1276 (kill-buffer "*Help*"))
29873
b0bbf97625c2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
1277 (setq program (or desc name))))))
b0bbf97625c2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
1278 (if (not program)
b0bbf97625c2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
1279 (eshell-error (format "which: no %s in (%s)\n"
b0bbf97625c2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
1280 name (getenv "PATH")))
b0bbf97625c2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
1281 (eshell-printn program)))))
b0bbf97625c2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
1282
37662
cb20d33bef50 (eshell-lisp-command): Don't perform numeric conversions if a Lisp
John Wiegley <johnw@newartisans.com>
parents: 37657
diff changeset
1283 (put 'eshell/which 'eshell-no-numeric-conversions t)
cb20d33bef50 (eshell-lisp-command): Don't perform numeric conversions if a Lisp
John Wiegley <johnw@newartisans.com>
parents: 37657
diff changeset
1284
29873
b0bbf97625c2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
1285 (defun eshell-named-command (command &optional args)
b0bbf97625c2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
1286 "Insert output from a plain COMMAND, using ARGS.
b0bbf97625c2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
1287 COMMAND may result in an alias being executed, or a plain command."
b0bbf97625c2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
1288 (setq eshell-last-arguments args
b0bbf97625c2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
1289 eshell-last-command-name (eshell-stringify command))
b0bbf97625c2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
1290 (run-hook-with-args 'eshell-prepare-command-hook)
b0bbf97625c2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
1291 (assert (stringp eshell-last-command-name))
b0bbf97625c2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
1292 (if eshell-last-command-name
b0bbf97625c2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
1293 (or (run-hook-with-args-until-success
b0bbf97625c2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
1294 'eshell-named-command-hook eshell-last-command-name
b0bbf97625c2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
1295 eshell-last-arguments)
b0bbf97625c2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
1296 (eshell-plain-command eshell-last-command-name
b0bbf97625c2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
1297 eshell-last-arguments))))
b0bbf97625c2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
1298
b0bbf97625c2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
1299 (defalias 'eshell-named-command* 'eshell-named-command)
b0bbf97625c2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
1300
b0bbf97625c2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
1301 (defun eshell-find-alias-function (name)
b0bbf97625c2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
1302 "Check whether a function called `eshell/NAME' exists."
b0bbf97625c2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
1303 (let* ((sym (intern-soft (concat "eshell/" name)))
59121
7b2031432b63 (eshell-find-alias-function): Call symbol-file with `defun'.
Richard M. Stallman <rms@gnu.org>
parents: 55968
diff changeset
1304 (file (symbol-file sym 'defun)))
37442
f4b209194d8c (eshell-find-alias-function): Return t in the case where the function
John Wiegley <johnw@newartisans.com>
parents: 33020
diff changeset
1305 ;; If the function exists, but is defined in an eshell module
f4b209194d8c (eshell-find-alias-function): Return t in the case where the function
John Wiegley <johnw@newartisans.com>
parents: 33020
diff changeset
1306 ;; that's not currently enabled, don't report it as found
29873
b0bbf97625c2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
1307 (if (and file
b0bbf97625c2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
1308 (string-match "\\(em\\|esh\\)-\\(.*\\)\\(\\.el\\)?\\'" file))
37442
f4b209194d8c (eshell-find-alias-function): Return t in the case where the function
John Wiegley <johnw@newartisans.com>
parents: 33020
diff changeset
1309 (let ((module-sym
29873
b0bbf97625c2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
1310 (intern (file-name-sans-extension
37442
f4b209194d8c (eshell-find-alias-function): Return t in the case where the function
John Wiegley <johnw@newartisans.com>
parents: 33020
diff changeset
1311 (file-name-nondirectory
f4b209194d8c (eshell-find-alias-function): Return t in the case where the function
John Wiegley <johnw@newartisans.com>
parents: 33020
diff changeset
1312 (concat "eshell-" (match-string 2 file)))))))
37450
b1c5785dbec5 (eshell-find-alias-function): Corrected the fix from last night, since
John Wiegley <johnw@newartisans.com>
parents: 37442
diff changeset
1313 (if (and (functionp sym)
b1c5785dbec5 (eshell-find-alias-function): Corrected the fix from last night, since
John Wiegley <johnw@newartisans.com>
parents: 37442
diff changeset
1314 (or (null module-sym)
b1c5785dbec5 (eshell-find-alias-function): Corrected the fix from last night, since
John Wiegley <johnw@newartisans.com>
parents: 37442
diff changeset
1315 (eshell-using-module module-sym)
b1c5785dbec5 (eshell-find-alias-function): Corrected the fix from last night, since
John Wiegley <johnw@newartisans.com>
parents: 37442
diff changeset
1316 (memq module-sym (eshell-subgroups 'eshell))))
37442
f4b209194d8c (eshell-find-alias-function): Return t in the case where the function
John Wiegley <johnw@newartisans.com>
parents: 33020
diff changeset
1317 sym))
f4b209194d8c (eshell-find-alias-function): Return t in the case where the function
John Wiegley <johnw@newartisans.com>
parents: 33020
diff changeset
1318 ;; Otherwise, if it's bound, return it.
f4b209194d8c (eshell-find-alias-function): Return t in the case where the function
John Wiegley <johnw@newartisans.com>
parents: 33020
diff changeset
1319 (if (functionp sym)
f4b209194d8c (eshell-find-alias-function): Return t in the case where the function
John Wiegley <johnw@newartisans.com>
parents: 33020
diff changeset
1320 sym))))
29873
b0bbf97625c2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
1321
b0bbf97625c2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
1322 (defun eshell-plain-command (command args)
b0bbf97625c2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
1323 "Insert output from a plain COMMAND, using ARGS.
b0bbf97625c2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
1324 COMMAND may result in either a Lisp function being executed by name,
b0bbf97625c2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
1325 or an external command."
b0bbf97625c2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
1326 (let* ((esym (eshell-find-alias-function command))
b0bbf97625c2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
1327 (sym (or esym (intern-soft command))))
b0bbf97625c2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
1328 (if (and sym (fboundp sym)
b0bbf97625c2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
1329 (or esym eshell-prefer-lisp-functions
b0bbf97625c2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
1330 (not (eshell-search-path command))))
b0bbf97625c2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
1331 (eshell-lisp-command sym args)
b0bbf97625c2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
1332 (eshell-external-command command args))))
b0bbf97625c2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
1333
b0bbf97625c2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
1334 (defun eshell-exec-lisp (printer errprint func-or-form args form-p)
b0bbf97625c2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
1335 "Execute a lisp FUNC-OR-FORM, maybe passing ARGS.
b0bbf97625c2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
1336 PRINTER and ERRPRINT are functions to use for printing regular
b0bbf97625c2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
1337 messages, and errors. FORM-P should be non-nil if FUNC-OR-FORM
b0bbf97625c2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
1338 represent a lisp form; ARGS will be ignored in that case."
b0bbf97625c2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
1339 (let (result)
b0bbf97625c2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
1340 (eshell-condition-case err
b0bbf97625c2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
1341 (progn
b0bbf97625c2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
1342 (setq result
b0bbf97625c2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
1343 (save-current-buffer
b0bbf97625c2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
1344 (if form-p
b0bbf97625c2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
1345 (eval func-or-form)
b0bbf97625c2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
1346 (apply func-or-form args))))
b0bbf97625c2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
1347 (and result (funcall printer result))
b0bbf97625c2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
1348 result)
b0bbf97625c2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
1349 (error
b0bbf97625c2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
1350 (let ((msg (error-message-string err)))
b0bbf97625c2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
1351 (if (and (not form-p)
b0bbf97625c2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
1352 (string-match "^Wrong number of arguments" msg)
b0bbf97625c2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
1353 (fboundp 'eldoc-get-fnsym-args-string))
b0bbf97625c2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
1354 (let ((func-doc (eldoc-get-fnsym-args-string func-or-form)))
b0bbf97625c2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
1355 (setq msg (format "usage: %s" func-doc))))
b0bbf97625c2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
1356 (funcall errprint msg))
b0bbf97625c2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
1357 nil))))
b0bbf97625c2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
1358
b0bbf97625c2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
1359 (defsubst eshell-apply* (printer errprint func args)
b0bbf97625c2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
1360 "Call FUNC, with ARGS, trapping errors and return them as output.
b0bbf97625c2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
1361 PRINTER and ERRPRINT are functions to use for printing regular
b0bbf97625c2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
1362 messages, and errors."
b0bbf97625c2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
1363 (eshell-exec-lisp printer errprint func args nil))
b0bbf97625c2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
1364
b0bbf97625c2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
1365 (defsubst eshell-funcall* (printer errprint func &rest args)
b0bbf97625c2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
1366 "Call FUNC, with ARGS, trapping errors and return them as output."
b0bbf97625c2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
1367 (eshell-apply* printer errprint func args))
b0bbf97625c2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
1368
b0bbf97625c2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
1369 (defsubst eshell-eval* (printer errprint form)
b0bbf97625c2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
1370 "Evaluate FORM, trapping errors and returning them."
b0bbf97625c2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
1371 (eshell-exec-lisp printer errprint form nil t))
b0bbf97625c2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
1372
b0bbf97625c2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
1373 (defsubst eshell-apply (func args)
b0bbf97625c2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
1374 "Call FUNC, with ARGS, trapping errors and return them as output.
b0bbf97625c2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
1375 PRINTER and ERRPRINT are functions to use for printing regular
b0bbf97625c2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
1376 messages, and errors."
b0bbf97625c2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
1377 (eshell-apply* 'eshell-print 'eshell-error func args))
b0bbf97625c2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
1378
b0bbf97625c2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
1379 (defsubst eshell-funcall (func &rest args)
b0bbf97625c2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
1380 "Call FUNC, with ARGS, trapping errors and return them as output."
b0bbf97625c2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
1381 (eshell-apply func args))
b0bbf97625c2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
1382
b0bbf97625c2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
1383 (defsubst eshell-eval (form)
b0bbf97625c2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
1384 "Evaluate FORM, trapping errors and returning them."
b0bbf97625c2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
1385 (eshell-eval* 'eshell-print 'eshell-error form))
b0bbf97625c2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
1386
b0bbf97625c2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
1387 (defsubst eshell-applyn (func args)
b0bbf97625c2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
1388 "Call FUNC, with ARGS, trapping errors and return them as output.
b0bbf97625c2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
1389 PRINTER and ERRPRINT are functions to use for printing regular
b0bbf97625c2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
1390 messages, and errors."
b0bbf97625c2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
1391 (eshell-apply* 'eshell-printn 'eshell-errorn func args))
b0bbf97625c2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
1392
b0bbf97625c2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
1393 (defsubst eshell-funcalln (func &rest args)
b0bbf97625c2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
1394 "Call FUNC, with ARGS, trapping errors and return them as output."
b0bbf97625c2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
1395 (eshell-applyn func args))
b0bbf97625c2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
1396
b0bbf97625c2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
1397 (defsubst eshell-evaln (form)
b0bbf97625c2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
1398 "Evaluate FORM, trapping errors and returning them."
b0bbf97625c2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
1399 (eshell-eval* 'eshell-printn 'eshell-errorn form))
b0bbf97625c2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
1400
b0bbf97625c2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
1401 (defun eshell-lisp-command (object &optional args)
b0bbf97625c2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
1402 "Insert Lisp OBJECT, using ARGS if a function."
b0bbf97625c2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
1403 (catch 'eshell-external ; deferred to an external command
b0bbf97625c2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
1404 (let* ((eshell-ensure-newline-p (eshell-interactive-output-p))
b0bbf97625c2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
1405 (result
b0bbf97625c2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
1406 (if (functionp object)
37662
cb20d33bef50 (eshell-lisp-command): Don't perform numeric conversions if a Lisp
John Wiegley <johnw@newartisans.com>
parents: 37657
diff changeset
1407 (progn
cb20d33bef50 (eshell-lisp-command): Don't perform numeric conversions if a Lisp
John Wiegley <johnw@newartisans.com>
parents: 37657
diff changeset
1408 (setq eshell-last-arguments args
cb20d33bef50 (eshell-lisp-command): Don't perform numeric conversions if a Lisp
John Wiegley <johnw@newartisans.com>
parents: 37657
diff changeset
1409 eshell-last-command-name
cb20d33bef50 (eshell-lisp-command): Don't perform numeric conversions if a Lisp
John Wiegley <johnw@newartisans.com>
parents: 37657
diff changeset
1410 (concat "#<function " (symbol-name object) ">"))
cb20d33bef50 (eshell-lisp-command): Don't perform numeric conversions if a Lisp
John Wiegley <johnw@newartisans.com>
parents: 37657
diff changeset
1411 ;; if any of the arguments are flagged as numbers
cb20d33bef50 (eshell-lisp-command): Don't perform numeric conversions if a Lisp
John Wiegley <johnw@newartisans.com>
parents: 37657
diff changeset
1412 ;; waiting for conversion, convert them now
cb20d33bef50 (eshell-lisp-command): Don't perform numeric conversions if a Lisp
John Wiegley <johnw@newartisans.com>
parents: 37657
diff changeset
1413 (unless (get object 'eshell-no-numeric-conversions)
cb20d33bef50 (eshell-lisp-command): Don't perform numeric conversions if a Lisp
John Wiegley <johnw@newartisans.com>
parents: 37657
diff changeset
1414 (while args
cb20d33bef50 (eshell-lisp-command): Don't perform numeric conversions if a Lisp
John Wiegley <johnw@newartisans.com>
parents: 37657
diff changeset
1415 (let ((arg (car args)))
cb20d33bef50 (eshell-lisp-command): Don't perform numeric conversions if a Lisp
John Wiegley <johnw@newartisans.com>
parents: 37657
diff changeset
1416 (if (and (stringp arg)
cb20d33bef50 (eshell-lisp-command): Don't perform numeric conversions if a Lisp
John Wiegley <johnw@newartisans.com>
parents: 37657
diff changeset
1417 (> (length arg) 0)
53051
bf3ee9e2ceda (eshell-lisp-command): Do not late-convert string arguments to numbers
John Wiegley <johnw@newartisans.com>
parents: 52401
diff changeset
1418 (not (text-property-not-all
bf3ee9e2ceda (eshell-lisp-command): Do not late-convert string arguments to numbers
John Wiegley <johnw@newartisans.com>
parents: 52401
diff changeset
1419 0 (length arg) 'number t arg)))
37665
ebd292552bfe Fixed reference to free variable.
John Wiegley <johnw@newartisans.com>
parents: 37662
diff changeset
1420 (setcar args (string-to-number arg))))
37662
cb20d33bef50 (eshell-lisp-command): Don't perform numeric conversions if a Lisp
John Wiegley <johnw@newartisans.com>
parents: 37657
diff changeset
1421 (setq args (cdr args))))
cb20d33bef50 (eshell-lisp-command): Don't perform numeric conversions if a Lisp
John Wiegley <johnw@newartisans.com>
parents: 37657
diff changeset
1422 (eshell-apply object eshell-last-arguments))
cb20d33bef50 (eshell-lisp-command): Don't perform numeric conversions if a Lisp
John Wiegley <johnw@newartisans.com>
parents: 37657
diff changeset
1423 (setq eshell-last-arguments args
cb20d33bef50 (eshell-lisp-command): Don't perform numeric conversions if a Lisp
John Wiegley <johnw@newartisans.com>
parents: 37657
diff changeset
1424 eshell-last-command-name "#<Lisp object>")
29873
b0bbf97625c2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
1425 (eshell-eval object))))
b0bbf97625c2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
1426 (if (and eshell-ensure-newline-p
b0bbf97625c2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
1427 (save-excursion
b0bbf97625c2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
1428 (goto-char eshell-last-output-end)
b0bbf97625c2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
1429 (not (bolp))))
b0bbf97625c2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
1430 (eshell-print "\n"))
b0bbf97625c2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
1431 (eshell-close-handles 0 (list 'quote result)))))
b0bbf97625c2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
1432
b0bbf97625c2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
1433 (defalias 'eshell-lisp-command* 'eshell-lisp-command)
b0bbf97625c2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
1434
87079
c1197dc2780b Require individual files if needed when compiling, rather than
Glenn Morris <rgm@gnu.org>
parents: 86202
diff changeset
1435 (provide 'esh-cmd)
c1197dc2780b Require individual files if needed when compiling, rather than
Glenn Morris <rgm@gnu.org>
parents: 86202
diff changeset
1436
29873
b0bbf97625c2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
1437 ;;; esh-cmd.el ends here