annotate lisp/env.el @ 8178:bd5b4c5dda7f

(msdos): Include sed4.inp in dist.
author Richard M. Stallman <rms@gnu.org>
date Thu, 07 Jul 1994 21:06:41 +0000
parents 12f59aa8e26d
children 8f05784959cc
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
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
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
489
3d2d0362a496 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
8 ;;; This file is part of GNU Emacs.
3d2d0362a496 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
9
3d2d0362a496 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
10 ;;; GNU Emacs is free software; you can redistribute it and/or modify
3d2d0362a496 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
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
3d2d0362a496 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
13 ;;; any later version.
3d2d0362a496 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
14
3d2d0362a496 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
15 ;;; GNU Emacs is distributed in the hope that it will be useful,
3d2d0362a496 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
16 ;;; but WITHOUT ANY WARRANTY; without even the implied warranty of
3d2d0362a496 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
17 ;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
3d2d0362a496 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
18 ;;; GNU General Public License for more details.
3d2d0362a496 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
19
3d2d0362a496 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
20 ;;; You should have received a copy of the GNU General Public License
3d2d0362a496 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
21 ;;; along with GNU Emacs; see the file COPYING. If not, write to
3d2d0362a496 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
22 ;;; the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
3d2d0362a496 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
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
1218
678ff000d9c8 (setenv): Make it autoload.
Richard M. Stallman <rms@gnu.org>
parents: 1216
diff changeset
33 ;;;###autoload
8004
a86eceda6537 (setenv): Rewrite. Provide a way to unset interactively.
Richard M. Stallman <rms@gnu.org>
parents: 8002
diff changeset
34 (defun setenv (variable &optional value unset)
489
3d2d0362a496 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
35 "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
36 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
37 `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
38
a86eceda6537 (setenv): Rewrite. Provide a way to unset interactively.
Richard M. Stallman <rms@gnu.org>
parents: 8002
diff changeset
39 Interactively, a prefix argument means to unset the variable.
1216
6a8704922fe8 Doc fix.
Richard M. Stallman <rms@gnu.org>
parents: 1185
diff changeset
40 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
41 (interactive
a86eceda6537 (setenv): Rewrite. Provide a way to unset interactively.
Richard M. Stallman <rms@gnu.org>
parents: 8002
diff changeset
42 (if current-prefix-arg
a86eceda6537 (setenv): Rewrite. Provide a way to unset interactively.
Richard M. Stallman <rms@gnu.org>
parents: 8002
diff changeset
43 (list (read-string "Clear environment variable: ") nil t)
a86eceda6537 (setenv): Rewrite. Provide a way to unset interactively.
Richard M. Stallman <rms@gnu.org>
parents: 8002
diff changeset
44 (let ((var (read-string "Set environment variable: ")))
a86eceda6537 (setenv): Rewrite. Provide a way to unset interactively.
Richard M. Stallman <rms@gnu.org>
parents: 8002
diff changeset
45 (list var (read-string (format "Set %s to value: " var))))))
a86eceda6537 (setenv): Rewrite. Provide a way to unset interactively.
Richard M. Stallman <rms@gnu.org>
parents: 8002
diff changeset
46 (if unset (setq value nil))
489
3d2d0362a496 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
47 (if (string-match "=" variable)
2403
05d8916e4cde renamed to env.el; changed setenv to putenv.
Noah Friedman <friedman@splode.com>
parents: 2315
diff changeset
48 (error "Environment variable name `%s' contains `='" variable)
1185
4ec50a934e54 entered into RCS
Eric S. Raymond <esr@snark.thyrsus.com>
parents: 814
diff changeset
49 (let ((pattern (concat "\\`" (regexp-quote (concat variable "="))))
3667
f4a7ac2ec651 (setenv): Treat case as significant.
Richard M. Stallman <rms@gnu.org>
parents: 2410
diff changeset
50 (case-fold-search nil)
8004
a86eceda6537 (setenv): Rewrite. Provide a way to unset interactively.
Richard M. Stallman <rms@gnu.org>
parents: 8002
diff changeset
51 (scan process-environment)
a86eceda6537 (setenv): Rewrite. Provide a way to unset interactively.
Richard M. Stallman <rms@gnu.org>
parents: 8002
diff changeset
52 found)
a86eceda6537 (setenv): Rewrite. Provide a way to unset interactively.
Richard M. Stallman <rms@gnu.org>
parents: 8002
diff changeset
53 (while scan
a86eceda6537 (setenv): Rewrite. Provide a way to unset interactively.
Richard M. Stallman <rms@gnu.org>
parents: 8002
diff changeset
54 (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
55 (setq found t)
a86eceda6537 (setenv): Rewrite. Provide a way to unset interactively.
Richard M. Stallman <rms@gnu.org>
parents: 8002
diff changeset
56 (if (eq nil value)
a86eceda6537 (setenv): Rewrite. Provide a way to unset interactively.
Richard M. Stallman <rms@gnu.org>
parents: 8002
diff changeset
57 (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
58 (setcar scan (concat variable "=" value)))
a86eceda6537 (setenv): Rewrite. Provide a way to unset interactively.
Richard M. Stallman <rms@gnu.org>
parents: 8002
diff changeset
59 (setq scan nil)))
a86eceda6537 (setenv): Rewrite. Provide a way to unset interactively.
Richard M. Stallman <rms@gnu.org>
parents: 8002
diff changeset
60 (setq scan (cdr scan)))
a86eceda6537 (setenv): Rewrite. Provide a way to unset interactively.
Richard M. Stallman <rms@gnu.org>
parents: 8002
diff changeset
61 (or found
a86eceda6537 (setenv): Rewrite. Provide a way to unset interactively.
Richard M. Stallman <rms@gnu.org>
parents: 8002
diff changeset
62 (if value
8002
f8c8bbeca971 (setenv): Do something even if process-environment is nil.
Richard M. Stallman <rms@gnu.org>
parents: 3667
diff changeset
63 (setq process-environment
8004
a86eceda6537 (setenv): Rewrite. Provide a way to unset interactively.
Richard M. Stallman <rms@gnu.org>
parents: 8002
diff changeset
64 (cons (concat variable "=" value)
a86eceda6537 (setenv): Rewrite. Provide a way to unset interactively.
Richard M. Stallman <rms@gnu.org>
parents: 8002
diff changeset
65 process-environment)))))))
584
4cd7543be581 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 489
diff changeset
66
2403
05d8916e4cde renamed to env.el; changed setenv to putenv.
Noah Friedman <friedman@splode.com>
parents: 2315
diff changeset
67 (provide 'env)
05d8916e4cde renamed to env.el; changed setenv to putenv.
Noah Friedman <friedman@splode.com>
parents: 2315
diff changeset
68
05d8916e4cde renamed to env.el; changed setenv to putenv.
Noah Friedman <friedman@splode.com>
parents: 2315
diff changeset
69 ;;; env.el ends here