aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorStefan Monnier2013-09-12 01:20:07 -0400
committerStefan Monnier2013-09-12 01:20:07 -0400
commit170266d096bc4d0952bee907532d14503e882bf6 (patch)
tree9c25a5a63af77941b8ee141e275406ed6eb9c27c
parentd3b049e6015c09a2d1ea101e5fb466c6ce9f61e0 (diff)
downloademacs-170266d096bc4d0952bee907532d14503e882bf6.tar.gz
emacs-170266d096bc4d0952bee907532d14503e882bf6.zip
Cleanup Eshell to rely less on dynamic scoping.
* lisp/eshell/esh-opt.el (eshell-eval-using-options): Don't bind usage-msg, last-value, and ext-command here. Bind `args' closer to `body'. (temp-args, last-value, usage-msg, ext-command, args): Don't defvar. (eshell--args): Declare new dynamic var. (eshell-do-opt): Add argument `args'. Bind our own usage-msg, last-value, and ext-command. Pass `args' to `body'. (eshell-process-args): Bind eshell--args. (eshell-set-option): Use eshell--args. * lisp/eshell/eshell.el (eshell): Use derived-mode-p. * lisp/eshell/esh-var.el (eshell-parse-variable): Use backquote. (eshell-parse-variable-ref): Remove unused vars `end' and `err'. (eshell-glob-function): Declare. * lisp/eshell/esh-util.el: Require cl-lib. (eshell-read-hosts-file): Avoid add-to-list. * lisp/eshell/esh-cmd.el (eshell-parse-lisp-argument): Remove unused var `err'. * lisp/eshell/em-unix.el (compilation-scroll-output, locate-history-list): Declare. (eshell/diff): Remove unused var `err'. * lisp/eshell/em-rebind.el (eshell-delete-backward-char): Remove unused arg `killflag'. * lisp/eshell/em-pred.el (eshell-parse-modifiers): Remove unused var `err'. * lisp/eshell/em-ls.el (eshell-ls-highlight-alist): Move defvars before first use. * lisp/eshell/em-glob.el (eshell-glob-matches, message-shown): Move declaration before first use. * lisp/eshell/em-alias.el (eshell-maybe-replace-by-alias): Use backquotes. * autorevert.el (auto-revert-notify-handler): Use `cl-dolist' since we rely on cl-return.
-rw-r--r--lisp/ChangeLog28
-rw-r--r--lisp/eshell/em-alias.el17
-rw-r--r--lisp/eshell/em-glob.el5
-rw-r--r--lisp/eshell/em-ls.el38
-rw-r--r--lisp/eshell/em-pred.el2
-rw-r--r--lisp/eshell/em-rebind.el2
-rw-r--r--lisp/eshell/em-unix.el6
-rw-r--r--lisp/eshell/esh-arg.el2
-rw-r--r--lisp/eshell/esh-cmd.el2
-rw-r--r--lisp/eshell/esh-opt.el59
-rw-r--r--lisp/eshell/esh-util.el10
-rw-r--r--lisp/eshell/esh-var.el128
-rw-r--r--lisp/eshell/eshell.el2
13 files changed, 161 insertions, 140 deletions
diff --git a/lisp/ChangeLog b/lisp/ChangeLog
index 61e9c9bf708..7984dc214c4 100644
--- a/lisp/ChangeLog
+++ b/lisp/ChangeLog
@@ -1,5 +1,33 @@
12013-09-12 Stefan Monnier <monnier@iro.umontreal.ca> 12013-09-12 Stefan Monnier <monnier@iro.umontreal.ca>
2 2
3 Cleanup Eshell to rely less on dynamic scoping.
4 * eshell/esh-opt.el (eshell-eval-using-options): Don't bind usage-msg,
5 last-value, and ext-command here. Bind `args' closer to `body'.
6 (temp-args, last-value, usage-msg, ext-command, args): Don't defvar.
7 (eshell--args): Declare new dynamic var.
8 (eshell-do-opt): Add argument `args'. Bind our own usage-msg,
9 last-value, and ext-command. Pass `args' to `body'.
10 (eshell-process-args): Bind eshell--args.
11 (eshell-set-option): Use eshell--args.
12 * eshell/eshell.el (eshell): Use derived-mode-p.
13 * eshell/esh-var.el (eshell-parse-variable): Use backquote.
14 (eshell-parse-variable-ref): Remove unused vars `end' and `err'.
15 (eshell-glob-function): Declare.
16 * eshell/esh-util.el: Require cl-lib.
17 (eshell-read-hosts-file): Avoid add-to-list.
18 * eshell/esh-cmd.el (eshell-parse-lisp-argument): Remove unused var
19 `err'.
20 * eshell/em-unix.el (compilation-scroll-output, locate-history-list):
21 Declare.
22 (eshell/diff): Remove unused var `err'.
23 * eshell/em-rebind.el (eshell-delete-backward-char): Remove unused arg
24 `killflag'.
25 * eshell/em-pred.el (eshell-parse-modifiers): Remove unused var `err'.
26 * eshell/em-ls.el (eshell-ls-highlight-alist): Move defvars before
27 first use.
28 * eshell/em-glob.el (eshell-glob-matches, message-shown):
29 Move declaration before first use.
30 * eshell/em-alias.el (eshell-maybe-replace-by-alias): Use backquotes.
3 * autorevert.el (auto-revert-notify-handler): Use `cl-dolist' since we 31 * autorevert.el (auto-revert-notify-handler): Use `cl-dolist' since we
4 rely on cl-return. 32 rely on cl-return.
5 33
diff --git a/lisp/eshell/em-alias.el b/lisp/eshell/em-alias.el
index a46b48c01b3..9a9cc4cd567 100644
--- a/lisp/eshell/em-alias.el
+++ b/lisp/eshell/em-alias.el
@@ -221,18 +221,11 @@ file named by `eshell-aliases-file'.")
221 (let ((alias (eshell-lookup-alias command))) 221 (let ((alias (eshell-lookup-alias command)))
222 (if alias 222 (if alias
223 (throw 'eshell-replace-command 223 (throw 'eshell-replace-command
224 (list 224 `(let ((eshell-command-name ',eshell-last-command-name)
225 'let 225 (eshell-command-arguments ',eshell-last-arguments)
226 (list 226 (eshell-prevent-alias-expansion
227 (list 'eshell-command-name 227 ',(cons command eshell-prevent-alias-expansion)))
228 (list 'quote eshell-last-command-name)) 228 ,(eshell-parse-command (nth 1 alias))))))))
229 (list 'eshell-command-arguments
230 (list 'quote eshell-last-arguments))
231 (list 'eshell-prevent-alias-expansion
232 (list 'quote
233 (cons command
234 eshell-prevent-alias-expansion))))
235 (eshell-parse-command (nth 1 alias))))))))
236 229
237(defun eshell-alias-completions (name) 230(defun eshell-alias-completions (name)
238 "Find all possible completions for NAME. 231 "Find all possible completions for NAME.
diff --git a/lisp/eshell/em-glob.el b/lisp/eshell/em-glob.el
index a58c7730ded..b5ca8119470 100644
--- a/lisp/eshell/em-glob.el
+++ b/lisp/eshell/em-glob.el
@@ -180,6 +180,8 @@ interpretation."
180 (goto-char (1+ end)))))))))) 180 (goto-char (1+ end))))))))))
181 181
182(defvar eshell-glob-chars-regexp nil) 182(defvar eshell-glob-chars-regexp nil)
183(defvar eshell-glob-matches)
184(defvar message-shown)
183 185
184(defun eshell-glob-regexp (pattern) 186(defun eshell-glob-regexp (pattern)
185 "Convert glob-pattern PATTERN to a regular expression. 187 "Convert glob-pattern PATTERN to a regular expression.
@@ -262,9 +264,6 @@ the form:
262 (error "No matches found: %s" glob) 264 (error "No matches found: %s" glob)
263 glob)))) 265 glob))))
264 266
265(defvar eshell-glob-matches)
266(defvar message-shown)
267
268;; FIXME does this really need to abuse eshell-glob-matches, message-shown? 267;; FIXME does this really need to abuse eshell-glob-matches, message-shown?
269(defun eshell-glob-entries (path globs &optional recurse-p) 268(defun eshell-glob-entries (path globs &optional recurse-p)
270 "Glob the entries in PATHS, possibly recursing if RECURSE-P is non-nil." 269 "Glob the entries in PATHS, possibly recursing if RECURSE-P is non-nil."
diff --git a/lisp/eshell/em-ls.el b/lisp/eshell/em-ls.el
index 41db4cd03d1..3dee1adb58a 100644
--- a/lisp/eshell/em-ls.el
+++ b/lisp/eshell/em-ls.el
@@ -268,6 +268,25 @@ scope during the evaluation of TEST-SEXP."
268 :type '(repeat (cons function face)) 268 :type '(repeat (cons function face))
269 :group 'eshell-ls) 269 :group 'eshell-ls)
270 270
271(defvar block-size)
272(defvar dereference-links)
273(defvar dir-literal)
274(defvar error-func)
275(defvar flush-func)
276(defvar human-readable)
277(defvar ignore-pattern)
278(defvar insert-func)
279(defvar listing-style)
280(defvar numeric-uid-gid)
281(defvar reverse-list)
282(defvar show-all)
283(defvar show-almost-all)
284(defvar show-recursive)
285(defvar show-size)
286(defvar sort-method)
287(defvar ange-cache)
288(defvar dired-flag)
289
271;;; Functions: 290;;; Functions:
272 291
273(defun eshell-ls-insert-directory 292(defun eshell-ls-insert-directory
@@ -315,25 +334,6 @@ instead."
315 334
316(put 'eshell/ls 'eshell-no-numeric-conversions t) 335(put 'eshell/ls 'eshell-no-numeric-conversions t)
317 336
318(defvar block-size)
319(defvar dereference-links)
320(defvar dir-literal)
321(defvar error-func)
322(defvar flush-func)
323(defvar human-readable)
324(defvar ignore-pattern)
325(defvar insert-func)
326(defvar listing-style)
327(defvar numeric-uid-gid)
328(defvar reverse-list)
329(defvar show-all)
330(defvar show-almost-all)
331(defvar show-recursive)
332(defvar show-size)
333(defvar sort-method)
334(defvar ange-cache)
335(defvar dired-flag)
336
337(declare-function eshell-glob-regexp "em-glob" (pattern)) 337(declare-function eshell-glob-regexp "em-glob" (pattern))
338 338
339(defun eshell-do-ls (&rest args) 339(defun eshell-do-ls (&rest args)
diff --git a/lisp/eshell/em-pred.el b/lisp/eshell/em-pred.el
index 3a7f46ebe83..14d3020530f 100644
--- a/lisp/eshell/em-pred.el
+++ b/lisp/eshell/em-pred.el
@@ -307,7 +307,7 @@ functions. PRED-FUNCS take a filename and return t if the test
307succeeds; MOD-FUNCS take any string and preform a modification, 307succeeds; MOD-FUNCS take any string and preform a modification,
308returning the resultant string." 308returning the resultant string."
309 (let (result negate follow preds mods) 309 (let (result negate follow preds mods)
310 (condition-case err 310 (condition-case nil
311 (while (not (eobp)) 311 (while (not (eobp))
312 (let ((char (char-after))) 312 (let ((char (char-after)))
313 (cond 313 (cond
diff --git a/lisp/eshell/em-rebind.el b/lisp/eshell/em-rebind.el
index 341191fc62f..a526d590307 100644
--- a/lisp/eshell/em-rebind.el
+++ b/lisp/eshell/em-rebind.el
@@ -218,7 +218,7 @@ lock it at that."
218 (cdar bindings)) 218 (cdar bindings))
219 (setq bindings (cdr bindings))))) 219 (setq bindings (cdr bindings)))))
220 220
221(defun eshell-delete-backward-char (n &optional killflag) 221(defun eshell-delete-backward-char (n)
222 "Delete the last character, unless it's part of the output." 222 "Delete the last character, unless it's part of the output."
223 (interactive "P") 223 (interactive "P")
224 (let ((count (prefix-numeric-value n))) 224 (let ((count (prefix-numeric-value n)))
diff --git a/lisp/eshell/em-unix.el b/lisp/eshell/em-unix.el
index af54d875cb0..b9b1c1635a5 100644
--- a/lisp/eshell/em-unix.el
+++ b/lisp/eshell/em-unix.el
@@ -714,6 +714,8 @@ available..."
714 (goto-char (point-min)) 714 (goto-char (point-min))
715 (resize-temp-buffer-window)))))) 715 (resize-temp-buffer-window))))))
716 716
717(defvar compilation-scroll-output)
718
717(defun eshell-grep (command args &optional maybe-use-occur) 719(defun eshell-grep (command args &optional maybe-use-occur)
718 "Generic service function for the various grep aliases. 720 "Generic service function for the various grep aliases.
719It calls Emacs's grep utility if the command is not redirecting output, 721It calls Emacs's grep utility if the command is not redirecting output,
@@ -989,7 +991,7 @@ Show wall-clock time elapsed during execution of COMMAND.")
989 (setq args nil) 991 (setq args nil)
990 (setcdr (last args 3) nil)) 992 (setcdr (last args 3) nil))
991 (with-current-buffer 993 (with-current-buffer
992 (condition-case err 994 (condition-case nil
993 (diff-no-select 995 (diff-no-select
994 old new 996 old new
995 (nil-blank-string (eshell-flatten-and-stringify args))) 997 (nil-blank-string (eshell-flatten-and-stringify args)))
@@ -1014,6 +1016,8 @@ Show wall-clock time elapsed during execution of COMMAND.")
1014 1016
1015(put 'eshell/diff 'eshell-no-numeric-conversions t) 1017(put 'eshell/diff 'eshell-no-numeric-conversions t)
1016 1018
1019(defvar locate-history-list)
1020
1017(defun eshell/locate (&rest args) 1021(defun eshell/locate (&rest args)
1018 "Alias \"locate\" to call Emacs `locate' function." 1022 "Alias \"locate\" to call Emacs `locate' function."
1019 (if (or eshell-plain-locate-behavior 1023 (if (or eshell-plain-locate-behavior
diff --git a/lisp/eshell/esh-arg.el b/lisp/eshell/esh-arg.el
index d7dfd27d8d3..e3a12d5ece5 100644
--- a/lisp/eshell/esh-arg.el
+++ b/lisp/eshell/esh-arg.el
@@ -278,7 +278,7 @@ Point is left at the end of the arguments."
278 (eshell-resolve-current-argument) 278 (eshell-resolve-current-argument)
279 eshell-current-argument)) 279 eshell-current-argument))
280 280
281(defsubst eshell-operator (&rest args) 281(defsubst eshell-operator (&rest _args)
282 "A stub function that generates an error if a floating operator is found." 282 "A stub function that generates an error if a floating operator is found."
283 (error "Unhandled operator in input text")) 283 (error "Unhandled operator in input text"))
284 284
diff --git a/lisp/eshell/esh-cmd.el b/lisp/eshell/esh-cmd.el
index ef8a53f3c0b..c2922983ae2 100644
--- a/lisp/eshell/esh-cmd.el
+++ b/lisp/eshell/esh-cmd.el
@@ -650,7 +650,7 @@ For an external command, it means an exit code of 0."
650 (looking-at eshell-lisp-regexp)) 650 (looking-at eshell-lisp-regexp))
651 (let* ((here (point)) 651 (let* ((here (point))
652 (obj 652 (obj
653 (condition-case err 653 (condition-case nil
654 (read (current-buffer)) 654 (read (current-buffer))
655 (end-of-file 655 (end-of-file
656 (throw 'eshell-incomplete ?\())))) 656 (throw 'eshell-incomplete ?\()))))
diff --git a/lisp/eshell/esh-opt.el b/lisp/eshell/esh-opt.el
index 33625433022..c62cbc7e1dc 100644
--- a/lisp/eshell/esh-opt.el
+++ b/lisp/eshell/esh-opt.el
@@ -28,11 +28,11 @@
28(require 'esh-ext) 28(require 'esh-ext)
29 29
30;; Unused. 30;; Unused.
31;;; (defgroup eshell-opt nil 31;; (defgroup eshell-opt nil
32;;; "The options processing code handles command argument parsing for 32;; "The options processing code handles command argument parsing for
33;;; Eshell commands implemented in Lisp." 33;; Eshell commands implemented in Lisp."
34;;; :tag "Command options processing" 34;; :tag "Command options processing"
35;;; :group 'eshell) 35;; :group 'eshell)
36 36
37;;; User Functions: 37;;; User Functions:
38 38
@@ -103,32 +103,25 @@ interned variable `args' (created using a `let' form)."
103 macro-args 103 macro-args
104 (list 'eshell-stringify-list 104 (list 'eshell-stringify-list
105 (list 'eshell-flatten-list macro-args))))) 105 (list 'eshell-flatten-list macro-args)))))
106 (let ,(append (delq nil (mapcar (lambda (opt) 106 (let ,(delq nil (mapcar (lambda (opt)
107 (and (listp opt) (nth 3 opt))) 107 (and (listp opt) (nth 3 opt)))
108 (cadr options))) 108 (cadr options)))
109 '(usage-msg last-value ext-command args))
110 ;; FIXME: `options' ends up hiding some variable names under `quote', 109 ;; FIXME: `options' ends up hiding some variable names under `quote',
111 ;; which is incompatible with lexical scoping!! 110 ;; which is incompatible with lexical scoping!!
112 (eshell-do-opt ,name ,options (lambda () ,@body-forms))))) 111 (eshell-do-opt ,name ,options (lambda (args) ,@body-forms) temp-args))))
113 112
114;;; Internal Functions: 113;;; Internal Functions:
115 114
116(defvar temp-args)
117(defvar last-value)
118(defvar usage-msg)
119(defvar ext-command)
120;; Documented part of the interface; see eshell-eval-using-options. 115;; Documented part of the interface; see eshell-eval-using-options.
121(defvar args) 116(defvar eshell--args)
122 117
123(defun eshell-do-opt (name options body-fun) 118(defun eshell-do-opt (name options body-fun args)
124 "Helper function for `eshell-eval-using-options'. 119 "Helper function for `eshell-eval-using-options'.
125This code doesn't really need to be macro expanded everywhere." 120This code doesn't really need to be macro expanded everywhere."
126 (setq args temp-args) 121 (let* (last-value
127 (if (setq 122 (ext-command
128 ext-command
129 (catch 'eshell-ext-command 123 (catch 'eshell-ext-command
130 (when (setq 124 (let ((usage-msg
131 usage-msg
132 (catch 'eshell-usage 125 (catch 'eshell-usage
133 (setq last-value nil) 126 (setq last-value nil)
134 (if (and (= (length args) 0) 127 (if (and (= (length args) 0)
@@ -136,12 +129,14 @@ This code doesn't really need to be macro expanded everywhere."
136 (throw 'eshell-usage 129 (throw 'eshell-usage
137 (eshell-show-usage name options))) 130 (eshell-show-usage name options)))
138 (setq args (eshell-process-args name args options) 131 (setq args (eshell-process-args name args options)
139 last-value (funcall body-fun)) 132 last-value (funcall body-fun args))
140 nil)) 133 nil)))
141 (error "%s" usage-msg)))) 134 (when usage-msg
135 (error "%s" usage-msg))))))
136 (if ext-command
142 (throw 'eshell-external 137 (throw 'eshell-external
143 (eshell-external-command ext-command args)) 138 (eshell-external-command ext-command args))
144 last-value)) 139 last-value)))
145 140
146(defun eshell-show-usage (name options) 141(defun eshell-show-usage (name options)
147 "Display the usage message for NAME, using OPTIONS." 142 "Display the usage message for NAME, using OPTIONS."
@@ -197,12 +192,13 @@ will be modified."
197 (if (not (nth 3 opt)) 192 (if (not (nth 3 opt))
198 (eshell-show-usage name options) 193 (eshell-show-usage name options)
199 (if (eq (nth 2 opt) t) 194 (if (eq (nth 2 opt) t)
200 (if (> ai (length args)) 195 (if (> ai (length eshell--args))
201 (error "%s: missing option argument" name) 196 (error "%s: missing option argument" name)
202 (set (nth 3 opt) (nth ai args)) 197 (set (nth 3 opt) (nth ai eshell--args))
203 (if (> ai 0) 198 (if (> ai 0)
204 (setcdr (nthcdr (1- ai) args) (nthcdr (1+ ai) args)) 199 (setcdr (nthcdr (1- ai) eshell--args)
205 (setq args (cdr args)))) 200 (nthcdr (1+ ai) eshell--args))
201 (setq eshell--args (cdr eshell--args))))
206 (set (nth 3 opt) (or (nth 2 opt) t))))) 202 (set (nth 3 opt) (or (nth 2 opt) t)))))
207 203
208(defun eshell-process-option (name switch kind ai options) 204(defun eshell-process-option (name switch kind ai options)
@@ -232,14 +228,15 @@ switch is unrecognized."
232 (setq extcmd (eshell-search-path (cadr extcmd))) 228 (setq extcmd (eshell-search-path (cadr extcmd)))
233 (if extcmd 229 (if extcmd
234 (throw 'eshell-ext-command extcmd) 230 (throw 'eshell-ext-command extcmd)
235 (if (characterp switch) 231 (error (if (characterp switch) "%s: unrecognized option -%c"
236 (error "%s: unrecognized option -%c" name switch) 232 "%s: unrecognized option --%s")
237 (error "%s: unrecognized option --%s" name switch)))))))) 233 name switch)))))))
238 234
239(defun eshell-process-args (name args options) 235(defun eshell-process-args (name args options)
240 "Process the given ARGS using OPTIONS. 236 "Process the given ARGS using OPTIONS.
241This assumes that symbols have been intern'd by `eshell-eval-using-options'." 237This assumes that symbols have been intern'd by `eshell-eval-using-options'."
242 (let ((ai 0) arg) 238 (let ((ai 0) arg
239 (eshell--args args))
243 (while (< ai (length args)) 240 (while (< ai (length args))
244 (setq arg (nth ai args)) 241 (setq arg (nth ai args))
245 (if (not (and (stringp arg) 242 (if (not (and (stringp arg)
diff --git a/lisp/eshell/esh-util.el b/lisp/eshell/esh-util.el
index dd344eb50a2..968d1ebad79 100644
--- a/lisp/eshell/esh-util.el
+++ b/lisp/eshell/esh-util.el
@@ -23,6 +23,8 @@
23 23
24;;; Code: 24;;; Code:
25 25
26(eval-when-compile (require 'cl-lib))
27
26(defgroup eshell-util nil 28(defgroup eshell-util nil
27 "This is general utility code, meant for use by Eshell itself." 29 "This is general utility code, meant for use by Eshell itself."
28 :tag "General utilities" 30 :tag "General utilities"
@@ -484,12 +486,12 @@ list."
484 (while (re-search-forward 486 (while (re-search-forward
485 "^\\([^#[:space:]]+\\)\\s-+\\(\\S-+\\)\\(\\s-*\\(\\S-+\\)\\)?" nil t) 487 "^\\([^#[:space:]]+\\)\\s-+\\(\\S-+\\)\\(\\s-*\\(\\S-+\\)\\)?" nil t)
486 (if (match-string 1) 488 (if (match-string 1)
487 (add-to-list 'hosts (match-string 1))) 489 (cl-pushnew (match-string 1) hosts :test #'equal))
488 (if (match-string 2) 490 (if (match-string 2)
489 (add-to-list 'hosts (match-string 2))) 491 (cl-pushnew (match-string 2) hosts :test #'equal))
490 (if (match-string 4) 492 (if (match-string 4)
491 (add-to-list 'hosts (match-string 4))))) 493 (cl-pushnew (match-string 4) hosts :test #'equal))))
492 (sort hosts 'string-lessp))) 494 (sort hosts #'string-lessp)))
493 495
494(defun eshell-read-hosts (file result-var timestamp-var) 496(defun eshell-read-hosts (file result-var timestamp-var)
495 "Read the contents of /etc/passwd for user names." 497 "Read the contents of /etc/passwd for user names."
diff --git a/lisp/eshell/esh-var.el b/lisp/eshell/esh-var.el
index 188b8165248..75c36a68544 100644
--- a/lisp/eshell/esh-var.el
+++ b/lisp/eshell/esh-var.el
@@ -395,12 +395,9 @@ process any indices that come after the variable reference."
395 indices (and (not (eobp)) 395 indices (and (not (eobp))
396 (eq (char-after) ?\[) 396 (eq (char-after) ?\[)
397 (eshell-parse-indices)) 397 (eshell-parse-indices))
398 value (list 'let 398 value `(let ((indices ',indices)) ,value))
399 (list (list 'indices
400 (list 'quote indices)))
401 value))
402 (if get-len 399 (if get-len
403 (list 'length value) 400 `(length ,value)
404 value))) 401 value)))
405 402
406(defun eshell-parse-variable-ref () 403(defun eshell-parse-variable-ref ()
@@ -414,67 +411,68 @@ Possible options are:
414 <LONG-NAME> disambiguates the length of the name 411 <LONG-NAME> disambiguates the length of the name
415 {COMMAND} result of command is variable's value 412 {COMMAND} result of command is variable's value
416 (LISP-FORM) result of Lisp form is variable's value" 413 (LISP-FORM) result of Lisp form is variable's value"
417 (let (end) 414 (cond
418 (cond 415 ((eq (char-after) ?{)
419 ((eq (char-after) ?{) 416 (let ((end (eshell-find-delimiter ?\{ ?\})))
420 (let ((end (eshell-find-delimiter ?\{ ?\}))) 417 (if (not end)
421 (if (not end) 418 (throw 'eshell-incomplete ?\{)
422 (throw 'eshell-incomplete ?\{) 419 (prog1
423 (prog1 420 (list 'eshell-convert
424 (list 'eshell-convert 421 (list 'eshell-command-to-value
425 (list 'eshell-command-to-value 422 (list 'eshell-as-subcommand
426 (list 'eshell-as-subcommand 423 (eshell-parse-command
427 (eshell-parse-command 424 (cons (1+ (point)) end)))))
428 (cons (1+ (point)) end))))) 425 (goto-char (1+ end))))))
429 (goto-char (1+ end)))))) 426 ((memq (char-after) '(?\' ?\"))
430 ((memq (char-after) '(?\' ?\")) 427 (let ((name (if (eq (char-after) ?\')
431 (let ((name (if (eq (char-after) ?\') 428 (eshell-parse-literal-quote)
432 (eshell-parse-literal-quote) 429 (eshell-parse-double-quote))))
433 (eshell-parse-double-quote)))) 430 (if name
434 (if name
435 (list 'eshell-get-variable (eval name) 'indices)))) 431 (list 'eshell-get-variable (eval name) 'indices))))
436 ((eq (char-after) ?\<) 432 ((eq (char-after) ?\<)
437 (let ((end (eshell-find-delimiter ?\< ?\>))) 433 (let ((end (eshell-find-delimiter ?\< ?\>)))
438 (if (not end) 434 (if (not end)
439 (throw 'eshell-incomplete ?\<) 435 (throw 'eshell-incomplete ?\<)
440 (let* ((temp (make-temp-file temporary-file-directory)) 436 (let* ((temp (make-temp-file temporary-file-directory))
441 (cmd (concat (buffer-substring (1+ (point)) end) 437 (cmd (concat (buffer-substring (1+ (point)) end)
442 " > " temp))) 438 " > " temp)))
443 (prog1 439 (prog1
444 (list 440 (list
445 'let (list (list 'eshell-current-handles 441 'let (list (list 'eshell-current-handles
446 (list 'eshell-create-handles temp 442 (list 'eshell-create-handles temp
447 (list 'quote 'overwrite)))) 443 (list 'quote 'overwrite))))
448 (list 444 (list
449 'progn 445 'progn
450 (list 'eshell-as-subcommand 446 (list 'eshell-as-subcommand
451 (eshell-parse-command cmd)) 447 (eshell-parse-command cmd))
452 (list 'ignore 448 (list 'ignore
453 (list 'nconc 'eshell-this-command-hook 449 (list 'nconc 'eshell-this-command-hook
454 (list 'list 450 (list 'list
455 (list 'function 451 (list 'function
456 (list 'lambda nil 452 (list 'lambda nil
457 (list 'delete-file temp)))))) 453 (list 'delete-file temp))))))
458 (list 'quote temp))) 454 (list 'quote temp)))
459 (goto-char (1+ end))))))) 455 (goto-char (1+ end)))))))
460 ((eq (char-after) ?\() 456 ((eq (char-after) ?\()
461 (condition-case err 457 (condition-case nil
462 (list 'eshell-command-to-value 458 (list 'eshell-command-to-value
463 (list 'eshell-lisp-command 459 (list 'eshell-lisp-command
464 (list 'quote (read (current-buffer))))) 460 (list 'quote (read (current-buffer)))))
465 (end-of-file 461 (end-of-file
466 (throw 'eshell-incomplete ?\()))) 462 (throw 'eshell-incomplete ?\())))
467 ((assoc (char-to-string (char-after)) 463 ((assoc (char-to-string (char-after))
468 eshell-variable-aliases-list) 464 eshell-variable-aliases-list)
469 (forward-char) 465 (forward-char)
470 (list 'eshell-get-variable 466 (list 'eshell-get-variable
471 (char-to-string (char-before)) 'indices)) 467 (char-to-string (char-before)) 'indices))
472 ((looking-at eshell-variable-name-regexp) 468 ((looking-at eshell-variable-name-regexp)
473 (prog1 469 (prog1
474 (list 'eshell-get-variable (match-string 0) 'indices) 470 (list 'eshell-get-variable (match-string 0) 'indices)
475 (goto-char (match-end 0)))) 471 (goto-char (match-end 0))))
476 (t 472 (t
477 (error "Invalid variable reference"))))) 473 (error "Invalid variable reference"))))
474
475(defvar eshell-glob-function)
478 476
479(defun eshell-parse-indices () 477(defun eshell-parse-indices ()
480 "Parse and return a list of list of indices." 478 "Parse and return a list of list of indices."
diff --git a/lisp/eshell/eshell.el b/lisp/eshell/eshell.el
index 9bdf8b3eb68..e3f8f0d11bc 100644
--- a/lisp/eshell/eshell.el
+++ b/lisp/eshell/eshell.el
@@ -300,7 +300,7 @@ buffer selected (or created)."
300 (get-buffer-create eshell-buffer-name))))) 300 (get-buffer-create eshell-buffer-name)))))
301 (cl-assert (and buf (buffer-live-p buf))) 301 (cl-assert (and buf (buffer-live-p buf)))
302 (pop-to-buffer-same-window buf) 302 (pop-to-buffer-same-window buf)
303 (unless (eq major-mode 'eshell-mode) 303 (unless (derived-mode-p 'eshell-mode)
304 (eshell-mode)) 304 (eshell-mode))
305 buf)) 305 buf))
306 306