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 15:37:10 -0800 Message-ID: <20101203.153710.363898753.Takaaki.Ota@am.sony.com> References: <20101028.115615.04128253.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 1291419441 9317 80.91.229.12 (3 Dec 2010 23:37:21 GMT) X-Complaints-To: usenet@dough.gmane.org NNTP-Posting-Date: Fri, 3 Dec 2010 23:37:21 +0000 (UTC) To: Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Sat Dec 04 00:37:17 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 1POfBj-00079V-Vr for ged-emacs-devel@m.gmane.org; Sat, 04 Dec 2010 00:37:17 +0100 Original-Received: from localhost ([127.0.0.1]:57149 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1POfBj-0002SM-9F for ged-emacs-devel@m.gmane.org; Fri, 03 Dec 2010 18:37:15 -0500 Original-Received: from [140.186.70.92] (port=34480 helo=eggs.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1POfBc-0002Ro-PJ for emacs-devel@gnu.org; Fri, 03 Dec 2010 18:37:09 -0500 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1POfBb-0004P2-H5 for emacs-devel@gnu.org; Fri, 03 Dec 2010 18:37:08 -0500 Original-Received: from tx2ehsobe003.messaging.microsoft.com ([65.55.88.13]:29715 helo=TX2EHSOBE005.bigfish.com) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1POfBb-0004Oy-9n for emacs-devel@gnu.org; Fri, 03 Dec 2010 18:37:07 -0500 Original-Received: from mail150-tx2-R.bigfish.com (10.9.14.249) by TX2EHSOBE005.bigfish.com (10.9.40.25) with Microsoft SMTP Server id 14.1.225.8; Fri, 3 Dec 2010 23:37:06 +0000 Original-Received: from mail150-tx2 (localhost.localdomain [127.0.0.1]) by mail150-tx2-R.bigfish.com (Postfix) with ESMTP id 0D29A6485E5 for ; Fri, 3 Dec 2010 23:37:06 +0000 (UTC) X-SpamScore: -12 X-BigFish: VPS-12(zz1432N98dNzz1202hzz8275bhz2fh2a8h668h) 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 mail150-tx2 (localhost.localdomain [127.0.0.1]) by mail150-tx2 (MessageSwitch) id 1291419425727744_15542; Fri, 3 Dec 2010 23:37:05 +0000 (UTC) Original-Received: from TX2EHSMHS018.bigfish.com (unknown [10.9.14.249]) by mail150-tx2.bigfish.com (Postfix) with ESMTP id 771A317D804F for ; Fri, 3 Dec 2010 23:37:05 +0000 (UTC) Original-Received: from mail7.fw-bc.sony.com (160.33.98.74) by TX2EHSMHS018.bigfish.com (10.9.99.118) with Microsoft SMTP Server (TLS) id 14.1.225.8; Fri, 3 Dec 2010 23:37:05 +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 oB3Nb38S001604 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=FAIL) for ; Fri, 3 Dec 2010 23:37:04 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 oB3Nb3cC027130 for ; Fri, 3 Dec 2010 23:37:03 GMT In-Reply-To: <20101028.115615.04128253.Takaaki.Ota@am.sony.com> 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:133379 Archived-At: Now `collect-string' seems to have found an appropriate place to fit in `occur' can we revisit `source' command? It would be useful if this is a part of shell.el or somewhere with more appropriate name. -Tak Thu, 28 Oct 2010 11:56:15 -0700: Tak Ota wrote: > If you think the following two functions are universally useful please > consider incorporating them in simple.el or any appropriate package. > If not disregard. > > -Tak > > (defun collect-string (regexp &optional num) > "Collect strings of REGEXP (or optional NUM paren) from the > current buffer into a collection buffer." > (interactive "sCollect string (regexp): \nP") > (let ((collection-buffer > (get-buffer-create (format "*Collection of \"%s\" *" regexp)))) > (with-current-buffer collection-buffer (erase-buffer)) > (save-excursion > (goto-char (point-min)) > (while (re-search-forward regexp nil t) > (let ((str (match-string (or num 0)))) > (if str > (with-current-buffer collection-buffer > (insert str) > (or (zerop (current-column)) > (insert "\n"))))))) > (pop-to-buffer collection-buffer) > (goto-char (point-min)))) > > (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)))))