Mercurial > hg > xemacs-beta
diff lisp/process.el @ 771:943eaba38521
[xemacs-hg @ 2002-03-13 08:51:24 by ben]
The big ben-mule-21-5 check-in!
Various files were added and deleted. See CHANGES-ben-mule.
There are still some test suite failures. No crashes, though.
Many of the failures have to do with problems in the test suite itself
rather than in the actual code. I'll be addressing these in the next
day or so -- none of the test suite failures are at all critical.
Meanwhile I'll be trying to address the biggest issues -- i.e. build
or run failures, which will almost certainly happen on various platforms.
All comments should be sent to ben@xemacs.org -- use a Cc: if necessary
when sending to mailing lists. There will be pre- and post- tags,
something like
pre-ben-mule-21-5-merge-in, and
post-ben-mule-21-5-merge-in.
author | ben |
---|---|
date | Wed, 13 Mar 2002 08:54:06 +0000 |
parents | 38db05db9cb5 |
children | 79940b592197 |
line wrap: on
line diff
--- a/lisp/process.el Fri Mar 08 13:33:14 2002 +0000 +++ b/lisp/process.el Wed Mar 13 08:54:06 2002 +0000 @@ -1,7 +1,7 @@ ;;; process.el --- commands for subprocesses; split out of simple.el ;; Copyright (C) 1985-7, 1993,4, 1997 Free Software Foundation, Inc. -;; Copyright (C) 1995, 2000 Ben Wing. +;; Copyright (C) 1995, 2000, 2001 Ben Wing. ;; Author: Ben Wing ;; Maintainer: XEmacs Development Team @@ -24,7 +24,8 @@ ;; Free Software Foundation, 59 Temple Place - Suite 330, ;; Boston, MA 02111-1307, USA. -;;; Synched up with: FSF 19.30. +;;; Synched up with: FSF 19.30, except for setenv/getenv (synched with FSF +;;; 21.0.105). ;;; Authorship: @@ -465,5 +466,84 @@ (call-process shell-file-name nil t nil shell-command-switch command))) (defalias 'exec-to-string 'shell-command-to-string) + + +;; History list for environment variable names. +(defvar read-envvar-name-history nil) + +(defun read-envvar-name (prompt &optional mustmatch) + "Read environment variable name, prompting with PROMPT. +Optional second arg MUSTMATCH, if non-nil, means require existing envvar name. +If it is also not t, RET does not exit if it does non-null completion." + (completing-read prompt + (mapcar (function + (lambda (enventry) + (list (substring enventry 0 + (string-match "=" enventry))))) + process-environment) + nil mustmatch nil 'read-envvar-name-history)) + +;; History list for VALUE argument to setenv. +(defvar setenv-history nil) + +(defun setenv (variable &optional value unset) + "Set the value of the environment variable named VARIABLE to VALUE. +VARIABLE should be a string. VALUE is optional; if not provided or is +`nil', the environment variable VARIABLE will be removed. + +Interactively, a prefix argument means to unset the variable. +Interactively, the current value (if any) of the variable +appears at the front of the history list when you type in the new value. + +This function works by modifying `process-environment'." + (interactive + (if current-prefix-arg + (list (read-envvar-name "Clear environment variable: " 'exact) nil t) + (let ((var (read-envvar-name "Set environment variable: " nil))) + ;; Here finally we specify the args to call setenv with. + (list var (read-from-minibuffer (format "Set %s to value: " var) + nil nil nil 'setenv-history + (getenv var)))))) + (if unset (setq value nil)) + (if (string-match "=" variable) + (error "Environment variable name `%s' contains `='" variable) + (let ((pattern (concat "\\`" (regexp-quote (concat variable "=")))) + (case-fold-search nil) + (scan process-environment) + found) + (if (string-equal "TZ" variable) + (set-time-zone-rule value)) + (while scan + (cond ((string-match pattern (car scan)) + (setq found t) + (if (eq nil value) + (setq process-environment (delq (car scan) process-environment)) + (setcar scan (concat variable "=" value))) + (setq scan nil))) + (setq scan (cdr scan))) + (or found + (if value + (setq process-environment + (cons (concat variable "=" value) + process-environment))))))) + +;; already in C. Can't move it to Lisp too easily because it's needed +;; extremely early in the Lisp loadup sequence. + +; (defun getenv (variable) +; "Get the value of environment variable VARIABLE. +; VARIABLE should be a string. Value is nil if VARIABLE is undefined in +; the environment. Otherwise, value is a string. +; +; This function consults the variable `process-environment' +; for its value." +; (interactive (list (read-envvar-name "Get environment variable: " t))) +; (let ((value (getenv-internal variable))) +; (when (interactive-p) +; (message "%s" (if value value "Not set"))) +; value)) + +(provide 'env) ;; Yuck. Formerly the above were in env.el, which did this + ;; provide. ;;; process.el ends here