summaryrefslogtreecommitdiff
path: root/lisp/eshell/esh-var.el
diff options
context:
space:
mode:
authorStefan Monnier <monnier@iro.umontreal.ca>2013-09-12 01:20:07 -0400
committerStefan Monnier <monnier@iro.umontreal.ca>2013-09-12 01:20:07 -0400
commit170266d096bc4d0952bee907532d14503e882bf6 (patch)
tree9c25a5a63af77941b8ee141e275406ed6eb9c27c /lisp/eshell/esh-var.el
parentd3b049e6015c09a2d1ea101e5fb466c6ce9f61e0 (diff)
downloademacs-170266d096bc4d0952bee907532d14503e882bf6.tar.gz
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.
Diffstat (limited to 'lisp/eshell/esh-var.el')
-rw-r--r--lisp/eshell/esh-var.el128
1 files changed, 63 insertions, 65 deletions
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."
indices (and (not (eobp))
(eq (char-after) ?\[)
(eshell-parse-indices))
- value (list 'let
- (list (list 'indices
- (list 'quote indices)))
- value))
+ value `(let ((indices ',indices)) ,value))
(if get-len
- (list 'length value)
+ `(length ,value)
value)))
(defun eshell-parse-variable-ref ()
@@ -414,67 +411,68 @@ Possible options are:
<LONG-NAME> disambiguates the length of the name
{COMMAND} result of command is variable's value
(LISP-FORM) result of Lisp form is variable's value"
- (let (end)
- (cond
- ((eq (char-after) ?{)
- (let ((end (eshell-find-delimiter ?\{ ?\})))
- (if (not end)
- (throw 'eshell-incomplete ?\{)
- (prog1
- (list 'eshell-convert
- (list 'eshell-command-to-value
- (list 'eshell-as-subcommand
- (eshell-parse-command
- (cons (1+ (point)) end)))))
- (goto-char (1+ end))))))
- ((memq (char-after) '(?\' ?\"))
- (let ((name (if (eq (char-after) ?\')
- (eshell-parse-literal-quote)
- (eshell-parse-double-quote))))
- (if name
+ (cond
+ ((eq (char-after) ?{)
+ (let ((end (eshell-find-delimiter ?\{ ?\})))
+ (if (not end)
+ (throw 'eshell-incomplete ?\{)
+ (prog1
+ (list 'eshell-convert
+ (list 'eshell-command-to-value
+ (list 'eshell-as-subcommand
+ (eshell-parse-command
+ (cons (1+ (point)) end)))))
+ (goto-char (1+ end))))))
+ ((memq (char-after) '(?\' ?\"))
+ (let ((name (if (eq (char-after) ?\')
+ (eshell-parse-literal-quote)
+ (eshell-parse-double-quote))))
+ (if name
(list 'eshell-get-variable (eval name) 'indices))))
- ((eq (char-after) ?\<)
- (let ((end (eshell-find-delimiter ?\< ?\>)))
- (if (not end)
- (throw 'eshell-incomplete ?\<)
- (let* ((temp (make-temp-file temporary-file-directory))
- (cmd (concat (buffer-substring (1+ (point)) end)
- " > " temp)))
- (prog1
- (list
- 'let (list (list 'eshell-current-handles
- (list 'eshell-create-handles temp
- (list 'quote 'overwrite))))
- (list
- 'progn
- (list 'eshell-as-subcommand
- (eshell-parse-command cmd))
- (list 'ignore
- (list 'nconc 'eshell-this-command-hook
- (list 'list
- (list 'function
- (list 'lambda nil
- (list 'delete-file temp))))))
- (list 'quote temp)))
- (goto-char (1+ end)))))))
- ((eq (char-after) ?\()
- (condition-case err
- (list 'eshell-command-to-value
- (list 'eshell-lisp-command
- (list 'quote (read (current-buffer)))))
- (end-of-file
- (throw 'eshell-incomplete ?\())))
- ((assoc (char-to-string (char-after))
- eshell-variable-aliases-list)
- (forward-char)
- (list 'eshell-get-variable
- (char-to-string (char-before)) 'indices))
- ((looking-at eshell-variable-name-regexp)
- (prog1
- (list 'eshell-get-variable (match-string 0) 'indices)
- (goto-char (match-end 0))))
- (t
- (error "Invalid variable reference")))))
+ ((eq (char-after) ?\<)
+ (let ((end (eshell-find-delimiter ?\< ?\>)))
+ (if (not end)
+ (throw 'eshell-incomplete ?\<)
+ (let* ((temp (make-temp-file temporary-file-directory))
+ (cmd (concat (buffer-substring (1+ (point)) end)
+ " > " temp)))
+ (prog1
+ (list
+ 'let (list (list 'eshell-current-handles
+ (list 'eshell-create-handles temp
+ (list 'quote 'overwrite))))
+ (list
+ 'progn
+ (list 'eshell-as-subcommand
+ (eshell-parse-command cmd))
+ (list 'ignore
+ (list 'nconc 'eshell-this-command-hook
+ (list 'list
+ (list 'function
+ (list 'lambda nil
+ (list 'delete-file temp))))))
+ (list 'quote temp)))
+ (goto-char (1+ end)))))))
+ ((eq (char-after) ?\()
+ (condition-case nil
+ (list 'eshell-command-to-value
+ (list 'eshell-lisp-command
+ (list 'quote (read (current-buffer)))))
+ (end-of-file
+ (throw 'eshell-incomplete ?\())))
+ ((assoc (char-to-string (char-after))
+ eshell-variable-aliases-list)
+ (forward-char)
+ (list 'eshell-get-variable
+ (char-to-string (char-before)) 'indices))
+ ((looking-at eshell-variable-name-regexp)
+ (prog1
+ (list 'eshell-get-variable (match-string 0) 'indices)
+ (goto-char (match-end 0))))
+ (t
+ (error "Invalid variable reference"))))
+
+(defvar eshell-glob-function)
(defun eshell-parse-indices ()
"Parse and return a list of list of indices."