From mboxrd@z Thu Jan 1 00:00:00 1970 Path: main.gmane.org!not-for-mail From: Jim Ottaway Newsgroups: gmane.emacs.help Subject: Re: bibtex-mode wishes Date: Fri, 10 Jan 2003 19:20:51 +0000 Sender: help-gnu-emacs-bounces+gnu-help-gnu-emacs=m.gmane.org@gnu.org Message-ID: <8765swn758.fsf@lse.ac.uk> References: <87iswza76o.fsf@antithese.de> NNTP-Posting-Host: main.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Trace: main.gmane.org 1042227114 10012 80.91.224.249 (10 Jan 2003 19:31:54 GMT) X-Complaints-To: usenet@main.gmane.org NNTP-Posting-Date: Fri, 10 Jan 2003 19:31:54 +0000 (UTC) Return-path: Original-Received: from monty-python.gnu.org ([199.232.76.173]) by main.gmane.org with esmtp (Exim 3.35 #1 (Debian)) id 18X4sI-0002ZV-00 for ; Fri, 10 Jan 2003 20:31:27 +0100 Original-Received: from localhost ([127.0.0.1] helo=monty-python.gnu.org) by monty-python.gnu.org with esmtp (Exim 4.10.13) id 18X4rN-000093-01 for gnu-help-gnu-emacs@m.gmane.org; Fri, 10 Jan 2003 14:30:29 -0500 Original-Received: from list by monty-python.gnu.org with tmda-scanned (Exim 4.10.13) id 18X4qw-00006J-00 for help-gnu-emacs@gnu.org; Fri, 10 Jan 2003 14:30:02 -0500 Original-Received: from mail by monty-python.gnu.org with spam-scanned (Exim 4.10.13) id 18X4og-0007HZ-00 for help-gnu-emacs@gnu.org; Fri, 10 Jan 2003 14:27:44 -0500 Original-Received: from mk-smarthost-1.mail.uk.tiscali.com ([212.74.114.37]) by monty-python.gnu.org with esmtp (Exim 4.10.13) id 18X4nE-0006ch-00 for help-gnu-emacs@gnu.org; Fri, 10 Jan 2003 14:26:12 -0500 Original-Received: from [80.40.6.9] (helo=runcible) by mk-smarthost-1.mail.uk.tiscali.com with esmtp (Exim 4.10) id 18X4mg-000PrS-00 for help-gnu-emacs@gnu.org; Fri, 10 Jan 2003 19:25:38 +0000 Original-Received: from jeho by runcible with local (Exim 3.12 #1 (Debian)) id 18X4i3-0000H7-00 for ; Fri, 10 Jan 2003 19:20:51 +0000 Original-To: help-gnu-emacs@gnu.org Original-Lines: 65 User-Agent: Gnus/5.090005 (Oort Gnus v0.05) Emacs/21.1 (i686-pc-linux-gnu) X-BeenThere: help-gnu-emacs@gnu.org X-Mailman-Version: 2.1b5 Precedence: list List-Id: Users list for the GNU Emacs text editor List-Help: List-Post: List-Subscribe: , List-Archive: List-Unsubscribe: , Errors-To: help-gnu-emacs-bounces+gnu-help-gnu-emacs=m.gmane.org@gnu.org Xref: main.gmane.org gmane.emacs.help:5336 X-Report-Spam: http://spam.gmane.org/gmane.emacs.help:5336 >>>>> "Michael" == Michael Below writes: > - If I crossreference an entry, the referencing entry should be > sorted before the entry referenced to, otherwise bibtex wont be > able to solve the reference. I have changed `bibtex-sort-buffer' to achieve this by fiddling with the sort keys: (defun bibtex-sort-buffer () "Sort BibTeX buffer alphabetically by key. Text outside of BibTeX entries is not affected. If `bibtex-sort-ignore-string-entries' is non-nil, @String entries will be ignored." (interactive) (save-restriction (narrow-to-region (bibtex-beginning-of-first-entry) (save-excursion (goto-char (point-max)) (bibtex-end-of-entry))) (bibtex-skip-to-valid-entry) (sort-subr nil ;; NEXTREC function 'bibtex-skip-to-valid-entry ;; ENDREC function 'bibtex-end-of-entry ;; STARTKEY function (lambda () (let* ((case-fold-search t) key entry-end xref-match) (re-search-forward bibtex-entry-head) (setq key (buffer-substring-no-properties (match-beginning bibtex-key-in-head) (match-end bibtex-key-in-head))) (save-excursion (bibtex-end-of-entry) (setq entry-end (point))) (if (re-search-forward "^[ \t]*crossref[ \t]*=[ \t]*" entry-end t) ;; If there is a cross-reference, make a new key that ;; will be less than the cross-referred item's key. (progn (setq xref-match (bibtex-search-forward-field-string entry-end)) (concat (buffer-substring-no-properties ;; Trim the braces/quotes and replace the last ;; character of the key with a space ;; (makes it string< than book key). ;; Concatenate this with the actual entry key, ;; so that it is sorted properly with other ;; entries with the same cross-reference. (1+ (car xref-match)) (- (cdr xref-match) 2)) " " key)) key)))))) It seems to work; perhaps I should send this to the maintainer. Regards, Jim Ottaway