Mercurial > emacs
comparison lisp/eshell/esh-cmd.el @ 87079:c1197dc2780b
Require individual files if needed when compiling, rather than
esh-maint. Collect any require statements. Leave provide at start.
Move any commentary to start.
(eshell-debug-command): Move definition before use.
author | Glenn Morris <rgm@gnu.org> |
---|---|
date | Wed, 05 Dec 2007 07:05:27 +0000 |
parents | 794e428cd497 |
children | 107ccd98fa12 53108e6cea98 |
comparison
equal
deleted
inserted
replaced
87078:dbc3d5372728 | 87079:c1197dc2780b |
---|---|
20 ;; You should have received a copy of the GNU General Public License | 20 ;; You should have received a copy of the GNU General Public License |
21 ;; along with GNU Emacs; see the file COPYING. If not, write to the | 21 ;; along with GNU Emacs; see the file COPYING. If not, write to the |
22 ;; Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, | 22 ;; Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, |
23 ;; Boston, MA 02110-1301, USA. | 23 ;; Boston, MA 02110-1301, USA. |
24 | 24 |
25 (provide 'esh-cmd) | 25 ;;; Commentary: |
26 | 26 |
27 (eval-when-compile (require 'esh-maint)) | 27 ;;;_* Invoking external commands |
28 ;; | |
29 ;; External commands cause processes to be created, by loading | |
30 ;; external executables into memory. This is what most normal shells | |
31 ;; do, most of the time. For more information, see [External commands]. | |
32 ;; | |
33 ;;;_* Invoking Lisp functions | |
34 ;; | |
35 ;; A Lisp function can be invoked using Lisp syntax, or command shell | |
36 ;; syntax. For example, to run `dired' to edit the current directory: | |
37 ;; | |
38 ;; /tmp $ (dired ".") | |
39 ;; | |
40 ;; Or: | |
41 ;; | |
42 ;; /tmp $ dired . | |
43 ;; | |
44 ;; The latter form is preferable, but the former is more precise, | |
45 ;; since it involves no translations. See [Argument parsing], to | |
46 ;; learn more about how arguments are transformed before passing them | |
47 ;; to commands. | |
48 ;; | |
49 ;; Ordinarily, if 'dired' were also available as an external command, | |
50 ;; the external version would be called in preference to any Lisp | |
51 ;; function of the same name. To change this behavior so that Lisp | |
52 ;; functions always take precedence, set | |
53 ;; `eshell-prefer-lisp-functions' to t. | |
54 | |
55 ;;;_* Alias functions | |
56 ;; | |
57 ;; Whenever a command is specified using a simple name, such as 'ls', | |
58 ;; Eshell will first look for a Lisp function of the name `eshell/ls'. | |
59 ;; If it exists, it will be called in preference to any other command | |
60 ;; which might have matched the name 'ls' (such as command aliases, | |
61 ;; external commands, Lisp functions of that name, etc). | |
62 ;; | |
63 ;; This is the most flexible mechanism for creating new commands, | |
64 ;; since it does not pollute the global namespace, yet allows you to | |
65 ;; use all of Lisp's facilities to define that piece of functionality. | |
66 ;; Most of Eshell's "builtin" commands are defined as alias functions. | |
67 ;; | |
68 ;;;_* Lisp arguments | |
69 ;; | |
70 ;; It is possible to invoke a Lisp form as an argument. This can be | |
71 ;; done either by specifying the form as you might in Lisp, or by | |
72 ;; using the '$' character to introduce a value-interpolation: | |
73 ;; | |
74 ;; echo (+ 1 2) | |
75 ;; | |
76 ;; Or | |
77 ;; | |
78 ;; echo $(+ 1 2) | |
79 ;; | |
80 ;; The two forms are equivalent. The second is required only if the | |
81 ;; form being interpolated is within a string, or is a subexpression | |
82 ;; of a larger argument: | |
83 ;; | |
84 ;; echo x$(+ 1 2) "String $(+ 1 2)" | |
85 ;; | |
86 ;; To pass a Lisp symbol as a argument, use the alternate quoting | |
87 ;; syntax, since the single quote character is far too overused in | |
88 ;; shell syntax: | |
89 ;; | |
90 ;; echo #'lisp-symbol | |
91 ;; | |
92 ;; Backquote can also be used: | |
93 ;; | |
94 ;; echo `(list ,lisp-symbol) | |
95 ;; | |
96 ;; Lisp arguments are identified using the following regexp: | |
97 | |
98 ;;;_* Command hooks | |
99 ;; | |
100 ;; There are several hooks involved with command execution, which can | |
101 ;; be used either to change or augment Eshell's behavior. | |
102 | |
103 | |
104 ;;; Code: | |
105 | |
106 (require 'esh-util) | |
107 (unless (featurep 'xemacs) | |
108 (require 'eldoc)) | |
109 (require 'esh-arg) | |
110 (require 'esh-proc) | |
111 (require 'esh-ext) | |
112 | |
113 (eval-when-compile | |
114 (require 'pcomplete)) | |
115 | |
28 | 116 |
29 (defgroup eshell-cmd nil | 117 (defgroup eshell-cmd nil |
30 "Executing an Eshell command is as simple as typing it in and | 118 "Executing an Eshell command is as simple as typing it in and |
31 pressing <RET>. There are several different kinds of commands, | 119 pressing <RET>. There are several different kinds of commands, |
32 however." | 120 however." |
33 :tag "Command invocation" | 121 :tag "Command invocation" |
34 ;; :link '(info-link "(eshell)Command invocation") | 122 ;; :link '(info-link "(eshell)Command invocation") |
35 :group 'eshell) | 123 :group 'eshell) |
36 | 124 |
37 ;;; Commentary: | |
38 | |
39 ;;;_* Invoking external commands | |
40 ;; | |
41 ;; External commands cause processes to be created, by loading | |
42 ;; external executables into memory. This is what most normal shells | |
43 ;; do, most of the time. For more information, see [External commands]. | |
44 ;; | |
45 ;;;_* Invoking Lisp functions | |
46 ;; | |
47 ;; A Lisp function can be invoked using Lisp syntax, or command shell | |
48 ;; syntax. For example, to run `dired' to edit the current directory: | |
49 ;; | |
50 ;; /tmp $ (dired ".") | |
51 ;; | |
52 ;; Or: | |
53 ;; | |
54 ;; /tmp $ dired . | |
55 ;; | |
56 ;; The latter form is preferable, but the former is more precise, | |
57 ;; since it involves no translations. See [Argument parsing], to | |
58 ;; learn more about how arguments are transformed before passing them | |
59 ;; to commands. | |
60 ;; | |
61 ;; Ordinarily, if 'dired' were also available as an external command, | |
62 ;; the external version would be called in preference to any Lisp | |
63 ;; function of the same name. To change this behavior so that Lisp | |
64 ;; functions always take precedence, set | |
65 ;; `eshell-prefer-lisp-functions' to t. | |
66 | |
67 (defcustom eshell-prefer-lisp-functions nil | 125 (defcustom eshell-prefer-lisp-functions nil |
68 "*If non-nil, prefer Lisp functions to external commands." | 126 "*If non-nil, prefer Lisp functions to external commands." |
69 :type 'boolean | 127 :type 'boolean |
70 :group 'eshell-cmd) | 128 :group 'eshell-cmd) |
71 | |
72 ;;;_* Alias functions | |
73 ;; | |
74 ;; Whenever a command is specified using a simple name, such as 'ls', | |
75 ;; Eshell will first look for a Lisp function of the name `eshell/ls'. | |
76 ;; If it exists, it will be called in preference to any other command | |
77 ;; which might have matched the name 'ls' (such as command aliases, | |
78 ;; external commands, Lisp functions of that name, etc). | |
79 ;; | |
80 ;; This is the most flexible mechanism for creating new commands, | |
81 ;; since it does not pollute the global namespace, yet allows you to | |
82 ;; use all of Lisp's facilities to define that piece of functionality. | |
83 ;; Most of Eshell's "builtin" commands are defined as alias functions. | |
84 ;; | |
85 ;;;_* Lisp arguments | |
86 ;; | |
87 ;; It is possible to invoke a Lisp form as an argument. This can be | |
88 ;; done either by specifying the form as you might in Lisp, or by | |
89 ;; using the '$' character to introduce a value-interpolation: | |
90 ;; | |
91 ;; echo (+ 1 2) | |
92 ;; | |
93 ;; Or | |
94 ;; | |
95 ;; echo $(+ 1 2) | |
96 ;; | |
97 ;; The two forms are equivalent. The second is required only if the | |
98 ;; form being interpolated is within a string, or is a subexpression | |
99 ;; of a larger argument: | |
100 ;; | |
101 ;; echo x$(+ 1 2) "String $(+ 1 2)" | |
102 ;; | |
103 ;; To pass a Lisp symbol as a argument, use the alternate quoting | |
104 ;; syntax, since the single quote character is far too overused in | |
105 ;; shell syntax: | |
106 ;; | |
107 ;; echo #'lisp-symbol | |
108 ;; | |
109 ;; Backquote can also be used: | |
110 ;; | |
111 ;; echo `(list ,lisp-symbol) | |
112 ;; | |
113 ;; Lisp arguments are identified using the following regexp: | |
114 | 129 |
115 (defcustom eshell-lisp-regexp "\\([(`]\\|#'\\)" | 130 (defcustom eshell-lisp-regexp "\\([(`]\\|#'\\)" |
116 "*A regexp which, if matched at beginning of an argument, means Lisp. | 131 "*A regexp which, if matched at beginning of an argument, means Lisp. |
117 Such arguments will be passed to `read', and then evaluated." | 132 Such arguments will be passed to `read', and then evaluated." |
118 :type 'regexp | 133 :type 'regexp |
119 :group 'eshell-cmd) | 134 :group 'eshell-cmd) |
120 | |
121 ;;;_* Command hooks | |
122 ;; | |
123 ;; There are several hooks involved with command execution, which can | |
124 ;; be used either to change or augment Eshell's behavior. | |
125 | 135 |
126 (defcustom eshell-pre-command-hook nil | 136 (defcustom eshell-pre-command-hook nil |
127 "*A hook run before each interactive command is invoked." | 137 "*A hook run before each interactive command is invoked." |
128 :type 'hook | 138 :type 'hook |
129 :group 'eshell-cmd) | 139 :group 'eshell-cmd) |
216 return non-nil if the command is complex." | 226 return non-nil if the command is complex." |
217 :type '(repeat :tag "Commands" | 227 :type '(repeat :tag "Commands" |
218 (choice (string :tag "Name") | 228 (choice (string :tag "Name") |
219 (function :tag "Predicate"))) | 229 (function :tag "Predicate"))) |
220 :group 'eshell-cmd) | 230 :group 'eshell-cmd) |
221 | |
222 ;;; Code: | |
223 | |
224 (require 'esh-util) | |
225 (unless (featurep 'xemacs) | |
226 (require 'eldoc)) | |
227 (require 'esh-arg) | |
228 (require 'esh-proc) | |
229 (require 'esh-ext) | |
230 | 231 |
231 ;;; User Variables: | 232 ;;; User Variables: |
232 | 233 |
233 (defcustom eshell-cmd-load-hook '(eshell-cmd-initialize) | 234 (defcustom eshell-cmd-load-hook '(eshell-cmd-initialize) |
234 "*A hook that gets run when `eshell-cmd' is loaded." | 235 "*A hook that gets run when `eshell-cmd' is loaded." |
392 '(run-hooks 'eshell-post-command-hook))))) | 393 '(run-hooks 'eshell-post-command-hook))))) |
393 (if top-level | 394 (if top-level |
394 (list 'eshell-commands commands) | 395 (list 'eshell-commands commands) |
395 commands))) | 396 commands))) |
396 | 397 |
398 (defun eshell-debug-command (tag subform) | |
399 "Output a debugging message to '*eshell last cmd*'." | |
400 (let ((buf (get-buffer-create "*eshell last cmd*")) | |
401 (text (eshell-stringify eshell-current-command))) | |
402 (save-excursion | |
403 (set-buffer buf) | |
404 (if (not tag) | |
405 (erase-buffer) | |
406 (insert "\n\C-l\n" tag "\n\n" text | |
407 (if subform | |
408 (concat "\n\n" (eshell-stringify subform)) "")))))) | |
409 | |
397 (defun eshell-debug-show-parsed-args (terms) | 410 (defun eshell-debug-show-parsed-args (terms) |
398 "Display parsed arguments in the debug buffer." | 411 "Display parsed arguments in the debug buffer." |
399 (ignore | 412 (ignore |
400 (if eshell-debug-command | 413 (if eshell-debug-command |
401 (eshell-debug-command "parsed arguments" terms)))) | 414 (eshell-debug-command "parsed arguments" terms)))) |
953 (setq args (cdr args))))))) | 966 (setq args (cdr args))))))) |
954 | 967 |
955 (defun pcomplete/eshell-mode/eshell-debug () | 968 (defun pcomplete/eshell-mode/eshell-debug () |
956 "Completion for the `debug' command." | 969 "Completion for the `debug' command." |
957 (while (pcomplete-here '("errors" "commands")))) | 970 (while (pcomplete-here '("errors" "commands")))) |
958 | |
959 (defun eshell-debug-command (tag subform) | |
960 "Output a debugging message to '*eshell last cmd*'." | |
961 (let ((buf (get-buffer-create "*eshell last cmd*")) | |
962 (text (eshell-stringify eshell-current-command))) | |
963 (save-excursion | |
964 (set-buffer buf) | |
965 (if (not tag) | |
966 (erase-buffer) | |
967 (insert "\n\C-l\n" tag "\n\n" text | |
968 (if subform | |
969 (concat "\n\n" (eshell-stringify subform)) "")))))) | |
970 | 971 |
971 (defun eshell-invoke-directly (command input) | 972 (defun eshell-invoke-directly (command input) |
972 (let ((base (cadr (nth 2 (nth 2 (cadr command))))) name) | 973 (let ((base (cadr (nth 2 (nth 2 (cadr command))))) name) |
973 (if (and (eq (car base) 'eshell-trap-errors) | 974 (if (and (eq (car base) 'eshell-trap-errors) |
974 (eq (car (cadr base)) 'eshell-named-command)) | 975 (eq (car (cadr base)) 'eshell-named-command)) |
1416 (eshell-print "\n")) | 1417 (eshell-print "\n")) |
1417 (eshell-close-handles 0 (list 'quote result))))) | 1418 (eshell-close-handles 0 (list 'quote result))))) |
1418 | 1419 |
1419 (defalias 'eshell-lisp-command* 'eshell-lisp-command) | 1420 (defalias 'eshell-lisp-command* 'eshell-lisp-command) |
1420 | 1421 |
1422 (provide 'esh-cmd) | |
1423 | |
1421 ;;; arch-tag: 8e4f3867-a0c5-441f-96ba-ddd142d94366 | 1424 ;;; arch-tag: 8e4f3867-a0c5-441f-96ba-ddd142d94366 |
1422 ;;; esh-cmd.el ends here | 1425 ;;; esh-cmd.el ends here |