Mercurial > emacs
annotate lisp/env.el @ 70783:216c04e10ca3
(CODING_REQUIRE_ENCODING): Elaborate the comment.
author | Eli Zaretskii <eliz@gnu.org> |
---|---|
date | Sat, 20 May 2006 19:04:35 +0000 |
parents | 95f3ef491663 |
children | e3694f1cb928 1321f6cfb389 146cd8369025 |
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 |
64762
41bb365f41c4
Update years in copyright notice; nfc.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
64091
diff
changeset
|
3 ;; Copyright (C) 1991, 1994, 2000, 2001, 2002, 2003, 2004, |
68651
3bd95f4f2941
Update years in copyright notice; nfc.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
64762
diff
changeset
|
4 ;; 2005, 2006 Free Software Foundation, Inc. |
1185 | 5 |
807
4f28bd14272c
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
658
diff
changeset
|
6 ;; Maintainer: FSF |
2315
9e7ec92a4fdf
Added or corrected Commentary headers
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
1218
diff
changeset
|
7 ;; Keywords: processes, unix |
807
4f28bd14272c
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
658
diff
changeset
|
8 |
14169 | 9 ;; This file is part of GNU Emacs. |
489 | 10 |
14169 | 11 ;; GNU Emacs is free software; you can redistribute it and/or modify |
12 ;; it under the terms of the GNU General Public License as published by | |
13 ;; the Free Software Foundation; either version 2, or (at your option) | |
14 ;; any later version. | |
489 | 15 |
14169 | 16 ;; GNU Emacs is distributed in the hope that it will be useful, |
17 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of | |
18 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
19 ;; GNU General Public License for more details. | |
489 | 20 |
14169 | 21 ;; You should have received a copy of the GNU General Public License |
22 ;; along with GNU Emacs; see the file COPYING. If not, write to the | |
64091 | 23 ;; Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, |
24 ;; Boston, MA 02110-1301, USA. | |
489 | 25 |
2315
9e7ec92a4fdf
Added or corrected Commentary headers
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
1218
diff
changeset
|
26 ;;; Commentary: |
9e7ec92a4fdf
Added or corrected Commentary headers
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
1218
diff
changeset
|
27 |
14169 | 28 ;; UNIX processes inherit a list of name-to-string associations from their |
29 ;; parents called their `environment'; these are commonly used to control | |
30 ;; program options. This package permits you to set environment variables | |
31 ;; 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
|
32 |
49968 | 33 ;; Note that the environment string `process-environment' is not |
34 ;; decoded, but the args of `setenv' and `getenv' are normally | |
35 ;; multibyte text and get coding conversion. | |
36 | |
807
4f28bd14272c
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
658
diff
changeset
|
37 ;;; Code: |
4f28bd14272c
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
658
diff
changeset
|
38 |
9220
8f05784959cc
(setenv-history): New history list.
Richard M. Stallman <rms@gnu.org>
parents:
8005
diff
changeset
|
39 ;; History list for environment variable names. |
8f05784959cc
(setenv-history): New history list.
Richard M. Stallman <rms@gnu.org>
parents:
8005
diff
changeset
|
40 (defvar read-envvar-name-history nil) |
8f05784959cc
(setenv-history): New history list.
Richard M. Stallman <rms@gnu.org>
parents:
8005
diff
changeset
|
41 |
8f05784959cc
(setenv-history): New history list.
Richard M. Stallman <rms@gnu.org>
parents:
8005
diff
changeset
|
42 (defun read-envvar-name (prompt &optional mustmatch) |
8f05784959cc
(setenv-history): New history list.
Richard M. Stallman <rms@gnu.org>
parents:
8005
diff
changeset
|
43 "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
|
44 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
|
45 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
|
46 (completing-read prompt |
49968 | 47 (mapcar (lambda (enventry) |
48 (list (if enable-multibyte-characters | |
49 (decode-coding-string | |
50 (substring enventry 0 | |
51 (string-match "=" enventry)) | |
52 locale-coding-system t) | |
53 (substring enventry 0 | |
54 (string-match "=" enventry))))) | |
9220
8f05784959cc
(setenv-history): New history list.
Richard M. Stallman <rms@gnu.org>
parents:
8005
diff
changeset
|
55 process-environment) |
8f05784959cc
(setenv-history): New history list.
Richard M. Stallman <rms@gnu.org>
parents:
8005
diff
changeset
|
56 nil mustmatch nil 'read-envvar-name-history)) |
8f05784959cc
(setenv-history): New history list.
Richard M. Stallman <rms@gnu.org>
parents:
8005
diff
changeset
|
57 |
8f05784959cc
(setenv-history): New history list.
Richard M. Stallman <rms@gnu.org>
parents:
8005
diff
changeset
|
58 ;; History list for VALUE argument to setenv. |
8f05784959cc
(setenv-history): New history list.
Richard M. Stallman <rms@gnu.org>
parents:
8005
diff
changeset
|
59 (defvar setenv-history nil) |
8f05784959cc
(setenv-history): New history list.
Richard M. Stallman <rms@gnu.org>
parents:
8005
diff
changeset
|
60 |
39554
c1fb5574fc7a
(substitute-env-vars): New function.
Gerd Moellmann <gerd@gnu.org>
parents:
39126
diff
changeset
|
61 |
c1fb5574fc7a
(substitute-env-vars): New function.
Gerd Moellmann <gerd@gnu.org>
parents:
39126
diff
changeset
|
62 (defun substitute-env-vars (string) |
c1fb5574fc7a
(substitute-env-vars): New function.
Gerd Moellmann <gerd@gnu.org>
parents:
39126
diff
changeset
|
63 "Substitute environment variables referred to in STRING. |
c1fb5574fc7a
(substitute-env-vars): New function.
Gerd Moellmann <gerd@gnu.org>
parents:
39126
diff
changeset
|
64 `$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
|
65 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
|
66 with a character not a letter, digit or underscore; otherwise, enclose |
51279
92f5fdc30889
(substitute-env-vars): Fix typo.
Richard M. Stallman <rms@gnu.org>
parents:
50873
diff
changeset
|
67 the entire variable name in braces. For instance, in `ab$cd-x', |
92f5fdc30889
(substitute-env-vars): Fix typo.
Richard M. Stallman <rms@gnu.org>
parents:
50873
diff
changeset
|
68 `$cd' is treated as an environment variable. |
92f5fdc30889
(substitute-env-vars): Fix typo.
Richard M. Stallman <rms@gnu.org>
parents:
50873
diff
changeset
|
69 |
92f5fdc30889
(substitute-env-vars): Fix typo.
Richard M. Stallman <rms@gnu.org>
parents:
50873
diff
changeset
|
70 Use `$$' to insert a single dollar sign." |
39554
c1fb5574fc7a
(substitute-env-vars): New function.
Gerd Moellmann <gerd@gnu.org>
parents:
39126
diff
changeset
|
71 (let ((start 0)) |
49588
37645a051842
Trailing whitespace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents:
40430
diff
changeset
|
72 (while (string-match |
49968 | 73 (eval-when-compile |
51279
92f5fdc30889
(substitute-env-vars): Fix typo.
Richard M. Stallman <rms@gnu.org>
parents:
50873
diff
changeset
|
74 (rx (or (and "$" (submatch (1+ (regexp "[[:alnum:]_]")))) |
49968 | 75 (and "${" (submatch (minimal-match (0+ anything))) "}") |
76 "$$"))) | |
39554
c1fb5574fc7a
(substitute-env-vars): New function.
Gerd Moellmann <gerd@gnu.org>
parents:
39126
diff
changeset
|
77 string start) |
c1fb5574fc7a
(substitute-env-vars): New function.
Gerd Moellmann <gerd@gnu.org>
parents:
39126
diff
changeset
|
78 (cond ((match-beginning 1) |
c1fb5574fc7a
(substitute-env-vars): New function.
Gerd Moellmann <gerd@gnu.org>
parents:
39126
diff
changeset
|
79 (let ((value (getenv (match-string 1 string)))) |
c1fb5574fc7a
(substitute-env-vars): New function.
Gerd Moellmann <gerd@gnu.org>
parents:
39126
diff
changeset
|
80 (setq string (replace-match (or value "") t t string) |
c1fb5574fc7a
(substitute-env-vars): New function.
Gerd Moellmann <gerd@gnu.org>
parents:
39126
diff
changeset
|
81 start (+ (match-beginning 0) (length value))))) |
c1fb5574fc7a
(substitute-env-vars): New function.
Gerd Moellmann <gerd@gnu.org>
parents:
39126
diff
changeset
|
82 ((match-beginning 2) |
c1fb5574fc7a
(substitute-env-vars): New function.
Gerd Moellmann <gerd@gnu.org>
parents:
39126
diff
changeset
|
83 (let ((value (getenv (match-string 2 string)))) |
c1fb5574fc7a
(substitute-env-vars): New function.
Gerd Moellmann <gerd@gnu.org>
parents:
39126
diff
changeset
|
84 (setq string (replace-match (or value "") t t string) |
c1fb5574fc7a
(substitute-env-vars): New function.
Gerd Moellmann <gerd@gnu.org>
parents:
39126
diff
changeset
|
85 start (+ (match-beginning 0) (length value))))) |
c1fb5574fc7a
(substitute-env-vars): New function.
Gerd Moellmann <gerd@gnu.org>
parents:
39126
diff
changeset
|
86 (t |
c1fb5574fc7a
(substitute-env-vars): New function.
Gerd Moellmann <gerd@gnu.org>
parents:
39126
diff
changeset
|
87 (setq string (replace-match "$" t t string) |
c1fb5574fc7a
(substitute-env-vars): New function.
Gerd Moellmann <gerd@gnu.org>
parents:
39126
diff
changeset
|
88 start (+ (match-beginning 0) 1))))) |
c1fb5574fc7a
(substitute-env-vars): New function.
Gerd Moellmann <gerd@gnu.org>
parents:
39126
diff
changeset
|
89 string)) |
c1fb5574fc7a
(substitute-env-vars): New function.
Gerd Moellmann <gerd@gnu.org>
parents:
39126
diff
changeset
|
90 |
49968 | 91 ;; Fixme: Should `process-environment' be recoded if LC_CTYPE &c is set? |
39554
c1fb5574fc7a
(substitute-env-vars): New function.
Gerd Moellmann <gerd@gnu.org>
parents:
39126
diff
changeset
|
92 |
70094
d893c3bf4c3b
(setenv): Get rid of arg UNSET. Interactive unsetting
Richard M. Stallman <rms@gnu.org>
parents:
68651
diff
changeset
|
93 (defun setenv (variable &optional value substitute-env-vars) |
489 | 94 "Set the value of the environment variable named VARIABLE to VALUE. |
50873
562c854aa190
(setenv): Don't quote nil and t in docstrings.
Juanma Barranquero <lekktu@gmail.com>
parents:
49977
diff
changeset
|
95 VARIABLE should be a string. VALUE is optional; if not provided or |
70094
d893c3bf4c3b
(setenv): Get rid of arg UNSET. Interactive unsetting
Richard M. Stallman <rms@gnu.org>
parents:
68651
diff
changeset
|
96 nil, the environment variable VARIABLE will be removed. |
8004
a86eceda6537
(setenv): Rewrite. Provide a way to unset interactively.
Richard M. Stallman <rms@gnu.org>
parents:
8002
diff
changeset
|
97 |
a86eceda6537
(setenv): Rewrite. Provide a way to unset interactively.
Richard M. Stallman <rms@gnu.org>
parents:
8002
diff
changeset
|
98 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
|
99 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
|
100 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
|
101 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
|
102 |
70094
d893c3bf4c3b
(setenv): Get rid of arg UNSET. Interactive unsetting
Richard M. Stallman <rms@gnu.org>
parents:
68651
diff
changeset
|
103 SUBSTITUTE-ENV-VARS, if non-nil, means to substitute environment |
d893c3bf4c3b
(setenv): Get rid of arg UNSET. Interactive unsetting
Richard M. Stallman <rms@gnu.org>
parents:
68651
diff
changeset
|
104 variables in VALUE with `substitute-env-vars', which see. |
d893c3bf4c3b
(setenv): Get rid of arg UNSET. Interactive unsetting
Richard M. Stallman <rms@gnu.org>
parents:
68651
diff
changeset
|
105 This is normally used only for interactive calls. |
d893c3bf4c3b
(setenv): Get rid of arg UNSET. Interactive unsetting
Richard M. Stallman <rms@gnu.org>
parents:
68651
diff
changeset
|
106 |
d893c3bf4c3b
(setenv): Get rid of arg UNSET. Interactive unsetting
Richard M. Stallman <rms@gnu.org>
parents:
68651
diff
changeset
|
107 The return value is the new value of VARIABLE, or nil if |
d893c3bf4c3b
(setenv): Get rid of arg UNSET. Interactive unsetting
Richard M. Stallman <rms@gnu.org>
parents:
68651
diff
changeset
|
108 it was removed from the environment. |
d893c3bf4c3b
(setenv): Get rid of arg UNSET. Interactive unsetting
Richard M. Stallman <rms@gnu.org>
parents:
68651
diff
changeset
|
109 |
49968 | 110 This function works by modifying `process-environment'. |
111 | |
112 As a special case, setting variable `TZ' calls `set-time-zone-rule' as | |
113 a side-effect." | |
8004
a86eceda6537
(setenv): Rewrite. Provide a way to unset interactively.
Richard M. Stallman <rms@gnu.org>
parents:
8002
diff
changeset
|
114 (interactive |
a86eceda6537
(setenv): Rewrite. Provide a way to unset interactively.
Richard M. Stallman <rms@gnu.org>
parents:
8002
diff
changeset
|
115 (if current-prefix-arg |
70094
d893c3bf4c3b
(setenv): Get rid of arg UNSET. Interactive unsetting
Richard M. Stallman <rms@gnu.org>
parents:
68651
diff
changeset
|
116 (list (read-envvar-name "Clear environment variable: " 'exact) nil) |
39126
c0713ad66d33
(setenv): Interactively, if VARIABLE has a current value,
Gerd Moellmann <gerd@gnu.org>
parents:
38412
diff
changeset
|
117 (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
|
118 (value (getenv var))) |
c0713ad66d33
(setenv): Interactively, if VARIABLE has a current value,
Gerd Moellmann <gerd@gnu.org>
parents:
38412
diff
changeset
|
119 (when value |
70417
95f3ef491663
(setenv): Use add-to-history.
Kim F. Storm <storm@cua.dk>
parents:
70094
diff
changeset
|
120 (add-to-history 'setenv-history value)) |
9220
8f05784959cc
(setenv-history): New history list.
Richard M. Stallman <rms@gnu.org>
parents:
8005
diff
changeset
|
121 ;; Here finally we specify the args to give call setenv with. |
49588
37645a051842
Trailing whitespace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents:
40430
diff
changeset
|
122 (list var |
39554
c1fb5574fc7a
(substitute-env-vars): New function.
Gerd Moellmann <gerd@gnu.org>
parents:
39126
diff
changeset
|
123 (read-from-minibuffer (format "Set %s to value: " var) |
c1fb5574fc7a
(substitute-env-vars): New function.
Gerd Moellmann <gerd@gnu.org>
parents:
39126
diff
changeset
|
124 nil nil nil 'setenv-history |
c1fb5574fc7a
(substitute-env-vars): New function.
Gerd Moellmann <gerd@gnu.org>
parents:
39126
diff
changeset
|
125 value) |
c1fb5574fc7a
(substitute-env-vars): New function.
Gerd Moellmann <gerd@gnu.org>
parents:
39126
diff
changeset
|
126 t)))) |
49968 | 127 (if (and (multibyte-string-p variable) locale-coding-system) |
49977
f491c5cee974
(setenv): Fix previous change.
Kenichi Handa <handa@m17n.org>
parents:
49968
diff
changeset
|
128 (let ((codings (find-coding-systems-string (concat variable value)))) |
f491c5cee974
(setenv): Fix previous change.
Kenichi Handa <handa@m17n.org>
parents:
49968
diff
changeset
|
129 (unless (or (eq 'undecided (car codings)) |
f491c5cee974
(setenv): Fix previous change.
Kenichi Handa <handa@m17n.org>
parents:
49968
diff
changeset
|
130 (memq (coding-system-base locale-coding-system) codings)) |
f491c5cee974
(setenv): Fix previous change.
Kenichi Handa <handa@m17n.org>
parents:
49968
diff
changeset
|
131 (error "Can't encode `%s=%s' with `locale-coding-system'" |
f491c5cee974
(setenv): Fix previous change.
Kenichi Handa <handa@m17n.org>
parents:
49968
diff
changeset
|
132 variable (or value ""))))) |
70094
d893c3bf4c3b
(setenv): Get rid of arg UNSET. Interactive unsetting
Richard M. Stallman <rms@gnu.org>
parents:
68651
diff
changeset
|
133 (and value |
d893c3bf4c3b
(setenv): Get rid of arg UNSET. Interactive unsetting
Richard M. Stallman <rms@gnu.org>
parents:
68651
diff
changeset
|
134 substitute-env-vars |
d893c3bf4c3b
(setenv): Get rid of arg UNSET. Interactive unsetting
Richard M. Stallman <rms@gnu.org>
parents:
68651
diff
changeset
|
135 (setq value (substitute-env-vars value))) |
49968 | 136 (if (multibyte-string-p variable) |
137 (setq variable (encode-coding-string variable locale-coding-system))) | |
138 (if (and value (multibyte-string-p value)) | |
139 (setq value (encode-coding-string value locale-coding-system))) | |
489 | 140 (if (string-match "=" variable) |
2403
05d8916e4cde
renamed to env.el; changed setenv to putenv.
Noah Friedman <friedman@splode.com>
parents:
2315
diff
changeset
|
141 (error "Environment variable name `%s' contains `='" variable) |
1185 | 142 (let ((pattern (concat "\\`" (regexp-quote (concat variable "=")))) |
3667
f4a7ac2ec651
(setenv): Treat case as significant.
Richard M. Stallman <rms@gnu.org>
parents:
2410
diff
changeset
|
143 (case-fold-search nil) |
8004
a86eceda6537
(setenv): Rewrite. Provide a way to unset interactively.
Richard M. Stallman <rms@gnu.org>
parents:
8002
diff
changeset
|
144 (scan process-environment) |
a86eceda6537
(setenv): Rewrite. Provide a way to unset interactively.
Richard M. Stallman <rms@gnu.org>
parents:
8002
diff
changeset
|
145 found) |
13018
9c090a7674c8
(setenv): Call set-time-zone-rule when setting TZ.
Richard M. Stallman <rms@gnu.org>
parents:
9345
diff
changeset
|
146 (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
|
147 (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
|
148 (while scan |
a86eceda6537
(setenv): Rewrite. Provide a way to unset interactively.
Richard M. Stallman <rms@gnu.org>
parents:
8002
diff
changeset
|
149 (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
|
150 (setq found t) |
a86eceda6537
(setenv): Rewrite. Provide a way to unset interactively.
Richard M. Stallman <rms@gnu.org>
parents:
8002
diff
changeset
|
151 (if (eq nil value) |
49968 | 152 (setq process-environment (delq (car scan) |
153 process-environment)) | |
8004
a86eceda6537
(setenv): Rewrite. Provide a way to unset interactively.
Richard M. Stallman <rms@gnu.org>
parents:
8002
diff
changeset
|
154 (setcar scan (concat variable "=" value))) |
a86eceda6537
(setenv): Rewrite. Provide a way to unset interactively.
Richard M. Stallman <rms@gnu.org>
parents:
8002
diff
changeset
|
155 (setq scan nil))) |
a86eceda6537
(setenv): Rewrite. Provide a way to unset interactively.
Richard M. Stallman <rms@gnu.org>
parents:
8002
diff
changeset
|
156 (setq scan (cdr scan))) |
a86eceda6537
(setenv): Rewrite. Provide a way to unset interactively.
Richard M. Stallman <rms@gnu.org>
parents:
8002
diff
changeset
|
157 (or found |
a86eceda6537
(setenv): Rewrite. Provide a way to unset interactively.
Richard M. Stallman <rms@gnu.org>
parents:
8002
diff
changeset
|
158 (if value |
8002
f8c8bbeca971
(setenv): Do something even if process-environment is nil.
Richard M. Stallman <rms@gnu.org>
parents:
3667
diff
changeset
|
159 (setq process-environment |
8004
a86eceda6537
(setenv): Rewrite. Provide a way to unset interactively.
Richard M. Stallman <rms@gnu.org>
parents:
8002
diff
changeset
|
160 (cons (concat variable "=" value) |
39554
c1fb5574fc7a
(substitute-env-vars): New function.
Gerd Moellmann <gerd@gnu.org>
parents:
39126
diff
changeset
|
161 process-environment)))))) |
c1fb5574fc7a
(substitute-env-vars): New function.
Gerd Moellmann <gerd@gnu.org>
parents:
39126
diff
changeset
|
162 value) |
584 | 163 |
28917
845292e36d62
(getenv): New function, interactively callable.
Gerd Moellmann <gerd@gnu.org>
parents:
21201
diff
changeset
|
164 (defun getenv (variable) |
845292e36d62
(getenv): New function, interactively callable.
Gerd Moellmann <gerd@gnu.org>
parents:
21201
diff
changeset
|
165 "Get the value of environment variable VARIABLE. |
845292e36d62
(getenv): New function, interactively callable.
Gerd Moellmann <gerd@gnu.org>
parents:
21201
diff
changeset
|
166 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
|
167 the environment. Otherwise, value is a string. |
845292e36d62
(getenv): New function, interactively callable.
Gerd Moellmann <gerd@gnu.org>
parents:
21201
diff
changeset
|
168 |
845292e36d62
(getenv): New function, interactively callable.
Gerd Moellmann <gerd@gnu.org>
parents:
21201
diff
changeset
|
169 This function consults the variable `process-environment' |
845292e36d62
(getenv): New function, interactively callable.
Gerd Moellmann <gerd@gnu.org>
parents:
21201
diff
changeset
|
170 for its value." |
845292e36d62
(getenv): New function, interactively callable.
Gerd Moellmann <gerd@gnu.org>
parents:
21201
diff
changeset
|
171 (interactive (list (read-envvar-name "Get environment variable: " t))) |
49968 | 172 (let ((value (getenv-internal (if (multibyte-string-p variable) |
173 (encode-coding-string | |
174 variable locale-coding-system) | |
175 variable)))) | |
176 (if (and enable-multibyte-characters value) | |
177 (setq value (decode-coding-string value locale-coding-system))) | |
28917
845292e36d62
(getenv): New function, interactively callable.
Gerd Moellmann <gerd@gnu.org>
parents:
21201
diff
changeset
|
178 (when (interactive-p) |
845292e36d62
(getenv): New function, interactively callable.
Gerd Moellmann <gerd@gnu.org>
parents:
21201
diff
changeset
|
179 (message "%s" (if value value "Not set"))) |
845292e36d62
(getenv): New function, interactively callable.
Gerd Moellmann <gerd@gnu.org>
parents:
21201
diff
changeset
|
180 value)) |
845292e36d62
(getenv): New function, interactively callable.
Gerd Moellmann <gerd@gnu.org>
parents:
21201
diff
changeset
|
181 |
2403
05d8916e4cde
renamed to env.el; changed setenv to putenv.
Noah Friedman <friedman@splode.com>
parents:
2315
diff
changeset
|
182 (provide 'env) |
05d8916e4cde
renamed to env.el; changed setenv to putenv.
Noah Friedman <friedman@splode.com>
parents:
2315
diff
changeset
|
183 |
52401 | 184 ;;; arch-tag: b7d6a8f7-bc81-46db-8e39-8d721d4ed0b8 |
2403
05d8916e4cde
renamed to env.el; changed setenv to putenv.
Noah Friedman <friedman@splode.com>
parents:
2315
diff
changeset
|
185 ;;; env.el ends here |