annotate lisp/env.el @ 41220:0a6ed29cea73

Comment change.
author Richard M. Stallman <rms@gnu.org>
date Sat, 17 Nov 2001 22:41:26 +0000
parents 48cf8bbd6e34
children 37645a051842
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
38412
253f761ad37b Some fixes to follow coding conventions in files maintained by FSF.
Pavel Janík <Pavel@Janik.cz>
parents: 28917
diff changeset
1 ;;; env.el --- functions to manipulate environment variables
658
7cbd4fcd8b0f *** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents: 584
diff changeset
2
39126
c0713ad66d33 (setenv): Interactively, if VARIABLE has a current value,
Gerd Moellmann <gerd@gnu.org>
parents: 38412
diff changeset
3 ;; Copyright (C) 1991, 1994, 2000, 2001 Free Software Foundation, Inc.
1185
4ec50a934e54 entered into RCS
Eric S. Raymond <esr@snark.thyrsus.com>
parents: 814
diff changeset
4
807
4f28bd14272c *** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents: 658
diff changeset
5 ;; Maintainer: FSF
2315
9e7ec92a4fdf Added or corrected Commentary headers
Eric S. Raymond <esr@snark.thyrsus.com>
parents: 1218
diff changeset
6 ;; Keywords: processes, unix
807
4f28bd14272c *** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents: 658
diff changeset
7
14169
83f275dcd93a Update FSF's address.
Erik Naggum <erik@naggum.no>
parents: 13018
diff changeset
8 ;; This file is part of GNU Emacs.
489
3d2d0362a496 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
9
14169
83f275dcd93a Update FSF's address.
Erik Naggum <erik@naggum.no>
parents: 13018
diff changeset
10 ;; GNU Emacs is free software; you can redistribute it and/or modify
83f275dcd93a Update FSF's address.
Erik Naggum <erik@naggum.no>
parents: 13018
diff changeset
11 ;; it under the terms of the GNU General Public License as published by
83f275dcd93a Update FSF's address.
Erik Naggum <erik@naggum.no>
parents: 13018
diff changeset
12 ;; the Free Software Foundation; either version 2, or (at your option)
83f275dcd93a Update FSF's address.
Erik Naggum <erik@naggum.no>
parents: 13018
diff changeset
13 ;; any later version.
489
3d2d0362a496 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
14
14169
83f275dcd93a Update FSF's address.
Erik Naggum <erik@naggum.no>
parents: 13018
diff changeset
15 ;; GNU Emacs is distributed in the hope that it will be useful,
83f275dcd93a Update FSF's address.
Erik Naggum <erik@naggum.no>
parents: 13018
diff changeset
16 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
83f275dcd93a Update FSF's address.
Erik Naggum <erik@naggum.no>
parents: 13018
diff changeset
17 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
83f275dcd93a Update FSF's address.
Erik Naggum <erik@naggum.no>
parents: 13018
diff changeset
18 ;; GNU General Public License for more details.
489
3d2d0362a496 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
19
14169
83f275dcd93a Update FSF's address.
Erik Naggum <erik@naggum.no>
parents: 13018
diff changeset
20 ;; You should have received a copy of the GNU General Public License
83f275dcd93a Update FSF's address.
Erik Naggum <erik@naggum.no>
parents: 13018
diff changeset
21 ;; along with GNU Emacs; see the file COPYING. If not, write to the
83f275dcd93a Update FSF's address.
Erik Naggum <erik@naggum.no>
parents: 13018
diff changeset
22 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
83f275dcd93a Update FSF's address.
Erik Naggum <erik@naggum.no>
parents: 13018
diff changeset
23 ;; Boston, MA 02111-1307, USA.
489
3d2d0362a496 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
24
2315
9e7ec92a4fdf Added or corrected Commentary headers
Eric S. Raymond <esr@snark.thyrsus.com>
parents: 1218
diff changeset
25 ;;; Commentary:
9e7ec92a4fdf Added or corrected Commentary headers
Eric S. Raymond <esr@snark.thyrsus.com>
parents: 1218
diff changeset
26
14169
83f275dcd93a Update FSF's address.
Erik Naggum <erik@naggum.no>
parents: 13018
diff changeset
27 ;; UNIX processes inherit a list of name-to-string associations from their
83f275dcd93a Update FSF's address.
Erik Naggum <erik@naggum.no>
parents: 13018
diff changeset
28 ;; parents called their `environment'; these are commonly used to control
83f275dcd93a Update FSF's address.
Erik Naggum <erik@naggum.no>
parents: 13018
diff changeset
29 ;; program options. This package permits you to set environment variables
83f275dcd93a Update FSF's address.
Erik Naggum <erik@naggum.no>
parents: 13018
diff changeset
30 ;; to be passed to any sub-process run under Emacs.
2315
9e7ec92a4fdf Added or corrected Commentary headers
Eric S. Raymond <esr@snark.thyrsus.com>
parents: 1218
diff changeset
31
807
4f28bd14272c *** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents: 658
diff changeset
32 ;;; Code:
4f28bd14272c *** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents: 658
diff changeset
33
9220
8f05784959cc (setenv-history): New history list.
Richard M. Stallman <rms@gnu.org>
parents: 8005
diff changeset
34 ;; History list for environment variable names.
8f05784959cc (setenv-history): New history list.
Richard M. Stallman <rms@gnu.org>
parents: 8005
diff changeset
35 (defvar read-envvar-name-history nil)
8f05784959cc (setenv-history): New history list.
Richard M. Stallman <rms@gnu.org>
parents: 8005
diff changeset
36
8f05784959cc (setenv-history): New history list.
Richard M. Stallman <rms@gnu.org>
parents: 8005
diff changeset
37 (defun read-envvar-name (prompt &optional mustmatch)
8f05784959cc (setenv-history): New history list.
Richard M. Stallman <rms@gnu.org>
parents: 8005
diff changeset
38 "Read environment variable name, prompting with PROMPT.
9345
832197fec54d (read-envvar-name): Special meaning for MUSTMATCH
Richard M. Stallman <rms@gnu.org>
parents: 9220
diff changeset
39 Optional second arg MUSTMATCH, if non-nil, means require existing envvar name.
832197fec54d (read-envvar-name): Special meaning for MUSTMATCH
Richard M. Stallman <rms@gnu.org>
parents: 9220
diff changeset
40 If it is also not t, RET does not exit if it does non-null completion."
9220
8f05784959cc (setenv-history): New history list.
Richard M. Stallman <rms@gnu.org>
parents: 8005
diff changeset
41 (completing-read prompt
8f05784959cc (setenv-history): New history list.
Richard M. Stallman <rms@gnu.org>
parents: 8005
diff changeset
42 (mapcar (function
8f05784959cc (setenv-history): New history list.
Richard M. Stallman <rms@gnu.org>
parents: 8005
diff changeset
43 (lambda (enventry)
8f05784959cc (setenv-history): New history list.
Richard M. Stallman <rms@gnu.org>
parents: 8005
diff changeset
44 (list (substring enventry 0
8f05784959cc (setenv-history): New history list.
Richard M. Stallman <rms@gnu.org>
parents: 8005
diff changeset
45 (string-match "=" enventry)))))
8f05784959cc (setenv-history): New history list.
Richard M. Stallman <rms@gnu.org>
parents: 8005
diff changeset
46 process-environment)
8f05784959cc (setenv-history): New history list.
Richard M. Stallman <rms@gnu.org>
parents: 8005
diff changeset
47 nil mustmatch nil 'read-envvar-name-history))
8f05784959cc (setenv-history): New history list.
Richard M. Stallman <rms@gnu.org>
parents: 8005
diff changeset
48
8f05784959cc (setenv-history): New history list.
Richard M. Stallman <rms@gnu.org>
parents: 8005
diff changeset
49 ;; History list for VALUE argument to setenv.
8f05784959cc (setenv-history): New history list.
Richard M. Stallman <rms@gnu.org>
parents: 8005
diff changeset
50 (defvar setenv-history nil)
8f05784959cc (setenv-history): New history list.
Richard M. Stallman <rms@gnu.org>
parents: 8005
diff changeset
51
39554
c1fb5574fc7a (substitute-env-vars): New function.
Gerd Moellmann <gerd@gnu.org>
parents: 39126
diff changeset
52
c1fb5574fc7a (substitute-env-vars): New function.
Gerd Moellmann <gerd@gnu.org>
parents: 39126
diff changeset
53 (defun substitute-env-vars (string)
c1fb5574fc7a (substitute-env-vars): New function.
Gerd Moellmann <gerd@gnu.org>
parents: 39126
diff changeset
54 "Substitute environment variables referred to in STRING.
c1fb5574fc7a (substitute-env-vars): New function.
Gerd Moellmann <gerd@gnu.org>
parents: 39126
diff changeset
55 `$FOO' where FOO is an environment variable name means to substitute
c1fb5574fc7a (substitute-env-vars): New function.
Gerd Moellmann <gerd@gnu.org>
parents: 39126
diff changeset
56 the value of that variable. The variable name should be terminated
c1fb5574fc7a (substitute-env-vars): New function.
Gerd Moellmann <gerd@gnu.org>
parents: 39126
diff changeset
57 with a character not a letter, digit or underscore; otherwise, enclose
c1fb5574fc7a (substitute-env-vars): New function.
Gerd Moellmann <gerd@gnu.org>
parents: 39126
diff changeset
58 the entire variable name in braces. Use `$$' to insert a single
c1fb5574fc7a (substitute-env-vars): New function.
Gerd Moellmann <gerd@gnu.org>
parents: 39126
diff changeset
59 dollar sign."
c1fb5574fc7a (substitute-env-vars): New function.
Gerd Moellmann <gerd@gnu.org>
parents: 39126
diff changeset
60 (let ((start 0))
c1fb5574fc7a (substitute-env-vars): New function.
Gerd Moellmann <gerd@gnu.org>
parents: 39126
diff changeset
61 (while (string-match
40430
48cf8bbd6e34 (substitute-env-vars): Don't quote argument to `rx';
Gerd Moellmann <gerd@gnu.org>
parents: 40274
diff changeset
62 (rx (or (and "$" (submatch (1+ (in "a-zA-Z0-9_"))))
48cf8bbd6e34 (substitute-env-vars): Don't quote argument to `rx';
Gerd Moellmann <gerd@gnu.org>
parents: 40274
diff changeset
63 (and "${" (submatch (minimal-match (0+ anything))) "}")
48cf8bbd6e34 (substitute-env-vars): Don't quote argument to `rx';
Gerd Moellmann <gerd@gnu.org>
parents: 40274
diff changeset
64 "$$"))
39554
c1fb5574fc7a (substitute-env-vars): New function.
Gerd Moellmann <gerd@gnu.org>
parents: 39126
diff changeset
65 string start)
c1fb5574fc7a (substitute-env-vars): New function.
Gerd Moellmann <gerd@gnu.org>
parents: 39126
diff changeset
66 (cond ((match-beginning 1)
c1fb5574fc7a (substitute-env-vars): New function.
Gerd Moellmann <gerd@gnu.org>
parents: 39126
diff changeset
67 (let ((value (getenv (match-string 1 string))))
c1fb5574fc7a (substitute-env-vars): New function.
Gerd Moellmann <gerd@gnu.org>
parents: 39126
diff changeset
68 (setq string (replace-match (or value "") t t string)
c1fb5574fc7a (substitute-env-vars): New function.
Gerd Moellmann <gerd@gnu.org>
parents: 39126
diff changeset
69 start (+ (match-beginning 0) (length value)))))
c1fb5574fc7a (substitute-env-vars): New function.
Gerd Moellmann <gerd@gnu.org>
parents: 39126
diff changeset
70 ((match-beginning 2)
c1fb5574fc7a (substitute-env-vars): New function.
Gerd Moellmann <gerd@gnu.org>
parents: 39126
diff changeset
71 (let ((value (getenv (match-string 2 string))))
c1fb5574fc7a (substitute-env-vars): New function.
Gerd Moellmann <gerd@gnu.org>
parents: 39126
diff changeset
72 (setq string (replace-match (or value "") t t string)
c1fb5574fc7a (substitute-env-vars): New function.
Gerd Moellmann <gerd@gnu.org>
parents: 39126
diff changeset
73 start (+ (match-beginning 0) (length value)))))
c1fb5574fc7a (substitute-env-vars): New function.
Gerd Moellmann <gerd@gnu.org>
parents: 39126
diff changeset
74 (t
c1fb5574fc7a (substitute-env-vars): New function.
Gerd Moellmann <gerd@gnu.org>
parents: 39126
diff changeset
75 (setq string (replace-match "$" t t string)
c1fb5574fc7a (substitute-env-vars): New function.
Gerd Moellmann <gerd@gnu.org>
parents: 39126
diff changeset
76 start (+ (match-beginning 0) 1)))))
c1fb5574fc7a (substitute-env-vars): New function.
Gerd Moellmann <gerd@gnu.org>
parents: 39126
diff changeset
77 string))
c1fb5574fc7a (substitute-env-vars): New function.
Gerd Moellmann <gerd@gnu.org>
parents: 39126
diff changeset
78
c1fb5574fc7a (substitute-env-vars): New function.
Gerd Moellmann <gerd@gnu.org>
parents: 39126
diff changeset
79
c1fb5574fc7a (substitute-env-vars): New function.
Gerd Moellmann <gerd@gnu.org>
parents: 39126
diff changeset
80 (defun setenv (variable &optional value unset substitute-env-vars)
489
3d2d0362a496 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
81 "Set the value of the environment variable named VARIABLE to VALUE.
2403
05d8916e4cde renamed to env.el; changed setenv to putenv.
Noah Friedman <friedman@splode.com>
parents: 2315
diff changeset
82 VARIABLE should be a string. VALUE is optional; if not provided or is
39554
c1fb5574fc7a (substitute-env-vars): New function.
Gerd Moellmann <gerd@gnu.org>
parents: 39126
diff changeset
83 `nil', the environment variable VARIABLE will be removed. UNSET
c1fb5574fc7a (substitute-env-vars): New function.
Gerd Moellmann <gerd@gnu.org>
parents: 39126
diff changeset
84 if non-nil means to remove VARIABLE from the environment.
c1fb5574fc7a (substitute-env-vars): New function.
Gerd Moellmann <gerd@gnu.org>
parents: 39126
diff changeset
85 SUBSTITUTE-ENV-VARS, if non-nil, means to substitute environment
c1fb5574fc7a (substitute-env-vars): New function.
Gerd Moellmann <gerd@gnu.org>
parents: 39126
diff changeset
86 variables in VALUE with `substitute-env-vars', where see.
c1fb5574fc7a (substitute-env-vars): New function.
Gerd Moellmann <gerd@gnu.org>
parents: 39126
diff changeset
87 Value is the new value if VARIABLE, or nil if removed from the
c1fb5574fc7a (substitute-env-vars): New function.
Gerd Moellmann <gerd@gnu.org>
parents: 39126
diff changeset
88 environment.
8004
a86eceda6537 (setenv): Rewrite. Provide a way to unset interactively.
Richard M. Stallman <rms@gnu.org>
parents: 8002
diff changeset
89
a86eceda6537 (setenv): Rewrite. Provide a way to unset interactively.
Richard M. Stallman <rms@gnu.org>
parents: 8002
diff changeset
90 Interactively, a prefix argument means to unset the variable.
9220
8f05784959cc (setenv-history): New history list.
Richard M. Stallman <rms@gnu.org>
parents: 8005
diff changeset
91 Interactively, the current value (if any) of the variable
8f05784959cc (setenv-history): New history list.
Richard M. Stallman <rms@gnu.org>
parents: 8005
diff changeset
92 appears at the front of the history list when you type in the new value.
39554
c1fb5574fc7a (substitute-env-vars): New function.
Gerd Moellmann <gerd@gnu.org>
parents: 39126
diff changeset
93 Interactively, always replace environment variables in the new value.
9220
8f05784959cc (setenv-history): New history list.
Richard M. Stallman <rms@gnu.org>
parents: 8005
diff changeset
94
1216
6a8704922fe8 Doc fix.
Richard M. Stallman <rms@gnu.org>
parents: 1185
diff changeset
95 This function works by modifying `process-environment'."
8004
a86eceda6537 (setenv): Rewrite. Provide a way to unset interactively.
Richard M. Stallman <rms@gnu.org>
parents: 8002
diff changeset
96 (interactive
a86eceda6537 (setenv): Rewrite. Provide a way to unset interactively.
Richard M. Stallman <rms@gnu.org>
parents: 8002
diff changeset
97 (if current-prefix-arg
9345
832197fec54d (read-envvar-name): Special meaning for MUSTMATCH
Richard M. Stallman <rms@gnu.org>
parents: 9220
diff changeset
98 (list (read-envvar-name "Clear environment variable: " 'exact) nil t)
39126
c0713ad66d33 (setenv): Interactively, if VARIABLE has a current value,
Gerd Moellmann <gerd@gnu.org>
parents: 38412
diff changeset
99 (let* ((var (read-envvar-name "Set environment variable: " nil))
c0713ad66d33 (setenv): Interactively, if VARIABLE has a current value,
Gerd Moellmann <gerd@gnu.org>
parents: 38412
diff changeset
100 (value (getenv var)))
c0713ad66d33 (setenv): Interactively, if VARIABLE has a current value,
Gerd Moellmann <gerd@gnu.org>
parents: 38412
diff changeset
101 (when value
c0713ad66d33 (setenv): Interactively, if VARIABLE has a current value,
Gerd Moellmann <gerd@gnu.org>
parents: 38412
diff changeset
102 (push value setenv-history))
9220
8f05784959cc (setenv-history): New history list.
Richard M. Stallman <rms@gnu.org>
parents: 8005
diff changeset
103 ;; Here finally we specify the args to give call setenv with.
39554
c1fb5574fc7a (substitute-env-vars): New function.
Gerd Moellmann <gerd@gnu.org>
parents: 39126
diff changeset
104 (list var
c1fb5574fc7a (substitute-env-vars): New function.
Gerd Moellmann <gerd@gnu.org>
parents: 39126
diff changeset
105 (read-from-minibuffer (format "Set %s to value: " var)
c1fb5574fc7a (substitute-env-vars): New function.
Gerd Moellmann <gerd@gnu.org>
parents: 39126
diff changeset
106 nil nil nil 'setenv-history
c1fb5574fc7a (substitute-env-vars): New function.
Gerd Moellmann <gerd@gnu.org>
parents: 39126
diff changeset
107 value)
c1fb5574fc7a (substitute-env-vars): New function.
Gerd Moellmann <gerd@gnu.org>
parents: 39126
diff changeset
108 nil
c1fb5574fc7a (substitute-env-vars): New function.
Gerd Moellmann <gerd@gnu.org>
parents: 39126
diff changeset
109 t))))
c1fb5574fc7a (substitute-env-vars): New function.
Gerd Moellmann <gerd@gnu.org>
parents: 39126
diff changeset
110 (if unset
c1fb5574fc7a (substitute-env-vars): New function.
Gerd Moellmann <gerd@gnu.org>
parents: 39126
diff changeset
111 (setq value nil)
c1fb5574fc7a (substitute-env-vars): New function.
Gerd Moellmann <gerd@gnu.org>
parents: 39126
diff changeset
112 (if substitute-env-vars
c1fb5574fc7a (substitute-env-vars): New function.
Gerd Moellmann <gerd@gnu.org>
parents: 39126
diff changeset
113 (setq value (substitute-env-vars value))))
489
3d2d0362a496 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
114 (if (string-match "=" variable)
2403
05d8916e4cde renamed to env.el; changed setenv to putenv.
Noah Friedman <friedman@splode.com>
parents: 2315
diff changeset
115 (error "Environment variable name `%s' contains `='" variable)
1185
4ec50a934e54 entered into RCS
Eric S. Raymond <esr@snark.thyrsus.com>
parents: 814
diff changeset
116 (let ((pattern (concat "\\`" (regexp-quote (concat variable "="))))
3667
f4a7ac2ec651 (setenv): Treat case as significant.
Richard M. Stallman <rms@gnu.org>
parents: 2410
diff changeset
117 (case-fold-search nil)
8004
a86eceda6537 (setenv): Rewrite. Provide a way to unset interactively.
Richard M. Stallman <rms@gnu.org>
parents: 8002
diff changeset
118 (scan process-environment)
a86eceda6537 (setenv): Rewrite. Provide a way to unset interactively.
Richard M. Stallman <rms@gnu.org>
parents: 8002
diff changeset
119 found)
13018
9c090a7674c8 (setenv): Call set-time-zone-rule when setting TZ.
Richard M. Stallman <rms@gnu.org>
parents: 9345
diff changeset
120 (if (string-equal "TZ" variable)
9c090a7674c8 (setenv): Call set-time-zone-rule when setting TZ.
Richard M. Stallman <rms@gnu.org>
parents: 9345
diff changeset
121 (set-time-zone-rule value))
8004
a86eceda6537 (setenv): Rewrite. Provide a way to unset interactively.
Richard M. Stallman <rms@gnu.org>
parents: 8002
diff changeset
122 (while scan
a86eceda6537 (setenv): Rewrite. Provide a way to unset interactively.
Richard M. Stallman <rms@gnu.org>
parents: 8002
diff changeset
123 (cond ((string-match pattern (car scan))
a86eceda6537 (setenv): Rewrite. Provide a way to unset interactively.
Richard M. Stallman <rms@gnu.org>
parents: 8002
diff changeset
124 (setq found t)
a86eceda6537 (setenv): Rewrite. Provide a way to unset interactively.
Richard M. Stallman <rms@gnu.org>
parents: 8002
diff changeset
125 (if (eq nil value)
a86eceda6537 (setenv): Rewrite. Provide a way to unset interactively.
Richard M. Stallman <rms@gnu.org>
parents: 8002
diff changeset
126 (setq process-environment (delq (car scan) process-environment))
a86eceda6537 (setenv): Rewrite. Provide a way to unset interactively.
Richard M. Stallman <rms@gnu.org>
parents: 8002
diff changeset
127 (setcar scan (concat variable "=" value)))
a86eceda6537 (setenv): Rewrite. Provide a way to unset interactively.
Richard M. Stallman <rms@gnu.org>
parents: 8002
diff changeset
128 (setq scan nil)))
a86eceda6537 (setenv): Rewrite. Provide a way to unset interactively.
Richard M. Stallman <rms@gnu.org>
parents: 8002
diff changeset
129 (setq scan (cdr scan)))
a86eceda6537 (setenv): Rewrite. Provide a way to unset interactively.
Richard M. Stallman <rms@gnu.org>
parents: 8002
diff changeset
130 (or found
a86eceda6537 (setenv): Rewrite. Provide a way to unset interactively.
Richard M. Stallman <rms@gnu.org>
parents: 8002
diff changeset
131 (if value
8002
f8c8bbeca971 (setenv): Do something even if process-environment is nil.
Richard M. Stallman <rms@gnu.org>
parents: 3667
diff changeset
132 (setq process-environment
8004
a86eceda6537 (setenv): Rewrite. Provide a way to unset interactively.
Richard M. Stallman <rms@gnu.org>
parents: 8002
diff changeset
133 (cons (concat variable "=" value)
39554
c1fb5574fc7a (substitute-env-vars): New function.
Gerd Moellmann <gerd@gnu.org>
parents: 39126
diff changeset
134 process-environment))))))
c1fb5574fc7a (substitute-env-vars): New function.
Gerd Moellmann <gerd@gnu.org>
parents: 39126
diff changeset
135 value)
584
4cd7543be581 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 489
diff changeset
136
28917
845292e36d62 (getenv): New function, interactively callable.
Gerd Moellmann <gerd@gnu.org>
parents: 21201
diff changeset
137 (defun getenv (variable)
845292e36d62 (getenv): New function, interactively callable.
Gerd Moellmann <gerd@gnu.org>
parents: 21201
diff changeset
138 "Get the value of environment variable VARIABLE.
845292e36d62 (getenv): New function, interactively callable.
Gerd Moellmann <gerd@gnu.org>
parents: 21201
diff changeset
139 VARIABLE should be a string. Value is nil if VARIABLE is undefined in
845292e36d62 (getenv): New function, interactively callable.
Gerd Moellmann <gerd@gnu.org>
parents: 21201
diff changeset
140 the environment. Otherwise, value is a string.
845292e36d62 (getenv): New function, interactively callable.
Gerd Moellmann <gerd@gnu.org>
parents: 21201
diff changeset
141
845292e36d62 (getenv): New function, interactively callable.
Gerd Moellmann <gerd@gnu.org>
parents: 21201
diff changeset
142 This function consults the variable `process-environment'
845292e36d62 (getenv): New function, interactively callable.
Gerd Moellmann <gerd@gnu.org>
parents: 21201
diff changeset
143 for its value."
845292e36d62 (getenv): New function, interactively callable.
Gerd Moellmann <gerd@gnu.org>
parents: 21201
diff changeset
144 (interactive (list (read-envvar-name "Get environment variable: " t)))
845292e36d62 (getenv): New function, interactively callable.
Gerd Moellmann <gerd@gnu.org>
parents: 21201
diff changeset
145 (let ((value (getenv-internal variable)))
845292e36d62 (getenv): New function, interactively callable.
Gerd Moellmann <gerd@gnu.org>
parents: 21201
diff changeset
146 (when (interactive-p)
845292e36d62 (getenv): New function, interactively callable.
Gerd Moellmann <gerd@gnu.org>
parents: 21201
diff changeset
147 (message "%s" (if value value "Not set")))
845292e36d62 (getenv): New function, interactively callable.
Gerd Moellmann <gerd@gnu.org>
parents: 21201
diff changeset
148 value))
845292e36d62 (getenv): New function, interactively callable.
Gerd Moellmann <gerd@gnu.org>
parents: 21201
diff changeset
149
2403
05d8916e4cde renamed to env.el; changed setenv to putenv.
Noah Friedman <friedman@splode.com>
parents: 2315
diff changeset
150 (provide 'env)
05d8916e4cde renamed to env.el; changed setenv to putenv.
Noah Friedman <friedman@splode.com>
parents: 2315
diff changeset
151
05d8916e4cde renamed to env.el; changed setenv to putenv.
Noah Friedman <friedman@splode.com>
parents: 2315
diff changeset
152 ;;; env.el ends here