Mercurial > emacs
annotate lisp/env.el @ 9292:ec707cca800a
(XSETFASTINT): New macro.
(CHECK_NUMBER_COERCE_MARKER): Don't use XFASTINT as an lvalue.
(CHECK_NUMBER_OR_FLOAT_COERCE_MARKER): Likewise.
author | Karl Heuer <kwzh@gnu.org> |
---|---|
date | Tue, 04 Oct 1994 15:24:13 +0000 |
parents | 8f05784959cc |
children | 832197fec54d |
rev | line source |
---|---|
2403
05d8916e4cde
renamed to env.el; changed setenv to putenv.
Noah Friedman <friedman@splode.com>
parents:
2315
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 |
8005
12f59aa8e26d
Update copyright notice.
Richard M. Stallman <rms@gnu.org>
parents:
8004
diff
changeset
|
3 ;;; Copyright 1991, 1994 Free Software Foundation, Inc. |
1185 | 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 |
489 | 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 | |
807
4f28bd14272c
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
658
diff
changeset
|
12 ;;; the Free Software Foundation; either version 2, or (at your option) |
489 | 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 | |
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 |
9e7ec92a4fdf
Added or corrected Commentary headers
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
1218
diff
changeset
|
26 ;; UNIX processes inherit a list of name-to-string associations from |
9e7ec92a4fdf
Added or corrected Commentary headers
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
1218
diff
changeset
|
27 ;; their parents called their `environment'; these are commonly used |
9e7ec92a4fdf
Added or corrected Commentary headers
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
1218
diff
changeset
|
28 ;; to control program options. This package permits you to set |
9e7ec92a4fdf
Added or corrected Commentary headers
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
1218
diff
changeset
|
29 ;; environment variables to be passed to any sub-process run under Emacs. |
9e7ec92a4fdf
Added or corrected Commentary headers
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
1218
diff
changeset
|
30 |
807
4f28bd14272c
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
658
diff
changeset
|
31 ;;; Code: |
4f28bd14272c
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
658
diff
changeset
|
32 |
9220
8f05784959cc
(setenv-history): New history list.
Richard M. Stallman <rms@gnu.org>
parents:
8005
diff
changeset
|
33 ;; History list for environment variable names. |
8f05784959cc
(setenv-history): New history list.
Richard M. Stallman <rms@gnu.org>
parents:
8005
diff
changeset
|
34 (defvar read-envvar-name-history nil) |
8f05784959cc
(setenv-history): New history list.
Richard M. Stallman <rms@gnu.org>
parents:
8005
diff
changeset
|
35 |
8f05784959cc
(setenv-history): New history list.
Richard M. Stallman <rms@gnu.org>
parents:
8005
diff
changeset
|
36 (defun read-envvar-name (prompt &optional mustmatch) |
8f05784959cc
(setenv-history): New history list.
Richard M. Stallman <rms@gnu.org>
parents:
8005
diff
changeset
|
37 "Read environment variable name, prompting with PROMPT. |
8f05784959cc
(setenv-history): New history list.
Richard M. Stallman <rms@gnu.org>
parents:
8005
diff
changeset
|
38 Optional second arg MUSTMATCH, if non-nil, means require existing envvar name." |
8f05784959cc
(setenv-history): New history list.
Richard M. Stallman <rms@gnu.org>
parents:
8005
diff
changeset
|
39 (completing-read prompt |
8f05784959cc
(setenv-history): New history list.
Richard M. Stallman <rms@gnu.org>
parents:
8005
diff
changeset
|
40 (mapcar (function |
8f05784959cc
(setenv-history): New history list.
Richard M. Stallman <rms@gnu.org>
parents:
8005
diff
changeset
|
41 (lambda (enventry) |
8f05784959cc
(setenv-history): New history list.
Richard M. Stallman <rms@gnu.org>
parents:
8005
diff
changeset
|
42 (list (substring enventry 0 |
8f05784959cc
(setenv-history): New history list.
Richard M. Stallman <rms@gnu.org>
parents:
8005
diff
changeset
|
43 (string-match "=" enventry))))) |
8f05784959cc
(setenv-history): New history list.
Richard M. Stallman <rms@gnu.org>
parents:
8005
diff
changeset
|
44 process-environment) |
8f05784959cc
(setenv-history): New history list.
Richard M. Stallman <rms@gnu.org>
parents:
8005
diff
changeset
|
45 nil mustmatch nil 'read-envvar-name-history)) |
8f05784959cc
(setenv-history): New history list.
Richard M. Stallman <rms@gnu.org>
parents:
8005
diff
changeset
|
46 |
8f05784959cc
(setenv-history): New history list.
Richard M. Stallman <rms@gnu.org>
parents:
8005
diff
changeset
|
47 ;; History list for VALUE argument to setenv. |
8f05784959cc
(setenv-history): New history list.
Richard M. Stallman <rms@gnu.org>
parents:
8005
diff
changeset
|
48 (defvar setenv-history nil) |
8f05784959cc
(setenv-history): New history list.
Richard M. Stallman <rms@gnu.org>
parents:
8005
diff
changeset
|
49 |
1218
678ff000d9c8
(setenv): Make it autoload.
Richard M. Stallman <rms@gnu.org>
parents:
1216
diff
changeset
|
50 ;;;###autoload |
8004
a86eceda6537
(setenv): Rewrite. Provide a way to unset interactively.
Richard M. Stallman <rms@gnu.org>
parents:
8002
diff
changeset
|
51 (defun setenv (variable &optional value unset) |
489 | 52 "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
|
53 VARIABLE should be a string. VALUE is optional; if not provided or is |
05d8916e4cde
renamed to env.el; changed setenv to putenv.
Noah Friedman <friedman@splode.com>
parents:
2315
diff
changeset
|
54 `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
|
55 |
a86eceda6537
(setenv): Rewrite. Provide a way to unset interactively.
Richard M. Stallman <rms@gnu.org>
parents:
8002
diff
changeset
|
56 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
|
57 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
|
58 appears at the front of the history list when you type in the new value. |
8f05784959cc
(setenv-history): New history list.
Richard M. Stallman <rms@gnu.org>
parents:
8005
diff
changeset
|
59 |
1216 | 60 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
|
61 (interactive |
a86eceda6537
(setenv): Rewrite. Provide a way to unset interactively.
Richard M. Stallman <rms@gnu.org>
parents:
8002
diff
changeset
|
62 (if current-prefix-arg |
9220
8f05784959cc
(setenv-history): New history list.
Richard M. Stallman <rms@gnu.org>
parents:
8005
diff
changeset
|
63 (list (read-envvar-name "Clear environment variable: " t) nil t) |
8f05784959cc
(setenv-history): New history list.
Richard M. Stallman <rms@gnu.org>
parents:
8005
diff
changeset
|
64 (let* ((var (read-envvar-name "Set environment variable: " nil)) |
8f05784959cc
(setenv-history): New history list.
Richard M. Stallman <rms@gnu.org>
parents:
8005
diff
changeset
|
65 (oldval (getenv var)) |
8f05784959cc
(setenv-history): New history list.
Richard M. Stallman <rms@gnu.org>
parents:
8005
diff
changeset
|
66 newval |
8f05784959cc
(setenv-history): New history list.
Richard M. Stallman <rms@gnu.org>
parents:
8005
diff
changeset
|
67 oldhist) |
8f05784959cc
(setenv-history): New history list.
Richard M. Stallman <rms@gnu.org>
parents:
8005
diff
changeset
|
68 ;; Don't put the current value on the history |
8f05784959cc
(setenv-history): New history list.
Richard M. Stallman <rms@gnu.org>
parents:
8005
diff
changeset
|
69 ;; if it is already there. |
8f05784959cc
(setenv-history): New history list.
Richard M. Stallman <rms@gnu.org>
parents:
8005
diff
changeset
|
70 (if (equal oldval (car setenv-history)) |
8f05784959cc
(setenv-history): New history list.
Richard M. Stallman <rms@gnu.org>
parents:
8005
diff
changeset
|
71 (setq oldval nil)) |
8f05784959cc
(setenv-history): New history list.
Richard M. Stallman <rms@gnu.org>
parents:
8005
diff
changeset
|
72 ;; Now if OLDVAL is non-nil, we should add it to the history. |
8f05784959cc
(setenv-history): New history list.
Richard M. Stallman <rms@gnu.org>
parents:
8005
diff
changeset
|
73 (if oldval |
8f05784959cc
(setenv-history): New history list.
Richard M. Stallman <rms@gnu.org>
parents:
8005
diff
changeset
|
74 (setq setenv-history (cons oldval setenv-history))) |
8f05784959cc
(setenv-history): New history list.
Richard M. Stallman <rms@gnu.org>
parents:
8005
diff
changeset
|
75 (setq oldhist setenv-history) |
8f05784959cc
(setenv-history): New history list.
Richard M. Stallman <rms@gnu.org>
parents:
8005
diff
changeset
|
76 (setq newval (read-from-minibuffer (format "Set %s to value: " var) |
8f05784959cc
(setenv-history): New history list.
Richard M. Stallman <rms@gnu.org>
parents:
8005
diff
changeset
|
77 nil nil nil 'setenv-history)) |
8f05784959cc
(setenv-history): New history list.
Richard M. Stallman <rms@gnu.org>
parents:
8005
diff
changeset
|
78 ;; If we added the current value to the history, remove it. |
8f05784959cc
(setenv-history): New history list.
Richard M. Stallman <rms@gnu.org>
parents:
8005
diff
changeset
|
79 ;; Note that read-from-minibuffer may have added the new value. |
8f05784959cc
(setenv-history): New history list.
Richard M. Stallman <rms@gnu.org>
parents:
8005
diff
changeset
|
80 ;; Don't remove that! |
8f05784959cc
(setenv-history): New history list.
Richard M. Stallman <rms@gnu.org>
parents:
8005
diff
changeset
|
81 (if oldval |
8f05784959cc
(setenv-history): New history list.
Richard M. Stallman <rms@gnu.org>
parents:
8005
diff
changeset
|
82 (if (eq oldhist setenv-history) |
8f05784959cc
(setenv-history): New history list.
Richard M. Stallman <rms@gnu.org>
parents:
8005
diff
changeset
|
83 (setq setenv-history (cdr setenv-history)) |
8f05784959cc
(setenv-history): New history list.
Richard M. Stallman <rms@gnu.org>
parents:
8005
diff
changeset
|
84 (setcdr setenv-history (cdr (cdr setenv-history))))) |
8f05784959cc
(setenv-history): New history list.
Richard M. Stallman <rms@gnu.org>
parents:
8005
diff
changeset
|
85 ;; Here finally we specify the args to give call setenv with. |
8f05784959cc
(setenv-history): New history list.
Richard M. Stallman <rms@gnu.org>
parents:
8005
diff
changeset
|
86 (list var newval)))) |
8004
a86eceda6537
(setenv): Rewrite. Provide a way to unset interactively.
Richard M. Stallman <rms@gnu.org>
parents:
8002
diff
changeset
|
87 (if unset (setq value nil)) |
489 | 88 (if (string-match "=" variable) |
2403
05d8916e4cde
renamed to env.el; changed setenv to putenv.
Noah Friedman <friedman@splode.com>
parents:
2315
diff
changeset
|
89 (error "Environment variable name `%s' contains `='" variable) |
1185 | 90 (let ((pattern (concat "\\`" (regexp-quote (concat variable "=")))) |
3667
f4a7ac2ec651
(setenv): Treat case as significant.
Richard M. Stallman <rms@gnu.org>
parents:
2410
diff
changeset
|
91 (case-fold-search nil) |
8004
a86eceda6537
(setenv): Rewrite. Provide a way to unset interactively.
Richard M. Stallman <rms@gnu.org>
parents:
8002
diff
changeset
|
92 (scan process-environment) |
a86eceda6537
(setenv): Rewrite. Provide a way to unset interactively.
Richard M. Stallman <rms@gnu.org>
parents:
8002
diff
changeset
|
93 found) |
a86eceda6537
(setenv): Rewrite. Provide a way to unset interactively.
Richard M. Stallman <rms@gnu.org>
parents:
8002
diff
changeset
|
94 (while scan |
a86eceda6537
(setenv): Rewrite. Provide a way to unset interactively.
Richard M. Stallman <rms@gnu.org>
parents:
8002
diff
changeset
|
95 (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
|
96 (setq found t) |
a86eceda6537
(setenv): Rewrite. Provide a way to unset interactively.
Richard M. Stallman <rms@gnu.org>
parents:
8002
diff
changeset
|
97 (if (eq nil value) |
a86eceda6537
(setenv): Rewrite. Provide a way to unset interactively.
Richard M. Stallman <rms@gnu.org>
parents:
8002
diff
changeset
|
98 (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
|
99 (setcar scan (concat variable "=" value))) |
a86eceda6537
(setenv): Rewrite. Provide a way to unset interactively.
Richard M. Stallman <rms@gnu.org>
parents:
8002
diff
changeset
|
100 (setq scan nil))) |
a86eceda6537
(setenv): Rewrite. Provide a way to unset interactively.
Richard M. Stallman <rms@gnu.org>
parents:
8002
diff
changeset
|
101 (setq scan (cdr scan))) |
a86eceda6537
(setenv): Rewrite. Provide a way to unset interactively.
Richard M. Stallman <rms@gnu.org>
parents:
8002
diff
changeset
|
102 (or found |
a86eceda6537
(setenv): Rewrite. Provide a way to unset interactively.
Richard M. Stallman <rms@gnu.org>
parents:
8002
diff
changeset
|
103 (if value |
8002
f8c8bbeca971
(setenv): Do something even if process-environment is nil.
Richard M. Stallman <rms@gnu.org>
parents:
3667
diff
changeset
|
104 (setq process-environment |
8004
a86eceda6537
(setenv): Rewrite. Provide a way to unset interactively.
Richard M. Stallman <rms@gnu.org>
parents:
8002
diff
changeset
|
105 (cons (concat variable "=" value) |
a86eceda6537
(setenv): Rewrite. Provide a way to unset interactively.
Richard M. Stallman <rms@gnu.org>
parents:
8002
diff
changeset
|
106 process-environment))))))) |
584 | 107 |
2403
05d8916e4cde
renamed to env.el; changed setenv to putenv.
Noah Friedman <friedman@splode.com>
parents:
2315
diff
changeset
|
108 (provide 'env) |
05d8916e4cde
renamed to env.el; changed setenv to putenv.
Noah Friedman <friedman@splode.com>
parents:
2315
diff
changeset
|
109 |
05d8916e4cde
renamed to env.el; changed setenv to putenv.
Noah Friedman <friedman@splode.com>
parents:
2315
diff
changeset
|
110 ;;; env.el ends here |