Cleanup Eshell to rely less on dynamic scoping.
[bpt/emacs.git] / lisp / eshell / esh-arg.el
index dcb2396..e3a12d5 100644 (file)
@@ -1,6 +1,6 @@
 ;;; esh-arg.el --- argument processing
 
-;; Copyright (C) 1999-201 Free Software Foundation, Inc.
+;; Copyright (C) 1999-2013 Free Software Foundation, Inc.
 
 ;; Author: John Wiegley <johnw@gnu.org>
 
@@ -27,7 +27,7 @@
 
 (provide 'esh-arg)
 
-(eval-when-compile (require 'eshell))
+(require 'esh-mode)
 
 (defgroup eshell-arg nil
   "Argument parsing involves transforming the arguments passed on the
@@ -202,6 +202,18 @@ If POS is nil, the location of point is checked."
     (or (= pos (point-max))
        (memq (char-after pos) eshell-delimiter-argument-list))))
 
+(defun eshell-quote-argument (string)
+  "Return STRING with magic characters quoted.
+Magic characters are those in `eshell-special-chars-outside-quoting'."
+  (let ((index 0))
+    (mapconcat (lambda (c)
+                (prog1
+                    (or (eshell-quote-backslash string index)
+                        (char-to-string c))
+                  (setq index (1+ index))))
+              string
+              "")))
+
 ;; Argument parsing
 
 (defun eshell-parse-arguments (beg end)
@@ -266,7 +278,7 @@ Point is left at the end of the arguments."
     (eshell-resolve-current-argument)
     eshell-current-argument))
 
-(defsubst eshell-operator (&rest args)
+(defsubst eshell-operator (&rest _args)
   "A stub function that generates an error if a floating operator is found."
   (error "Unhandled operator in input text"))