Make save-some-buffers message more informative (Bug#8134).
[bpt/emacs.git] / lisp / eshell / esh-var.el
CommitLineData
60370d40 1;;; esh-var.el --- handling of variables
affbf647 2
73b0cd50 3;; Copyright (C) 1999-2011 Free Software Foundation, Inc.
affbf647 4
7de5b421
GM
5;; Author: John Wiegley <johnw@gnu.org>
6
affbf647
GM
7;; This file is part of GNU Emacs.
8
4ee57b2a 9;; GNU Emacs is free software: you can redistribute it and/or modify
affbf647 10;; it under the terms of the GNU General Public License as published by
4ee57b2a
GM
11;; the Free Software Foundation, either version 3 of the License, or
12;; (at your option) any later version.
affbf647
GM
13
14;; GNU Emacs is distributed in the hope that it will be useful,
15;; but WITHOUT ANY WARRANTY; without even the implied warranty of
16;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17;; GNU General Public License for more details.
18
19;; You should have received a copy of the GNU General Public License
4ee57b2a 20;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
affbf647 21
affbf647
GM
22;;; Commentary:
23
24;; These are the possible variable interpolation syntaxes. Also keep
25;; in mind that if an argument looks like a number, it will be
26;; converted to a number. This is not significant when invoking
27;; external commands, but it's important when calling Lisp functions.
28;;
29;; $VARIABLE
30;;
31;; Interval the value of an environment variable, or a Lisp variable
32;;
33;; $ALSO-VAR
34;;
0138efd4 35;; "-" is a valid part of a variable name.
affbf647
GM
36;;
37;; $<MYVAR>-TOO
38;;
39;; Only "MYVAR" is part of the variable name in this case.
40;;
41;; $#VARIABLE
42;;
43;; Returns the length of the value of VARIABLE. This could also be
44;; done using the `length' Lisp function.
45;;
46;; $(lisp)
47;;
48;; Returns result of lisp evaluation. Note: Used alone like this, it
49;; is identical to just saying (lisp); but with the variable expansion
50;; form, the result may be interpolated a larger string, such as
51;; '$(lisp)/other'.
52;;
53;; ${command}
54;;
55;; Returns the value of an eshell subcommand. See the note above
56;; regarding Lisp evaluations.
57;;
58;; $ANYVAR[10]
59;;
60;; Return the 10th element of ANYVAR. If ANYVAR's value is a string,
61;; it will be split in order to make it a list. The splitting will
62;; occur at whitespace.
63;;
64;; $ANYVAR[: 10]
65;;
66;; As above, except that splitting occurs at the colon now.
67;;
68;; $ANYVAR[: 10 20]
69;;
70;; As above, but instead of returning just a string, it now returns a
71;; list of two strings. If the result is being interpolated into a
72;; larger string, this list will be flattened into one big string,
73;; with each element separated by a space.
74;;
75;; $ANYVAR["\\\\" 10]
76;;
77;; Separate on backslash characters. Actually, the first argument --
78;; if it doesn't have the form of a number, or a plain variable name
79;; -- can be any regular expression. So to split on numbers, use
80;; '$ANYVAR["[0-9]+" 10 20]'.
81;;
82;; $ANYVAR[hello]
83;;
84;; Calls `assoc' on ANYVAR with 'hello', expecting it to be an alist.
85;;
86;; $#ANYVAR[hello]
87;;
88;; Returns the length of the cdr of the element of ANYVAR who car is
89;; equal to "hello".
90;;
91;; There are also a few special variables defined by Eshell. '$$' is
92;; the value of the last command (t or nil, in the case of an external
93;; command). This makes it possible to chain results:
94;;
95;; /tmp $ echo /var/spool/mail/johnw
96;; /var/spool/mail/johnw
97;; /tmp $ dirname $$
98;; /var/spool/mail/
99;; /tmp $ cd $$
100;; /var/spool/mail $
101;;
102;; '$_' refers to the last argument of the last command. And $?
103;; contains the exit code of the last command (0 or 1 for Lisp
104;; functions, based on successful completion).
105
8c7309fe
GM
106;;; Code:
107
11740ce5
GM
108(provide 'esh-var)
109
110(eval-when-compile
111 (require 'pcomplete)
112 (require 'esh-test)
113 (require 'esh-util)
114 (require 'esh-opt)
115 (require 'esh-mode))
affbf647
GM
116(require 'env)
117(require 'ring)
118
11740ce5
GM
119(defgroup eshell-var nil
120 "Variable interpolation is introduced whenever the '$' character
121appears unquoted in any argument (except when that argument is
122surrounded by single quotes). It may be used to interpolate a
123variable value, a subcommand, or even the result of a Lisp form."
124 :tag "Variable handling"
125 :group 'eshell)
126
affbf647
GM
127;;; User Variables:
128
d783d303 129(defcustom eshell-var-load-hook nil
ec60da52 130 "A list of functions to call when loading `eshell-var'."
d783d303 131 :version "24.1" ; removed eshell-var-initialize
affbf647
GM
132 :type 'hook
133 :group 'eshell-var)
134
135(defcustom eshell-prefer-lisp-variables nil
ec60da52 136 "If non-nil, prefer Lisp variables to environment variables."
affbf647
GM
137 :type 'boolean
138 :group 'eshell-var)
139
140(defcustom eshell-complete-export-definition t
ec60da52 141 "If non-nil, completing names for `export' shows current definition."
affbf647
GM
142 :type 'boolean
143 :group 'eshell-var)
144
6995786d 145(defcustom eshell-modify-global-environment nil
ec60da52 146 "If non-nil, using `export' changes Emacs's global environment."
6995786d
JW
147 :type 'boolean
148 :group 'eshell-var)
149
affbf647 150(defcustom eshell-variable-name-regexp "[A-Za-z0-9_-]+"
ec60da52 151 "A regexp identifying what constitutes a variable name reference.
affbf647
GM
152Note that this only applies for '$NAME'. If the syntax '$<NAME>' is
153used, then NAME can contain any character, including angle brackets,
154if they are quoted with a backslash."
155 :type 'regexp
156 :group 'eshell-var)
157
158(defcustom eshell-variable-aliases-list
159 '(;; for eshell.el
160 ("COLUMNS" (lambda (indices) (window-width)) t)
161 ("LINES" (lambda (indices) (window-height)) t)
162
163 ;; for eshell-cmd.el
164 ("_" (lambda (indices)
165 (if (not indices)
166 (car (last eshell-last-arguments))
167 (eshell-apply-indices eshell-last-arguments
168 indices))))
169 ("?" eshell-last-command-status)
170 ("$" eshell-last-command-result)
171 ("0" eshell-command-name)
172 ("1" (lambda (indices) (nth 0 eshell-command-arguments)))
173 ("2" (lambda (indices) (nth 1 eshell-command-arguments)))
174 ("3" (lambda (indices) (nth 2 eshell-command-arguments)))
175 ("4" (lambda (indices) (nth 3 eshell-command-arguments)))
176 ("5" (lambda (indices) (nth 4 eshell-command-arguments)))
177 ("6" (lambda (indices) (nth 5 eshell-command-arguments)))
178 ("7" (lambda (indices) (nth 6 eshell-command-arguments)))
179 ("8" (lambda (indices) (nth 7 eshell-command-arguments)))
180 ("9" (lambda (indices) (nth 8 eshell-command-arguments)))
181 ("*" (lambda (indices)
182 (if (not indices)
183 eshell-command-arguments
184 (eshell-apply-indices eshell-command-arguments
185 indices)))))
ec60da52 186 "This list provides aliasing for variable references.
affbf647
GM
187It is very similar in concept to what `eshell-user-aliases-list' does
188for commands. Each member of this defines defines the name of a
189command, and the Lisp value to return for that variable if it is
190accessed via the syntax '$NAME'.
191
192If the value is a function, that function will be called with two
193arguments: the list of the indices that was used in the reference, and
194whether the user is requesting the length of the ultimate element.
195For example, a reference of '$NAME[10][20]' would result in the
196function for alias `NAME' being called (assuming it were aliased to a
197function), and the arguments passed to this function would be the list
198'(10 20)', and nil."
199 :type '(repeat (list string sexp
200 (choice (const :tag "Copy to environment" t)
201 (const :tag "Use only in Eshell" nil))))
202 :group 'eshell-var)
203
204(put 'eshell-variable-aliases-list 'risky-local-variable t)
205
206;;; Functions:
207
208(defun eshell-var-initialize ()
209 "Initialize the variable handle code."
210 ;; Break the association with our parent's environment. Otherwise,
211 ;; changing a variable will affect all of Emacs.
6995786d
JW
212 (unless eshell-modify-global-environment
213 (set (make-local-variable 'process-environment)
214 (eshell-copy-environment)))
affbf647
GM
215
216 (define-key eshell-command-map [(meta ?v)] 'eshell-insert-envvar)
217
218 (set (make-local-variable 'eshell-special-chars-inside-quoting)
219 (append eshell-special-chars-inside-quoting '(?$)))
220 (set (make-local-variable 'eshell-special-chars-outside-quoting)
221 (append eshell-special-chars-outside-quoting '(?$)))
222
affbf647
GM
223 (add-hook 'eshell-parse-argument-hook 'eshell-interpolate-variable t t)
224
affbf647
GM
225 (add-hook 'eshell-prepare-command-hook
226 'eshell-handle-local-variables nil t)
227
228 (when (eshell-using-module 'eshell-cmpl)
affbf647
GM
229 (add-hook 'pcomplete-try-first-hook
230 'eshell-complete-variable-reference nil t)
231 (add-hook 'pcomplete-try-first-hook
232 'eshell-complete-variable-assignment nil t)))
233
234(defun eshell-handle-local-variables ()
235 "Allow for the syntax 'VAR=val <command> <args>'."
236 ;; strip off any null commands, which can only happen if a variable
237 ;; evaluates to nil, such as "$var x", where `var' is nil. The
238 ;; command name in that case becomes `x', for compatibility with
239 ;; most regular shells (the difference is that they do an
240 ;; interpolation pass before the argument parsing pass, but Eshell
241 ;; does both at the same time).
242 (while (and (not eshell-last-command-name)
243 eshell-last-arguments)
244 (setq eshell-last-command-name (car eshell-last-arguments)
245 eshell-last-arguments (cdr eshell-last-arguments)))
246 (let ((setvar "\\`\\([A-Za-z_][A-Za-z0-9_]*\\)=\\(.*\\)\\'")
247 (command (eshell-stringify eshell-last-command-name))
248 (args eshell-last-arguments))
249 ;; local variable settings (such as 'CFLAGS=-O2 make') are handled
250 ;; by making the whole command into a subcommand, and calling
251 ;; setenv immediately before the command is invoked. This means
252 ;; that 'BLAH=x cd blah' won't work exactly as expected, but that
253 ;; is by no means a typical use of local environment variables.
254 (if (and command (string-match setvar command))
255 (throw
256 'eshell-replace-command
257 (list
258 'eshell-as-subcommand
259 (append
260 (list 'progn)
261 (let ((l (list t)))
262 (while (string-match setvar command)
263 (nconc
264 l (list
265 (list 'setenv (match-string 1 command)
266 (match-string 2 command)
267 (= (length (match-string 2 command)) 0))))
268 (setq command (eshell-stringify (car args))
269 args (cdr args)))
270 (cdr l))
271 (list (list 'eshell-named-command
272 command (list 'quote args)))))))))
273
274(defun eshell-interpolate-variable ()
275 "Parse a variable interpolation.
276This function is explicit for adding to `eshell-parse-argument-hook'."
277 (when (and (eq (char-after) ?$)
ca7aae91 278 (/= (1+ (point)) (point-max)))
affbf647
GM
279 (forward-char)
280 (list 'eshell-escape-arg
281 (eshell-parse-variable))))
282
283(defun eshell/define (var-alias definition)
012d3cb5 284 "Define a VAR-ALIAS using DEFINITION."
affbf647
GM
285 (if (not definition)
286 (setq eshell-variable-aliases-list
287 (delq (assoc var-alias eshell-variable-aliases-list)
288 eshell-variable-aliases-list))
289 (let ((def (assoc var-alias eshell-variable-aliases-list))
290 (alias-def
291 (list var-alias
292 (list 'quote (if (= (length definition) 1)
293 (car definition)
294 definition)))))
295 (if def
296 (setq eshell-variable-aliases-list
297 (delq (assoc var-alias eshell-variable-aliases-list)
298 eshell-variable-aliases-list)))
299 (setq eshell-variable-aliases-list
300 (cons alias-def
301 eshell-variable-aliases-list))))
302 nil)
303
304(defun eshell/export (&rest sets)
a4fd4556 305 "This alias allows the `export' command to act as bash users expect."
affbf647 306 (while sets
ca7aae91
JW
307 (if (and (stringp (car sets))
308 (string-match "^\\([^=]+\\)=\\(.*\\)" (car sets)))
affbf647
GM
309 (setenv (match-string 1 (car sets))
310 (match-string 2 (car sets))))
311 (setq sets (cdr sets))))
312
79cf8e80
JW
313(defun pcomplete/eshell-mode/export ()
314 "Completion function for Eshell's `export'."
315 (while (pcomplete-here
316 (if eshell-complete-export-definition
317 process-environment
318 (eshell-envvar-names)))))
319
ca7aae91
JW
320(defun eshell/unset (&rest args)
321 "Unset an environment variable."
322 (while args
323 (if (stringp (car args))
324 (setenv (car args) nil t))
325 (setq args (cdr args))))
326
79cf8e80
JW
327(defun pcomplete/eshell-mode/unset ()
328 "Completion function for Eshell's `unset'."
329 (while (pcomplete-here (eshell-envvar-names))))
affbf647
GM
330
331(defun eshell/setq (&rest args)
332 "Allow command-ish use of `setq'."
333 (let (last-value)
334 (while args
335 (let ((sym (intern (car args)))
336 (val (cadr args)))
337 (setq last-value (set sym val)
338 args (cddr args))))
339 last-value))
340
341(defun pcomplete/eshell-mode/setq ()
342 "Completion function for Eshell's `setq'."
343 (while (and (pcomplete-here (all-completions pcomplete-stub
344 obarray 'boundp))
345 (pcomplete-here))))
346
347(defun eshell/env (&rest args)
348 "Implemention of `env' in Lisp."
349 (eshell-init-print-buffer)
350 (eshell-eval-using-options
351 "env" args
352 '((?h "help" nil nil "show this usage screen")
353 :external "env"
354 :usage "<no arguments>")
a9eeff78 355 (dolist (setting (sort (eshell-environment-variables) 'string-lessp))
affbf647
GM
356 (eshell-buffered-print setting "\n"))
357 (eshell-flush)))
358
359(defun eshell-insert-envvar (envvar-name)
360 "Insert ENVVAR-NAME into the current buffer at point."
361 (interactive
362 (list (read-envvar-name "Name of environment variable: " t)))
363 (insert-and-inherit "$" envvar-name))
364
365(defun eshell-envvar-names (&optional environment)
366 "Return a list of currently visible environment variable names."
367 (mapcar (function
368 (lambda (x)
369 (substring x 0 (string-match "=" x))))
370 (or environment process-environment)))
371
372(defun eshell-environment-variables ()
373 "Return a `process-environment', fully updated.
374This involves setting any variable aliases which affect the
375environment, as specified in `eshell-variable-aliases-list'."
376 (let ((process-environment (eshell-copy-environment)))
a9eeff78 377 (dolist (var-alias eshell-variable-aliases-list)
affbf647
GM
378 (if (nth 2 var-alias)
379 (setenv (car var-alias)
380 (eshell-stringify
381 (or (eshell-get-variable (car var-alias)) "")))))
382 process-environment))
383
384(defun eshell-parse-variable ()
385 "Parse the next variable reference at point.
386The variable name could refer to either an environment variable, or a
387Lisp variable. The priority order depends on the setting of
388`eshell-prefer-lisp-variables'.
389
390Its purpose is to call `eshell-parse-variable-ref', and then to
391process any indices that come after the variable reference."
392 (let* ((get-len (when (eq (char-after) ?#)
393 (forward-char) t))
394 value indices)
395 (setq value (eshell-parse-variable-ref)
396 indices (and (not (eobp))
397 (eq (char-after) ?\[)
398 (eshell-parse-indices))
399 value (list 'let
400 (list (list 'indices
401 (list 'quote indices)))
402 value))
403 (if get-len
404 (list 'length value)
405 value)))
406
407(defun eshell-parse-variable-ref ()
408 "Eval a variable reference.
409Returns a Lisp form which, if evaluated, will return the value of the
410variable.
411
412Possible options are:
413
414 NAME an environment or Lisp variable value
415 <LONG-NAME> disambiguates the length of the name
416 {COMMAND} result of command is variable's value
417 (LISP-FORM) result of Lisp form is variable's value"
418 (let (end)
419 (cond
420 ((eq (char-after) ?{)
421 (let ((end (eshell-find-delimiter ?\{ ?\})))
422 (if (not end)
423 (throw 'eshell-incomplete ?\{)
424 (prog1
425 (list 'eshell-convert
426 (list 'eshell-command-to-value
427 (list 'eshell-as-subcommand
428 (eshell-parse-command
429 (cons (1+ (point)) end)))))
430 (goto-char (1+ end))))))
431 ((memq (char-after) '(?\' ?\"))
432 (let ((name (if (eq (char-after) ?\')
433 (eshell-parse-literal-quote)
434 (eshell-parse-double-quote))))
435 (if name
436 (list 'eshell-get-variable (eval name) 'indices))))
f1572159 437 ((eq (char-after) ?\<)
affbf647
GM
438 (let ((end (eshell-find-delimiter ?\< ?\>)))
439 (if (not end)
440 (throw 'eshell-incomplete ?\<)
1ae720ac 441 (let* ((temp (make-temp-file temporary-file-directory))
affbf647
GM
442 (cmd (concat (buffer-substring (1+ (point)) end)
443 " > " temp)))
444 (prog1
445 (list
446 'let (list (list 'eshell-current-handles
447 (list 'eshell-create-handles temp
448 (list 'quote 'overwrite))))
449 (list
450 'progn
451 (list 'eshell-as-subcommand
452 (eshell-parse-command cmd))
453 (list 'ignore
454 (list 'nconc 'eshell-this-command-hook
455 (list 'list
456 (list 'function
457 (list 'lambda nil
458 (list 'delete-file temp))))))
459 (list 'quote temp)))
460 (goto-char (1+ end)))))))
461 ((eq (char-after) ?\()
462 (condition-case err
463 (list 'eshell-command-to-value
464 (list 'eshell-lisp-command
465 (list 'quote (read (current-buffer)))))
466 (end-of-file
467 (throw 'eshell-incomplete ?\())))
468 ((assoc (char-to-string (char-after))
469 eshell-variable-aliases-list)
470 (forward-char)
471 (list 'eshell-get-variable
472 (char-to-string (char-before)) 'indices))
473 ((looking-at eshell-variable-name-regexp)
474 (prog1
475 (list 'eshell-get-variable (match-string 0) 'indices)
476 (goto-char (match-end 0))))
477 (t
478 (error "Invalid variable reference")))))
479
480(eshell-deftest var interp-cmd
481 "Interpolate command result"
482 (eshell-command-result-p "+ ${+ 1 2} 3" "6\n"))
483
484(eshell-deftest var interp-lisp
485 "Interpolate Lisp form evalution"
486 (eshell-command-result-p "+ $(+ 1 2) 3" "6\n"))
487
488(eshell-deftest var interp-concat
489 "Interpolate and concat command"
490 (eshell-command-result-p "+ ${+ 1 2}3 3" "36\n"))
491
492(eshell-deftest var interp-concat-lisp
493 "Interpolate and concat Lisp form"
494 (eshell-command-result-p "+ $(+ 1 2)3 3" "36\n"))
495
496(eshell-deftest var interp-concat2
497 "Interpolate and concat two commands"
498 (eshell-command-result-p "+ ${+ 1 2}${+ 1 2} 3" "36\n"))
499
500(eshell-deftest var interp-concat-lisp2
501 "Interpolate and concat two Lisp forms"
502 (eshell-command-result-p "+ $(+ 1 2)$(+ 1 2) 3" "36\n"))
503
504(defun eshell-parse-indices ()
505 "Parse and return a list of list of indices."
506 (let (indices)
507 (while (eq (char-after) ?\[)
508 (let ((end (eshell-find-delimiter ?\[ ?\])))
509 (if (not end)
510 (throw 'eshell-incomplete ?\[)
511 (forward-char)
512 (let (eshell-glob-function)
513 (setq indices (cons (eshell-parse-arguments (point) end)
514 indices)))
515 (goto-char (1+ end)))))
516 (nreverse indices)))
517
518(defun eshell-get-variable (name &optional indices)
519 "Get the value for the variable NAME."
520 (let* ((alias (assoc name eshell-variable-aliases-list))
521 (var (if alias
522 (cadr alias)
523 name)))
524 (if (and alias (functionp var))
525 (funcall var indices)
526 (eshell-apply-indices
527 (cond
528 ((stringp var)
529 (let ((sym (intern-soft var)))
530 (if (and sym (boundp sym)
531 (or eshell-prefer-lisp-variables
532 (not (getenv var))))
533 (symbol-value sym)
534 (getenv var))))
535 ((symbolp var)
536 (symbol-value var))
537 (t
538 (error "Unknown variable `%s'" (eshell-stringify var))))
539 indices))))
540
541(defun eshell-apply-indices (value indices)
542 "Apply to VALUE all of the given INDICES, returning the sub-result.
543The format of INDICES is:
544
545 ((INT-OR-NAME-OR-OTHER INT-OR-NAME INT-OR-NAME ...)
546 ...)
547
548Each member of INDICES represents a level of nesting. If the first
549member of a sublist is not an integer or name, and the value it's
550reference is a string, that will be used as the regexp with which is
551to divide the string into sub-parts. The default is whitespace.
552Otherwise, each INT-OR-NAME refers to an element of the list value.
553Integers imply a direct index, and names, an associate lookup using
554`assoc'.
555
556For example, to retrieve the second element of a user's record in
557'/etc/passwd', the variable reference would look like:
558
559 ${egrep johnw /etc/passwd}[: 2]"
560 (while indices
561 (let ((refs (car indices)))
562 (when (stringp value)
563 (let (separator)
564 (if (not (or (not (stringp (caar indices)))
565 (string-match
566 (concat "^" eshell-variable-name-regexp "$")
567 (caar indices))))
568 (setq separator (caar indices)
569 refs (cdr refs)))
570 (setq value
571 (mapcar 'eshell-convert
572 (split-string value separator)))))
573 (cond
574 ((< (length refs) 0)
5b423d48 575 (error "Invalid array variable index: %s"
affbf647
GM
576 (eshell-stringify refs)))
577 ((= (length refs) 1)
578 (setq value (eshell-index-value value (car refs))))
579 (t
580 (let ((new-value (list t)))
581 (while refs
582 (nconc new-value
583 (list (eshell-index-value value
584 (car refs))))
585 (setq refs (cdr refs)))
586 (setq value (cdr new-value))))))
587 (setq indices (cdr indices)))
588 value)
589
590(defun eshell-index-value (value index)
591 "Reference VALUE using the given INDEX."
592 (if (stringp index)
593 (cdr (assoc index value))
594 (cond
595 ((ring-p value)
596 (if (> index (ring-length value))
597 (error "Index exceeds length of ring")
598 (ring-ref value index)))
599 ((listp value)
600 (if (> index (length value))
601 (error "Index exceeds length of list")
602 (nth index value)))
603 ((vectorp value)
604 (if (> index (length value))
605 (error "Index exceeds length of vector")
606 (aref value index)))
607 (t
608 (error "Invalid data type for indexing")))))
609
610;;;_* Variable name completion
611
612(defun eshell-complete-variable-reference ()
613 "If there is a variable reference, complete it."
614 (let ((arg (pcomplete-actual-arg)) index)
615 (when (setq index
616 (string-match
617 (concat "\\$\\(" eshell-variable-name-regexp
618 "\\)?\\'") arg))
619 (setq pcomplete-stub (substring arg (1+ index)))
620 (throw 'pcomplete-completions (eshell-variables-list)))))
621
622(defun eshell-variables-list ()
623 "Generate list of applicable variables."
624 (let ((argname pcomplete-stub)
625 completions)
a9eeff78 626 (dolist (alias eshell-variable-aliases-list)
affbf647
GM
627 (if (string-match (concat "^" argname) (car alias))
628 (setq completions (cons (car alias) completions))))
629 (sort
630 (append
631 (mapcar
632 (function
633 (lambda (varname)
634 (let ((value (eshell-get-variable varname)))
635 (if (and value
636 (stringp value)
637 (file-directory-p value))
6b0e3e4d 638 (concat varname "/")
affbf647
GM
639 varname))))
640 (eshell-envvar-names (eshell-environment-variables)))
641 (all-completions argname obarray 'boundp)
642 completions)
643 'string-lessp)))
644
645(defun eshell-complete-variable-assignment ()
646 "If there is a variable assignment, allow completion of entries."
647 (let ((arg (pcomplete-actual-arg)) pos)
648 (when (string-match (concat "\\`" eshell-variable-name-regexp "=") arg)
649 (setq pos (match-end 0))
650 (if (string-match "\\(:\\)[^:]*\\'" arg)
651 (setq pos (match-end 1)))
652 (setq pcomplete-stub (substring arg pos))
653 (throw 'pcomplete-completions (pcomplete-entries)))))
654
affbf647 655;;; esh-var.el ends here