*** empty log message ***
[bpt/emacs.git] / lisp / env.el
1 ;;; setenv.el --- functions to manipulate environment variables.
2
3 ;;; Copyright Free Software Foundation 1991
4
5 ;;; This file is part of GNU Emacs.
6
7 ;;; GNU Emacs is free software; you can redistribute it and/or modify
8 ;;; it under the terms of the GNU General Public License as published by
9 ;;; the Free Software Foundation; either version 1, or (at your option)
10 ;;; any later version.
11
12 ;;; GNU Emacs is distributed in the hope that it will be useful,
13 ;;; but WITHOUT ANY WARRANTY; without even the implied warranty of
14 ;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 ;;; GNU General Public License for more details.
16
17 ;;; You should have received a copy of the GNU General Public License
18 ;;; along with GNU Emacs; see the file COPYING. If not, write to
19 ;;; the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
20
21 (defun setenv (variable value)
22 "Set the value of the environment variable named VARIABLE to VALUE.
23 VARIABLE and VALUE should both be strings.
24 This function works by modifying process-environment."
25 (if (string-match "=" variable)
26 (error "name of environment variable contains an '=' character")
27 (let ((pattern (concat "^" (regexp-quote (concat variable "="))))
28 (scan process-environment))
29 (while scan
30 (cond
31 ((string-match pattern (car scan))
32 (setcar scan (concat variable "=" value))
33 (setq scan nil))
34 ((null (setq scan (cdr scan)))
35 (setq process-environment
36 (cons (concat variable "=" value) process-environment))))))))
37
38 (provide 'setenv)
39
40 ;;; setenv.el ends here