emacs-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: sourcing environment


From: Giorgos Keramidas
Subject: Re: sourcing environment
Date: Wed, 11 Oct 2006 23:22:11 +0300

On 2006-10-11 12:15, Tak Ota <address@hidden> wrote:
> Wed, 11 Oct 2006 22:00:12 +0300: Giorgos Keramidas <address@hidden> wrote:
> > > M-x kill-emacs
> > > $ source env-xxx.sh
> > > $ emacs
> > 
> > It looks like you would have to spawn a subshell, save its environment
> > somewhere, source the script, save the new environment, diff the two
> > environments and 'translate' the diff output to appropriate
> > 
> >     (setenv "FOO" "bar")
> > 
> > or
> > 
> >     (setenv "FOO" nil)
> > 
> > calls :(
> 
> That is pretty much what I do with the following function.  My
> question is if this equivalent feature is already available in any
> form in the current emacs?

I don't think so, but I don't know everything about Emacs :-/

> ;;
> ;; Shell Script Sourcing
> ;;
> (defun source (script &optional shell keep-current-directory)
>   "Source the specified shell script.
> Source the shell SCRIPT and import the environment into this
> emacs.  The optional SHELL specifies the shell other than the
> default `shell-file-name'.  When KEEP-CURRENT-DIRECTORY is nil,
> which is the default, the current directory is temporarily
> changed to the directory where the script resides while sourcing
> the script."
>   (interactive "fscript file: ")
>   (if (null shell)
>       (setq shell shell-file-name))
>   (with-temp-buffer
>     (unless keep-current-directory
>       (setq default-directory (file-name-directory script)))
>     (call-process shell nil t nil "-c" (concat "source " script "; printenv"))
>     (while (re-search-backward "^\\([^=]+\\)=\\(.*\\)$" nil t)
>       (setenv (match-string 1) (match-string 2)))))




reply via email to

[Prev in Thread] Current Thread [Next in Thread]