[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Patch for Re: bibtex-mode and "format region" incredibly slow

From: Lawrence Mitchell
Subject: Patch for Re: bibtex-mode and "format region" incredibly slow
Date: Sun, 11 Apr 2004 12:58:58 +0100
User-agent: Gnus/5.110002 (No Gnus v0.2) Emacs/21.3.50

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)
-                              (open-line 2))))
+                              (when (not (eobp))
+                                (newline)))))
       (bibtex-progress-message 'done))
     (when (and reformat-reference-keys

Lawrence Mitchell <address@hidden>

reply via email to

[Prev in Thread] Current Thread [Next in Thread]