From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Kevin Rodgers Newsgroups: gmane.emacs.help Subject: Re: How to circumvent warning in batch mode Date: Fri, 09 Oct 2009 07:43:40 -0600 Message-ID: References: <5ebdc222-a8b5-4eed-9481-39b813da5f1c@j28g2000vbl.googlegroups.com> NNTP-Posting-Host: lo.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-Trace: ger.gmane.org 1255095886 25508 80.91.229.12 (9 Oct 2009 13:44:46 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Fri, 9 Oct 2009 13:44:46 +0000 (UTC) To: help-gnu-emacs@gnu.org Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Fri Oct 09 15:44:35 2009 Return-path: Envelope-to: geh-help-gnu-emacs@m.gmane.org Original-Received: from lists.gnu.org ([199.232.76.165]) by lo.gmane.org with esmtp (Exim 4.50) id 1MwFlp-0000l1-NY for geh-help-gnu-emacs@m.gmane.org; Fri, 09 Oct 2009 15:44:34 +0200 Original-Received: from localhost ([127.0.0.1]:39171 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1MwFlo-0001O7-Nh for geh-help-gnu-emacs@m.gmane.org; Fri, 09 Oct 2009 09:44:32 -0400 Original-Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1MwFlL-0001LV-Hu for help-gnu-emacs@gnu.org; Fri, 09 Oct 2009 09:44:03 -0400 Original-Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1MwFlG-0001BZ-UM for help-gnu-emacs@gnu.org; Fri, 09 Oct 2009 09:44:02 -0400 Original-Received: from [199.232.76.173] (port=48926 helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1MwFlG-0001BI-JM for help-gnu-emacs@gnu.org; Fri, 09 Oct 2009 09:43:58 -0400 Original-Received: from lo.gmane.org ([80.91.229.12]:55095) by monty-python.gnu.org with esmtps (TLS-1.0:RSA_AES_256_CBC_SHA1:32) (Exim 4.60) (envelope-from ) id 1MwFlF-0001E0-W4 for help-gnu-emacs@gnu.org; Fri, 09 Oct 2009 09:43:58 -0400 Original-Received: from list by lo.gmane.org with local (Exim 4.50) id 1MwFlC-0000OJ-IJ for help-gnu-emacs@gnu.org; Fri, 09 Oct 2009 15:43:54 +0200 Original-Received: from c-71-237-24-138.hsd1.co.comcast.net ([71.237.24.138]) by main.gmane.org with esmtp (Gmexim 0.1 (Debian)) id 1AlnuQ-0007hv-00 for ; Fri, 09 Oct 2009 15:43:54 +0200 Original-Received: from kevin.d.rodgers by c-71-237-24-138.hsd1.co.comcast.net with local (Gmexim 0.1 (Debian)) id 1AlnuQ-0007hv-00 for ; Fri, 09 Oct 2009 15:43:54 +0200 X-Injected-Via-Gmane: http://gmane.org/ Original-Lines: 63 Original-X-Complaints-To: usenet@ger.gmane.org X-Gmane-NNTP-Posting-Host: c-71-237-24-138.hsd1.co.comcast.net User-Agent: Thunderbird 2.0.0.23 (Macintosh/20090812) In-Reply-To: <5ebdc222-a8b5-4eed-9481-39b813da5f1c@j28g2000vbl.googlegroups.com> X-detected-operating-system: by monty-python.gnu.org: GNU/Linux 2.6 (newer, 3) X-BeenThere: help-gnu-emacs@gnu.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Users list for the GNU Emacs text editor List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Original-Sender: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Errors-To: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.help:68791 Archived-At: Decebal wrote: > I have the following code: > emacs -batch -nw --eval=' > (let ( > (match-length) > (reg-exp "^ +") > (substitute-str "@") > ) > (find-file "input") > (goto-char (point-min)) > (while (re-search-forward "^ +" nil t) > (setq match-length (- (point) (match-beginning 0))) > (while (> match-length (length substitute-str)) > (setq substitute-str (concat substitute-str substitute-str))) > (replace-match (substring substitute-str 0 match-length)) > ) > (write-file "outputEmacs") > ) > ' > I have severall questions about it. > The input file is quite big and I get: > File input is large (31MB), really open? (y or n) > Is there a way to circumvent this? let-bind large-file-warning-threshold to nil around the call to find-file. > Is there a way to do this more efficient? This script needs about 20 > seconds. When doing it with a Perl script, it takes about 6 seconds. 1. Put the code in a file (FILE.el) and byte-compile it. Then instead of --eval 'CODE' on the command line, use --load FILE.elc 2. It looks like you are doing a lot of unnecessary string allocation with concat and substring: For every character after the first character in the match, you double the length of the replacement string until it is at least as long as the length of the match string, then you only use the number of characters that were in the match string anyway. Change the loop to: (while (re-search-forward "^ +" nil t) (setq match-length (- (point) (match-beginning 0))) (if (> match-length 1) (replace-match (make-string match-length ?@)) (replace-match "@"))) That could be improved further by caching each replacement string of length > 1, so it is only allocated once... But now, I can see that my version using make-string does the same amount of string allocation as yours using substring, and that your use of concat is infrequent (only needed when the match string jumps to a larger length than has been seen so far). So caching the replacement string (in an array, indexed by its length) is the way to go. > Instead of the '@' or chr$(64) I would like to use a nbsp or chr > $(160). But then the script needs almost 3 minutes. Also every space > is replaced by two characters chr$(194) + chr$(160). > What is going wrong here? In UTF-8, NBSP is 2 bytes: decimal 194 160 aka hex 00C2 00A0. -- Kevin Rodgers Denver, Colorado, USA