Function: setenv-internal

setenv-internal is a byte-compiled function defined in env.el.gz.

Signature

(setenv-internal ENV VARIABLE VALUE KEEP-EMPTY)

Documentation

Set VARIABLE to VALUE in ENV, adding empty entries if KEEP-EMPTY.

Changes ENV by side-effect, and returns its new value.

Source Code

;; Defined in /usr/src/emacs/lisp/env.el.gz
(defun setenv-internal (env variable value keep-empty)
  "Set VARIABLE to VALUE in ENV, adding empty entries if KEEP-EMPTY.
Changes ENV by side-effect, and returns its new value."
  (declare (important-return-value t))
  (let ((pattern (concat "\\`" (regexp-quote variable) "\\(=\\|\\'\\)"))
	(case-fold-search nil)
	(scan env)
	prev found)
    ;; Handle deletions from the beginning of the list specially.
    (if (and (null value)
	     (not keep-empty)
	     env
	     (stringp (car env))
             (string-match-p pattern (car env)))
	(cdr env)
      ;; Try to find existing entry for VARIABLE in ENV.
      (while (and scan (stringp (car scan)))
        (when (string-match-p pattern (car scan))
	  (if value
	      (setcar scan (concat variable "=" value))
	    (if keep-empty
		(setcar scan variable)
	      (setcdr prev (cdr scan))))
	  (setq found t
		scan nil))
	(setq prev scan
	      scan (cdr scan)))
      (if (and (not found) (or value keep-empty))
	  (cons (if value
		    (concat variable "=" value)
		  variable)
		env)
	env))))