From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Giorgos Keramidas Newsgroups: gmane.emacs.devel Subject: Re: sourcing environment Date: Wed, 11 Oct 2006 23:22:11 +0300 Message-ID: <20061011202211.GA82982@gothmog.pc> References: <20061011.090745.01371169.Takaaki.Ota@am.sony.com> <20061011190012.GD64381@gothmog.pc> <20061011.121557.186976084.Takaaki.Ota@am.sony.com> NNTP-Posting-Host: main.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Trace: sea.gmane.org 1160598281 31806 80.91.229.2 (11 Oct 2006 20:24:41 GMT) X-Complaints-To: usenet@sea.gmane.org NNTP-Posting-Date: Wed, 11 Oct 2006 20:24:41 +0000 (UTC) Cc: stephen_leake@member.fsf.org, emacs-devel@gnu.org Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Wed Oct 11 22:24:38 2006 Return-path: Envelope-to: ged-emacs-devel@m.gmane.org Original-Received: from lists.gnu.org ([199.232.76.165]) by ciao.gmane.org with esmtp (Exim 4.43) id 1GXkb7-0001i5-P4 for ged-emacs-devel@m.gmane.org; Wed, 11 Oct 2006 22:22:38 +0200 Original-Received: from localhost ([127.0.0.1] helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1GXkb7-0004tx-6j for ged-emacs-devel@m.gmane.org; Wed, 11 Oct 2006 16:22:37 -0400 Original-Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1GXkar-0004sg-JN for emacs-devel@gnu.org; Wed, 11 Oct 2006 16:22:21 -0400 Original-Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1GXkaq-0004sI-20 for emacs-devel@gnu.org; Wed, 11 Oct 2006 16:22:21 -0400 Original-Received: from [199.232.76.173] (helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1GXkap-0004sA-Qx for emacs-devel@gnu.org; Wed, 11 Oct 2006 16:22:19 -0400 Original-Received: from [62.1.205.36] (helo=igloo.linux.gr) by monty-python.gnu.org with esmtps (TLS-1.0:DHE_RSA_AES_256_CBC_SHA:32) (Exim 4.52) id 1GXkil-0000Uz-1B; Wed, 11 Oct 2006 16:30:31 -0400 Original-Received: from gothmog.pc (host5.bedc.ondsl.gr [62.103.39.229]) (authenticated bits=128) by igloo.linux.gr (8.13.8/8.13.8/Debian-2) with ESMTP id k9BKLZMM030906 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NOT); Wed, 11 Oct 2006 23:21:41 +0300 Original-Received: from gothmog.pc (gothmog [127.0.0.1]) by gothmog.pc (8.13.8/8.13.8) with ESMTP id k9BKMCmO083015; Wed, 11 Oct 2006 23:22:13 +0300 (EEST) (envelope-from keramida@ceid.upatras.gr) Original-Received: (from giorgos@localhost) by gothmog.pc (8.13.8/8.13.8/Submit) id k9BKMBkI083014; Wed, 11 Oct 2006 23:22:11 +0300 (EEST) (envelope-from keramida@ceid.upatras.gr) Original-To: Tak Ota Content-Disposition: inline In-Reply-To: <20061011.121557.186976084.Takaaki.Ota@am.sony.com> X-Hellug-MailScanner: Found to be clean X-Hellug-MailScanner-SpamCheck: not spam, SpamAssassin (score=-2.594, required 5, AWL -0.20, BAYES_00 -2.60, DNS_FROM_RFC_ABUSE 0.20, UNPARSEABLE_RELAY 0.00) X-Hellug-MailScanner-From: keramida@ceid.upatras.gr X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: "Emacs development discussions." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Original-Sender: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Errors-To: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.devel:60619 Archived-At: On 2006-10-11 12:15, Tak Ota wrote: > Wed, 11 Oct 2006 22:00:12 +0300: Giorgos Keramidas 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)))))