Function: eshell-set-variable

eshell-set-variable is a byte-compiled function defined in esh-var.el.gz.

Signature

(eshell-set-variable NAME VALUE)

Documentation

Set the variable named NAME to VALUE.

NAME can be a string (in which case it refers to an environment variable or variable alias) or a symbol (in which case it refers to a Lisp variable).

Source Code

;; Defined in /usr/src/emacs/lisp/eshell/esh-var.el.gz
(defun eshell-set-variable (name value)
  "Set the variable named NAME to VALUE.
NAME can be a string (in which case it refers to an environment
variable or variable alias) or a symbol (in which case it refers
to a Lisp variable)."
  (if-let ((alias (assoc name eshell-variable-aliases-list)))
      (let ((target (nth 1 alias)))
        (cond
         ((functionp target)
          (setq target nil))
         ((consp target)
          (setq target (cdr target))))
        (cond
         ((functionp target)
          (funcall target nil value))
         ((null target)
          (unless eshell-in-subcommand-p
            (error "Variable `%s' is not settable" (eshell-stringify name)))
          (push `(,name ,(lambda () value) t t)
                eshell-variable-aliases-list)
          value)
         ;; Since getting a variable alias with a string target and
         ;; `eshell-prefer-lisp-variables' non-nil gets the
         ;; corresponding Lisp variable, make sure setting does the
         ;; same.
         ((and eshell-prefer-lisp-variables
               (stringp target))
          (eshell-set-variable (intern target) value))
         (t
          (eshell-set-variable target value))))
    (cond
     ((stringp name)
      (setenv name value))
     ((symbolp name)
      (set name value))
     (t
      (error "Unknown variable `%s'" (eshell-stringify name))))))