Mercurial > emacs
annotate lisp/env.el @ 96025:86b03e4cc6d7
Remove unneeded Gnus ChangeLog entries
Remove entries in lisp/gnus/ChangeLog* which described changes to
dgnushack.el, lpath.el, or Makefile.in, which are not part of the Emacs
source tree
Revision: emacs@sv.gnu.org/emacs--devo--0--patch-1245
author | Miles Bader <miles@gnu.org> |
---|---|
date | Tue, 17 Jun 2008 02:33:12 +0000 |
parents | ee5932bf781d |
children | a9dc0e7c3f2b |
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, |
79721 | 4 ;; 2005, 2006, 2007, 2008 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 |
94678
ee5932bf781d
Switch to recommended form of GPLv3 permissions notice.
Glenn Morris <rgm@gnu.org>
parents:
87649
diff
changeset
|
11 ;; GNU Emacs is free software: you can redistribute it and/or modify |
14169 | 12 ;; it under the terms of the GNU General Public License as published by |
94678
ee5932bf781d
Switch to recommended form of GPLv3 permissions notice.
Glenn Morris <rgm@gnu.org>
parents:
87649
diff
changeset
|
13 ;; the Free Software Foundation, either version 3 of the License, or |
ee5932bf781d
Switch to recommended form of GPLv3 permissions notice.
Glenn Morris <rgm@gnu.org>
parents:
87649
diff
changeset
|
14 ;; (at your option) 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 |
94678
ee5932bf781d
Switch to recommended form of GPLv3 permissions notice.
Glenn Morris <rgm@gnu.org>
parents:
87649
diff
changeset
|
22 ;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>. |
489 | 23 |
2315
9e7ec92a4fdf
Added or corrected Commentary headers
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
1218
diff
changeset
|
24 ;;; Commentary: |
9e7ec92a4fdf
Added or corrected Commentary headers
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
1218
diff
changeset
|
25 |
14169 | 26 ;; UNIX processes inherit a list of name-to-string associations from their |
27 ;; parents called their `environment'; these are commonly used to control | |
28 ;; program options. This package permits you to set environment variables | |
29 ;; 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
|
30 |
49968 | 31 ;; Note that the environment string `process-environment' is not |
32 ;; decoded, but the args of `setenv' and `getenv' are normally | |
33 ;; multibyte text and get coding conversion. | |
34 | |
807
4f28bd14272c
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
658
diff
changeset
|
35 ;;; Code: |
4f28bd14272c
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
658
diff
changeset
|
36 |
83425
c82829d08b89
Fix semantics of let-binding `process-environment'.
Karoly Lorentey <lorentey@elte.hu>
parents:
83421
diff
changeset
|
37 (eval-when-compile (require 'cl)) |
c82829d08b89
Fix semantics of let-binding `process-environment'.
Karoly Lorentey <lorentey@elte.hu>
parents:
83421
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) |
85142
740ac1a0736b
(let-environment): Remove. Unused.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
84751
diff
changeset
|
48 (let ((str (substring enventry 0 |
740ac1a0736b
(let-environment): Remove. Unused.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
84751
diff
changeset
|
49 (string-match "=" enventry)))) |
740ac1a0736b
(let-environment): Remove. Unused.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
84751
diff
changeset
|
50 (if (multibyte-string-p str) |
740ac1a0736b
(let-environment): Remove. Unused.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
84751
diff
changeset
|
51 (decode-coding-string |
740ac1a0736b
(let-environment): Remove. Unused.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
84751
diff
changeset
|
52 str locale-coding-system t) |
740ac1a0736b
(let-environment): Remove. Unused.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
84751
diff
changeset
|
53 str))) |
83425
c82829d08b89
Fix semantics of let-binding `process-environment'.
Karoly Lorentey <lorentey@elte.hu>
parents:
83421
diff
changeset
|
54 (append process-environment |
85142
740ac1a0736b
(let-environment): Remove. Unused.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
84751
diff
changeset
|
55 ;;(frame-environment) |
83640
2aee92eacdab
* server.el (server-process-filter): Likewise.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
83594
diff
changeset
|
56 )) |
9220
8f05784959cc
(setenv-history): New history list.
Richard M. Stallman <rms@gnu.org>
parents:
8005
diff
changeset
|
57 nil mustmatch nil 'read-envvar-name-history)) |
8f05784959cc
(setenv-history): New history list.
Richard M. Stallman <rms@gnu.org>
parents:
8005
diff
changeset
|
58 |
8f05784959cc
(setenv-history): New history list.
Richard M. Stallman <rms@gnu.org>
parents:
8005
diff
changeset
|
59 ;; History list for VALUE argument to setenv. |
8f05784959cc
(setenv-history): New history list.
Richard M. Stallman <rms@gnu.org>
parents:
8005
diff
changeset
|
60 (defvar setenv-history nil) |
8f05784959cc
(setenv-history): New history list.
Richard M. Stallman <rms@gnu.org>
parents:
8005
diff
changeset
|
61 |
39554
c1fb5574fc7a
(substitute-env-vars): New function.
Gerd Moellmann <gerd@gnu.org>
parents:
39126
diff
changeset
|
62 |
c1fb5574fc7a
(substitute-env-vars): New function.
Gerd Moellmann <gerd@gnu.org>
parents:
39126
diff
changeset
|
63 (defun substitute-env-vars (string) |
c1fb5574fc7a
(substitute-env-vars): New function.
Gerd Moellmann <gerd@gnu.org>
parents:
39126
diff
changeset
|
64 "Substitute environment variables referred to in STRING. |
c1fb5574fc7a
(substitute-env-vars): New function.
Gerd Moellmann <gerd@gnu.org>
parents:
39126
diff
changeset
|
65 `$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
|
66 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
|
67 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
|
68 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
|
69 `$cd' is treated as an environment variable. |
92f5fdc30889
(substitute-env-vars): Fix typo.
Richard M. Stallman <rms@gnu.org>
parents:
50873
diff
changeset
|
70 |
92f5fdc30889
(substitute-env-vars): Fix typo.
Richard M. Stallman <rms@gnu.org>
parents:
50873
diff
changeset
|
71 Use `$$' to insert a single dollar sign." |
39554
c1fb5574fc7a
(substitute-env-vars): New function.
Gerd Moellmann <gerd@gnu.org>
parents:
39126
diff
changeset
|
72 (let ((start 0)) |
49588
37645a051842
Trailing whitespace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents:
40430
diff
changeset
|
73 (while (string-match |
49968 | 74 (eval-when-compile |
51279
92f5fdc30889
(substitute-env-vars): Fix typo.
Richard M. Stallman <rms@gnu.org>
parents:
50873
diff
changeset
|
75 (rx (or (and "$" (submatch (1+ (regexp "[[:alnum:]_]")))) |
49968 | 76 (and "${" (submatch (minimal-match (0+ anything))) "}") |
77 "$$"))) | |
39554
c1fb5574fc7a
(substitute-env-vars): New function.
Gerd Moellmann <gerd@gnu.org>
parents:
39126
diff
changeset
|
78 string start) |
c1fb5574fc7a
(substitute-env-vars): New function.
Gerd Moellmann <gerd@gnu.org>
parents:
39126
diff
changeset
|
79 (cond ((match-beginning 1) |
c1fb5574fc7a
(substitute-env-vars): New function.
Gerd Moellmann <gerd@gnu.org>
parents:
39126
diff
changeset
|
80 (let ((value (getenv (match-string 1 string)))) |
c1fb5574fc7a
(substitute-env-vars): New function.
Gerd Moellmann <gerd@gnu.org>
parents:
39126
diff
changeset
|
81 (setq string (replace-match (or value "") t t string) |
c1fb5574fc7a
(substitute-env-vars): New function.
Gerd Moellmann <gerd@gnu.org>
parents:
39126
diff
changeset
|
82 start (+ (match-beginning 0) (length value))))) |
c1fb5574fc7a
(substitute-env-vars): New function.
Gerd Moellmann <gerd@gnu.org>
parents:
39126
diff
changeset
|
83 ((match-beginning 2) |
c1fb5574fc7a
(substitute-env-vars): New function.
Gerd Moellmann <gerd@gnu.org>
parents:
39126
diff
changeset
|
84 (let ((value (getenv (match-string 2 string)))) |
c1fb5574fc7a
(substitute-env-vars): New function.
Gerd Moellmann <gerd@gnu.org>
parents:
39126
diff
changeset
|
85 (setq string (replace-match (or value "") t t string) |
c1fb5574fc7a
(substitute-env-vars): New function.
Gerd Moellmann <gerd@gnu.org>
parents:
39126
diff
changeset
|
86 start (+ (match-beginning 0) (length value))))) |
c1fb5574fc7a
(substitute-env-vars): New function.
Gerd Moellmann <gerd@gnu.org>
parents:
39126
diff
changeset
|
87 (t |
c1fb5574fc7a
(substitute-env-vars): New function.
Gerd Moellmann <gerd@gnu.org>
parents:
39126
diff
changeset
|
88 (setq string (replace-match "$" t t string) |
c1fb5574fc7a
(substitute-env-vars): New function.
Gerd Moellmann <gerd@gnu.org>
parents:
39126
diff
changeset
|
89 start (+ (match-beginning 0) 1))))) |
c1fb5574fc7a
(substitute-env-vars): New function.
Gerd Moellmann <gerd@gnu.org>
parents:
39126
diff
changeset
|
90 string)) |
c1fb5574fc7a
(substitute-env-vars): New function.
Gerd Moellmann <gerd@gnu.org>
parents:
39126
diff
changeset
|
91 |
c1fb5574fc7a
(substitute-env-vars): New function.
Gerd Moellmann <gerd@gnu.org>
parents:
39126
diff
changeset
|
92 |
83529
0d9e16eab053
Rework environment variable support. (Reported by Kalle Olavi Niemitalo and Noah Friedman.)
Karoly Lorentey <lorentey@elte.hu>
parents:
83516
diff
changeset
|
93 (defun setenv-internal (env variable value keep-empty) |
0d9e16eab053
Rework environment variable support. (Reported by Kalle Olavi Niemitalo and Noah Friedman.)
Karoly Lorentey <lorentey@elte.hu>
parents:
83516
diff
changeset
|
94 "Set VARIABLE to VALUE in ENV, adding empty entries if KEEP-EMPTY. |
0d9e16eab053
Rework environment variable support. (Reported by Kalle Olavi Niemitalo and Noah Friedman.)
Karoly Lorentey <lorentey@elte.hu>
parents:
83516
diff
changeset
|
95 Changes ENV by side-effect, and returns its new value." |
0d9e16eab053
Rework environment variable support. (Reported by Kalle Olavi Niemitalo and Noah Friedman.)
Karoly Lorentey <lorentey@elte.hu>
parents:
83516
diff
changeset
|
96 (let ((pattern (concat "\\`" (regexp-quote variable) "\\(=\\|\\'\\)")) |
0d9e16eab053
Rework environment variable support. (Reported by Kalle Olavi Niemitalo and Noah Friedman.)
Karoly Lorentey <lorentey@elte.hu>
parents:
83516
diff
changeset
|
97 (case-fold-search nil) |
0d9e16eab053
Rework environment variable support. (Reported by Kalle Olavi Niemitalo and Noah Friedman.)
Karoly Lorentey <lorentey@elte.hu>
parents:
83516
diff
changeset
|
98 (scan env) |
0d9e16eab053
Rework environment variable support. (Reported by Kalle Olavi Niemitalo and Noah Friedman.)
Karoly Lorentey <lorentey@elte.hu>
parents:
83516
diff
changeset
|
99 prev found) |
0d9e16eab053
Rework environment variable support. (Reported by Kalle Olavi Niemitalo and Noah Friedman.)
Karoly Lorentey <lorentey@elte.hu>
parents:
83516
diff
changeset
|
100 ;; Handle deletions from the beginning of the list specially. |
0d9e16eab053
Rework environment variable support. (Reported by Kalle Olavi Niemitalo and Noah Friedman.)
Karoly Lorentey <lorentey@elte.hu>
parents:
83516
diff
changeset
|
101 (if (and (null value) |
0d9e16eab053
Rework environment variable support. (Reported by Kalle Olavi Niemitalo and Noah Friedman.)
Karoly Lorentey <lorentey@elte.hu>
parents:
83516
diff
changeset
|
102 (not keep-empty) |
0d9e16eab053
Rework environment variable support. (Reported by Kalle Olavi Niemitalo and Noah Friedman.)
Karoly Lorentey <lorentey@elte.hu>
parents:
83516
diff
changeset
|
103 env |
0d9e16eab053
Rework environment variable support. (Reported by Kalle Olavi Niemitalo and Noah Friedman.)
Karoly Lorentey <lorentey@elte.hu>
parents:
83516
diff
changeset
|
104 (stringp (car env)) |
0d9e16eab053
Rework environment variable support. (Reported by Kalle Olavi Niemitalo and Noah Friedman.)
Karoly Lorentey <lorentey@elte.hu>
parents:
83516
diff
changeset
|
105 (string-match pattern (car env))) |
0d9e16eab053
Rework environment variable support. (Reported by Kalle Olavi Niemitalo and Noah Friedman.)
Karoly Lorentey <lorentey@elte.hu>
parents:
83516
diff
changeset
|
106 (cdr env) |
0d9e16eab053
Rework environment variable support. (Reported by Kalle Olavi Niemitalo and Noah Friedman.)
Karoly Lorentey <lorentey@elte.hu>
parents:
83516
diff
changeset
|
107 ;; Try to find existing entry for VARIABLE in ENV. |
0d9e16eab053
Rework environment variable support. (Reported by Kalle Olavi Niemitalo and Noah Friedman.)
Karoly Lorentey <lorentey@elte.hu>
parents:
83516
diff
changeset
|
108 (while (and scan (stringp (car scan))) |
0d9e16eab053
Rework environment variable support. (Reported by Kalle Olavi Niemitalo and Noah Friedman.)
Karoly Lorentey <lorentey@elte.hu>
parents:
83516
diff
changeset
|
109 (when (string-match pattern (car scan)) |
0d9e16eab053
Rework environment variable support. (Reported by Kalle Olavi Niemitalo and Noah Friedman.)
Karoly Lorentey <lorentey@elte.hu>
parents:
83516
diff
changeset
|
110 (if value |
0d9e16eab053
Rework environment variable support. (Reported by Kalle Olavi Niemitalo and Noah Friedman.)
Karoly Lorentey <lorentey@elte.hu>
parents:
83516
diff
changeset
|
111 (setcar scan (concat variable "=" value)) |
0d9e16eab053
Rework environment variable support. (Reported by Kalle Olavi Niemitalo and Noah Friedman.)
Karoly Lorentey <lorentey@elte.hu>
parents:
83516
diff
changeset
|
112 (if keep-empty |
0d9e16eab053
Rework environment variable support. (Reported by Kalle Olavi Niemitalo and Noah Friedman.)
Karoly Lorentey <lorentey@elte.hu>
parents:
83516
diff
changeset
|
113 (setcar scan variable) |
0d9e16eab053
Rework environment variable support. (Reported by Kalle Olavi Niemitalo and Noah Friedman.)
Karoly Lorentey <lorentey@elte.hu>
parents:
83516
diff
changeset
|
114 (setcdr prev (cdr scan)))) |
0d9e16eab053
Rework environment variable support. (Reported by Kalle Olavi Niemitalo and Noah Friedman.)
Karoly Lorentey <lorentey@elte.hu>
parents:
83516
diff
changeset
|
115 (setq found t |
0d9e16eab053
Rework environment variable support. (Reported by Kalle Olavi Niemitalo and Noah Friedman.)
Karoly Lorentey <lorentey@elte.hu>
parents:
83516
diff
changeset
|
116 scan nil)) |
0d9e16eab053
Rework environment variable support. (Reported by Kalle Olavi Niemitalo and Noah Friedman.)
Karoly Lorentey <lorentey@elte.hu>
parents:
83516
diff
changeset
|
117 (setq prev scan |
0d9e16eab053
Rework environment variable support. (Reported by Kalle Olavi Niemitalo and Noah Friedman.)
Karoly Lorentey <lorentey@elte.hu>
parents:
83516
diff
changeset
|
118 scan (cdr scan))) |
0d9e16eab053
Rework environment variable support. (Reported by Kalle Olavi Niemitalo and Noah Friedman.)
Karoly Lorentey <lorentey@elte.hu>
parents:
83516
diff
changeset
|
119 (if (and (not found) (or value keep-empty)) |
0d9e16eab053
Rework environment variable support. (Reported by Kalle Olavi Niemitalo and Noah Friedman.)
Karoly Lorentey <lorentey@elte.hu>
parents:
83516
diff
changeset
|
120 (cons (if value |
0d9e16eab053
Rework environment variable support. (Reported by Kalle Olavi Niemitalo and Noah Friedman.)
Karoly Lorentey <lorentey@elte.hu>
parents:
83516
diff
changeset
|
121 (concat variable "=" value) |
0d9e16eab053
Rework environment variable support. (Reported by Kalle Olavi Niemitalo and Noah Friedman.)
Karoly Lorentey <lorentey@elte.hu>
parents:
83516
diff
changeset
|
122 variable) |
0d9e16eab053
Rework environment variable support. (Reported by Kalle Olavi Niemitalo and Noah Friedman.)
Karoly Lorentey <lorentey@elte.hu>
parents:
83516
diff
changeset
|
123 env) |
0d9e16eab053
Rework environment variable support. (Reported by Kalle Olavi Niemitalo and Noah Friedman.)
Karoly Lorentey <lorentey@elte.hu>
parents:
83516
diff
changeset
|
124 env)))) |
0d9e16eab053
Rework environment variable support. (Reported by Kalle Olavi Niemitalo and Noah Friedman.)
Karoly Lorentey <lorentey@elte.hu>
parents:
83516
diff
changeset
|
125 |
83425
c82829d08b89
Fix semantics of let-binding `process-environment'.
Karoly Lorentey <lorentey@elte.hu>
parents:
83421
diff
changeset
|
126 ;; Fixme: Should the 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
|
127 |
70094
d893c3bf4c3b
(setenv): Get rid of arg UNSET. Interactive unsetting
Richard M. Stallman <rms@gnu.org>
parents:
68651
diff
changeset
|
128 (defun setenv (variable &optional value substitute-env-vars) |
489 | 129 "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
|
130 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
|
131 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
|
132 |
83430
10f26433fe3f
Update environment-related doc strings.
Karoly Lorentey <lorentey@elte.hu>
parents:
83427
diff
changeset
|
133 Interactively, a prefix argument means to unset the variable, and |
10f26433fe3f
Update environment-related doc strings.
Karoly Lorentey <lorentey@elte.hu>
parents:
83427
diff
changeset
|
134 otherwise the current value (if any) of the variable appears at |
10f26433fe3f
Update environment-related doc strings.
Karoly Lorentey <lorentey@elte.hu>
parents:
83427
diff
changeset
|
135 the front of the history list when you type in the new value. |
10f26433fe3f
Update environment-related doc strings.
Karoly Lorentey <lorentey@elte.hu>
parents:
83427
diff
changeset
|
136 This function always replaces environment variables in the new |
10f26433fe3f
Update environment-related doc strings.
Karoly Lorentey <lorentey@elte.hu>
parents:
83427
diff
changeset
|
137 value when called interactively. |
9220
8f05784959cc
(setenv-history): New history list.
Richard M. Stallman <rms@gnu.org>
parents:
8005
diff
changeset
|
138 |
70094
d893c3bf4c3b
(setenv): Get rid of arg UNSET. Interactive unsetting
Richard M. Stallman <rms@gnu.org>
parents:
68651
diff
changeset
|
139 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
|
140 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
|
141 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
|
142 |
d893c3bf4c3b
(setenv): Get rid of arg UNSET. Interactive unsetting
Richard M. Stallman <rms@gnu.org>
parents:
68651
diff
changeset
|
143 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
|
144 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
|
145 |
49968 | 146 This function works by modifying `process-environment'. |
147 | |
148 As a special case, setting variable `TZ' calls `set-time-zone-rule' as | |
149 a side-effect." | |
8004
a86eceda6537
(setenv): Rewrite. Provide a way to unset interactively.
Richard M. Stallman <rms@gnu.org>
parents:
8002
diff
changeset
|
150 (interactive |
a86eceda6537
(setenv): Rewrite. Provide a way to unset interactively.
Richard M. Stallman <rms@gnu.org>
parents:
8002
diff
changeset
|
151 (if current-prefix-arg |
70094
d893c3bf4c3b
(setenv): Get rid of arg UNSET. Interactive unsetting
Richard M. Stallman <rms@gnu.org>
parents:
68651
diff
changeset
|
152 (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
|
153 (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
|
154 (value (getenv var))) |
c0713ad66d33
(setenv): Interactively, if VARIABLE has a current value,
Gerd Moellmann <gerd@gnu.org>
parents:
38412
diff
changeset
|
155 (when value |
70417
95f3ef491663
(setenv): Use add-to-history.
Kim F. Storm <storm@cua.dk>
parents:
70094
diff
changeset
|
156 (add-to-history 'setenv-history value)) |
9220
8f05784959cc
(setenv-history): New history list.
Richard M. Stallman <rms@gnu.org>
parents:
8005
diff
changeset
|
157 ;; 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
|
158 (list var |
39554
c1fb5574fc7a
(substitute-env-vars): New function.
Gerd Moellmann <gerd@gnu.org>
parents:
39126
diff
changeset
|
159 (read-from-minibuffer (format "Set %s to value: " var) |
c1fb5574fc7a
(substitute-env-vars): New function.
Gerd Moellmann <gerd@gnu.org>
parents:
39126
diff
changeset
|
160 nil nil nil 'setenv-history |
c1fb5574fc7a
(substitute-env-vars): New function.
Gerd Moellmann <gerd@gnu.org>
parents:
39126
diff
changeset
|
161 value) |
c1fb5574fc7a
(substitute-env-vars): New function.
Gerd Moellmann <gerd@gnu.org>
parents:
39126
diff
changeset
|
162 t)))) |
49968 | 163 (if (and (multibyte-string-p variable) locale-coding-system) |
49977
f491c5cee974
(setenv): Fix previous change.
Kenichi Handa <handa@m17n.org>
parents:
49968
diff
changeset
|
164 (let ((codings (find-coding-systems-string (concat variable value)))) |
f491c5cee974
(setenv): Fix previous change.
Kenichi Handa <handa@m17n.org>
parents:
49968
diff
changeset
|
165 (unless (or (eq 'undecided (car codings)) |
f491c5cee974
(setenv): Fix previous change.
Kenichi Handa <handa@m17n.org>
parents:
49968
diff
changeset
|
166 (memq (coding-system-base locale-coding-system) codings)) |
f491c5cee974
(setenv): Fix previous change.
Kenichi Handa <handa@m17n.org>
parents:
49968
diff
changeset
|
167 (error "Can't encode `%s=%s' with `locale-coding-system'" |
f491c5cee974
(setenv): Fix previous change.
Kenichi Handa <handa@m17n.org>
parents:
49968
diff
changeset
|
168 variable (or value ""))))) |
70094
d893c3bf4c3b
(setenv): Get rid of arg UNSET. Interactive unsetting
Richard M. Stallman <rms@gnu.org>
parents:
68651
diff
changeset
|
169 (and value |
d893c3bf4c3b
(setenv): Get rid of arg UNSET. Interactive unsetting
Richard M. Stallman <rms@gnu.org>
parents:
68651
diff
changeset
|
170 substitute-env-vars |
d893c3bf4c3b
(setenv): Get rid of arg UNSET. Interactive unsetting
Richard M. Stallman <rms@gnu.org>
parents:
68651
diff
changeset
|
171 (setq value (substitute-env-vars value))) |
49968 | 172 (if (multibyte-string-p variable) |
173 (setq variable (encode-coding-string variable locale-coding-system))) | |
174 (if (and value (multibyte-string-p value)) | |
175 (setq value (encode-coding-string value locale-coding-system))) | |
489 | 176 (if (string-match "=" variable) |
83421
bb2edc915032
Implement automatic terminal-local environment variables via `local-environment-variables'.
Karoly Lorentey <lorentey@elte.hu>
parents:
64762
diff
changeset
|
177 (error "Environment variable name `%s' contains `='" variable)) |
83529
0d9e16eab053
Rework environment variable support. (Reported by Kalle Olavi Niemitalo and Noah Friedman.)
Karoly Lorentey <lorentey@elte.hu>
parents:
83516
diff
changeset
|
178 (if (string-equal "TZ" variable) |
0d9e16eab053
Rework environment variable support. (Reported by Kalle Olavi Niemitalo and Noah Friedman.)
Karoly Lorentey <lorentey@elte.hu>
parents:
83516
diff
changeset
|
179 (set-time-zone-rule value)) |
85142
740ac1a0736b
(let-environment): Remove. Unused.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
84751
diff
changeset
|
180 (setq process-environment (setenv-internal process-environment |
740ac1a0736b
(let-environment): Remove. Unused.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
84751
diff
changeset
|
181 variable value t)) |
39554
c1fb5574fc7a
(substitute-env-vars): New function.
Gerd Moellmann <gerd@gnu.org>
parents:
39126
diff
changeset
|
182 value) |
584 | 183 |
83427
2afc49c9f0c0
Store local environment in frame (not terminal) parameters.
Karoly Lorentey <lorentey@elte.hu>
parents:
83425
diff
changeset
|
184 (defun getenv (variable &optional frame) |
28917
845292e36d62
(getenv): New function, interactively callable.
Gerd Moellmann <gerd@gnu.org>
parents:
21201
diff
changeset
|
185 "Get the value of environment variable VARIABLE. |
845292e36d62
(getenv): New function, interactively callable.
Gerd Moellmann <gerd@gnu.org>
parents:
21201
diff
changeset
|
186 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
|
187 the environment. Otherwise, value is a string. |
845292e36d62
(getenv): New function, interactively callable.
Gerd Moellmann <gerd@gnu.org>
parents:
21201
diff
changeset
|
188 |
83427
2afc49c9f0c0
Store local environment in frame (not terminal) parameters.
Karoly Lorentey <lorentey@elte.hu>
parents:
83425
diff
changeset
|
189 If optional parameter FRAME is non-nil, then it should be a |
83529
0d9e16eab053
Rework environment variable support. (Reported by Kalle Olavi Niemitalo and Noah Friedman.)
Karoly Lorentey <lorentey@elte.hu>
parents:
83516
diff
changeset
|
190 frame. This function will look up VARIABLE in its 'environment |
0d9e16eab053
Rework environment variable support. (Reported by Kalle Olavi Niemitalo and Noah Friedman.)
Karoly Lorentey <lorentey@elte.hu>
parents:
83516
diff
changeset
|
191 parameter. |
83421
bb2edc915032
Implement automatic terminal-local environment variables via `local-environment-variables'.
Karoly Lorentey <lorentey@elte.hu>
parents:
64762
diff
changeset
|
192 |
83427
2afc49c9f0c0
Store local environment in frame (not terminal) parameters.
Karoly Lorentey <lorentey@elte.hu>
parents:
83425
diff
changeset
|
193 Otherwise, this function searches `process-environment' for |
83529
0d9e16eab053
Rework environment variable support. (Reported by Kalle Olavi Niemitalo and Noah Friedman.)
Karoly Lorentey <lorentey@elte.hu>
parents:
83516
diff
changeset
|
194 VARIABLE. If it is not found there, then it continues the search |
0d9e16eab053
Rework environment variable support. (Reported by Kalle Olavi Niemitalo and Noah Friedman.)
Karoly Lorentey <lorentey@elte.hu>
parents:
83516
diff
changeset
|
195 in the environment list of the selected frame." |
28917
845292e36d62
(getenv): New function, interactively callable.
Gerd Moellmann <gerd@gnu.org>
parents:
21201
diff
changeset
|
196 (interactive (list (read-envvar-name "Get environment variable: " t))) |
49968 | 197 (let ((value (getenv-internal (if (multibyte-string-p variable) |
198 (encode-coding-string | |
199 variable locale-coding-system) | |
83594
2716535391b7
Rudimentary fix for environment variable handling.
Miles Bader <miles@gnu.org>
parents:
83568
diff
changeset
|
200 variable) |
2716535391b7
Rudimentary fix for environment variable handling.
Miles Bader <miles@gnu.org>
parents:
83568
diff
changeset
|
201 frame))) |
49968 | 202 (if (and enable-multibyte-characters value) |
203 (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
|
204 (when (interactive-p) |
845292e36d62
(getenv): New function, interactively callable.
Gerd Moellmann <gerd@gnu.org>
parents:
21201
diff
changeset
|
205 (message "%s" (if value value "Not set"))) |
845292e36d62
(getenv): New function, interactively callable.
Gerd Moellmann <gerd@gnu.org>
parents:
21201
diff
changeset
|
206 value)) |
845292e36d62
(getenv): New function, interactively callable.
Gerd Moellmann <gerd@gnu.org>
parents:
21201
diff
changeset
|
207 |
83594
2716535391b7
Rudimentary fix for environment variable handling.
Miles Bader <miles@gnu.org>
parents:
83568
diff
changeset
|
208 (defun environment (&optional frame) |
83425
c82829d08b89
Fix semantics of let-binding `process-environment'.
Karoly Lorentey <lorentey@elte.hu>
parents:
83421
diff
changeset
|
209 "Return a list of environment variables with their values. |
c82829d08b89
Fix semantics of let-binding `process-environment'.
Karoly Lorentey <lorentey@elte.hu>
parents:
83421
diff
changeset
|
210 Each entry in the list is a string of the form NAME=VALUE. |
c82829d08b89
Fix semantics of let-binding `process-environment'.
Karoly Lorentey <lorentey@elte.hu>
parents:
83421
diff
changeset
|
211 |
c82829d08b89
Fix semantics of let-binding `process-environment'.
Karoly Lorentey <lorentey@elte.hu>
parents:
83421
diff
changeset
|
212 The returned list can not be used to change environment |
c82829d08b89
Fix semantics of let-binding `process-environment'.
Karoly Lorentey <lorentey@elte.hu>
parents:
83421
diff
changeset
|
213 variables, only read them. See `setenv' to do that. |
c82829d08b89
Fix semantics of let-binding `process-environment'.
Karoly Lorentey <lorentey@elte.hu>
parents:
83421
diff
changeset
|
214 |
83594
2716535391b7
Rudimentary fix for environment variable handling.
Miles Bader <miles@gnu.org>
parents:
83568
diff
changeset
|
215 If optional parameter FRAME is non-nil, then it should be a |
2716535391b7
Rudimentary fix for environment variable handling.
Miles Bader <miles@gnu.org>
parents:
83568
diff
changeset
|
216 frame. The function returns the environment of that frame. |
2716535391b7
Rudimentary fix for environment variable handling.
Miles Bader <miles@gnu.org>
parents:
83568
diff
changeset
|
217 |
83529
0d9e16eab053
Rework environment variable support. (Reported by Kalle Olavi Niemitalo and Noah Friedman.)
Karoly Lorentey <lorentey@elte.hu>
parents:
83516
diff
changeset
|
218 The list is constructed by concatenating the elements of |
0d9e16eab053
Rework environment variable support. (Reported by Kalle Olavi Niemitalo and Noah Friedman.)
Karoly Lorentey <lorentey@elte.hu>
parents:
83516
diff
changeset
|
219 `process-environment' and the 'environment parameter of the |
0d9e16eab053
Rework environment variable support. (Reported by Kalle Olavi Niemitalo and Noah Friedman.)
Karoly Lorentey <lorentey@elte.hu>
parents:
83516
diff
changeset
|
220 selected frame, and removing duplicated and empty values. |
83425
c82829d08b89
Fix semantics of let-binding `process-environment'.
Karoly Lorentey <lorentey@elte.hu>
parents:
83421
diff
changeset
|
221 |
c82829d08b89
Fix semantics of let-binding `process-environment'.
Karoly Lorentey <lorentey@elte.hu>
parents:
83421
diff
changeset
|
222 Non-ASCII characters are encoded according to the initial value of |
c82829d08b89
Fix semantics of let-binding `process-environment'.
Karoly Lorentey <lorentey@elte.hu>
parents:
83421
diff
changeset
|
223 `locale-coding-system', i.e. the elements must normally be decoded for use. |
c82829d08b89
Fix semantics of let-binding `process-environment'.
Karoly Lorentey <lorentey@elte.hu>
parents:
83421
diff
changeset
|
224 See `setenv' and `getenv'." |
83529
0d9e16eab053
Rework environment variable support. (Reported by Kalle Olavi Niemitalo and Noah Friedman.)
Karoly Lorentey <lorentey@elte.hu>
parents:
83516
diff
changeset
|
225 (let* ((env (append process-environment |
85142
740ac1a0736b
(let-environment): Remove. Unused.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
84751
diff
changeset
|
226 ;; (frame-environment frame) |
83529
0d9e16eab053
Rework environment variable support. (Reported by Kalle Olavi Niemitalo and Noah Friedman.)
Karoly Lorentey <lorentey@elte.hu>
parents:
83516
diff
changeset
|
227 nil)) |
0d9e16eab053
Rework environment variable support. (Reported by Kalle Olavi Niemitalo and Noah Friedman.)
Karoly Lorentey <lorentey@elte.hu>
parents:
83516
diff
changeset
|
228 (scan env) |
0d9e16eab053
Rework environment variable support. (Reported by Kalle Olavi Niemitalo and Noah Friedman.)
Karoly Lorentey <lorentey@elte.hu>
parents:
83516
diff
changeset
|
229 prev seen) |
0d9e16eab053
Rework environment variable support. (Reported by Kalle Olavi Niemitalo and Noah Friedman.)
Karoly Lorentey <lorentey@elte.hu>
parents:
83516
diff
changeset
|
230 ;; Remove unset variables from the beginning of the list. |
0d9e16eab053
Rework environment variable support. (Reported by Kalle Olavi Niemitalo and Noah Friedman.)
Karoly Lorentey <lorentey@elte.hu>
parents:
83516
diff
changeset
|
231 (while (and env |
0d9e16eab053
Rework environment variable support. (Reported by Kalle Olavi Niemitalo and Noah Friedman.)
Karoly Lorentey <lorentey@elte.hu>
parents:
83516
diff
changeset
|
232 (or (not (stringp (car env))) |
0d9e16eab053
Rework environment variable support. (Reported by Kalle Olavi Niemitalo and Noah Friedman.)
Karoly Lorentey <lorentey@elte.hu>
parents:
83516
diff
changeset
|
233 (not (string-match "=" (car env))))) |
0d9e16eab053
Rework environment variable support. (Reported by Kalle Olavi Niemitalo and Noah Friedman.)
Karoly Lorentey <lorentey@elte.hu>
parents:
83516
diff
changeset
|
234 (or (member (car env) seen) |
0d9e16eab053
Rework environment variable support. (Reported by Kalle Olavi Niemitalo and Noah Friedman.)
Karoly Lorentey <lorentey@elte.hu>
parents:
83516
diff
changeset
|
235 (setq seen (cons (car env) seen))) |
0d9e16eab053
Rework environment variable support. (Reported by Kalle Olavi Niemitalo and Noah Friedman.)
Karoly Lorentey <lorentey@elte.hu>
parents:
83516
diff
changeset
|
236 (setq env (cdr env) |
0d9e16eab053
Rework environment variable support. (Reported by Kalle Olavi Niemitalo and Noah Friedman.)
Karoly Lorentey <lorentey@elte.hu>
parents:
83516
diff
changeset
|
237 scan env)) |
0d9e16eab053
Rework environment variable support. (Reported by Kalle Olavi Niemitalo and Noah Friedman.)
Karoly Lorentey <lorentey@elte.hu>
parents:
83516
diff
changeset
|
238 (let (name) |
0d9e16eab053
Rework environment variable support. (Reported by Kalle Olavi Niemitalo and Noah Friedman.)
Karoly Lorentey <lorentey@elte.hu>
parents:
83516
diff
changeset
|
239 (while scan |
0d9e16eab053
Rework environment variable support. (Reported by Kalle Olavi Niemitalo and Noah Friedman.)
Karoly Lorentey <lorentey@elte.hu>
parents:
83516
diff
changeset
|
240 (cond ((or (not (stringp (car scan))) |
0d9e16eab053
Rework environment variable support. (Reported by Kalle Olavi Niemitalo and Noah Friedman.)
Karoly Lorentey <lorentey@elte.hu>
parents:
83516
diff
changeset
|
241 (not (string-match "=" (car scan)))) |
83425
c82829d08b89
Fix semantics of let-binding `process-environment'.
Karoly Lorentey <lorentey@elte.hu>
parents:
83421
diff
changeset
|
242 ;; Unset variable. |
83529
0d9e16eab053
Rework environment variable support. (Reported by Kalle Olavi Niemitalo and Noah Friedman.)
Karoly Lorentey <lorentey@elte.hu>
parents:
83516
diff
changeset
|
243 (or (member (car scan) seen) |
0d9e16eab053
Rework environment variable support. (Reported by Kalle Olavi Niemitalo and Noah Friedman.)
Karoly Lorentey <lorentey@elte.hu>
parents:
83516
diff
changeset
|
244 (setq seen (cons (car scan) seen))) |
0d9e16eab053
Rework environment variable support. (Reported by Kalle Olavi Niemitalo and Noah Friedman.)
Karoly Lorentey <lorentey@elte.hu>
parents:
83516
diff
changeset
|
245 (setcdr prev (cdr scan))) |
0d9e16eab053
Rework environment variable support. (Reported by Kalle Olavi Niemitalo and Noah Friedman.)
Karoly Lorentey <lorentey@elte.hu>
parents:
83516
diff
changeset
|
246 ((member (setq name (substring (car scan) 0 (string-match "=" (car scan)))) seen) |
0d9e16eab053
Rework environment variable support. (Reported by Kalle Olavi Niemitalo and Noah Friedman.)
Karoly Lorentey <lorentey@elte.hu>
parents:
83516
diff
changeset
|
247 ;; Duplicated variable. |
0d9e16eab053
Rework environment variable support. (Reported by Kalle Olavi Niemitalo and Noah Friedman.)
Karoly Lorentey <lorentey@elte.hu>
parents:
83516
diff
changeset
|
248 (setcdr prev (cdr scan))) |
83425
c82829d08b89
Fix semantics of let-binding `process-environment'.
Karoly Lorentey <lorentey@elte.hu>
parents:
83421
diff
changeset
|
249 (t |
c82829d08b89
Fix semantics of let-binding `process-environment'.
Karoly Lorentey <lorentey@elte.hu>
parents:
83421
diff
changeset
|
250 ;; New variable. |
83529
0d9e16eab053
Rework environment variable support. (Reported by Kalle Olavi Niemitalo and Noah Friedman.)
Karoly Lorentey <lorentey@elte.hu>
parents:
83516
diff
changeset
|
251 (setq seen (cons name seen)))) |
0d9e16eab053
Rework environment variable support. (Reported by Kalle Olavi Niemitalo and Noah Friedman.)
Karoly Lorentey <lorentey@elte.hu>
parents:
83516
diff
changeset
|
252 (setq prev scan |
0d9e16eab053
Rework environment variable support. (Reported by Kalle Olavi Niemitalo and Noah Friedman.)
Karoly Lorentey <lorentey@elte.hu>
parents:
83516
diff
changeset
|
253 scan (cdr scan)))) |
83425
c82829d08b89
Fix semantics of let-binding `process-environment'.
Karoly Lorentey <lorentey@elte.hu>
parents:
83421
diff
changeset
|
254 env)) |
c82829d08b89
Fix semantics of let-binding `process-environment'.
Karoly Lorentey <lorentey@elte.hu>
parents:
83421
diff
changeset
|
255 |
2403
05d8916e4cde
renamed to env.el; changed setenv to putenv.
Noah Friedman <friedman@splode.com>
parents:
2315
diff
changeset
|
256 (provide 'env) |
05d8916e4cde
renamed to env.el; changed setenv to putenv.
Noah Friedman <friedman@splode.com>
parents:
2315
diff
changeset
|
257 |
83797
f86e7a61b05e
Trivial spacing and comment.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
83648
diff
changeset
|
258 ;; 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
|
259 ;;; env.el ends here |