help-gnu-emacs
[Top][All Lists]
Advanced

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

Re: bibtex-mode wishes


From: Jim Ottaway
Subject: Re: bibtex-mode wishes
Date: Fri, 10 Jan 2003 19:20:51 +0000
User-agent: Gnus/5.090005 (Oort Gnus v0.05) Emacs/21.1 (i686-pc-linux-gnu)

>>>>> "Michael" == Michael Below <mbelow@antithese.de> 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




reply via email to

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