comparison 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
comparison
equal deleted inserted replaced
770:336a418893b5 771:943eaba38521
1 ;;; process.el --- commands for subprocesses; split out of simple.el 1 ;;; process.el --- commands for subprocesses; split out of simple.el
2 2
3 ;; Copyright (C) 1985-7, 1993,4, 1997 Free Software Foundation, Inc. 3 ;; Copyright (C) 1985-7, 1993,4, 1997 Free Software Foundation, Inc.
4 ;; Copyright (C) 1995, 2000 Ben Wing. 4 ;; Copyright (C) 1995, 2000, 2001 Ben Wing.
5 5
6 ;; Author: Ben Wing 6 ;; Author: Ben Wing
7 ;; Maintainer: XEmacs Development Team 7 ;; Maintainer: XEmacs Development Team
8 ;; Keywords: internal, processes, dumped 8 ;; Keywords: internal, processes, dumped
9 9
22 ;; You should have received a copy of the GNU General Public License 22 ;; You should have received a copy of the GNU General Public License
23 ;; along with XEmacs; see the file COPYING. If not, write to the 23 ;; along with XEmacs; see the file COPYING. If not, write to the
24 ;; Free Software Foundation, 59 Temple Place - Suite 330, 24 ;; Free Software Foundation, 59 Temple Place - Suite 330,
25 ;; Boston, MA 02111-1307, USA. 25 ;; Boston, MA 02111-1307, USA.
26 26
27 ;;; Synched up with: FSF 19.30. 27 ;;; Synched up with: FSF 19.30, except for setenv/getenv (synched with FSF
28 ;;; 21.0.105).
28 29
29 ;;; Authorship: 30 ;;; Authorship:
30 31
31 ;; Created 1995 by Ben Wing during Mule work -- some commands split out 32 ;; Created 1995 by Ben Wing during Mule work -- some commands split out
32 ;; of simple.el and wrappers of *-internal functions created so they could 33 ;; of simple.el and wrappers of *-internal functions created so they could
463 "Execute shell command COMMAND and return its output as a string." 464 "Execute shell command COMMAND and return its output as a string."
464 (with-output-to-string 465 (with-output-to-string
465 (call-process shell-file-name nil t nil shell-command-switch command))) 466 (call-process shell-file-name nil t nil shell-command-switch command)))
466 467
467 (defalias 'exec-to-string 'shell-command-to-string) 468 (defalias 'exec-to-string 'shell-command-to-string)
469
470
471 ;; History list for environment variable names.
472 (defvar read-envvar-name-history nil)
473
474 (defun read-envvar-name (prompt &optional mustmatch)
475 "Read environment variable name, prompting with PROMPT.
476 Optional second arg MUSTMATCH, if non-nil, means require existing envvar name.
477 If it is also not t, RET does not exit if it does non-null completion."
478 (completing-read prompt
479 (mapcar (function
480 (lambda (enventry)
481 (list (substring enventry 0
482 (string-match "=" enventry)))))
483 process-environment)
484 nil mustmatch nil 'read-envvar-name-history))
485
486 ;; History list for VALUE argument to setenv.
487 (defvar setenv-history nil)
488
489 (defun setenv (variable &optional value unset)
490 "Set the value of the environment variable named VARIABLE to VALUE.
491 VARIABLE should be a string. VALUE is optional; if not provided or is
492 `nil', the environment variable VARIABLE will be removed.
493
494 Interactively, a prefix argument means to unset the variable.
495 Interactively, the current value (if any) of the variable
496 appears at the front of the history list when you type in the new value.
497
498 This function works by modifying `process-environment'."
499 (interactive
500 (if current-prefix-arg
501 (list (read-envvar-name "Clear environment variable: " 'exact) nil t)
502 (let ((var (read-envvar-name "Set environment variable: " nil)))
503 ;; Here finally we specify the args to call setenv with.
504 (list var (read-from-minibuffer (format "Set %s to value: " var)
505 nil nil nil 'setenv-history
506 (getenv var))))))
507 (if unset (setq value nil))
508 (if (string-match "=" variable)
509 (error "Environment variable name `%s' contains `='" variable)
510 (let ((pattern (concat "\\`" (regexp-quote (concat variable "="))))
511 (case-fold-search nil)
512 (scan process-environment)
513 found)
514 (if (string-equal "TZ" variable)
515 (set-time-zone-rule value))
516 (while scan
517 (cond ((string-match pattern (car scan))
518 (setq found t)
519 (if (eq nil value)
520 (setq process-environment (delq (car scan) process-environment))
521 (setcar scan (concat variable "=" value)))
522 (setq scan nil)))
523 (setq scan (cdr scan)))
524 (or found
525 (if value
526 (setq process-environment
527 (cons (concat variable "=" value)
528 process-environment)))))))
529
530 ;; already in C. Can't move it to Lisp too easily because it's needed
531 ;; extremely early in the Lisp loadup sequence.
532
533 ; (defun getenv (variable)
534 ; "Get the value of environment variable VARIABLE.
535 ; VARIABLE should be a string. Value is nil if VARIABLE is undefined in
536 ; the environment. Otherwise, value is a string.
537 ;
538 ; This function consults the variable `process-environment'
539 ; for its value."
540 ; (interactive (list (read-envvar-name "Get environment variable: " t)))
541 ; (let ((value (getenv-internal variable)))
542 ; (when (interactive-p)
543 ; (message "%s" (if value value "Not set")))
544 ; value))
545
546 (provide 'env) ;; Yuck. Formerly the above were in env.el, which did this
547 ;; provide.
468 548
469 ;;; process.el ends here 549 ;;; process.el ends here