1 ;;; env.el --- functions to manipulate environment variables.
3 ;;; Copyright Free Software Foundation 1991
6 ;; Keywords: processes, unix
8 ;;; This file is part of GNU Emacs.
10 ;;; GNU Emacs is free software; you can redistribute it and/or modify
11 ;;; it under the terms of the GNU General Public License as published by
12 ;;; the Free Software Foundation; either version 2, or (at your option)
13 ;;; any later version.
15 ;;; GNU Emacs is distributed in the hope that it will be useful,
16 ;;; but WITHOUT ANY WARRANTY; without even the implied warranty of
17 ;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 ;;; GNU General Public License for more details.
20 ;;; You should have received a copy of the GNU General Public License
21 ;;; along with GNU Emacs; see the file COPYING. If not, write to
22 ;;; the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
26 ;; UNIX processes inherit a list of name-to-string associations from
27 ;; their parents called their `environment'; these are commonly used
28 ;; to control program options. This package permits you to set
29 ;; environment variables to be passed to any sub-process run under Emacs.
34 (defun setenv (variable &optional value unset
)
35 "Set the value of the environment variable named VARIABLE to VALUE.
36 VARIABLE should be a string. VALUE is optional; if not provided or is
37 `nil', the environment variable VARIABLE will be removed.
39 Interactively, a prefix argument means to unset the variable.
40 This function works by modifying `process-environment'."
42 (if current-prefix-arg
43 (list (read-string "Clear environment variable: ") nil t
)
44 (let ((var (read-string "Set environment variable: ")))
45 (list var
(read-string (format "Set %s to value: " var
))))))
46 (if unset
(setq value nil
))
47 (if (string-match "=" variable
)
48 (error "Environment variable name `%s' contains `='" variable
)
49 (let ((pattern (concat "\\`" (regexp-quote (concat variable
"="))))
50 (case-fold-search nil
)
51 (scan process-environment
)
54 (cond ((string-match pattern
(car scan
))
57 (setq process-environment
(delq (car scan
) process-environment
))
58 (setcar scan
(concat variable
"=" value
)))
60 (setq scan
(cdr scan
)))
63 (setq process-environment
64 (cons (concat variable
"=" value
)
65 process-environment
)))))))