diff options
| author | Richard M. Stallman | 1997-08-22 23:37:38 +0000 |
|---|---|---|
| committer | Richard M. Stallman | 1997-08-22 23:37:38 +0000 |
| commit | c64d8c5548b574a0b075f54cca77d61e5cbcfc60 (patch) | |
| tree | 583835d72c15eec697c244b9fff5b3111f135d24 | |
| parent | e45502331b9c4073da3cc77418676798d32c59fe (diff) | |
| download | emacs-c64d8c5548b574a0b075f54cca77d61e5cbcfc60.tar.gz emacs-c64d8c5548b574a0b075f54cca77d61e5cbcfc60.zip | |
(shell-snarf-envar, shell-copy-environment-variable): New functions.
| -rw-r--r-- | lisp/shell.el | 31 |
1 files changed, 31 insertions, 0 deletions
diff --git a/lisp/shell.el b/lisp/shell.el index 9fbfd61e226..c28f1649eb6 100644 --- a/lisp/shell.el +++ b/lisp/shell.el | |||
| @@ -731,6 +731,37 @@ command again." | |||
| 731 | (setq ds (cdr ds)))) | 731 | (setq ds (cdr ds)))) |
| 732 | (message "%s" msg))) | 732 | (message "%s" msg))) |
| 733 | 733 | ||
| 734 | ;; This was mostly copied from shell-resync-dirs. | ||
| 735 | (defun shell-snarf-envar (var) | ||
| 736 | "Return as a string the shell's value of environment variable VAR." | ||
| 737 | (let* ((cmd (format "printenv '%s'\n" var)) | ||
| 738 | (proc (get-buffer-process (current-buffer))) | ||
| 739 | (pmark (process-mark proc))) | ||
| 740 | (goto-char pmark) | ||
| 741 | (insert cmd) | ||
| 742 | (sit-for 0) ; force redisplay | ||
| 743 | (comint-send-string proc cmd) | ||
| 744 | (set-marker pmark (point)) | ||
| 745 | (let ((pt (point))) ; wait for 1 line | ||
| 746 | ;; This extra newline prevents the user's pending input from spoofing us. | ||
| 747 | (insert "\n") (backward-char 1) | ||
| 748 | (while (not (looking-at ".+\n")) | ||
| 749 | (accept-process-output proc) | ||
| 750 | (goto-char pt))) | ||
| 751 | (goto-char pmark) (delete-char 1) ; remove the extra newline | ||
| 752 | (buffer-substring (match-beginning 0) (1- (match-end 0))))) | ||
| 753 | |||
| 754 | (defun shell-copy-environment-variable (variable) | ||
| 755 | "Copy the environment variable VARIABLE from the subshell to Emacs. | ||
| 756 | This command reads the value of the specified environment variable | ||
| 757 | in the shell, and sets the same environment variable in Emacs | ||
| 758 | \(what `getenv' in Emacvs would return) to that value. | ||
| 759 | That value will affect any new subprocesses that you subsequently start | ||
| 760 | from Emacs." | ||
| 761 | (interactive (list (read-envvar-name "\ | ||
| 762 | Copy Shell environment variable to Emacs: "))) | ||
| 763 | (setenv variable (shell-snarf-envar variable))) | ||
| 764 | |||
| 734 | (defun shell-forward-command (&optional arg) | 765 | (defun shell-forward-command (&optional arg) |
| 735 | "Move forward across ARG shell command(s). Does not cross lines. | 766 | "Move forward across ARG shell command(s). Does not cross lines. |
| 736 | See `shell-command-regexp'." | 767 | See `shell-command-regexp'." |