summaryrefslogtreecommitdiff
path: root/lisp/eshell/esh-opt.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-opt.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-opt.el')
-rw-r--r--lisp/eshell/esh-opt.el59
1 files changed, 28 insertions, 31 deletions
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 @@
(require 'esh-ext)
;; Unused.
-;;; (defgroup eshell-opt nil
-;;; "The options processing code handles command argument parsing for
-;;; Eshell commands implemented in Lisp."
-;;; :tag "Command options processing"
-;;; :group 'eshell)
+;; (defgroup eshell-opt nil
+;; "The options processing code handles command argument parsing for
+;; Eshell commands implemented in Lisp."
+;; :tag "Command options processing"
+;; :group 'eshell)
;;; User Functions:
@@ -103,32 +103,25 @@ interned variable `args' (created using a `let' form)."
macro-args
(list 'eshell-stringify-list
(list 'eshell-flatten-list macro-args)))))
- (let ,(append (delq nil (mapcar (lambda (opt)
+ (let ,(delq nil (mapcar (lambda (opt)
(and (listp opt) (nth 3 opt)))
(cadr options)))
- '(usage-msg last-value ext-command args))
;; FIXME: `options' ends up hiding some variable names under `quote',
;; which is incompatible with lexical scoping!!
- (eshell-do-opt ,name ,options (lambda () ,@body-forms)))))
+ (eshell-do-opt ,name ,options (lambda (args) ,@body-forms) temp-args))))
;;; Internal Functions:
-(defvar temp-args)
-(defvar last-value)
-(defvar usage-msg)
-(defvar ext-command)
;; Documented part of the interface; see eshell-eval-using-options.
-(defvar args)
+(defvar eshell--args)
-(defun eshell-do-opt (name options body-fun)
+(defun eshell-do-opt (name options body-fun args)
"Helper function for `eshell-eval-using-options'.
This code doesn't really need to be macro expanded everywhere."
- (setq args temp-args)
- (if (setq
- ext-command
+ (let* (last-value
+ (ext-command
(catch 'eshell-ext-command
- (when (setq
- usage-msg
+ (let ((usage-msg
(catch 'eshell-usage
(setq last-value nil)
(if (and (= (length args) 0)
@@ -136,12 +129,14 @@ This code doesn't really need to be macro expanded everywhere."
(throw 'eshell-usage
(eshell-show-usage name options)))
(setq args (eshell-process-args name args options)
- last-value (funcall body-fun))
- nil))
- (error "%s" usage-msg))))
+ last-value (funcall body-fun args))
+ nil)))
+ (when usage-msg
+ (error "%s" usage-msg))))))
+ (if ext-command
(throw 'eshell-external
(eshell-external-command ext-command args))
- last-value))
+ last-value)))
(defun eshell-show-usage (name options)
"Display the usage message for NAME, using OPTIONS."
@@ -197,12 +192,13 @@ will be modified."
(if (not (nth 3 opt))
(eshell-show-usage name options)
(if (eq (nth 2 opt) t)
- (if (> ai (length args))
+ (if (> ai (length eshell--args))
(error "%s: missing option argument" name)
- (set (nth 3 opt) (nth ai args))
+ (set (nth 3 opt) (nth ai eshell--args))
(if (> ai 0)
- (setcdr (nthcdr (1- ai) args) (nthcdr (1+ ai) args))
- (setq args (cdr args))))
+ (setcdr (nthcdr (1- ai) eshell--args)
+ (nthcdr (1+ ai) eshell--args))
+ (setq eshell--args (cdr eshell--args))))
(set (nth 3 opt) (or (nth 2 opt) t)))))
(defun eshell-process-option (name switch kind ai options)
@@ -232,14 +228,15 @@ switch is unrecognized."
(setq extcmd (eshell-search-path (cadr extcmd)))
(if extcmd
(throw 'eshell-ext-command extcmd)
- (if (characterp switch)
- (error "%s: unrecognized option -%c" name switch)
- (error "%s: unrecognized option --%s" name switch))))))))
+ (error (if (characterp switch) "%s: unrecognized option -%c"
+ "%s: unrecognized option --%s")
+ name switch)))))))
(defun eshell-process-args (name args options)
"Process the given ARGS using OPTIONS.
This assumes that symbols have been intern'd by `eshell-eval-using-options'."
- (let ((ai 0) arg)
+ (let ((ai 0) arg
+ (eshell--args args))
(while (< ai (length args))
(setq arg (nth ai args))
(if (not (and (stringp arg)