]> code.delx.au - gnu-emacs/blobdiff - lisp/eshell/esh-var.el
Update copyright year to 2015
[gnu-emacs] / lisp / eshell / esh-var.el
index 69004a841f1cd5496e2e2559adc0796b834a0ccd..197a8e77cc7041806adfd21947a92f577ddc9bc6 100644 (file)
@@ -1,6 +1,6 @@
-;;; esh-var.el --- handling of variables
+;;; esh-var.el --- handling of variables  -*- lexical-binding:t -*-
 
-;; Copyright (C) 1999-201 Free Software Foundation, Inc.
+;; Copyright (C) 1999-2015 Free Software Foundation, Inc.
 
 ;; Author: John Wiegley <johnw@gnu.org>
 
 
 (provide 'esh-var)
 
-(eval-when-compile
-  (require 'pcomplete)
-  (require 'esh-util)
-  (require 'esh-opt)
-  (require 'esh-mode))
+(require 'esh-util)
+(require 'esh-cmd)
+(require 'esh-opt)
+
+(require 'pcomplete)
 (require 'env)
 (require 'ring)
 
@@ -184,9 +184,9 @@ if they are quoted with a backslash."
                                   indices)))))
   "This list provides aliasing for variable references.
 It is very similar in concept to what `eshell-user-aliases-list' does
-for commands.  Each member of this defines defines the name of a
-command, and the Lisp value to return for that variable if it is
-accessed via the syntax '$NAME'.
+for commands.  Each member of this defines the name of a command,
+and the Lisp value to return for that variable if it is accessed
+via the syntax '$NAME'.
 
 If the value is a function, that function will be called with two
 arguments: the list of the indices that was used in the reference, and
@@ -344,7 +344,7 @@ This function is explicit for adding to `eshell-parse-argument-hook'."
              (pcomplete-here))))
 
 (defun eshell/env (&rest args)
-  "Implemention of `env' in Lisp."
+  "Implementation of `env' in Lisp."
   (eshell-init-print-buffer)
   (eshell-eval-using-options
    "env" args
@@ -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."
@@ -504,6 +502,7 @@ Possible options are:
         (let ((sym (intern-soft var)))
           (if (and sym (boundp sym)
                    (or eshell-prefer-lisp-variables
+                       (memq sym eshell--local-vars) ; bug#15372
                        (not (getenv var))))
               (symbol-value sym)
             (getenv var))))