Commit | Line | Data |
---|---|---|
1bbda2d6 | 1 | ;;; env.el --- functions to manipulate environment variables. |
c88ab9ce | 2 | |
971571b9 ER |
3 | ;;; Copyright Free Software Foundation 1991 |
4 | ||
e5167999 | 5 | ;; Maintainer: FSF |
d9ecc911 | 6 | ;; Keywords: processes, unix |
e5167999 | 7 | |
6449c898 JB |
8 | ;;; This file is part of GNU Emacs. |
9 | ||
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 | |
e5167999 | 12 | ;;; the Free Software Foundation; either version 2, or (at your option) |
6449c898 JB |
13 | ;;; any later version. |
14 | ||
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. | |
19 | ||
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. | |
23 | ||
d9ecc911 ER |
24 | ;;; Commentary: |
25 | ||
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. | |
30 | ||
e5167999 ER |
31 | ;;; Code: |
32 | ||
aa673ecc | 33 | ;;;###autoload |
b3b8e915 | 34 | (defun setenv (variable &optional value) |
6449c898 | 35 | "Set the value of the environment variable named VARIABLE to VALUE. |
1bbda2d6 NF |
36 | VARIABLE should be a string. VALUE is optional; if not provided or is |
37 | `nil', the environment variable VARIABLE will be removed. | |
b6a5978e | 38 | This function works by modifying `process-environment'." |
971571b9 | 39 | (interactive "sSet environment variable: \nsSet %s to value: ") |
6449c898 | 40 | (if (string-match "=" variable) |
1bbda2d6 | 41 | (error "Environment variable name `%s' contains `='" variable) |
971571b9 | 42 | (let ((pattern (concat "\\`" (regexp-quote (concat variable "=")))) |
6449c898 JB |
43 | (scan process-environment)) |
44 | (while scan | |
45 | (cond | |
46 | ((string-match pattern (car scan)) | |
1bbda2d6 NF |
47 | (if (eq nil value) |
48 | (setq process-environment (delq (car scan) process-environment)) | |
49 | (setcar scan (concat variable "=" value))) | |
6449c898 JB |
50 | (setq scan nil)) |
51 | ((null (setq scan (cdr scan))) | |
52 | (setq process-environment | |
53 | (cons (concat variable "=" value) process-environment)))))))) | |
49116ac0 | 54 | |
1bbda2d6 NF |
55 | (provide 'env) |
56 | ||
57 | ;;; env.el ends here |