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: simple useful functions Date: Thu, 28 Oct 2010 11:56:15 -0700 Organization: Sony Electronics Inc. Message-ID: <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 1288294885 19897 80.91.229.12 (28 Oct 2010 19:41:25 GMT) X-Complaints-To: usenet@dough.gmane.org NNTP-Posting-Date: Thu, 28 Oct 2010 19:41:25 +0000 (UTC) To: Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Thu Oct 28 21:41:22 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 1PBYLc-0004oY-MW for ged-emacs-devel@m.gmane.org; Thu, 28 Oct 2010 21:41:16 +0200 Original-Received: from localhost ([127.0.0.1]:57450 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1PBYGt-0006CB-1Z for ged-emacs-devel@m.gmane.org; Thu, 28 Oct 2010 15:36:23 -0400 Original-Received: from [140.186.70.92] (port=60923 helo=eggs.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1PBY5l-00021m-Od for emacs-devel@gnu.org; Thu, 28 Oct 2010 15:24:59 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1PBXe8-0007bZ-II for emacs-devel@gnu.org; Thu, 28 Oct 2010 14:56:21 -0400 Original-Received: from am1ehsobe002.messaging.microsoft.com ([213.199.154.205]:27551 helo=AM1EHSOBE002.bigfish.com) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1PBXe8-0007bS-8d for emacs-devel@gnu.org; Thu, 28 Oct 2010 14:56:20 -0400 Original-Received: from mail16-am1-R.bigfish.com (10.3.201.254) by AM1EHSOBE002.bigfish.com (10.3.204.22) with Microsoft SMTP Server id 14.1.225.8; Thu, 28 Oct 2010 18:56:18 +0000 Original-Received: from mail16-am1 (localhost.localdomain [127.0.0.1]) by mail16-am1-R.bigfish.com (Postfix) with ESMTP id 9A4BA50306 for ; Thu, 28 Oct 2010 18:56:18 +0000 (UTC) X-SpamScore: 4 X-BigFish: VPS4(z33fclzzz1202hzzz2fh2a8h64h) 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 mail16-am1 (localhost.localdomain [127.0.0.1]) by mail16-am1 (MessageSwitch) id 1288292178212165_20535; Thu, 28 Oct 2010 18:56:18 +0000 (UTC) Original-Received: from AM1EHSMHS007.bigfish.com (unknown [10.3.201.249]) by mail16-am1.bigfish.com (Postfix) with ESMTP id 305A61BC0052 for ; Thu, 28 Oct 2010 18:56:18 +0000 (UTC) Original-Received: from mail7.fw-bc.sony.com (160.33.98.74) by AM1EHSMHS007.bigfish.com (10.3.207.107) with Microsoft SMTP Server (TLS) id 14.1.225.8; Thu, 28 Oct 2010 18:56:15 +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 o9SIuDGI024302 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=FAIL) for ; Thu, 28 Oct 2010 18:56:13 GMT Original-Received: from localhost (tak-vaio-z790.am.sony.com [43.191.18.92]) by mail1x.bc.in.sel.sony.com (Switch-3.4.2/Switch-3.4.2) with ESMTP id o9SIuCmZ029578 for ; Thu, 28 Oct 2010 18:56:12 GMT X-Telephone: +1-858-942-3239 X-Fax------: +1-858-942-9142 X-SnailMail: 16530 Via Esprillo, MZ7205, San Diego, CA 92127 X-Mailer: Mew-6.3.50 on Emacs-23.2.1 (i386-mingw-nt6.1.7600 built on 2010-06-30) 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:132165 Archived-At: 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)))))