comparison lisp/process.el @ 4327:466ad8ad5f13

Fix a #'setenv bug, merge other changes from GNU's env.el. 2007-12-14 Aidan Kehoe <kehoea@parhasard.net> * process.el (substitute-env-vars): Merge an example from GNU's docstring. * process.el (setenv): Pass nil as the default abbrev table to the #'read-from-minibuffer call, instead of passing the current value of the variable. Bug introduced by an incorrect sync from GNU by Ben; reported by Thomas Mittelstaedt in 47626712.40609@cadenas.de. Document the #'set-time-zone-rule call when TZ is set. Push the old value on to the beginning of setenv-history. (Both merged from GNU.) Document that we don't do the coding-system frobbing at this level that GNU does. Provide a commented-out, sample implementation of GNU's #'environment; document why I think we shouldn't include it.
author Aidan Kehoe <kehoea@parhasard.net>
date Fri, 14 Dec 2007 14:13:02 +0100
parents 81975997fb1a
children 38e8af61f38d
comparison
equal deleted inserted replaced
4326:a5ff7e67ac1b 4327:466ad8ad5f13
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, except for setenv/getenv (synched with FSF 27 ;;; Synched up with: FSF 19.30, except for setenv/getenv (synched with FSF
28 ;;; 21.0.105). 28 ;;; 21.2.1).
29 29
30 ;;; Authorship: 30 ;;; Authorship:
31 31
32 ;; 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
33 ;; 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
540 (defun substitute-env-vars (string) 540 (defun substitute-env-vars (string)
541 "Substitute environment variables referred to in STRING. 541 "Substitute environment variables referred to in STRING.
542 `$FOO' where FOO is an environment variable name means to substitute 542 `$FOO' where FOO is an environment variable name means to substitute
543 the value of that variable. The variable name should be terminated 543 the value of that variable. The variable name should be terminated
544 with a character not a letter, digit or underscore; otherwise, enclose 544 with a character not a letter, digit or underscore; otherwise, enclose
545 the entire variable name in braces. Use `$$' to insert a single 545 the entire variable name in braces. For instance, in `ab$cd-x',
546 dollar sign." 546 `$cd' is treated as an environment variable.
547
548 Use `$$' to insert a single dollar sign."
547 (let ((start 0)) 549 (let ((start 0))
548 (while (string-match 550 (while (string-match
549 ;; XEmacs change - FSF use their rx macro to generate this regexp 551 ;; XEmacs change - FSF use their rx macro to generate this regexp
550 "\\(?:\\$\\(\\(?:[a-zA-Z0-9_]\\)+\\)\\)\\|\\(?:\\${\\(\\(?:.\\|\n\\)*?\\)}\\)\\|\\$\\$" 552 "\\(?:\\$\\(\\(?:[a-zA-Z0-9_]\\)+\\)\\)\\|\\(?:\\${\\(\\(?:.\\|\n\\)*?\\)}\\)\\|\\$\\$"
551 string start) 553 string start)
573 575
574 Interactively, a prefix argument means to unset the variable. 576 Interactively, a prefix argument means to unset the variable.
575 Interactively, the current value (if any) of the variable 577 Interactively, the current value (if any) of the variable
576 appears at the front of the history list when you type in the new value. 578 appears at the front of the history list when you type in the new value.
577 579
578 This function works by modifying `process-environment'." 580 This function works by modifying `process-environment'.
581
582 As a special case, setting variable `TZ' calls `set-time-zone-rule' as
583 a side-effect."
579 (interactive 584 (interactive
580 (if current-prefix-arg 585 (if current-prefix-arg
581 (list (read-envvar-name "Clear environment variable: " 'exact) nil t) 586 (list (read-envvar-name "Clear environment variable: " 'exact) nil t)
582 (let ((var (read-envvar-name "Set environment variable: " nil))) 587 (let* ((var (read-envvar-name "Set environment variable: " nil))
588 (value (getenv var)))
589 (when value
590 (push value setenv-history))
583 ;; Here finally we specify the args to call setenv with. 591 ;; Here finally we specify the args to call setenv with.
584 (list var (read-from-minibuffer (format "Set %s to value: " var) 592 (list var (read-from-minibuffer (format "Set %s to value: " var)
585 nil nil nil 'setenv-history 593 nil nil nil 'setenv-history
586 (getenv var)))))) 594 ;; XEmacs change; don't specify a
595 ;; default. (Nor an abbrev table.)
596 )))))
587 (if unset 597 (if unset
588 (setq value nil) 598 (setq value nil)
589 (if substitute-env-vars 599 (if substitute-env-vars
590 (setq value (substitute-env-vars value)))) 600 (setq value (substitute-env-vars value))))
601
602 ;; GNU fuck around with coding systems here. We do it at a much lower
603 ;; level; an equivalent of the following code of Handa's would be
604 ;; worthwhile here, though:
605
606 ; (let ((codings (find-coding-systems-string (concat variable value))))
607 ; (unless (or (eq 'undecided (car codings))
608 ; (memq (coding-system-base locale-coding-system) codings))
609 ; (error "Can't encode `%s=%s' with `locale-coding-system'"
610 ; variable (or value "")))))
611
612 ;; But then right now our find-coding-systems analogue is in packages.
613
591 (if (string-match "=" variable) 614 (if (string-match "=" variable)
592 (error "Environment variable name `%s' contains `='" variable) 615 (error "Environment variable name `%s' contains `='" variable)
593 (let ((pattern (concat "\\`" (regexp-quote (concat variable "=")))) 616 (let ((pattern (concat "\\`" (regexp-quote (concat variable "="))))
594 (case-fold-search nil) 617 (case-fold-search nil)
595 (scan process-environment) 618 (scan process-environment)
624 ; (let ((value (getenv-internal variable))) 647 ; (let ((value (getenv-internal variable)))
625 ; (when (interactive-p) 648 ; (when (interactive-p)
626 ; (message "%s" (if value value "Not set"))) 649 ; (message "%s" (if value value "Not set")))
627 ; value)) 650 ; value))
628 651
652
653 ;; GNU have an #'environment function here, as of 2007-12-14. If someone
654 ;; actually uses it in the wild, this would suffice as an implementation:
655
656 ; (defun environment (&optional frame)
657 ; "Return a list of environment variables with their values.
658 ; Each entry in the list is a string of the form NAME=VALUE.
659 ;
660 ; Optional argument FRAME is ignored, for GNU compatibility.
661 ;
662 ; Non-ASCII characters look like Mojibake (that is, they are unreadable.)"
663 ; (loop
664 ; for entry in process-environment
665 ; collect (encode-coding-string entry 'native)))
666 ;
667
668 ;; but we shouldn't encourage that sort of ugliness and needless backwards
669 ;; incompatibility.
670
629 (provide 'env) ;; Yuck. Formerly the above were in env.el, which did this 671 (provide 'env) ;; Yuck. Formerly the above were in env.el, which did this
630 ;; provide. 672 ;; provide.
631 673
632 ;;; process.el ends here 674 ;;; process.el ends here