unofficial mirror of emacs-devel@gnu.org 
 help / color / mirror / code / Atom feed
* bibtex-mode and "format region" incredibly slow
@ 2004-04-11  4:54 John Owens
  2004-04-11 11:58 ` Patch for " Lawrence Mitchell
  0 siblings, 1 reply; 4+ messages in thread
From: John Owens @ 2004-04-11  4:54 UTC (permalink / raw)
  Cc: John Owens

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?

JDO

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Patch for Re: bibtex-mode and "format region" incredibly slow
  2004-04-11  4:54 bibtex-mode and "format region" incredibly slow John Owens
@ 2004-04-11 11:58 ` Lawrence Mitchell
  2004-04-11 15:33   ` John Owens
  2004-04-11 23:25   ` Stefan Monnier
  0 siblings, 2 replies; 4+ messages in thread
From: Lawrence Mitchell @ 2004-04-11 11:58 UTC (permalink / raw)


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 <wence@gmx.li>

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: Patch for Re: bibtex-mode and "format region" incredibly slow
  2004-04-11 11:58 ` Patch for " Lawrence Mitchell
@ 2004-04-11 15:33   ` John Owens
  2004-04-11 23:25   ` Stefan Monnier
  1 sibling, 0 replies; 4+ messages in thread
From: John Owens @ 2004-04-11 15:33 UTC (permalink / raw)
  Cc: roland.winkler

Awesome. That patch worked great. Kindly consider adopting it for
good. 

Another difference between 21.3 and the CVS version is sorting
behavior. In 21.3 if you "sort region" in bibtex-mode it just sorts
it, no questions asked. In the CVS version it errors with
"bibtex-sort-buffer: You must choose a sorting scheme". 

To choose a sorting scheme you must set
bibtex-maintain-sorted-entries. This does not seem intuitive to me. If
a user wants to sort manually but NOT maintain sorted entries (as I
can do in 21.3), that's not possible unless this variable is set. It
would seem to me that bibtex-maintain-sorted-entries should be t or
nil and bibtex-sorting-scheme should be what b-m-s-e is now (either
"plain", "crossref", or "entry-class", and perhaps defaulting to
"plain").

JDO

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: Patch for Re: bibtex-mode and "format region" incredibly slow
  2004-04-11 11:58 ` Patch for " Lawrence Mitchell
  2004-04-11 15:33   ` John Owens
@ 2004-04-11 23:25   ` Stefan Monnier
  1 sibling, 0 replies; 4+ messages in thread
From: Stefan Monnier @ 2004-04-11 23:25 UTC (permalink / raw)


> It appears to be a problem in `bibtex-clean-entry'.  An entry is
> deleted, and then reinserted, but after its "end" marker.  Try

Instead of using insert-before-markers, we should just make the `end'
marker of the "insert before" type.


        Stefan

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2004-04-11 23:25 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2004-04-11  4:54 bibtex-mode and "format region" incredibly slow John Owens
2004-04-11 11:58 ` Patch for " Lawrence Mitchell
2004-04-11 15:33   ` John Owens
2004-04-11 23:25   ` Stefan Monnier

Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).