comparison lisp/eshell/esh-var.el @ 87089:9c568a5e8648

Require individual files if needed when compiling, rather than esh-maint. Collect any require statements. Leave provide at start. Move any commentary to start.
author Glenn Morris <rgm@gnu.org>
date Wed, 05 Dec 2007 07:09:31 +0000
parents a1e8300d3c55
children 107ccd98fa12 53108e6cea98
comparison
equal deleted inserted replaced
87088:ddc1d773fb48 87089:9c568a5e8648
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 ;;; Commentary:
26
27 ;; These are the possible variable interpolation syntaxes. Also keep
28 ;; in mind that if an argument looks like a number, it will be
29 ;; converted to a number. This is not significant when invoking
30 ;; external commands, but it's important when calling Lisp functions.
31 ;;
32 ;; $VARIABLE
33 ;;
34 ;; Interval the value of an environment variable, or a Lisp variable
35 ;;
36 ;; $ALSO-VAR
37 ;;
38 ;; "-" is a legal part of a variable name.
39 ;;
40 ;; $<MYVAR>-TOO
41 ;;
42 ;; Only "MYVAR" is part of the variable name in this case.
43 ;;
44 ;; $#VARIABLE
45 ;;
46 ;; Returns the length of the value of VARIABLE. This could also be
47 ;; done using the `length' Lisp function.
48 ;;
49 ;; $(lisp)
50 ;;
51 ;; Returns result of lisp evaluation. Note: Used alone like this, it
52 ;; is identical to just saying (lisp); but with the variable expansion
53 ;; form, the result may be interpolated a larger string, such as
54 ;; '$(lisp)/other'.
55 ;;
56 ;; ${command}
57 ;;
58 ;; Returns the value of an eshell subcommand. See the note above
59 ;; regarding Lisp evaluations.
60 ;;
61 ;; $ANYVAR[10]
62 ;;
63 ;; Return the 10th element of ANYVAR. If ANYVAR's value is a string,
64 ;; it will be split in order to make it a list. The splitting will
65 ;; occur at whitespace.
66 ;;
67 ;; $ANYVAR[: 10]
68 ;;
69 ;; As above, except that splitting occurs at the colon now.
70 ;;
71 ;; $ANYVAR[: 10 20]
72 ;;
73 ;; As above, but instead of returning just a string, it now returns a
74 ;; list of two strings. If the result is being interpolated into a
75 ;; larger string, this list will be flattened into one big string,
76 ;; with each element separated by a space.
77 ;;
78 ;; $ANYVAR["\\\\" 10]
79 ;;
80 ;; Separate on backslash characters. Actually, the first argument --
81 ;; if it doesn't have the form of a number, or a plain variable name
82 ;; -- can be any regular expression. So to split on numbers, use
83 ;; '$ANYVAR["[0-9]+" 10 20]'.
84 ;;
85 ;; $ANYVAR[hello]
86 ;;
87 ;; Calls `assoc' on ANYVAR with 'hello', expecting it to be an alist.
88 ;;
89 ;; $#ANYVAR[hello]
90 ;;
91 ;; Returns the length of the cdr of the element of ANYVAR who car is
92 ;; equal to "hello".
93 ;;
94 ;; There are also a few special variables defined by Eshell. '$$' is
95 ;; the value of the last command (t or nil, in the case of an external
96 ;; command). This makes it possible to chain results:
97 ;;
98 ;; /tmp $ echo /var/spool/mail/johnw
99 ;; /var/spool/mail/johnw
100 ;; /tmp $ dirname $$
101 ;; /var/spool/mail/
102 ;; /tmp $ cd $$
103 ;; /var/spool/mail $
104 ;;
105 ;; '$_' refers to the last argument of the last command. And $?
106 ;; contains the exit code of the last command (0 or 1 for Lisp
107 ;; functions, based on successful completion).
108
25 (provide 'esh-var) 109 (provide 'esh-var)
26 110
27 (eval-when-compile (require 'esh-maint)) 111 (eval-when-compile
112 (require 'pcomplete)
113 (require 'esh-test)
114 (require 'esh-util)
115 (require 'esh-opt)
116 (require 'esh-mode))
117 (require 'env)
118 (require 'ring)
28 119
29 (defgroup eshell-var nil 120 (defgroup eshell-var nil
30 "Variable interpolation is introduced whenever the '$' character 121 "Variable interpolation is introduced whenever the '$' character
31 appears unquoted in any argument (except when that argument is 122 appears unquoted in any argument (except when that argument is
32 surrounded by single quotes). It may be used to interpolate a 123 surrounded by single quotes). It may be used to interpolate a
33 variable value, a subcommand, or even the result of a Lisp form." 124 variable value, a subcommand, or even the result of a Lisp form."
34 :tag "Variable handling" 125 :tag "Variable handling"
35 :group 'eshell) 126 :group 'eshell)
36
37 ;;; Commentary:
38
39 ;; These are the possible variable interpolation syntaxes. Also keep
40 ;; in mind that if an argument looks like a number, it will be
41 ;; converted to a number. This is not significant when invoking
42 ;; external commands, but it's important when calling Lisp functions.
43 ;;
44 ;; $VARIABLE
45 ;;
46 ;; Interval the value of an environment variable, or a Lisp variable
47 ;;
48 ;; $ALSO-VAR
49 ;;
50 ;; "-" is a legal part of a variable name.
51 ;;
52 ;; $<MYVAR>-TOO
53 ;;
54 ;; Only "MYVAR" is part of the variable name in this case.
55 ;;
56 ;; $#VARIABLE
57 ;;
58 ;; Returns the length of the value of VARIABLE. This could also be
59 ;; done using the `length' Lisp function.
60 ;;
61 ;; $(lisp)
62 ;;
63 ;; Returns result of lisp evaluation. Note: Used alone like this, it
64 ;; is identical to just saying (lisp); but with the variable expansion
65 ;; form, the result may be interpolated a larger string, such as
66 ;; '$(lisp)/other'.
67 ;;
68 ;; ${command}
69 ;;
70 ;; Returns the value of an eshell subcommand. See the note above
71 ;; regarding Lisp evaluations.
72 ;;
73 ;; $ANYVAR[10]
74 ;;
75 ;; Return the 10th element of ANYVAR. If ANYVAR's value is a string,
76 ;; it will be split in order to make it a list. The splitting will
77 ;; occur at whitespace.
78 ;;
79 ;; $ANYVAR[: 10]
80 ;;
81 ;; As above, except that splitting occurs at the colon now.
82 ;;
83 ;; $ANYVAR[: 10 20]
84 ;;
85 ;; As above, but instead of returning just a string, it now returns a
86 ;; list of two strings. If the result is being interpolated into a
87 ;; larger string, this list will be flattened into one big string,
88 ;; with each element separated by a space.
89 ;;
90 ;; $ANYVAR["\\\\" 10]
91 ;;
92 ;; Separate on backslash characters. Actually, the first argument --
93 ;; if it doesn't have the form of a number, or a plain variable name
94 ;; -- can be any regular expression. So to split on numbers, use
95 ;; '$ANYVAR["[0-9]+" 10 20]'.
96 ;;
97 ;; $ANYVAR[hello]
98 ;;
99 ;; Calls `assoc' on ANYVAR with 'hello', expecting it to be an alist.
100 ;;
101 ;; $#ANYVAR[hello]
102 ;;
103 ;; Returns the length of the cdr of the element of ANYVAR who car is
104 ;; equal to "hello".
105 ;;
106 ;; There are also a few special variables defined by Eshell. '$$' is
107 ;; the value of the last command (t or nil, in the case of an external
108 ;; command). This makes it possible to chain results:
109 ;;
110 ;; /tmp $ echo /var/spool/mail/johnw
111 ;; /var/spool/mail/johnw
112 ;; /tmp $ dirname $$
113 ;; /var/spool/mail/
114 ;; /tmp $ cd $$
115 ;; /var/spool/mail $
116 ;;
117 ;; '$_' refers to the last argument of the last command. And $?
118 ;; contains the exit code of the last command (0 or 1 for Lisp
119 ;; functions, based on successful completion).
120
121 (require 'env)
122 (require 'ring)
123 127
124 ;;; User Variables: 128 ;;; User Variables:
125 129
126 (defcustom eshell-var-load-hook '(eshell-var-initialize) 130 (defcustom eshell-var-load-hook '(eshell-var-initialize)
127 "*A list of functions to call when loading `eshell-var'." 131 "*A list of functions to call when loading `eshell-var'."