From mboxrd@z Thu Jan 1 00:00:00 1970 Path: main.gmane.org!not-for-mail From: Lawrence Mitchell Newsgroups: gmane.emacs.devel Subject: Patch for Re: bibtex-mode and "format region" incredibly slow Date: Sun, 11 Apr 2004 12:58:58 +0100 Organization: funfunfun Sender: emacs-devel-bounces+emacs-devel=quimby.gnus.org@gnu.org Message-ID: References: <16504.53102.905929.74629@samba2.ece.ucdavis.edu> NNTP-Posting-Host: deer.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Trace: sea.gmane.org 1081685054 10602 80.91.224.253 (11 Apr 2004 12:04:14 GMT) X-Complaints-To: usenet@sea.gmane.org NNTP-Posting-Date: Sun, 11 Apr 2004 12:04:14 +0000 (UTC) Original-X-From: emacs-devel-bounces+emacs-devel=quimby.gnus.org@gnu.org Sun Apr 11 14:04:06 2004 Return-path: Original-Received: from quimby.gnus.org ([80.91.224.244]) by deer.gmane.org with esmtp (Exim 3.35 #1 (Debian)) id 1BCdh0-0006lI-00 for ; Sun, 11 Apr 2004 14:04:06 +0200 Original-Received: from monty-python.gnu.org ([199.232.76.173]) by quimby.gnus.org with esmtp (Exim 3.35 #1 (Debian)) id 1BCdgz-0005rM-00 for ; Sun, 11 Apr 2004 14:04:05 +0200 Original-Received: from localhost ([127.0.0.1] helo=monty-python.gnu.org) by monty-python.gnu.org with esmtp (Exim 4.30) id 1BCdg7-0007LD-2H for emacs-devel@quimby.gnus.org; Sun, 11 Apr 2004 08:03:11 -0400 Original-Received: from list by monty-python.gnu.org with tmda-scanned (Exim 4.30) id 1BCdcd-0006ky-S6 for emacs-devel@gnu.org; Sun, 11 Apr 2004 07:59:35 -0400 Original-Received: from mail by monty-python.gnu.org with spam-scanned (Exim 4.30) id 1BCdc7-0006dz-4Y for emacs-devel@gnu.org; Sun, 11 Apr 2004 07:59:34 -0400 Original-Received: from [80.91.224.249] (helo=main.gmane.org) by monty-python.gnu.org with esmtp (Exim 4.30) id 1BCdc6-0006dO-90 for emacs-devel@gnu.org; Sun, 11 Apr 2004 07:59:02 -0400 Original-Received: from list by main.gmane.org with local (Exim 3.35 #1 (Debian)) id 1BCdc5-00037B-00 for ; Sun, 11 Apr 2004 13:59:01 +0200 Original-Received: from vegetable.demon.co.uk ([80.177.16.3]) by main.gmane.org with esmtp (Gmexim 0.1 (Debian)) id 1AlnuQ-0007hv-00 for ; Sun, 11 Apr 2004 13:59:00 +0200 Original-Received: from wence by vegetable.demon.co.uk with local (Gmexim 0.1 (Debian)) id 1AlnuQ-0007hv-00 for ; Sun, 11 Apr 2004 13:59:00 +0200 X-Injected-Via-Gmane: http://gmane.org/ Mail-Followup-To: emacs-devel@gnu.org Original-To: emacs-devel@gnu.org Original-Lines: 69 Original-X-Complaints-To: usenet@sea.gmane.org X-Gmane-NNTP-Posting-Host: vegetable.demon.co.uk X-No-Yes: No Mail-Copies-To: nobody User-Agent: Gnus/5.110002 (No Gnus v0.2) Emacs/21.3.50 Cancel-Lock: sha1:Z+MdBNKoxNDW81LpDAufADLj4gM= X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1.4 Precedence: list List-Id: "Emacs development discussions." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-devel-bounces+emacs-devel=quimby.gnus.org@gnu.org Xref: main.gmane.org gmane.emacs.devel:21477 X-Report-Spam: http://spam.gmane.org/gmane.emacs.devel:21477 John Owens wrote: > I use BibTeX mode for my bibliographies. I use it on both NT emacs > (the 21.3 release) and the CVS build for OS X. I have ~150 entries in > a BibTeX file and want to format and sort them. > Calling "format region" on the whole file via the BibTeX menu is > *incredibly* slow on OS X emacs, but very quick on NT emacs. I would > estimate on NT it's a few seconds and works fine. I've never actually > waited for a OS X "format region" to finish on the Mac but it's at > least several minutes. Nothing else I do on OS X emacs is even close > to this discrepancy in performance. In addition, emacs is accounting > for ~70% of my CPU utilization while it attemps to format the region. > When I hit C-g, it leaves my BibTeX buffer with thousands of blank > lines in it (and on this test, crashed immediately afterwards). > It appears that I'm using straight bibtex mode (locate-library bibtex > returns /usr/local/share/emacs/21.3.50/lisp/textmodes/bibtex.elc). > Ideas? It appears to be a problem in `bibtex-clean-entry'. An entry is deleted, and then reinserted, but after its "end" marker. Try this patch. The second part is fixes a problem by which a newline would be inserted at the beginning of the file, and newlines would be inserted at the end. Index: bibtex.el =================================================================== RCS file: /cvsroot/emacs/emacs/lisp/textmodes/bibtex.el,v retrieving revision 1.79 diff -u -r1.79 bibtex.el --- bibtex.el 20 Oct 2003 23:31:01 -0000 1.79 +++ bibtex.el 11 Apr 2004 11:55:35 -0000 @@ -3539,7 +3539,7 @@ (equal entry-type "string")))) (bibtex-prepare-new-entry index) (not (bibtex-find-entry (car index))))) - (insert entry) + (insert-before-markers entry) (forward-char -1) (bibtex-beginning-of-entry) ; moves backward (re-search-forward bibtex-entry-head)) @@ -3674,7 +3674,9 @@ (narrow-to-region start-point end-point) (when (memq 'realign bibtex-entry-format) (goto-char (point-min)) - (while (re-search-forward bibtex-valid-entry-whitespace-re nil t) + (while (re-search-forward + (concat "[ \t\n]" + bibtex-valid-entry-whitespace-re) nil t) (replace-match "\n\\1"))) (goto-char start-point) (bibtex-progress-message "Formatting" 1) @@ -3684,7 +3686,8 @@ (when (memq 'realign bibtex-entry-format) (goto-char end) (bibtex-delete-whitespace) - (open-line 2)))) + (when (not (eobp)) + (newline))))) (bibtex-progress-message 'done)) (when (and reformat-reference-keys bibtex-maintain-sorted-entries -- Lawrence Mitchell