From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Stefan Monnier Newsgroups: gmane.emacs.devel Subject: Re: simple useful functions Date: Fri, 03 Dec 2010 21:36:31 -0500 Message-ID: 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 X-Trace: dough.gmane.org 1291430221 13884 80.91.229.12 (4 Dec 2010 02:37:01 GMT) X-Complaints-To: usenet@dough.gmane.org NNTP-Posting-Date: Sat, 4 Dec 2010 02:37:01 +0000 (UTC) Cc: emacs-devel@gnu.org To: Tak Ota Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Sat Dec 04 03:36:57 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 1POhzc-0004zX-DI for ged-emacs-devel@m.gmane.org; Sat, 04 Dec 2010 03:36:56 +0100 Original-Received: from localhost ([127.0.0.1]:58222 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1POhzb-0006Wa-QY for ged-emacs-devel@m.gmane.org; Fri, 03 Dec 2010 21:36:55 -0500 Original-Received: from [140.186.70.92] (port=43758 helo=eggs.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1POhzU-0006Vj-HU for emacs-devel@gnu.org; Fri, 03 Dec 2010 21:36:49 -0500 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1POhzT-0002cJ-9C for emacs-devel@gnu.org; Fri, 03 Dec 2010 21:36:48 -0500 Original-Received: from chene.dit.umontreal.ca ([132.204.246.20]:50139) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1POhzT-0002c5-6m for emacs-devel@gnu.org; Fri, 03 Dec 2010 21:36:47 -0500 Original-Received: from pastel.home (lechon.iro.umontreal.ca [132.204.27.242]) by chene.dit.umontreal.ca (8.14.1/8.14.1) with ESMTP id oB42aaas009975; Fri, 3 Dec 2010 21:36:36 -0500 Original-Received: by pastel.home (Postfix, from userid 20848) id C17E1A8364; Fri, 3 Dec 2010 21:36:31 -0500 (EST) In-Reply-To: <20101203.153710.363898753.Takaaki.Ota@am.sony.com> (Tak Ota's message of "Fri, 3 Dec 2010 15:37:10 -0800") User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/24.0.50 (gnu/linux) X-NAI-Spam-Score: 0 X-NAI-Spam-Rules: 1 Rules triggered RV3698=0 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6 (newer, 3) 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:133385 Archived-At: > (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. - 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