From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Tak Ota Newsgroups: gmane.emacs.devel Subject: Re: simple useful functions Date: Fri, 3 Dec 2010 18:58:02 -0800 Message-ID: <20101203.185802.425329138.Takaaki.Ota@am.sony.com> References: <20101028.115615.04128253.Takaaki.Ota@am.sony.com> <20101203.153710.363898753.Takaaki.Ota@am.sony.com> NNTP-Posting-Host: lo.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit X-Trace: dough.gmane.org 1291431495 17422 80.91.229.12 (4 Dec 2010 02:58:15 GMT) X-Complaints-To: usenet@dough.gmane.org NNTP-Posting-Date: Sat, 4 Dec 2010 02:58:15 +0000 (UTC) Cc: emacs-devel@gnu.org To: Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Sat Dec 04 03:58:08 2010 Return-path: Envelope-to: ged-emacs-devel@m.gmane.org Original-Received: from lists.gnu.org ([199.232.76.165]) by lo.gmane.org with esmtp (Exim 4.69) (envelope-from ) id 1POiK7-0001fh-Fh for ged-emacs-devel@m.gmane.org; Sat, 04 Dec 2010 03:58:07 +0100 Original-Received: from localhost ([127.0.0.1]:50830 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1POiK6-0002Ik-NG for ged-emacs-devel@m.gmane.org; Fri, 03 Dec 2010 21:58:06 -0500 Original-Received: from [140.186.70.92] (port=33791 helo=eggs.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1POiK1-0002I4-5I for emacs-devel@gnu.org; Fri, 03 Dec 2010 21:58:02 -0500 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1POiK0-0006Jt-2i for emacs-devel@gnu.org; Fri, 03 Dec 2010 21:58:01 -0500 Original-Received: from db3ehsobe001.messaging.microsoft.com ([213.199.154.139]:57158 helo=DB3EHSOBE001.bigfish.com) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1POiJz-0006Jn-Lv for emacs-devel@gnu.org; Fri, 03 Dec 2010 21:58:00 -0500 Original-Received: from mail34-db3-R.bigfish.com (10.3.81.243) by DB3EHSOBE001.bigfish.com (10.3.84.21) with Microsoft SMTP Server id 14.1.225.8; Sat, 4 Dec 2010 02:57:58 +0000 Original-Received: from mail34-db3 (localhost.localdomain [127.0.0.1]) by mail34-db3-R.bigfish.com (Postfix) with ESMTP id 06E523C82CC; Sat, 4 Dec 2010 02:57:58 +0000 (UTC) X-SpamScore: -25 X-BigFish: VPS-25(zz1102K1432N98dN1447Rzz1202hzzz2fh2a8h668h61h) X-Forefront-Antispam-Report: KIP:(null); UIP:(null); IPVD:NLI; H:mail7.fw-bc.sony.com; RD:mail7.fw-bc.sony.com; EFVD:NLI Original-Received: from mail34-db3 (localhost.localdomain [127.0.0.1]) by mail34-db3 (MessageSwitch) id 1291431477558476_14946; Sat, 4 Dec 2010 02:57:57 +0000 (UTC) Original-Received: from DB3EHSMHS010.bigfish.com (unknown [10.3.81.253]) by mail34-db3.bigfish.com (Postfix) with ESMTP id 85E541B4804F; Sat, 4 Dec 2010 02:57:57 +0000 (UTC) Original-Received: from mail7.fw-bc.sony.com (160.33.98.74) by DB3EHSMHS010.bigfish.com (10.3.87.110) with Microsoft SMTP Server (TLS) id 14.1.225.8; Sat, 4 Dec 2010 02:57:57 +0000 Original-Received: from mail1x.bc.in.sel.sony.com ([43.144.65.112]) by mail7.fw-bc.sony.com (Switch-3.4.2/Switch-3.3.2mp) with ESMTP id oB42vthr015560 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=FAIL); Sat, 4 Dec 2010 02:57:55 GMT Original-Received: from localhost (tak-vaio-z1290-043191017095.am.sony.com [43.191.17.95]) by mail1x.bc.in.sel.sony.com (Switch-3.4.2/Switch-3.4.2) with ESMTP id oB42vsum017376; Sat, 4 Dec 2010 02:57:55 GMT In-Reply-To: X-Mailer: Mew-6.3.50 on Emacs-23.2.90.1 (i386-mingw-nt6.1.7600 built on 2010-11-22) X-OriginatorOrg: am.sony.com X-detected-operating-system: by eggs.gnu.org: Windows 2000 SP2+, XP SP1+ (seldom 98) 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:133387 Archived-At: Fri, 3 Dec 2010 18:36:31 -0800: Stefan Monnier wrote: > > (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))))) > > Some problems I see with it, by order of decreasing importance: > - I fail to see in which circumstance(s) this is useful. OK, I see this may not be useful for everybody. The reason I wrote this command was to support embedded software development. In embedded development work we are usually required to use some cross compilation tools. Such tools often come with a setup script which includes setting up necessary environment variables for command paths and library paths. In order to compile software in this environment from emacs I need to start emacs from the shell that has run the script. But to me emacs is not a text editor but a working environment. I don't want to kill the current emacs or start another emacs for this purpose. My emacs has been running before running the script. I take care of shell needs from inferior shell. But running the setup script from an inferior shell doesn't help. Therefore this command became handy. After writing this up I now realize it is useful for minority groups. Thanks for the comments anyway. -Tak > - What if the user uses scsh/emacs for his shell. > - Most scripts don't setup much of environment. > - AFAIC things like ~/.cshrc are not a scripts but a config files. > - The call-process needs to quote `script' (and should probably be > replaced by process-file). > - The prompt should start with a capital. > > > Stefan >