Function: bibtex-validate-globally
bibtex-validate-globally is an interactive and byte-compiled function
defined in bibtex.el.gz.
Signature
(bibtex-validate-globally &optional STRINGS)
Documentation
Check for duplicate keys in bibtex-files.
With optional prefix arg STRINGS, check for duplicate strings, too. Return t if test was successful, nil otherwise.
Probably introduced at or before Emacs version 22.1.
Key Bindings
Source Code
;; Defined in /usr/src/emacs/lisp/textmodes/bibtex.el.gz
t))) ; return t (i.e., buffer is valid)
(defun bibtex-validate-globally (&optional strings)
"Check for duplicate keys in `bibtex-files'.
With optional prefix arg STRINGS, check for duplicate strings, too.
Return t if test was successful, nil otherwise."
(interactive "P")
(let ((buffer-list (bibtex-initialize t))
buffer-key-list current-buf current-keys error-list)
;; Check for duplicate keys within BibTeX buffer
(dolist (buffer buffer-list)
(with-current-buffer buffer
(save-excursion
(let (entry-type key key-list)
(goto-char (point-min))
(while (re-search-forward bibtex-entry-head nil t)
(setq entry-type (bibtex-type-in-head)
key (bibtex-key-in-head))
(if (or (and strings (string-equal-ignore-case entry-type "string"))
(assoc-string entry-type bibtex-entry-alist t))
(if (member key key-list)
(push (format-message
"%s:%d: Duplicate key `%s'\n"
(buffer-file-name)
(bibtex-current-line) key)
error-list)
(push key key-list))))
(push (cons buffer key-list) buffer-key-list)))))
;; Check for duplicate keys among BibTeX buffers
(while (setq current-buf (pop buffer-list))
(setq current-keys (cdr (assq current-buf buffer-key-list)))
(with-current-buffer current-buf
(dolist (buffer buffer-list)
(dolist (key (cdr (assq buffer buffer-key-list)))
(when (assoc-string key current-keys)
(bibtex-search-entry key)
(push (format-message
"%s:%d: Duplicate key `%s' in %s\n"
(buffer-file-name) (bibtex-current-line) key
(abbreviate-file-name (buffer-file-name buffer)))
error-list))))))
;; Process error list
(if error-list
(let ((err-buf "*BibTeX validation errors*"))
(with-current-buffer (get-buffer-create err-buf)
(unless (eq major-mode 'compilation-mode) (compilation-mode))
(let ((inhibit-read-only t))
(delete-region (point-min) (point-max))
(insert (substitute-command-keys
"BibTeX mode command `bibtex-validate-globally'\n\n"))
(dolist (err (sort error-list #'string-lessp)) (insert err))
(set-buffer-modified-p nil))
(goto-char (point-min))
(forward-line 2)) ; first error message
(display-buffer err-buf)
nil) ; return nil (i.e., buffer is invalid)
(message "No duplicate keys.")
t))) ; return t (i.e., buffer is valid)