diff options
| author | Richard M. Stallman | 1997-06-10 17:58:43 +0000 |
|---|---|---|
| committer | Richard M. Stallman | 1997-06-10 17:58:43 +0000 |
| commit | 50e4b39edefaa410aaa1a14a3c9b4c6be46a0ddb (patch) | |
| tree | 26ffc910e9735bf2c11f66ef84fc85e77f88874b | |
| parent | a09aa6595151996fcea51b4f67561d73703c78df (diff) | |
| download | emacs-50e4b39edefaa410aaa1a14a3c9b4c6be46a0ddb.tar.gz emacs-50e4b39edefaa410aaa1a14a3c9b4c6be46a0ddb.zip | |
(bibtex-mode-map): Changed the binding of the C-TAB
key, such that XEmacs will understand it, too.
(bibtex-format-entry, bibtex-end-of-entry): Give specific
error message if not on valid BibTeX entry.
(bibtex-field-string-quoted): Small bug fix. Allow
backslash followed by newline.
(bibtex-reposition-window, bibtex-mark-entry): Two new
functions, bound to M-C-l and M-C-h, respectively.
(bibtex-reformat-previous-options, bibtex-reformat-previous-labels):
New internal variables used by bibtex-reformat.
(bibtex-clean-entry-hook): New hook to be called after
entry has been cleaned.
(bibtex-clean-entry): Run the hook bibtex-clean-entry-hook.
(bibtex-entry-field-alist): Small bug fix.
(bibtex-autokey-title-terminators): Made -- a terminator instead
of ---.
(bibtex-font-lock-keywords): Don't treat ALT prefixed entries as
comments.
(bibtex-entry): Fixed parameter list. This function is not
intended to be called with required and optional fields as
optional arguments anymore.
(bibtex-generate-autokey): Now split into various
small functions.
(bibtex-autokey-names-stretch, bibtex-autokey-additional-names):
New variables used by bibtex-generate-autokey.
(bibtex-autokey-get-namefield, bibtex-autokey-get-names)
(bibtex-autokey-demangle-name, bibtex-autokey-get-namelist)
(bibtex-autokey-get-yearfield, bibtex-autokey-get-titlestring)
(bibtex-autokey-get-titles, bibtex-autokey-get-titlelist):
New helper functions for bibtex-generate-autokey.
(bibtex-submit-bug-report): Report all variables.
(bibtex-contline-indentation): New user option.
(bibtex-entry-offset): Renamed from bibtex-entry-indentation.
(bibtex-entry-field-alist): Used different order for
some fields (as documented in btxdoc.tex). Changed one of the
comment strings.
(bibtex-mode-hook, bibtex-add-entry-hook): Add var doc.
(bibtex-autokey-before-presentation-hook): New variable to be
called before autokey presentation.
(bibtex-generate-autokey):
Call bibtex-autokey-before-presentation-hook. Doc fix.
(bibtex-reference-key): Reincluded parentheses.
Parentheses should be disallowed only in field constants.
(bibtex-autokey-transcriptions): Fixed bug (two
entries for `\o' while `\oe' entry was missing).
(bibtex-entry-indentation): New variable to determine
the indentation of all entries.
(bibtex-move-outside-of-entry): Use `skip-chars-forward' instead
of `re-search-forward'.
(bibtex-beginning-of-first-entry, bibtex-beginning-of-last-entry):
Renamed from beginning-of-first-bibtex-entry and
beginning-of-last-bibtex-entry. Go to beginning of line, return point.
(bibtex-do-auto-fill, bibtex-make-field, bibtex-entry)
(bibtex-String, bibtex-Preamble): Respect `bibtex-entry-indentation'.
(bibtex-beginning-of-entry, bibtex-end-of-entry): Make it work
with indented entries.
(bibtex-count-entries, bibtex-sort-buffer, bibtex-validate,
bibtex-kill-entry, bibtex-reformat): Use return value from
bibtex-beginning-of-first-entry.
(bibtex-clean-entry): Use `bibtex-reference-maybe-empty-head'
instead of a fixed string.
(bibtex-beginning-of-entry, bibtex-end-of-entry): Now
return point if called from a program.
(bibtex-enclosing-field, bibtex-format-entry,
bibtex-generate-autokey, bibtex-parse-keys, bibtex-mode,
bibtex-ispell-entry, bibtex-narrow-to-entry, bibtex-sort-buffer,
bibtex-find-entry-location, bibtex-validate, bibtex-clean-entry,
bibtex-fill-entry): Use new return values of these functions.
(bibtex-ispell-abstract): Bug fix (inherently by the change to
bibtex-end-of-entry).
(bibtex-field-history): New variable for history
buffer of field name reading.
(bibtex-make-field): Use completion. Object to completion are all
standard fields defined for the current entry. Bound to `C-c C-f'.
(bibtex-mode): Set `comment-start' and `comment-start-skip' to
"@Comment ", `comment-column' to 0.
(bibtex-autokey-transcriptions): New variable.
(bibtex-autokey-name-change-strings)
(bibtex-autokey-titleword-change-strings):
Use bibtex-autokey-transcriptions as default value.
(bibtex-find-entry-location): Handle empty buffer.
(bibtex-entry-delimiters): New variable to determine
if entries shall be delimited by braces or parentheses.
(bibtex-entry-left-delimiter, bibtex-entry-right-delimiter): New
helper functions.
(bibtex-entry, bibtex-String, bibtex-Preamble): Respect
`bibtex-entry-delimiters'.
(bibtex-entry-format): Doc fix.
(bibtex-reference-key, bibtex-field-const): Removed parentheses
from allowed characters.
(bibtex-end-of-entry): Better handling of incorrect preambles.
(bibtex-validate): Small change to avoid reparsing of
errors, if you enter `compile-goto-error' in compilation buffer.
(bibtex-progress-message): New function to show
progress of some long-lasting functions in BibTeX mode by
indicating percentage of done work.
(bibtex-progress-lastperc, bibtex-progress-lastmes)
(bibtex-progress-interval):
New internal variables for `bibtex-progress-message'.
(bibtex-parse-keys, bibtex-reformat, bibtex-validate): Use new
function `bibtex-progress-message'.
(current-line): New helper function to calculate current
linenumber. Something like this should really be defined somewhere
else in Emacs.
(bibtex-validate): Changed to show all errors in buffer in a
`compilation mode' buffer. If there are syntax errors, it aborts
after the syntax check, since higher-level check functions rely on
the syntactical correctness of buffer. If called from another lisp
function (as `bibtex-convert-alien') the return value shows
whether validating has been successful. Fixed bug which made
checking for absent required fields work incorrectly.
(bibtex-parse-keys-timeout): Set to a value reasonable higher
(twice as high) than `lazy-lock-stealth-time'.
(bibtex-member-of-regexp, assoc-of-regexp): Small cosmetic changes.
(bibtex-buffer-last-parsed-tick): Renamed from
bibtex-buffer-last-parsed-for-keys-tick and made it really
buffer-local (bug fix).
(bibtex-parse-keys): Make it use bibtex-buffer-last-parsed-tick.
(bibtex-parse-buffers-stealthily): New function which parses all
BibTeX buffers if emacs has been idle an efficient amount of time.
(bibtex-parse-idle-timer): New variable which stores whether idle
timer for parsing already is installed.
(bibtex-parse-keys): Make it callable verbosely. Returns now nil
if it has been aborted.
(bibtex-mode): Run the new function bibtex-parse-buffers-stealthily.
(bibtex-generate-autokey): Changed the name part
generation (bugfix). This function handles now correctly all three
forms of BibTeX names, "First von Last", "von Last, First", "von
Last, Jr, First". In every case the "Last" part is correctly
extracted. If the "Last" part consists of more than one token only
the first is used. Name fields spread over more than one line are
no problem anymore.
(bibtex-entry-format): Changed default value to
exclude 'page-dashes. Modified documentation.
(bibtex-autokey-name-change-strings)
(bibtex-autokey-titleword-abbrevs)
(bibtex-autokey-titleword-change-strings, bibtex-entry)
(bibtex-validate): Doc fixes.
(bibtex-mode-map): Bound `C-c $' to bibtex-ispell-abstract.
(bibtex-generate-autokey): Changed documentation. Small
modification in calculating title field.
(bibtex-mode): Included bibtex-ispell-entry into the list of
`interesting' functions.
(bibtex-kill-field): Bug fix (killing of first field in entry
yielded error).
(bibtex-string-file-path): New variable which defines
the path to search for bibtex-string-files. It defaults to
contents of environment variable BIBINPUTS.
(bibtex-mode): Use this variable.
(bibtex-next-field, bibtex-find-text): Will now work
with string entries as well.
(bibtex-mode-map): bibtex-complete-key wasn't bound
correctly.
(bibtex-complete): Fixed bug (used string entries defined in
buffer as object to completion).
(Menu): Use easymenu. More menu items for
`BibTeX-Edit' menu. Use nested menus.
(bibtex-field-kill-ring-max)
(bibtex-entry-kill-ring-max): Two new variables substituting
bibtex-kill-ring-max.
(bibtex-field-kill-ring, bibtex-entry-kill-ring): Two new
variables substituting bibtex-kill-ring.
(bibtex-field-kill-ring-yank-pointer)
(bibtex-entry-kill-ring-yank-pointer): Two new variables
substituting bibtex-kill-ring-yank-pointer.
(bibtex-last-kill-command): New variable keeping the type of the
last kill command.
(bibtex-insert-current-kill): Clean distinction between the two
BibTeX kill rings.
(bibtex-kill-field): Use new variable bibtex-field-kill-ring.
(bibtex-kill-entry): Use new variable bibtex-entry-kill-ring.
(bibtex-kill-ring, bibtex-kill-ring-yank-pointer): New
internal variables like kill-ring and kill-ring-yank-pointer, but
bibtex-kill-ring holds fields or complete reference entries
instead of raw strings.
(bibtex-kill-ring-max): New user option similar to kill-ring-max.
(bibtex-kill-field): Renamed from bibtex-delete-field again. It
now supports the new variable bibtex-kill-ring.
(bibtex-copy-field-as-kill, bibtex-kill-entry)
(bibtex-copy-entry-as-kill, bibtex-yank, bibtex-yank-pop): New
interactive functions, which work on the bibtex-kill-ring
variable.
(bibtex-insert-current-kill): New helper function to insert
contents of bibtex-kill-ring in an appropriate way.
(bibtex-make-field): New optional argument to tell the function if
it was called by bibtex-yank. It operates slightly different then.
(bibtex-find-text): New optional argument to tell the function if
it was called by bibtex-make-field. It moves in this case to the
end of the key if it was called on the reference head line. If it
is called interactively on the head line, it works in an
appropriate manner, too.
(bibtex-enclosing-field): New optional argument to tell
bibtex-enclosing-field not to print an error message if enclosing
field isn't found, but to return nil in this case (t is returned
otherwise). This is used by bibtex-find-text such that no error
message is given if bibtex-find-text is called interactively in
the key line of an entry.
(bibtex-autokey-year-use-crossref-entry): New variable
to determine if crossreferenced entry should be used for autokey
generation, if year field of current entry is absent.
(bibtex-generate-autokey): Use this new variable.
(bibtex-include-OPTannote): Deleted (is set in
bibtex-user-optional-fields).
(bibtex-entry, bibtex-print-help-message): Removed support for
bibtex-include-OPTannote.
(bibtex-entry-format): New constant
`inherit-booktitle' allowed.
(bibtex-mode): Set value for
font-lock-mark-block-function.
(bibtex-font-lock-keywords): Changed to distinguish
optional from ordinary fields.
(bibtex-format-entry, bibtex-print-help-message)
(bibtex-remove-OPT-or-ALT, bibtex-pop): Used simpler regexps.
(bibtex-delete-field): Changed from
bibtex-delete-optional-or-alternative-field. Deletes now mandatory
fields as well.
(bibtex-mode): Changed documentation.
(bibtex-entry-type-history, bibtex-key-history): New
variables to use own histories in BibTeX buffers.
(bibtex-entry, bibtex-clean-entry, bibtex-String): Use these new
variables.
(bibtex-entry, bibtex-make-field): A function can now
be used to generate a fields init string.
(bibtex-include-OPTkey, bibtex-include-OPTannote)
(bibtex-entry-field-alist): Changed documentation accordingly.
(bibtex-mode): bibtex-parse-keys on start of mode is
now abortable, too.
(bibtex-entry, bibtex-complete-key, bibtex-String): If bibtex-keys
isn't set correctly due to abortion of bibtex-parse-keys, this
function is called now non-abortable.
(bibtex-entry-field-alist): Small change in comments.
(bibtex-find-entry-location): Bug fix: Insertion into
completely empty buffer didn't work.
(bibtex-user-optional-fields): Renamed from
bibtex-mode-user-optional-fields.
(bibtex-submit-bug-report, bibtex-entry, bibtex-print-help-message):
Use bibtex-user-optional-fields.
(bibtex-remove-delimiters): Bug fix: Only remove
delimiting braces and not those inside fields.
(skip-to-valid-bibtex-entry, bibtex-parse-keys)
(bibtex-end-of-entry, bibtex-validate, bibtex-reformat): Calculate
complex regexps outside of loops.
(bibtex-mode): Changed documentation on how to convert third party
buffers.
(bibtex-convert-alien): New function to convert a
buffer not created by BibTeX mode to a format, whichs enables all
features of BibTeX mode.
(bibtex-mode): Small bug fix for call to bibtex-parse-keys.
(bibtex-mode): Bug fix for using bibtex-parse-keys.
(bibtex-mode): Used other policy to initiate the first
call of bibtex-parse-keys. This avoids unnecessary double call if
Font Lock mode is chosen for buffer at startup.
(bibtex-String, bibtex-Preamble): Renamed from
bibtex-string and bibtex-preamble.
(bibtex-String): If bibtex-maintain-sorted-entries and
bibtex-sort-ignore-string-entries are both non-nil, read string
key from minibuffer (with completion) and insert entry at correct
location (as for normal entries).
(bibtex-autokey-titleword-first-ignore)
(bibtex-autokey-titleword-abbrevs): Changed documentation: case of
regexps doesn't matter anymore.
(bibtex-field-const, bibtex-reference-key): Simplified to not
contain uppercase letters.
(member-of-regexp, assoc-of-regexp): Ignore case of regexp.
(map-bibtex-entries): Call function not for every syntactical correct
entry, but only for entries with known type.
(map-bibtex-entries, skip-to-valid-bibtex-entry)
(bibtex-flash-head, bibtex-enclosing-field)
(bibtex-enclosing-reference-maybe-empty-head, bibtex-format-entry)
(bibtex-autokey-change, bibtex-generate-autokey, bibtex-parse-keys)
(bibtex-ispell-abstract, bibtex-sort-buffer)
(bibtex-find-entry-location, bibtex-validate, bibtex-remove-delimiters)
(bibtex-delete-optional-or-alternative-field, bibtex-pop)
(bibtex-clean-entry, bibtex-print-help-message): Make them work
regardless of user's value of case-fold-search.
(bibtex-generate-autokey): Use bibtex-cfield for generating the
year field regexp.
(bibtex-parse-keys): Only gather keys of known (and not of
syntactical correct) entries.
(bibtex-end-of-entry): Only report an "unknown entry" message if
called interactively.
(bibtex-sort-ignore-string-entries): Renamed back from
bibtex-sort-ignore-string-and-preamble. Of course, preambles are
always ignored, since they have no key at all.
(bibtex-string): Slightly less complex regexp.
(skip-to-valid-bibtex-entry): New helper function to skip forward
(or backward) to beginning of next syntactical correct known
BibTeX entry, if not already there. Respects
bibtex-sort-ignore-string-entries.
(map-bibtex-entries): Bug fix: It wasn't called for string entries
even if bibtex-sort-ignore-string-entries was nil.
(beginning-of-last-bibtex-entry): New helper function to go to
last entry in buffer.
(bibtex-end-of-entry): Bug fix: Now works with string and preamble
entries as well.
(bibtex-sort-buffer): Renamed from bibtex-sort-entries. Simplified
by using new function skip-to-valid-bibtex-entry. Now only known
entries are checked.
(bibtex-find-entry-location): Simplified by using new functions
skip-to-valid-bibtex-entry and beginning-of-last-bibtex-entry.
Only known entries are used to determine location.
(bibtex-validate): Now checks string entries, too.
(bibtex-move-outside-of-entry): Don't use forward-paragraph, but
bibtex-end-of-entry.
(bibtex-end-of-entry): Don't use forward-sexp anymore,
since this fails on entries with non-escaped souble-quotes. Use
search-bibtex-reference instead (though it is slower, it is more
reliable).
(bibtex-ispell-abstract): Use normal regexps created by
bibtex-cfield instead of special ones.
(beginning-of-first-bibtex-entry): No warning on
empty buffer.
(bibtex-validate): Bug fix. Syntactical check didn't
work, since due to a bug all entries were simply skipped.
(bibtex-mode): Doc fix.
(bibtex-delete-optional-or-alternative-field): Renamed from
bibtex-kill-optional-or-alternative-field.
(bibtex-delete-optional-or-alternative-field, bibtex-empty-field):
Use delete-region, not kill-region.
(bibtex-clean-entry): New second argument called-by-reformat
indicates if bibtex-clean-entry was called by reformat. Don't try
to find correct buffer position for newly generated key and don't
call bibtex-parse-keys in this case.
(map-bibtex-entries): Bugfix (missed first entry in
buffer, died on entries with `@' in other than first column).
(beginning-of-first-bibtex-entry, bibtex-format-entry)
(bibtex-beginning-of-entry, bibtex-validate, bibtex-clean-entry):
Changed to allow BibTeX entries to start in a column different
from 1 (but still for speed reasons only whitespace is allowed
prior to the `@' on the same line.
(map-bibtex-entries): Call it for known BibTeX entries
only. This allows entries as @Comment{...} which follow no
specific structure without breaking the validation functions.
(bibtex-validate): Check syntactical structure for known entries
only.
(bibtex-autokey-abbrev): Sped up and changed to allow
a length of zero.
(bibtex-entry-format): Remove option `month-strings'.
(bibtex-validate): If given a prefix argument, check for
questionable month fields.
(bibtex-generate-autokey): Use normal regexps created
by bibtex-cfield instead of special ones.
(bibtex-hide-entry-bodies): Sped up by using subst-char-in-region
instead of using replace-regexp or replace-match.
(bibtex-find-entry-location): A bug had been introduced by using
search-bibtex-reference instead of re-search-forward (fixed).
(bibtex-field-delimiters): Renamed from
bibtex-field-delimiter.
(bibtex-entry-format): Constant empty-opts renamed to
empty-opts-or-alts.
(bibtex-remove-delimiters): Renamed from
bibtex-remove-double-quotes-or-braces.
(bibtex-reformat): New function.
(bibtex-fill-entry): New function to refill entry.
(bibtex-mode-map): Defined key for bibtex-fill-entry.
(bibtex-field-delimiter): Substitutes variables
bibtex-field-left-delimiter and bibtex-field-right-delimiter.
(bibtex-field-left-delimiter, bibtex-field-right-delimiter): New
helper functions.
(bibtex-make-field, bibtex-pop): Use new variable
bibtex-field-delimiter.
(bibtex-empty-field, bibtex-string): Use new functions
bibtex-field-left-delimiter and bibtex-field-right-delimiter.
(bibtex-predefined-month-strings): New variable.
(bibtex-predefined-strings): Use bibtex-predefined-month-strings.
(bibtex-submit-bug-report): Use new variables
bibtex-field-delimiter and bibtex-predefined-month-strings.
(bibtex-entry-format): Substitutes variable
bibtex-clean-entry-zap-empty-opts-or-alts. Various types of
formatting options are available (see variable documentation).
(bibtex-format-entry): New function doing the formatting of entries.
Taken from bibtex-clean-entry and enhanced to support new variable
bibtex-entry-format.
(delete-whitespace): New helper function used by bibtex-format-entry.
(bibtex-clean-entry): Call new function bibtex-format-entry.
(bibtex-submit-bug-report): Use bibtex-entry-format instead of
bibtex-clean-entry-zap-empty-opts-or-alts.
(bibtex-do-auto-fill): New function to perform auto-filling in
BibTeX mode. In fact, this is the old function
bibtex-auto-fill-function.
(bibtex-mode): Don't set fill-prefix anymore, but use new function
bibtex-do-auto-fill.
(bibtex-find-entry-location): Fixed bug (when
bibtex-maintain-sorted-entries was non-nil, an entry with a key
greater than all other keys wasn't inserted in the correct place).
(bibtex-mode): Don't use bibtex-auto-fill-function
anymore, but use directly variable fill-prefix.
(bibtex-find-entry-location): Fixed bug (on duplicate
keys, point must move to beginning of entry, so that bibtex-entry
works correctly).
(bibtex-complete): Fixed bug (parameter string-list
was mistakenly altered by the function itself).
(bibtex-mode-map): Bind bibtex-complete-key to C-TAB.
(bibtex-validate): Renamed from bibtex-validate-buffer
since it can acts on region if active. Use search-bibtex-reference.
(search-bibtex-reference): New function to be used in places where
prior a re-search-{forward|backward} for bibtex-reference or
something alike was used. This function is necessary due to the
new limit of failure stack size in 19.32 and above.
(bibtex-enclosing-reference-maybe-empty-head)
(bibtex-sort-entries, bibtex-find-entry-location, bibtex-validate):
Use new function search-bibtex-reference.
(bibtex-pop, bibtex-clean-entry): Small change due to change in
bibtex-enclosing-reference-maybe-empty-head.
(bibtex-reference-infix, bibtex-reference-postfix): New constants
necessary due to splitting bibtex-reference.
(bibtex-reference): Deleted.
(bibtex-type-in-reference, skip-whitespace-and-comments): Deleted.
(bibtex-mode): Don't turn auto-fill-mode on. Use new
variable normal-auto-fill-function.
(bibtex-field-string): Simplified.
(bibtex-mode-syntax-table): Changed syntax of
double-quote back to quote syntax.
(bibtex-complete): New generic function for interface
functions bibtex-complete-string and bibtex-complete-key.
(bibtex-complete-key): New function.
(bibtex-sort-ignore-string-and-preamble): Renamed from
bibtex-sort-ignore-string-entries.
(map-bibtex-entries): Use bibtex-sort-ignore-string-and-preamble
and ignore preamble entries as well.
(bibtex-mode, bibtex-submit-bug-report, bibtex-sort-entries):
Use bibtex-sort-ignore-string-and-preamble.
(bibtex-count-entries): New function to count entries in buffer or
region.
(bibtex-comma-after-last-field): New variable to
decide if comma should be inserted at end of last field.
(bibtex-entry): Support new variable bibtex-comma-after-last-field.
(bibtex-field-indentation, bibtex-text-indentation):
Two new user options (replacing the former constants
bibtex-field-alignment and bibtex-text-alignment).
(bibtex-align-at-equal-sign): New user option.
(bibtex-auto-fill-function, bibtex-make-field)
(bibtex-remove-OPT-or-ALT, bibtex-clean-entry): Support new variables.
(bibtex-validate-buffer): Now only checks region if
mark is active. With optional argument checks if required fields
are missing, too.
(bibtex-mode): Added support for imenu.
(bibtex-entry-field-alist)
(bibtex-mode-user-optional-fields): Modified syntax to allow
preinitialization of fields.
(bibtex-make-field, bibtex-make-optional-field):
Support preinitialization of fields.
(bibtex-autokey-prefix-string)
(bibtex-autokey-preserve-case): New variables to support
bibtex-generate-autokey.
(bibtex-generate-autokey): Use new variables.
(bibtex-field-const, bibtex-reference-type)
(bibtex-reference-key): Changed to match the (according to Oren
Patashnik) allowed characters.
(bibtex-clean-entry-zap-empty-opts-or-alts): Renamed
from bibtex-clean-entry-zap-empty-opts.
(bibtex-entry-field-alist): Slightly modified syntax to support
alternative fields needed for Book and InBook references.
(bibtex-font-lock-keywords, bibtex-print-help-message)
(bibtex-make-field, bibtex-pop, bibtex-clean-entry):
Support ALT prefixed entries.
(bibtex-mode): Documented new ALT prefixed fields.
(bibtex-make-optional-field): Modified to give only field name as
arg to bibtex-make-field.
(bibtex-remove-OPT-or-ALT, bibtex-kill-optional-or-alternative-field):
Renamed from bibtex-remove-OPT and bibtex-kill-optional-field,
respectively. Modified to support ALT prefixes.
(bibtex-enclosing-field, bibtex-print-help-message):
Speed up things by not using bibtex-enclosing-regexp anymore.
(bibtex-enclosing-regexp): Function deleted.
| -rw-r--r-- | lisp/textmodes/bibtex.el | 4073 |
1 files changed, 2701 insertions, 1372 deletions
diff --git a/lisp/textmodes/bibtex.el b/lisp/textmodes/bibtex.el index d55321142ad..8972b74dca2 100644 --- a/lisp/textmodes/bibtex.el +++ b/lisp/textmodes/bibtex.el | |||
| @@ -38,50 +38,74 @@ | |||
| 38 | ;; Todo: | 38 | ;; Todo: |
| 39 | ;; Distribute texinfo file. | 39 | ;; Distribute texinfo file. |
| 40 | 40 | ||
| 41 | ;; Known Bugs: | ||
| 42 | ;; 1. using regular expressions to match the entire BibTeX entry dies | ||
| 43 | ;; on long entries (e.g. those containing abstracts) since | ||
| 44 | ;; the length of regular expression matches is fairly limited. | ||
| 45 | ;; 2. Calling bibtex-find-text in a string entry results in the | ||
| 46 | ;; error message "Can't find enclosing Bibtex field" instead of | ||
| 47 | ;; moving to the empty string. [reported by gernot@cs.unsw.oz.au] | ||
| 48 | |||
| 49 | ;; (current keeper: schoef@offis.uni-oldenburg.de | ||
| 50 | ;; previous: alarson@src.honeywell.com) | ||
| 51 | |||
| 52 | ;;; Code: | 41 | ;;; Code: |
| 53 | 42 | ||
| 43 | (eval-when-compile | ||
| 44 | (require 'compile)) | ||
| 45 | |||
| 54 | ;; User Options: | 46 | ;; User Options: |
| 55 | 47 | ||
| 56 | (defvar bibtex-field-left-delimiter "{" | 48 | (defvar bibtex-mode-hook nil |
| 57 | "*Set this to { or \" according to your personal preferences. | 49 | "List of functions to call on entry to BibTeX mode.") |
| 58 | This variable is buffer local.") | ||
| 59 | (make-variable-buffer-local 'bibtex-field-left-delimiter) | ||
| 60 | 50 | ||
| 61 | (defvar bibtex-field-right-delimiter "}" | 51 | (defvar bibtex-field-delimiters 'braces |
| 62 | "*Set this to } or \" according to your personal preferences. | 52 | "*Controls type of field delimiters used. |
| 63 | This variable is buffer local.") | 53 | Set this to 'braces or 'double-quotes according to your personal |
| 64 | (make-variable-buffer-local 'bibtex-field-right-delimiter) | 54 | preferences. This variable is buffer local.") |
| 55 | (make-variable-buffer-local 'bibtex-field-delimiters) | ||
| 56 | |||
| 57 | (defvar bibtex-entry-delimiters 'braces | ||
| 58 | "*Controls type of entry delimiters used. | ||
| 59 | Set this to 'braces or 'parentheses according to your personal | ||
| 60 | preferences. This variable is buffer local.") | ||
| 61 | (make-variable-buffer-local 'bibtex-entry-delimiters) | ||
| 65 | 62 | ||
| 66 | (defvar bibtex-include-OPTcrossref '("InProceedings" "InCollection") | 63 | (defvar bibtex-include-OPTcrossref '("InProceedings" "InCollection") |
| 67 | "*All entries listed here will have an OPTcrossref field.") | 64 | "*All entries listed here will have an OPTcrossref field.") |
| 68 | 65 | ||
| 69 | (defvar bibtex-include-OPTkey t | 66 | (defvar bibtex-include-OPTkey t |
| 70 | "*If non-nil, all entries will have an OPTkey field.") | 67 | "*If non-nil, all entries will have an OPTkey field. |
| 71 | 68 | If this is a string, it will be used as the initial field text. | |
| 72 | (defvar bibtex-include-OPTannote t | 69 | If this is a function, it will be called to generate the initial field text.") |
| 73 | "*If non-nil, all entries will have an OPTannote field.") | ||
| 74 | 70 | ||
| 75 | (defvar bibtex-mode-user-optional-fields nil | 71 | (defvar bibtex-user-optional-fields |
| 72 | '(("annote" "Personal annotation (ignored)")) | ||
| 76 | "*List of optional fields the user wants to have always present. | 73 | "*List of optional fields the user wants to have always present. |
| 77 | Entries should be lists of strings with two elements (first element = | 74 | Entries should be of the same form as the OPTIONAL and |
| 78 | name of the field, second element = comment to appear in the echo area).") | 75 | CROSSREF-OPTIONAL lists in bibtex-entry-field-alist (see documentation |
| 79 | 76 | of this variable for details).") | |
| 80 | (defvar bibtex-clean-entry-zap-empty-opts t | 77 | |
| 81 | "*If non-nil, bibtex-clean-entry will delete all empty optional fields.") | 78 | (defvar bibtex-entry-format '(opts-or-alts numerical-fields) |
| 79 | "*Controls type of formatting performed by bibtex-clean-entry. | ||
| 80 | It may be t, nil, or a list of symbols out of the following: | ||
| 81 | 'opts-or-alts (delete empty optional and alternative fields and | ||
| 82 | remove OPT and ALT prefixes from used fields) | ||
| 83 | 'numerical-fields (delete delimiters around numeral fields) | ||
| 84 | 'page-dashes (change double dashes in page field to single dash | ||
| 85 | (for scribe compatibility)) | ||
| 86 | 'inherit-booktitle (if entry contains a crossref field and booktitle | ||
| 87 | field is empty, it is set to the contents of the | ||
| 88 | title field of the crossreferenced entry | ||
| 89 | (caution: this will work only if buffer is | ||
| 90 | correctly sorted)) | ||
| 91 | 'realign (realign entries, so that field texts and perhaps equal | ||
| 92 | signs (depending on the value of | ||
| 93 | bibtex-align-at-equal-sign) begin in the same column) | ||
| 94 | 'last-comma (add or delete comma on end of last field in entry, | ||
| 95 | depending on the value of bibtex-comma-after-last-field) | ||
| 96 | 'delimiters (change delimiters according to variables | ||
| 97 | bibtex-field-delimiters and bibtex-entry-delimiters) | ||
| 98 | 'unify-case (change case of entry and field names) | ||
| 99 | Value t means do all of the above formatting actions, | ||
| 100 | value nil means do no formatting at all.") | ||
| 101 | |||
| 102 | (defvar bibtex-clean-entry-hook nil | ||
| 103 | "*List of functions to call when entry has been cleaned. | ||
| 104 | Functions are called with point inside the cleaned entry, buffer is | ||
| 105 | narrowed to just the entry.") | ||
| 82 | 106 | ||
| 83 | (defvar bibtex-sort-ignore-string-entries t | 107 | (defvar bibtex-sort-ignore-string-entries t |
| 84 | "*If non-nil, BibTeX @STRING entries are not sort-significant. | 108 | "*If non-nil, BibTeX @String entries are not sort-significant. |
| 85 | That means they are ignored when determining ordering of the buffer | 109 | That means they are ignored when determining ordering of the buffer |
| 86 | (e.g. sorting, locating alphabetical position for new entries, etc.). | 110 | (e.g. sorting, locating alphabetical position for new entries, etc.). |
| 87 | This variable is buffer local.") | 111 | This variable is buffer local.") |
| @@ -95,12 +119,17 @@ duplicates) from bibtex-mode. See also bibtex-sort-ignore-string-entries. | |||
| 95 | This variable is buffer local.") | 119 | This variable is buffer local.") |
| 96 | (make-variable-buffer-local 'bibtex-maintain-sorted-entries) | 120 | (make-variable-buffer-local 'bibtex-maintain-sorted-entries) |
| 97 | 121 | ||
| 98 | (defvar bibtex-parse-keys-timeout auto-save-timeout | 122 | (defvar bibtex-field-kill-ring-max 20 |
| 99 | "*Specifies interval for parsing buffer for keys. | 123 | "*Maximum length of bibtex-field-kill-ring before oldest elements are deleted.") |
| 100 | The buffer is checked every bibtex-parse-keys-timeout seconds if it is | 124 | |
| 101 | modified since last parsing and is parsed if necessary. This is needed | 125 | (defvar bibtex-entry-kill-ring-max 20 |
| 102 | only if buffer is maintained sorted (bibtex-maintain-sorted-entries | 126 | "*Maximum length of bibtex-entry-kill-ring before oldest elements are deleted.") |
| 103 | non-nil).") | 127 | |
| 128 | (defvar bibtex-parse-keys-timeout 60 | ||
| 129 | "*Specifies interval for parsing buffers. | ||
| 130 | All BibTeX buffers in emacs are parsed if emacs has been idle | ||
| 131 | `bibtex-parse-keys-timeout' seconds. Only buffers which were modified | ||
| 132 | after last parsing and which are maintained in sorted order are parsed.") | ||
| 104 | 133 | ||
| 105 | (defvar bibtex-entry-field-alist | 134 | (defvar bibtex-entry-field-alist |
| 106 | '( | 135 | '( |
| @@ -109,24 +138,36 @@ non-nil).") | |||
| 109 | ("journal" "Name of the journal (use string, remove braces)") | 138 | ("journal" "Name of the journal (use string, remove braces)") |
| 110 | ("year" "Year of publication")) | 139 | ("year" "Year of publication")) |
| 111 | (("volume" "Volume of the journal") | 140 | (("volume" "Volume of the journal") |
| 112 | ("number" "Number of the journal") | 141 | ("number" "Number of the journal (only allowed if entry contains volume)") |
| 113 | ("month" "Month of the publication as a string (remove braces)") | ||
| 114 | ("pages" "Pages in the journal") | 142 | ("pages" "Pages in the journal") |
| 143 | ("month" "Month of the publication as a string (remove braces)") | ||
| 115 | ("note" "Remarks to be put at the end of the \\bibitem"))) | 144 | ("note" "Remarks to be put at the end of the \\bibitem"))) |
| 116 | ((("author" "Author1 [and Author2 ...] [and others]") | 145 | ((("author" "Author1 [and Author2 ...] [and others]") |
| 117 | ("title" "Title of the article (BibTeX converts it to lowercase)")) | 146 | ("title" "Title of the article (BibTeX converts it to lowercase)")) |
| 118 | (("journal" "Name of the journal (use string, remove braces)") | 147 | (("pages" "Pages in the journal") |
| 148 | ("journal" "Name of the journal (use string, remove braces)") | ||
| 119 | ("year" "Year of publication") | 149 | ("year" "Year of publication") |
| 120 | ("volume" "Volume of the journal") | 150 | ("volume" "Volume of the journal") |
| 121 | ("number" "Number of the journal") | 151 | ("number" "Number of the journal") |
| 122 | ("month" "Month of the publication as a string (remove braces)") | 152 | ("month" "Month of the publication as a string (remove braces)") |
| 123 | ("pages" "Pages in the journal") | ||
| 124 | ("note" "Remarks to be put at the end of the \\bibitem"))))) | 153 | ("note" "Remarks to be put at the end of the \\bibitem"))))) |
| 125 | ("Book" . (((("author" "Author1 [and Author2 ...] [and others]") | 154 | ("Book" . (((("author" "Author1 [and Author2 ...] [and others]" "" t) |
| 155 | ("editor" "Editor1 [and Editor2 ...] [and others]" "" t) | ||
| 126 | ("title" "Title of the book") | 156 | ("title" "Title of the book") |
| 127 | ("publisher" "Publishing company") | 157 | ("publisher" "Publishing company") |
| 128 | ("year" "Year of publication")) | 158 | ("year" "Year of publication")) |
| 129 | (("editor" "Editor1 [and Editor2 ...] [and others]") | 159 | (("volume" "Volume of the book in the series") |
| 160 | ("number" "Number of the book in a small series (overwritten by volume)") | ||
| 161 | ("series" "Series in which the book appeared") | ||
| 162 | ("address" "Address of the publisher") | ||
| 163 | ("edition" "Edition of the book as a capitalized English word") | ||
| 164 | ("month" "Month of the publication as a string (remove braces)") | ||
| 165 | ("note" "Remarks to be put at the end of the \\bibitem"))) | ||
| 166 | ((("author" "Author1 [and Author2 ...] [and others]" "" t) | ||
| 167 | ("editor" "Editor1 [and Editor2 ...] [and others]" "" t) | ||
| 168 | ("title" "Title of the book")) | ||
| 169 | (("publisher" "Publishing company") | ||
| 170 | ("year" "Year of publication") | ||
| 130 | ("volume" "Volume of the book in the series") | 171 | ("volume" "Volume of the book in the series") |
| 131 | ("number" "Number of the book in a small series (overwritten by volume)") | 172 | ("number" "Number of the book in a small series (overwritten by volume)") |
| 132 | ("series" "Series in which the book appeared") | 173 | ("series" "Series in which the book appeared") |
| @@ -138,38 +179,38 @@ non-nil).") | |||
| 138 | (("author" "Author1 [and Author2 ...] [and others]") | 179 | (("author" "Author1 [and Author2 ...] [and others]") |
| 139 | ("howpublished" "The way in which the booklet was published") | 180 | ("howpublished" "The way in which the booklet was published") |
| 140 | ("address" "Address of the publisher") | 181 | ("address" "Address of the publisher") |
| 141 | ("year" "Year of publication") | ||
| 142 | ("month" "Month of the publication as a string (remove braces)") | 182 | ("month" "Month of the publication as a string (remove braces)") |
| 183 | ("year" "Year of publication") | ||
| 143 | ("note" "Remarks to be put at the end of the \\bibitem"))))) | 184 | ("note" "Remarks to be put at the end of the \\bibitem"))))) |
| 144 | ("InBook" . (((("author" "Author1 [and Author2 ...] [and others]") | 185 | ("InBook" . (((("author" "Author1 [and Author2 ...] [and others]" "" t) |
| 186 | ("editor" "Editor1 [and Editor2 ...] [and others]" "" t) | ||
| 145 | ("title" "Title of the book") | 187 | ("title" "Title of the book") |
| 146 | ("chapter" "Chapter in the book") | 188 | ("chapter" "Chapter in the book") |
| 147 | ("publisher" "Publishing company") | 189 | ("publisher" "Publishing company") |
| 148 | ("year" "Year of publication")) | 190 | ("year" "Year of publication")) |
| 149 | (("editor" "Editor1 [and Editor2 ...] [and others]") | 191 | (("volume" "Volume of the book in the series") |
| 150 | ("volume" "Volume of the book in the series") | ||
| 151 | ("number" "Number of the book in a small series (overwritten by volume)") | 192 | ("number" "Number of the book in a small series (overwritten by volume)") |
| 152 | ("series" "Series in which the book appeared") | 193 | ("series" "Series in which the book appeared") |
| 194 | ("type" "Word to use instead of \"chapter\"") | ||
| 153 | ("address" "Address of the publisher") | 195 | ("address" "Address of the publisher") |
| 154 | ("edition" "Edition of the book as a capitalized English word") | 196 | ("edition" "Edition of the book as a capitalized English word") |
| 155 | ("month" "Month of the publication as a string (remove braces)") | 197 | ("month" "Month of the publication as a string (remove braces)") |
| 156 | ("pages" "Pages in the book") | 198 | ("pages" "Pages in the book") |
| 157 | ("type" "Word to use instead of \"chapter\"") | ||
| 158 | ("note" "Remarks to be put at the end of the \\bibitem"))) | 199 | ("note" "Remarks to be put at the end of the \\bibitem"))) |
| 159 | ((("author" "Author1 [and Author2 ...] [and others]") | 200 | ((("author" "Author1 [and Author2 ...] [and others]" "" t) |
| 201 | ("editor" "Editor1 [and Editor2 ...] [and others]" "" t) | ||
| 160 | ("title" "Title of the book") | 202 | ("title" "Title of the book") |
| 161 | ("chapter" "Chapter in the book")) | 203 | ("chapter" "Chapter in the book")) |
| 162 | (("publisher" "Publishing company") | 204 | (("pages" "Pages in the book") |
| 205 | ("publisher" "Publishing company") | ||
| 163 | ("year" "Year of publication") | 206 | ("year" "Year of publication") |
| 164 | ("editor" "Editor1 [and Editor2 ...] [and others]") | ||
| 165 | ("volume" "Volume of the book in the series") | 207 | ("volume" "Volume of the book in the series") |
| 166 | ("number" "Number of the book in a small series (overwritten by volume)") | 208 | ("number" "Number of the book in a small series (overwritten by volume)") |
| 167 | ("series" "Series in which the book appeared") | 209 | ("series" "Series in which the book appeared") |
| 210 | ("type" "Word to use instead of \"chapter\"") | ||
| 168 | ("address" "Address of the publisher") | 211 | ("address" "Address of the publisher") |
| 169 | ("edition" "Edition of the book as a capitalized English word") | 212 | ("edition" "Edition of the book as a capitalized English word") |
| 170 | ("month" "Month of the publication as a string (remove braces)") | 213 | ("month" "Month of the publication as a string (remove braces)") |
| 171 | ("pages" "Pages in the book") | ||
| 172 | ("type" "Word to use instead of \"chapter\"") | ||
| 173 | ("note" "Remarks to be put at the end of the \\bibitem"))))) | 214 | ("note" "Remarks to be put at the end of the \\bibitem"))))) |
| 174 | ("InCollection" . (((("author" "Author1 [and Author2 ...] [and others]") | 215 | ("InCollection" . (((("author" "Author1 [and Author2 ...] [and others]") |
| 175 | ("title" "Title of the article in book (BibTeX converts it to lowercase)") | 216 | ("title" "Title of the article in book (BibTeX converts it to lowercase)") |
| @@ -180,28 +221,28 @@ non-nil).") | |||
| 180 | ("volume" "Volume of the book in the series") | 221 | ("volume" "Volume of the book in the series") |
| 181 | ("number" "Number of the book in a small series (overwritten by volume)") | 222 | ("number" "Number of the book in a small series (overwritten by volume)") |
| 182 | ("series" "Series in which the book appeared") | 223 | ("series" "Series in which the book appeared") |
| 183 | ("chapter" "Chapter in the book") | ||
| 184 | ("type" "Word to use instead of \"chapter\"") | 224 | ("type" "Word to use instead of \"chapter\"") |
| 225 | ("chapter" "Chapter in the book") | ||
| 226 | ("pages" "Pages in the book") | ||
| 185 | ("address" "Address of the publisher") | 227 | ("address" "Address of the publisher") |
| 186 | ("edition" "Edition of the book as a capitalized English word") | 228 | ("edition" "Edition of the book as a capitalized English word") |
| 187 | ("month" "Month of the publication as a string (remove braces)") | 229 | ("month" "Month of the publication as a string (remove braces)") |
| 188 | ("pages" "Pages in the book") | ||
| 189 | ("note" "Remarks to be put at the end of the \\bibitem"))) | 230 | ("note" "Remarks to be put at the end of the \\bibitem"))) |
| 190 | ((("author" "Author1 [and Author2 ...] [and others]") | 231 | ((("author" "Author1 [and Author2 ...] [and others]") |
| 191 | ("title" "Title of the article in book (BibTeX converts it to lowercase)") | 232 | ("title" "Title of the article in book (BibTeX converts it to lowercase)") |
| 192 | ("booktitle" "Name of the book")) | 233 | ("booktitle" "Name of the book")) |
| 193 | (("publisher" "Publishing company") | 234 | (("pages" "Pages in the book") |
| 235 | ("publisher" "Publishing company") | ||
| 194 | ("year" "Year of publication") | 236 | ("year" "Year of publication") |
| 195 | ("editor" "Editor1 [and Editor2 ...] [and others]") | 237 | ("editor" "Editor1 [and Editor2 ...] [and others]") |
| 196 | ("volume" "Volume of the book in the series") | 238 | ("volume" "Volume of the book in the series") |
| 197 | ("number" "Number of the book in a small series (overwritten by volume)") | 239 | ("number" "Number of the book in a small series (overwritten by volume)") |
| 198 | ("series" "Series in which the book appeared") | 240 | ("series" "Series in which the book appeared") |
| 199 | ("chapter" "Chapter in the book") | ||
| 200 | ("type" "Word to use instead of \"chapter\"") | 241 | ("type" "Word to use instead of \"chapter\"") |
| 242 | ("chapter" "Chapter in the book") | ||
| 201 | ("address" "Address of the publisher") | 243 | ("address" "Address of the publisher") |
| 202 | ("edition" "Edition of the book as a capitalized English word") | 244 | ("edition" "Edition of the book as a capitalized English word") |
| 203 | ("month" "Month of the publication as a string (remove braces)") | 245 | ("month" "Month of the publication as a string (remove braces)") |
| 204 | ("pages" "Pages in the book") | ||
| 205 | ("note" "Remarks to be put at the end of the \\bibitem"))))) | 246 | ("note" "Remarks to be put at the end of the \\bibitem"))))) |
| 206 | ("InProceedings" . (((("author" "Author1 [and Author2 ...] [and others]") | 247 | ("InProceedings" . (((("author" "Author1 [and Author2 ...] [and others]") |
| 207 | ("title" "Title of the article in proceedings (BibTeX converts it to lowercase)") | 248 | ("title" "Title of the article in proceedings (BibTeX converts it to lowercase)") |
| @@ -211,56 +252,55 @@ non-nil).") | |||
| 211 | ("volume" "Volume of the conference proceedings in the series") | 252 | ("volume" "Volume of the conference proceedings in the series") |
| 212 | ("number" "Number of the conference proceedings in a small series (overwritten by volume)") | 253 | ("number" "Number of the conference proceedings in a small series (overwritten by volume)") |
| 213 | ("series" "Series in which the conference proceedings appeared") | 254 | ("series" "Series in which the conference proceedings appeared") |
| 214 | ("organization" "Sponsoring organization of the conference") | 255 | ("pages" "Pages in the conference proceedings") |
| 215 | ("publisher" "Publishing company, its location") | ||
| 216 | ("address" "Location of the Proceedings") | 256 | ("address" "Location of the Proceedings") |
| 217 | ("month" "Month of the publication as a string (remove braces)") | 257 | ("month" "Month of the publication as a string (remove braces)") |
| 218 | ("pages" "Pages in the conference proceedings") | 258 | ("organization" "Sponsoring organization of the conference") |
| 259 | ("publisher" "Publishing company, its location") | ||
| 219 | ("note" "Remarks to be put at the end of the \\bibitem"))) | 260 | ("note" "Remarks to be put at the end of the \\bibitem"))) |
| 220 | ((("author" "Author1 [and Author2 ...] [and others]") | 261 | ((("author" "Author1 [and Author2 ...] [and others]") |
| 221 | ("title" "Title of the article in proceedings (BibTeX converts it to lowercase)") | 262 | ("title" "Title of the article in proceedings (BibTeX converts it to lowercase)") |
| 222 | ("booktitle" "Name of the conference proceedings")) | 263 | ("booktitle" "Name of the conference proceedings")) |
| 223 | (("editor" "Editor1 [and Editor2 ...] [and others]") | 264 | (("pages" "Pages in the conference proceedings") |
| 265 | ("year" "Year of publication") | ||
| 266 | ("editor" "Editor1 [and Editor2 ...] [and others]") | ||
| 224 | ("volume" "Volume of the conference proceedings in the series") | 267 | ("volume" "Volume of the conference proceedings in the series") |
| 225 | ("number" "Number of the conference proceedings in a small series (overwritten by volume)") | 268 | ("number" "Number of the conference proceedings in a small series (overwritten by volume)") |
| 226 | ("series" "Series in which the conference proceedings appeared") | 269 | ("series" "Series in which the conference proceedings appeared") |
| 227 | ("year" "Year of publication") | ||
| 228 | ("organization" "Sponsoring organization of the conference") | ||
| 229 | ("publisher" "Publishing company, its location") | ||
| 230 | ("address" "Location of the Proceedings") | 270 | ("address" "Location of the Proceedings") |
| 231 | ("month" "Month of the publication as a string (remove braces)") | 271 | ("month" "Month of the publication as a string (remove braces)") |
| 232 | ("pages" "Pages in the conference proceedings") | 272 | ("organization" "Sponsoring organization of the conference") |
| 273 | ("publisher" "Publishing company, its location") | ||
| 233 | ("note" "Remarks to be put at the end of the \\bibitem"))))) | 274 | ("note" "Remarks to be put at the end of the \\bibitem"))))) |
| 234 | ("Manual" . (((("title" "Title of the manual")) | 275 | ("Manual" . (((("title" "Title of the manual")) |
| 235 | (("author" "Author1 [and Author2 ...] [and others]") | 276 | (("author" "Author1 [and Author2 ...] [and others]") |
| 236 | ("organization" "Publishing organization of the manual") | 277 | ("organization" "Publishing organization of the manual") |
| 237 | ("address" "Address of the organization") | 278 | ("address" "Address of the organization") |
| 238 | ("edition" "Edition of the manual as a capitalized English word") | 279 | ("edition" "Edition of the manual as a capitalized English word") |
| 239 | ("year" "Year of publication") | ||
| 240 | ("month" "Month of the publication as a string (remove braces)") | 280 | ("month" "Month of the publication as a string (remove braces)") |
| 281 | ("year" "Year of publication") | ||
| 241 | ("note" "Remarks to be put at the end of the \\bibitem"))))) | 282 | ("note" "Remarks to be put at the end of the \\bibitem"))))) |
| 242 | |||
| 243 | ("MastersThesis" . (((("author" "Author1 [and Author2 ...] [and others]") | 283 | ("MastersThesis" . (((("author" "Author1 [and Author2 ...] [and others]") |
| 244 | ("title" "Title of the master\'s thesis (BibTeX converts it to lowercase)") | 284 | ("title" "Title of the master\'s thesis (BibTeX converts it to lowercase)") |
| 245 | ("school" "School where the master\'s thesis was written") | 285 | ("school" "School where the master\'s thesis was written") |
| 246 | ("year" "Year of publication")) | 286 | ("year" "Year of publication")) |
| 247 | (("address" "Address of the school (if not part of field \"school\") or country") | 287 | (("type" "Type of the master\'s thesis (if other than \"Master\'s thesis\")") |
| 248 | ("type" "Type of the master\'s thesis") | 288 | ("address" "Address of the school (if not part of field \"school\") or country") |
| 249 | ("month" "Month of the publication as a string (remove braces)") | 289 | ("month" "Month of the publication as a string (remove braces)") |
| 250 | ("note" "Remarks to be put at the end of the \\bibitem"))))) | 290 | ("note" "Remarks to be put at the end of the \\bibitem"))))) |
| 251 | ("Misc" . ((() | 291 | ("Misc" . ((() |
| 252 | (("author" "Author1 [and Author2 ...] [and others]") | 292 | (("author" "Author1 [and Author2 ...] [and others]") |
| 253 | ("title" "Title of the reference (BibTeX converts it to lowercase)") | 293 | ("title" "Title of the reference (BibTeX converts it to lowercase)") |
| 254 | ("howpublished" "The way in which the reference was published") | 294 | ("howpublished" "The way in which the reference was published") |
| 255 | ("year" "Year of publication") | ||
| 256 | ("month" "Month of the publication as a string (remove braces)") | 295 | ("month" "Month of the publication as a string (remove braces)") |
| 296 | ("year" "Year of publication") | ||
| 257 | ("note" "Remarks to be put at the end of the \\bibitem"))))) | 297 | ("note" "Remarks to be put at the end of the \\bibitem"))))) |
| 258 | ("PhdThesis" . (((("author" "Author1 [and Author2 ...] [and others]") | 298 | ("PhdThesis" . (((("author" "Author1 [and Author2 ...] [and others]") |
| 259 | ("title" "Title of the PhD. thesis") | 299 | ("title" "Title of the PhD. thesis") |
| 260 | ("school" "School where the PhD. thesis was written") | 300 | ("school" "School where the PhD. thesis was written") |
| 261 | ("year" "Year of publication")) | 301 | ("year" "Year of publication")) |
| 262 | (("address" "Address of the school (if not part of field \"school\") or country") | 302 | (("type" "Type of the PhD. thesis") |
| 263 | ("type" "Type of the PhD. thesis") | 303 | ("address" "Address of the school (if not part of field \"school\") or country") |
| 264 | ("month" "Month of the publication as a string (remove braces)") | 304 | ("month" "Month of the publication as a string (remove braces)") |
| 265 | ("note" "Remarks to be put at the end of the \\bibitem"))))) | 305 | ("note" "Remarks to be put at the end of the \\bibitem"))))) |
| 266 | ("Proceedings" . (((("title" "Title of the conference proceedings") | 306 | ("Proceedings" . (((("title" "Title of the conference proceedings") |
| @@ -269,10 +309,10 @@ non-nil).") | |||
| 269 | ("volume" "Volume of the conference proceedings in the series") | 309 | ("volume" "Volume of the conference proceedings in the series") |
| 270 | ("number" "Number of the conference proceedings in a small series (overwritten by volume)") | 310 | ("number" "Number of the conference proceedings in a small series (overwritten by volume)") |
| 271 | ("series" "Series in which the conference proceedings appeared") | 311 | ("series" "Series in which the conference proceedings appeared") |
| 272 | ("publisher" "Publishing company, its location") | ||
| 273 | ("organization" "Sponsoring organization of the conference") | ||
| 274 | ("address" "Location of the Proceedings") | 312 | ("address" "Location of the Proceedings") |
| 275 | ("month" "Month of the publication as a string (remove braces)") | 313 | ("month" "Month of the publication as a string (remove braces)") |
| 314 | ("organization" "Sponsoring organization of the conference") | ||
| 315 | ("publisher" "Publishing company, its location") | ||
| 276 | ("note" "Remarks to be put at the end of the \\bibitem"))))) | 316 | ("note" "Remarks to be put at the end of the \\bibitem"))))) |
| 277 | ("TechReport" . (((("author" "Author1 [and Author2 ...] [and others]") | 317 | ("TechReport" . (((("author" "Author1 [and Author2 ...] [and others]") |
| 278 | ("title" "Title of the technical report (BibTeX converts it to lowercase)") | 318 | ("title" "Title of the technical report (BibTeX converts it to lowercase)") |
| @@ -286,31 +326,49 @@ non-nil).") | |||
| 286 | ("Unpublished" . (((("author" "Author1 [and Author2 ...] [and others]") | 326 | ("Unpublished" . (((("author" "Author1 [and Author2 ...] [and others]") |
| 287 | ("title" "Title of the unpublished reference (BibTeX converts it to lowercase)") | 327 | ("title" "Title of the unpublished reference (BibTeX converts it to lowercase)") |
| 288 | ("note" "Remarks to be put at the end of the \\bibitem")) | 328 | ("note" "Remarks to be put at the end of the \\bibitem")) |
| 289 | (("year" "Year of publication") | 329 | (("month" "Month of the publication as a string (remove braces)") |
| 290 | ("month" "Month of the publication as a string (remove braces)"))))) | 330 | ("year" "Year of publication"))))) |
| 291 | ) | 331 | ) |
| 292 | 332 | ||
| 293 | "Defines reference types and their associated fields. | 333 | "Defines reference types and their associated fields. |
| 294 | List of | 334 | List of |
| 295 | (entry-name (required optional) (crossref-required crossref-optional)) | 335 | (ENTRY-NAME (REQUIRED OPTIONAL) (CROSSREF-REQUIRED CROSSREF-OPTIONAL)) |
| 296 | triples. | 336 | triples. |
| 297 | If the third element is nil, the first pair is always to be used. | 337 | If the third element is nil, the first pair is always used. |
| 298 | If not, the second pair is to be used in the case of presence of a | 338 | If not, the second pair is used in the case of presence of a crossref |
| 299 | crossref field and the third in the case of absence. | 339 | field and the third in the case of absence. |
| 300 | Required , optional, crossref-required and crossref-optional are lists. | 340 | REQUIRED, OPTIONAL, CROSSREF-REQUIRED and CROSSREF-OPTIONAL are lists. |
| 301 | Each element of these lists is a list of strings with two elements | 341 | Each element of these lists is a list of the form |
| 302 | (first element = name of the field, | 342 | (FIELD-NAME COMMENT-STRING INIT ALTERNATIVE-FLAG). |
| 303 | second element = comment to appear in the echo area).") | 343 | COMMENT-STRING, INIT, and ALTERNATIVE-FLAG are optional. |
| 304 | 344 | FIELD-NAME is the name of the field, COMMENT-STRING the comment to | |
| 305 | (defvar bibtex-predefined-strings | 345 | appear in the echo area, INIT is either the initial content of the |
| 346 | field or a function, which is called to determine the initial content | ||
| 347 | of the field, and ALTERNATIVE-FLAG (either nil or t) marks if the | ||
| 348 | field is an alternative. ALTERNATIVE-FLAG may be t only in the | ||
| 349 | REQUIRED or CROSSREF-REQUIRED lists.") | ||
| 350 | |||
| 351 | (defvar bibtex-add-entry-hook nil | ||
| 352 | "List of functions to call when entry has been inserted.") | ||
| 353 | |||
| 354 | (defvar bibtex-predefined-month-strings | ||
| 306 | '( | 355 | '( |
| 307 | ("jan") ("feb") ("mar") ("apr") ("may") ("jun") ("jul") ("aug") | 356 | ("jan") ("feb") ("mar") ("apr") ("may") ("jun") |
| 308 | ("sep") ("oct") ("nov") ("dec") | 357 | ("jul") ("aug") ("sep") ("oct") ("nov") ("dec") |
| 309 | ("acmcs") ("acta") ("cacm") ("ibmjrd") ("ibmsj") ("ieeese") | ||
| 310 | ("ieeetc") ("ieeetcad") ("ipl") ("jacm") ("jcss") ("scp") | ||
| 311 | ("sicomp") ("tcs") ("tocs") ("tods") ("tog") ("toms") ("toois") | ||
| 312 | ("toplas") | ||
| 313 | ) | 358 | ) |
| 359 | "Alist of month string definitions. | ||
| 360 | Should contain all strings used for months in the BibTeX style files. | ||
| 361 | Each element is a list with just one element: the string.") | ||
| 362 | |||
| 363 | (defvar bibtex-predefined-strings | ||
| 364 | (append | ||
| 365 | bibtex-predefined-month-strings | ||
| 366 | '( | ||
| 367 | ("acmcs") ("acta") ("cacm") ("ibmjrd") ("ibmsj") ("ieeese") | ||
| 368 | ("ieeetc") ("ieeetcad") ("ipl") ("jacm") ("jcss") ("scp") | ||
| 369 | ("sicomp") ("tcs") ("tocs") ("tods") ("tog") ("toms") ("toois") | ||
| 370 | ("toplas") | ||
| 371 | )) | ||
| 314 | "Alist of string definitions. | 372 | "Alist of string definitions. |
| 315 | Should contain the strings defined in the BibTeX style files. Each | 373 | Should contain the strings defined in the BibTeX style files. Each |
| 316 | element is a list with just one element: the string.") | 374 | element is a list with just one element: the string.") |
| @@ -318,118 +376,201 @@ element is a list with just one element: the string.") | |||
| 318 | (defvar bibtex-string-files nil | 376 | (defvar bibtex-string-files nil |
| 319 | "*List of BibTeX files containing string definitions. | 377 | "*List of BibTeX files containing string definitions. |
| 320 | Those files must be specified using pathnames relative to the | 378 | Those files must be specified using pathnames relative to the |
| 321 | directories specified in $BIBINPUTS. This variable is only evaluated | 379 | directories specified in bibtex-string-file-path. This variable is only |
| 322 | when bibtex-mode is entered (i. e. when loading the BibTeX file).") | 380 | evaluated when bibtex-mode is entered (i. e. when loading the BibTeX |
| 381 | file).") | ||
| 382 | |||
| 383 | (defvar bibtex-string-file-path (getenv "BIBINPUTS") | ||
| 384 | "*Colon separated list of pathes to search for bibtex-string-files.") | ||
| 323 | 385 | ||
| 324 | (defvar bibtex-help-message t | 386 | (defvar bibtex-help-message t |
| 325 | "*If not nil print help messages in the echo area on entering a new field.") | 387 | "*If not nil print help messages in the echo area on entering a new field.") |
| 326 | 388 | ||
| 389 | (defvar bibtex-autokey-prefix-string "" | ||
| 390 | "*String to use as a prefix for all generated keys. | ||
| 391 | See the documentation of function bibtex-generate-autokey for further detail.") | ||
| 392 | |||
| 327 | (defvar bibtex-autokey-names 1 | 393 | (defvar bibtex-autokey-names 1 |
| 328 | "*Number of names to use for the automatically generated reference key. | 394 | "*Number of names to use for the automatically generated reference key. |
| 329 | If this is set to anything but a number, all names are used. | 395 | If this is set to anything but a number, all names are used. |
| 396 | Possibly more names are used according to bibtex-autokey-names-stretch. | ||
| 330 | See the documentation of function bibtex-generate-autokey for further detail.") | 397 | See the documentation of function bibtex-generate-autokey for further detail.") |
| 331 | 398 | ||
| 332 | (defvar bibtex-autokey-name-change-strings | 399 | (defvar bibtex-autokey-names-stretch 0 |
| 333 | '(("\\\\\\\"a" "ae") ("\\\\\\\"o" "oe") ("\\\\\\\"u" "ue") | 400 | "*Number of names that can additionally be used. |
| 334 | ("\\\\\\\"s" "ss") | 401 | These names are used only, if all names are used then. |
| 335 | ("\\\\\\\"A" "Ae") ("\\\\\\\"O" "Oe") ("\\\\\\\"U" "Ue") | 402 | See the documentation of function bibtex-generate-autokey for details.") |
| 336 | ("\\\"a" "ae") ("\\\"o" "oe") ("\\\"u" "ue") ("\\\"s" "ss") | 403 | |
| 337 | ("\\\"A" "Ae") ("\\\"O" "Oe") ("\\\"U" "Ue") | 404 | (defvar bibtex-autokey-additional-names "" |
| 405 | "*String to prepend to the generated key if not all names could be used. | ||
| 406 | See the documentation of function bibtex-generate-autokey for details.") | ||
| 407 | |||
| 408 | (defvar bibtex-autokey-transcriptions | ||
| 409 | '( | ||
| 410 | ;; language specific characters | ||
| 411 | ("\\\\aa" "a") | ||
| 412 | ("\\\\AA" "A") | ||
| 413 | ("\\\"a\\|\\\\\\\"a\\|\\\\ae" "ae") | ||
| 414 | ("\\\"A\\|\\\\\\\"A\\|\\\\AE" "Ae") | ||
| 415 | ("\\\\i" "i") | ||
| 416 | ("\\\\j" "j") | ||
| 417 | ("\\\\l" "l") | ||
| 418 | ("\\\\L" "L") | ||
| 419 | ("\\\"o\\|\\\\\\\"o\\|\\\\o\\|\\\\oe" "oe") | ||
| 420 | ("\\\"O\\|\\\\\\\"O\\|\\\\O\\|\\\\OE" "Oe") | ||
| 421 | ("\\\"s\\|\\\\\\\"s" "ss") | ||
| 422 | ("\\\"u\\|\\\\\\\"u" "ue") | ||
| 423 | ("\\\"U\\|\\\\\\\"U" "Ue") | ||
| 424 | ;; accents | ||
| 425 | ("\\\\`\\|\\\\'\\|\\\\\\^\\|\\\\~\\|\\\\=\\|\\\\\\.\\|\\\\u\\|\\\\v\\|\\\\H\\|\\\\t\\|\\\\c\\|\\\\d\\|\\\\b" "") | ||
| 426 | ;; braces | ||
| 338 | ("{" "") ("}" "")) | 427 | ("{" "") ("}" "")) |
| 339 | "Alist of (old-regexp new-string) pairs. | 428 | "Alist of (old-regexp new-string) pairs. |
| 429 | Used by the default values of bibtex-autokey-name-change-strings and | ||
| 430 | bibtex-autokey-titleword-change-strings. Defaults to translating some | ||
| 431 | language specific characters to their ascii transcriptions and | ||
| 432 | removing any character accents.") | ||
| 433 | |||
| 434 | (defvar bibtex-autokey-name-change-strings | ||
| 435 | bibtex-autokey-transcriptions | ||
| 436 | "Alist of (old-regexp new-string) pairs. | ||
| 340 | Any part of name matching a old-regexp is replaced by new-string. | 437 | Any part of name matching a old-regexp is replaced by new-string. |
| 341 | Case of the old-regexp is significant. All regexps are tried in the | 438 | Case of the old-regexp is significant. All regexps are tried in the |
| 342 | order in which they appear in the list, so be sure to avoid recursion here. | 439 | order in which they appear in the list, so be sure to avoid inifinite |
| 343 | See the documentation of function bibtex-generate-autokey for further detail.") | 440 | loops here. |
| 441 | See the documentation of function bibtex-generate-autokey for details.") | ||
| 344 | 442 | ||
| 345 | (defvar bibtex-autokey-name-length 'infty | 443 | (defvar bibtex-autokey-name-length 'infty |
| 346 | "*Number of characters from name to incorporate into key. | 444 | "*Number of characters from name to incorporate into key. |
| 347 | If this is set to anything but a number, all characters are used. | 445 | If this is set to anything but a number, all characters are used. |
| 348 | See the documentation of function bibtex-generate-autokey for further detail.") | 446 | See the documentation of function bibtex-generate-autokey for details.") |
| 349 | 447 | ||
| 350 | (defvar bibtex-autokey-name-separator "" | 448 | (defvar bibtex-autokey-name-separator "" |
| 351 | "*String that comes between any two names in the key. | 449 | "*String that comes between any two names in the key. |
| 352 | See the documentation of function bibtex-generate-autokey for further detail.") | 450 | See the documentation of function bibtex-generate-autokey for details.") |
| 353 | 451 | ||
| 354 | (defvar bibtex-autokey-year-length 2 | 452 | (defvar bibtex-autokey-year-length 2 |
| 355 | "*Number of rightmost digits from the year field yo incorporate into key. | 453 | "*Number of rightmost digits from the year field yo incorporate into key. |
| 356 | See the documentation of function bibtex-generate-autokey for further detail.") | 454 | See the documentation of function bibtex-generate-autokey for details.") |
| 455 | |||
| 456 | (defvar bibtex-autokey-year-use-crossref-entry t | ||
| 457 | "*If non-nil use year field from crossreferenced entry if necessary. | ||
| 458 | If this variable is non-nil and the current entry has no year, but a | ||
| 459 | valid crossref entry, the year field from the crossreferenced entry is | ||
| 460 | used. | ||
| 461 | See the documentation of function bibtex-generate-autokey for details.") | ||
| 357 | 462 | ||
| 358 | (defvar bibtex-autokey-titlewords 5 | 463 | (defvar bibtex-autokey-titlewords 5 |
| 359 | "*Number of title words to use for the automatically generated reference key. | 464 | "*Number of title words to use for the automatically generated reference key. |
| 360 | If this is set to anything but a number, all title words are used. | 465 | If this is set to anything but a number, all title words are used. |
| 361 | See the documentation of function bibtex-generate-autokey for further detail.") | 466 | Possibly more words from the title are used according to |
| 467 | bibtex-autokey-titlewords-stretch. | ||
| 468 | See the documentation of function bibtex-generate-autokey for details.") | ||
| 362 | 469 | ||
| 363 | (defvar bibtex-autokey-title-terminators | 470 | (defvar bibtex-autokey-title-terminators |
| 364 | '("\\." "!" "\\?" ":" ";" "---") | 471 | '("\\." "!" "\\?" ":" ";" "--") |
| 365 | "*Regexp list defining the termination of the main part of the title. | 472 | "*Regexp list defining the termination of the main part of the title. |
| 366 | Case of the regexps is ignored. | 473 | Case of the regexps is ignored. |
| 367 | See the documentation of function bibtex-generate-autokey for further detail.") | 474 | See the documentation of function bibtex-generate-autokey for details.") |
| 368 | 475 | ||
| 369 | (defvar bibtex-autokey-titlewords-stretch 2 | 476 | (defvar bibtex-autokey-titlewords-stretch 2 |
| 370 | "*Number of words that can additionally be used from the title. | 477 | "*Number of words that can additionally be used from the title. |
| 371 | These words are used only, if a sentence from the title can be ended then. | 478 | These words are used only, if a sentence from the title can be ended then. |
| 372 | See the documentation of function bibtex-generate-autokey for further detail.") | 479 | See the documentation of function bibtex-generate-autokey for details.") |
| 373 | 480 | ||
| 374 | (defvar bibtex-autokey-titleword-first-ignore | 481 | (defvar bibtex-autokey-titleword-first-ignore |
| 375 | '("a" "an" "on" "the" "eine?" "der" "die" "das") | 482 | '("a" "an" "on" "the" "eine?" "der" "die" "das") |
| 376 | "*Determines words that may begin a title but are not to be used in the key. | 483 | "*Determines words that may begin a title but are not to be used in the key. |
| 377 | Each item of the list is a regexp. If the first word of the title matchs a | 484 | Each item of the list is a regexp. If the first word of the title matchs a |
| 378 | regexp from that list, it is not included in the title, even if it is | 485 | regexp from that list, it is not included in the title, even if it is |
| 379 | capitalized. Regexps in the list must be entered using lowercase letters.") | 486 | capitalized. Case of regexps in this list doesn't matter. |
| 487 | See the documentation of function bibtex-generate-autokey for details.") | ||
| 380 | 488 | ||
| 381 | (defvar bibtex-autokey-titleword-abbrevs nil | 489 | (defvar bibtex-autokey-titleword-abbrevs nil |
| 382 | "*Determines exceptions to the usual abbreviation mechanism. | 490 | "*Determines exceptions to the usual abbreviation mechanism. |
| 383 | A list of (old-regexp new-string) pairs. | 491 | An alist of (old-regexp new-string) pairs. Case of old-regexp ignored. |
| 384 | Use all lowercase letters for old-regexp. | 492 | The first matching pair is used. |
| 385 | See the documentation of function bibtex-generate-autokey for further detail.") | 493 | See the documentation of function bibtex-generate-autokey for details.") |
| 386 | 494 | ||
| 387 | (defvar bibtex-autokey-titleword-change-strings | 495 | (defvar bibtex-autokey-titleword-change-strings |
| 388 | '(("\\\\\\\"a" "ae") ("\\\\\\\"o" "oe") ("\\\\\\\"u" "ue") | 496 | bibtex-autokey-transcriptions |
| 389 | ("\\\\\\\"s" "ss") | ||
| 390 | ("\\\\\\\"A" "Ae") ("\\\\\\\"O" "Oe") ("\\\\\\\"U" "Ue") | ||
| 391 | ("\\\"a" "ae") ("\\\"o" "oe") ("\\\"u" "ue") ("\\\"s" "ss") | ||
| 392 | ("\\\"A" "Ae") ("\\\"O" "Oe") ("\\\"U" "Ue") | ||
| 393 | ("{" "") ("}" "")) | ||
| 394 | "Alist of (old-regexp new-string) pairs. | 497 | "Alist of (old-regexp new-string) pairs. |
| 395 | Any part of title word matching a old-regexp is replaced by new-string. | 498 | Any part of title word matching a old-regexp is replaced by new-string. |
| 396 | Case of the old-regexp is significant. | 499 | Case of the old-regexp is significant. All regexps are tried in the |
| 397 | See the documentation of function bibtex-generate-autokey for further detail.") | 500 | order in which they appear in the list, so be sure to avoid inifinite |
| 501 | loops here. | ||
| 502 | See the documentation of function bibtex-generate-autokey for details.") | ||
| 398 | 503 | ||
| 399 | (defvar bibtex-autokey-titleword-length 5 | 504 | (defvar bibtex-autokey-titleword-length 5 |
| 400 | "*Number of characters from title words to incorporate into key. | 505 | "*Number of characters from title words to incorporate into key. |
| 401 | If this is set to anything but a number, all characters are used. | 506 | If this is set to anything but a number, all characters are used. |
| 402 | See the documentation of function bibtex-generate-autokey for further detail.") | 507 | See the documentation of function bibtex-generate-autokey for details.") |
| 403 | 508 | ||
| 404 | (defvar bibtex-autokey-titleword-separator "_" | 509 | (defvar bibtex-autokey-titleword-separator "_" |
| 405 | "*String to be put between the title words. | 510 | "*String to be put between the title words. |
| 406 | See the documentation of function bibtex-generate-autokey for further detail.") | 511 | See the documentation of function bibtex-generate-autokey for details.") |
| 407 | 512 | ||
| 408 | (defvar bibtex-autokey-name-year-separator "" | 513 | (defvar bibtex-autokey-name-year-separator "" |
| 409 | "*String to be put between name part and year part of key. | 514 | "*String to be put between name part and year part of key. |
| 410 | See the documentation of function bibtex-generate-autokey for further detail.") | 515 | See the documentation of function bibtex-generate-autokey for details.") |
| 411 | 516 | ||
| 412 | (defvar bibtex-autokey-year-title-separator ":_" | 517 | (defvar bibtex-autokey-year-title-separator ":_" |
| 413 | "*String to be put between name part and year part of key. | 518 | "*String to be put between name part and year part of key. |
| 414 | See the documentation of function bibtex-generate-autokey for further detail.") | 519 | See the documentation of function bibtex-generate-autokey for details.") |
| 520 | |||
| 521 | (defvar bibtex-autokey-preserve-case nil | ||
| 522 | "*If non-nil, names and titlewords used aren't converted to lowercase. | ||
| 523 | See the documentation of function bibtex-generate-autokey for details.") | ||
| 415 | 524 | ||
| 416 | (defvar bibtex-autokey-edit-before-use t | 525 | (defvar bibtex-autokey-edit-before-use t |
| 417 | "*If non-nil, user is allowed to edit the generated key before it is used.") | 526 | "*If non-nil, user is allowed to edit the generated key before it is used.") |
| 418 | 527 | ||
| 528 | (defvar bibtex-autokey-before-presentation-hook nil | ||
| 529 | "Function to call before the generated key is presented. | ||
| 530 | If non-nil this should be a single function, which is called before | ||
| 531 | the generated key is presented (in entry or, if | ||
| 532 | `bibtex-autokey-edit-before-use' is t, in minibuffer). This function | ||
| 533 | must take one argument (the automatically generated key), and must | ||
| 534 | return with a string (the key to use).") | ||
| 535 | |||
| 536 | (defvar bibtex-entry-offset 0 | ||
| 537 | "*Offset for BibTeX entries. | ||
| 538 | Added to the value of all other variables which determine colums.") | ||
| 539 | |||
| 540 | (defvar bibtex-field-indentation 2 | ||
| 541 | "*Starting column for the name part in BibTeX fields.") | ||
| 542 | |||
| 543 | (defvar bibtex-text-indentation | ||
| 544 | (+ | ||
| 545 | bibtex-field-indentation | ||
| 546 | (length "organization = ")) | ||
| 547 | "*Starting column for the text part in BibTeX fields. | ||
| 548 | Should be equal to the space needed for the longest name part.") | ||
| 549 | |||
| 550 | (defvar bibtex-contline-indentation | ||
| 551 | (+ bibtex-text-indentation 1) | ||
| 552 | "*Starting column for continuation lines of BibTeX fields.") | ||
| 553 | |||
| 554 | (defvar bibtex-align-at-equal-sign nil | ||
| 555 | "*If non-nil, align fields at equal sign instead of field text. | ||
| 556 | If non nil, column of equal sign is bibtex-text-indentation - 2.") | ||
| 557 | |||
| 558 | (defvar bibtex-comma-after-last-field nil | ||
| 559 | "*If non-nil, a comma is put at end of last field in the entry template.") | ||
| 560 | |||
| 419 | ;; bibtex-font-lock-keywords is a user option as well, but since the | 561 | ;; bibtex-font-lock-keywords is a user option as well, but since the |
| 420 | ;; patterns used to define this variable are defined in a later | 562 | ;; patterns used to define this variable are defined in a later |
| 421 | ;; section of this file, its definition comes later. | 563 | ;; section of this file, it is defined later. |
| 422 | 564 | ||
| 423 | 565 | ||
| 424 | ;; Syntax Table, Keybindings and BibTeX Entry List | 566 | ;; Syntax Table, Keybindings and BibTeX Entry List |
| 425 | (defvar bibtex-mode-syntax-table | 567 | (defvar bibtex-mode-syntax-table |
| 426 | (let ((st (make-syntax-table))) | 568 | (let ((st (make-syntax-table))) |
| 427 | (modify-syntax-entry ?\" "w" st) | 569 | (modify-syntax-entry ?\" "\"" st) |
| 428 | ;; this was formerly "\"". Does this cause any problems? | ||
| 429 | (modify-syntax-entry ?$ "$$ " st) | 570 | (modify-syntax-entry ?$ "$$ " st) |
| 430 | (modify-syntax-entry ?% "< " st) | 571 | (modify-syntax-entry ?% "< " st) |
| 431 | (modify-syntax-entry ?' "w " st) | 572 | (modify-syntax-entry ?' "w " st) |
| 432 | (modify-syntax-entry ?@ "w " st) | 573 | (modify-syntax-entry ?@ "w " st) |
| 433 | (modify-syntax-entry ?\\ "\\" st) | 574 | (modify-syntax-entry ?\\ "\\" st) |
| 434 | (modify-syntax-entry ?\f "> " st) | 575 | (modify-syntax-entry ?\f "> " st) |
| 435 | (modify-syntax-entry ?\n "> " st) | 576 | (modify-syntax-entry ?\n "> " st) |
| @@ -438,28 +579,36 @@ See the documentation of function bibtex-generate-autokey for further detail.") | |||
| 438 | 579 | ||
| 439 | (defvar bibtex-mode-map | 580 | (defvar bibtex-mode-map |
| 440 | (let ((km (make-sparse-keymap))) | 581 | (let ((km (make-sparse-keymap))) |
| 441 | |||
| 442 | (define-key km "\t" 'bibtex-find-text) | 582 | (define-key km "\t" 'bibtex-find-text) |
| 443 | (define-key km "\n" 'bibtex-next-field) | 583 | (define-key km "\n" 'bibtex-next-field) |
| 444 | (define-key km "\M-\t" 'bibtex-complete-string) | 584 | (define-key km "\M-\t" 'bibtex-complete-string) |
| 445 | (define-key km "\C-c\"" 'bibtex-remove-double-quotes-or-braces) | 585 | (define-key km [(control tab)] 'bibtex-complete-key) |
| 446 | (define-key km "\C-c{" 'bibtex-remove-double-quotes-or-braces) | 586 | (define-key km "\C-c\"" 'bibtex-remove-delimiters) |
| 447 | (define-key km "\C-c}" 'bibtex-remove-double-quotes-or-braces) | 587 | (define-key km "\C-c{" 'bibtex-remove-delimiters) |
| 588 | (define-key km "\C-c}" 'bibtex-remove-delimiters) | ||
| 448 | (define-key km "\C-c\C-c" 'bibtex-clean-entry) | 589 | (define-key km "\C-c\C-c" 'bibtex-clean-entry) |
| 590 | (define-key km "\C-c\C-q" 'bibtex-fill-entry) | ||
| 449 | (define-key km "\C-c?" 'bibtex-print-help-message) | 591 | (define-key km "\C-c?" 'bibtex-print-help-message) |
| 450 | (define-key km "\C-c\C-p" 'bibtex-pop-previous) | 592 | (define-key km "\C-c\C-p" 'bibtex-pop-previous) |
| 451 | (define-key km "\C-c\C-n" 'bibtex-pop-next) | 593 | (define-key km "\C-c\C-n" 'bibtex-pop-next) |
| 452 | (define-key km "\C-c\C-k" 'bibtex-kill-optional-field) | 594 | (define-key km "\C-c\C-k" 'bibtex-kill-field) |
| 595 | (define-key km "\C-c\M-k" 'bibtex-copy-field-as-kill) | ||
| 596 | (define-key km "\C-c\C-w" 'bibtex-kill-entry) | ||
| 597 | (define-key km "\C-c\M-w" 'bibtex-copy-entry-as-kill) | ||
| 598 | (define-key km "\C-c\C-y" 'bibtex-yank) | ||
| 599 | (define-key km "\C-c\M-y" 'bibtex-yank-pop) | ||
| 453 | (define-key km "\C-c\C-d" 'bibtex-empty-field) | 600 | (define-key km "\C-c\C-d" 'bibtex-empty-field) |
| 454 | (define-key km "\C-c$" 'bibtex-ispell-entry) | 601 | (define-key km "\C-c\C-f" 'bibtex-make-field) |
| 455 | (define-key km "\M-\C-a" 'bibtex-beginning-of-entry) | 602 | (define-key km "\C-c$" 'bibtex-ispell-abstract) |
| 456 | (define-key km "\M-\C-e" 'bibtex-end-of-entry) | 603 | (define-key km "\M-\C-a" 'bibtex-beginning-of-entry) |
| 457 | (define-key km "\C-c\C-b" 'bibtex-entry) | 604 | (define-key km "\M-\C-e" 'bibtex-end-of-entry) |
| 458 | (define-key km "\C-c\C-q" 'bibtex-hide-entry-bodies) | 605 | (define-key km "\C-\M-l" 'bibtex-reposition-window) |
| 606 | (define-key km "\C-\M-h" 'bibtex-mark-entry) | ||
| 607 | (define-key km "\C-c\C-b" 'bibtex-entry) | ||
| 608 | (define-key km "\C-c\C-t" 'bibtex-hide-entry-bodies) | ||
| 459 | (define-key km "\C-c\C-rn" 'bibtex-narrow-to-entry) | 609 | (define-key km "\C-c\C-rn" 'bibtex-narrow-to-entry) |
| 460 | (define-key km "\C-c\C-rw" 'widen) | 610 | (define-key km "\C-c\C-rw" 'widen) |
| 461 | (define-key km "\C-c\C-o" 'bibtex-remove-OPT) | 611 | (define-key km "\C-c\C-o" 'bibtex-remove-OPT-or-ALT) |
| 462 | |||
| 463 | (define-key km "\C-c\C-e\C-i" 'bibtex-InProceedings) | 612 | (define-key km "\C-c\C-e\C-i" 'bibtex-InProceedings) |
| 464 | (define-key km "\C-c\C-ei" 'bibtex-InCollection) | 613 | (define-key km "\C-c\C-ei" 'bibtex-InCollection) |
| 465 | (define-key km "\C-c\C-eI" 'bibtex-InBook) | 614 | (define-key km "\C-c\C-eI" 'bibtex-InBook) |
| @@ -474,75 +623,79 @@ See the documentation of function bibtex-generate-autokey for further detail.") | |||
| 474 | (define-key km "\C-c\C-e\C-p" 'bibtex-InProceedings) | 623 | (define-key km "\C-c\C-e\C-p" 'bibtex-InProceedings) |
| 475 | (define-key km "\C-c\C-ep" 'bibtex-Proceedings) | 624 | (define-key km "\C-c\C-ep" 'bibtex-Proceedings) |
| 476 | (define-key km "\C-c\C-eP" 'bibtex-PhdThesis) | 625 | (define-key km "\C-c\C-eP" 'bibtex-PhdThesis) |
| 477 | (define-key km "\C-c\C-e\M-p" 'bibtex-preamble) | 626 | (define-key km "\C-c\C-e\M-p" 'bibtex-Preamble) |
| 478 | (define-key km "\C-c\C-e\C-s" 'bibtex-string) | 627 | (define-key km "\C-c\C-e\C-s" 'bibtex-String) |
| 479 | (define-key km "\C-c\C-e\C-t" 'bibtex-TechReport) | 628 | (define-key km "\C-c\C-e\C-t" 'bibtex-TechReport) |
| 480 | (define-key km "\C-c\C-e\C-u" 'bibtex-Unpublished) | 629 | (define-key km "\C-c\C-e\C-u" 'bibtex-Unpublished) |
| 481 | km)) | 630 | km)) |
| 482 | 631 | ||
| 483 | (define-key bibtex-mode-map [menu-bar bibtex-edit] | 632 | (easy-menu-define |
| 484 | (cons "BibTeX-Edit" (make-sparse-keymap "BibTeX-Edit"))) | 633 | bibtex-edit-menu bibtex-mode-map "BibTeX-Edit Menu in BibTeX mode" |
| 485 | (define-key bibtex-mode-map [menu-bar bibtex-edit bibtex-print-help-message] | 634 | '("BibTeX-Edit" |
| 486 | '("Help about Current Field" . bibtex-print-help-message)) | 635 | ("Moving inside an Entry" |
| 487 | (define-key bibtex-mode-map [menu-bar bibtex-edit bibtex-complete-string] | 636 | ["End of Field" bibtex-find-text t] |
| 488 | '("String Complete" . bibtex-complete-string)) | 637 | ["Next Field" bibtex-next-field t] |
| 489 | (define-key bibtex-mode-map [menu-bar bibtex-edit bibtex-next-field] | 638 | ["Beginning of Entry" bibtex-beginning-of-entry t] |
| 490 | '("Next Field" . bibtex-next-field)) | 639 | ["End of Entry" bibtex-end-of-entry t]) |
| 491 | (define-key bibtex-mode-map [menu-bar bibtex-edit bibtex-find-text] | 640 | ("Operating on Current Entry" |
| 492 | '("End of Field" . bibtex-find-text)) | 641 | ["Fill Entry" bibtex-fill-entry t] |
| 493 | (define-key bibtex-mode-map [menu-bar bibtex-edit bibtex-pop-previous] | 642 | ["Clean Entry" bibtex-clean-entry t] |
| 494 | '("Snatch from Similar Preceding Field" . bibtex-pop-previous)) | 643 | "--" |
| 495 | (define-key bibtex-mode-map [menu-bar bibtex-edit bibtex-pop-next] | 644 | ["Kill Entry" bibtex-kill-entry t] |
| 496 | '("Snatch from Similar Following Field" . bibtex-pop-next)) | 645 | ["Copy Entry to Kill Ring" bibtex-copy-entry-as-kill t] |
| 497 | (define-key bibtex-mode-map [menu-bar bibtex-edit bibtex-remove-OPT] | 646 | ["Paste Most Recently Killed Entry" bibtex-yank t] |
| 498 | '("Remove OPT" . bibtex-remove-OPT)) | 647 | ["Paste Previously Killed Entry" bibtex-yank-pop t] |
| 499 | (define-key bibtex-mode-map [menu-bar bibtex-edit bibtex-remove-double-quotes-or-braces] | 648 | "--" |
| 500 | '("Remove Quotes or Braces" . bibtex-remove-double-quotes-or-braces)) | 649 | ["Ispell Entry" bibtex-ispell-entry t] |
| 501 | (define-key bibtex-mode-map [menu-bar bibtex-edit bibtex-clean-entry] | 650 | ["Ispell Entry Abstract" bibtex-ispell-abstract t] |
| 502 | '("Clean Up Entry" . bibtex-clean-entry)) | 651 | ["Narrow to Entry" bibtex-narrow-to-entry t]) |
| 503 | (define-key bibtex-mode-map [menu-bar bibtex-edit bibtex-sort-entries] | 652 | ("Operating on Current Field" |
| 504 | '("Sort Entries" . bibtex-sort-entries)) | 653 | ["Remove Delimiters" bibtex-remove-delimiters t] |
| 505 | (define-key bibtex-mode-map | 654 | ["Remove OPT or ALT Prefix" bibtex-remove-OPT-or-ALT t] |
| 506 | [menu-bar bibtex-edit bibtex-validate-buffer-from-point] | 655 | ["Clear Field" bibtex-empty-field t] |
| 507 | '("Validate Entries Starting at Point" . | 656 | "--" |
| 508 | (lambda () | 657 | ["Kill Field" bibtex-kill-field t] |
| 509 | (interactive) | 658 | ["Copy Field to Kill Ring" bibtex-copy-field-as-kill t] |
| 510 | (bibtex-validate-buffer t)))) | 659 | ["Paste Most Recently Killed Field" bibtex-yank t] |
| 511 | (define-key bibtex-mode-map [menu-bar bibtex-edit bibtex-validate-buffer] | 660 | ["Paste Previously Killed Field" bibtex-yank-pop t] |
| 512 | '("Validate Entries" . bibtex-validate-buffer)) | 661 | "--" |
| 513 | 662 | ["Make New Field" bibtex-make-field t] | |
| 514 | (define-key bibtex-mode-map [menu-bar entry-types] | 663 | "--" |
| 515 | (cons "Entry-Types" (make-sparse-keymap "Entry-Types"))) | 664 | ["Snatch from Similar Following Field" bibtex-pop-next t] |
| 516 | (define-key bibtex-mode-map [menu-bar entry-types bibtex-preamble] | 665 | ["Snatch from Similar Preceding Field" bibtex-pop-previous t] |
| 517 | '("Preamble" . bibtex-preamble)) | 666 | "--" |
| 518 | (define-key bibtex-mode-map [menu-bar entry-types bibtex-string] | 667 | ["String Complete" bibtex-complete-string t] |
| 519 | '("String" . bibtex-string)) | 668 | ["Key Complete" bibtex-complete-key t] |
| 520 | (define-key bibtex-mode-map [menu-bar entry-types bibtex-Misc] | 669 | "--" |
| 521 | '("Miscellaneous" . bibtex-Misc)) | 670 | ["Help about Current Field" bibtex-print-help-message t]) |
| 522 | (define-key bibtex-mode-map [menu-bar entry-types bibtex-Unpublished] | 671 | ("Operating on Buffer or Region" |
| 523 | '("Unpublished" . bibtex-Unpublished)) | 672 | ["Validate Entries" bibtex-validate t] |
| 524 | (define-key bibtex-mode-map [menu-bar entry-types bibtex-Manual] | 673 | ["Sort Entries" bibtex-sort-buffer t] |
| 525 | '("Technical Manual" . bibtex-Manual)) | 674 | ["Reformat Entries" bibtex-reformat t] |
| 526 | (define-key bibtex-mode-map [menu-bar entry-types bibtex-TechReport] | 675 | ["Hide Entry Bodies" bibtex-hide-entry-bodies t] |
| 527 | '("Technical Report" . bibtex-TechReport)) | 676 | ["Count Entries" bibtex-count-entries t]) |
| 528 | (define-key bibtex-mode-map [menu-bar entry-types bibtex-MastersThesis] | 677 | ("Miscellaneous" |
| 529 | '("Master's Thesis" . bibtex-MastersThesis)) | 678 | ["Convert Alien Buffer" bibtex-convert-alien t] |
| 530 | (define-key bibtex-mode-map [menu-bar entry-types bibtex-PhdThesis] | 679 | ["Submit Bug Report" bibtex-submit-bug-report t]))) |
| 531 | '("PhD. Thesis" . bibtex-PhdThesis)) | 680 | |
| 532 | (define-key bibtex-mode-map [menu-bar entry-types bibtex-Booklet] | 681 | (easy-menu-define |
| 533 | '("Booklet (Bound, but no Publisher/Institution)" . bibtex-Booklet)) | 682 | bibtex-entry-menu bibtex-mode-map "Entry-Types Menu in BibTeX mode" |
| 534 | (define-key bibtex-mode-map [menu-bar entry-types bibtex-Book] | 683 | (list "Entry-Types" |
| 535 | '("Book" . bibtex-Book)) | 684 | ["Article in Journal" bibtex-Article t] |
| 536 | (define-key bibtex-mode-map [menu-bar entry-types bibtex-Proceedings] | 685 | ["Article in Conference Proceedings" bibtex-InProceedings t] |
| 537 | '("Conference Proceedings" . bibtex-Proceedings)) | 686 | ["Article in a Collection" bibtex-InCollection t] |
| 538 | (define-key bibtex-mode-map [menu-bar entry-types bibtex-InBook] | 687 | ["Chapter or Pages in a Book" bibtex-InBook t] |
| 539 | '("Chapter or Pages in a Book" . bibtex-InBook)) | 688 | ["Conference Proceedings" bibtex-Proceedings t] |
| 540 | (define-key bibtex-mode-map [menu-bar entry-types bibtex-InCollection] | 689 | ["Book" bibtex-Book t] |
| 541 | '("Article in a Collection" . bibtex-InCollection)) | 690 | ["Booklet (Bound, but no Publisher/Institution)" bibtex-Booklet t] |
| 542 | (define-key bibtex-mode-map [menu-bar entry-types bibtex-InProceedings] | 691 | ["PhD. Thesis" bibtex-PhdThesis t] |
| 543 | '("Article in Conference Proceedings" . bibtex-InProceedings)) | 692 | ["Master's Thesis" bibtex-MastersThesis t] |
| 544 | (define-key bibtex-mode-map [menu-bar entry-types bibtex-Article] | 693 | ["Technical Report" bibtex-TechReport t] |
| 545 | '("Article in Journal" . bibtex-Article)) | 694 | ["Technical Manual" bibtex-Manual t] |
| 695 | ["Unpublished" bibtex-Unpublished t] | ||
| 696 | ["Miscellaneous" bibtex-Misc t] | ||
| 697 | ["String" bibtex-String t] | ||
| 698 | ["Preamble" bibtex-Preamble t])) | ||
| 546 | 699 | ||
| 547 | 700 | ||
| 548 | ;; Bug Reporting | 701 | ;; Bug Reporting |
| @@ -561,22 +714,67 @@ See the documentation of function bibtex-generate-autokey for further detail.") | |||
| 561 | (defvar bibtex-pop-next-search-point nil) | 714 | (defvar bibtex-pop-next-search-point nil) |
| 562 | ;; Next point where bibtex-pop-next starts looking for a similar entry. | 715 | ;; Next point where bibtex-pop-next starts looking for a similar entry. |
| 563 | 716 | ||
| 564 | (defvar bibtex-completion-candidates nil) | 717 | (defvar bibtex-field-kill-ring nil) |
| 718 | ;; Ring of least recently killed fields. At most | ||
| 719 | ;; bibtex-field-kill-ring-max items are kept here. | ||
| 720 | |||
| 721 | (defvar bibtex-field-kill-ring-yank-pointer nil) | ||
| 722 | ;; The tail of bibtex-field-kill-ring whose car is the last item yanked. | ||
| 723 | |||
| 724 | (defvar bibtex-entry-kill-ring nil) | ||
| 725 | ;; Ring of least recently killed entries. At most | ||
| 726 | ;; bibtex-entry-kill-ring-max items are kept here. | ||
| 727 | |||
| 728 | (defvar bibtex-entry-kill-ring-yank-pointer nil) | ||
| 729 | ;; The tail of bibtex-entry-kill-ring whose car is the last item yanked. | ||
| 730 | |||
| 731 | (defvar bibtex-last-kill-command nil) | ||
| 732 | ;; Holds the type of the last kill command (either 'field or 'entry) | ||
| 733 | |||
| 734 | (defvar bibtex-strings nil) | ||
| 565 | ;; Candidates for bibtex-complete-string. Initialized from | 735 | ;; Candidates for bibtex-complete-string. Initialized from |
| 566 | ;; bibtex-predefined-strings and bibtex-string-files. This variable is | 736 | ;; bibtex-predefined-strings and bibtex-string-files. This variable is |
| 567 | ;; buffer-local. | 737 | ;; buffer-local. |
| 568 | (make-variable-buffer-local 'bibtex-completion-candidates) | 738 | (make-variable-buffer-local 'bibtex-strings) |
| 569 | 739 | ||
| 570 | (defvar bibtex-keys nil) | 740 | (defvar bibtex-keys nil) |
| 571 | ;; Candidates for TAB completion when entering a reference key using | 741 | ;; Candidates for TAB completion when entering a reference key using |
| 572 | ;; the minibuffer. Initialized in bibtex-mode and updated for each | 742 | ;; the minibuffer. Also used for bibtex-complete-key. Initialized in |
| 573 | ;; new entry. This variable is buffer-local. | 743 | ;; bibtex-mode and updated for each new entry. This variable is |
| 744 | ;; buffer-local. | ||
| 574 | (make-variable-buffer-local 'bibtex-keys) | 745 | (make-variable-buffer-local 'bibtex-keys) |
| 575 | 746 | ||
| 576 | (defvar bibtex-buffer-last-parsed-for-keys-tick nil) | 747 | (defvar bibtex-buffer-last-parsed-tick nil) |
| 577 | ;; Remembers the value returned by buffer-modified-tick when buffer | 748 | ;; Remembers the value returned by buffer-modified-tick when buffer |
| 578 | ;; was parsed for keys the last time. | 749 | ;; was parsed for keys the last time. |
| 579 | (make-variable-buffer-local 'bibtex-keys) | 750 | (make-variable-buffer-local 'bibtex-buffer-last-parsed-tick) |
| 751 | |||
| 752 | (defvar bibtex-parse-idle-timer nil) | ||
| 753 | ;; Stores if timer is already installed | ||
| 754 | |||
| 755 | (defvar bibtex-progress-lastperc nil) | ||
| 756 | ;; Holds the last reported percentage for the progress message | ||
| 757 | |||
| 758 | (defvar bibtex-progress-lastmes nil) | ||
| 759 | ;; Holds the last reported progress message | ||
| 760 | |||
| 761 | (defvar bibtex-progress-interval nil) | ||
| 762 | ;; Holds the chosen interval | ||
| 763 | |||
| 764 | (defvar bibtex-key-history nil) | ||
| 765 | ;; Used to store the history list for reading keys | ||
| 766 | |||
| 767 | (defvar bibtex-entry-type-history nil) | ||
| 768 | ;; Used to store the history list for reading entry types | ||
| 769 | |||
| 770 | (defvar bibtex-field-history nil) | ||
| 771 | ;; Used to store the history list for reading field names | ||
| 772 | |||
| 773 | (defvar bibtex-reformat-previous-options nil) | ||
| 774 | ;; Used to store the last reformat options given | ||
| 775 | |||
| 776 | (defvar bibtex-reformat-previous-labels nil) | ||
| 777 | ;; Used to store the last reformat label option given | ||
| 580 | 778 | ||
| 581 | 779 | ||
| 582 | ;; Functions to Parse the BibTeX Entries | 780 | ;; Functions to Parse the BibTeX Entries |
| @@ -594,11 +792,19 @@ See the documentation of function bibtex-generate-autokey for further detail.") | |||
| 594 | (defconst bibtex-text-in-cfield 2) | 792 | (defconst bibtex-text-in-cfield 2) |
| 595 | ;; The regexp subexpression number of the text part in bibtex-cfield. | 793 | ;; The regexp subexpression number of the text part in bibtex-cfield. |
| 596 | 794 | ||
| 795 | (defconst bibtex-reference-type "@[^\"#%'(),={} \t\n0-9][^\"#%'(),={} \t\n]*") | ||
| 796 | ;; Regexp defining the type part of a BibTeX reference entry (almost | ||
| 797 | ;; the same as bibtex-field-name) | ||
| 798 | |||
| 799 | (defconst bibtex-reference-key "[][a-z0-9.:;?!`'/*@+=|()<>&_^$-]+") | ||
| 800 | ;; Regexp defining the label part of a BibTeX reference entry | ||
| 801 | |||
| 597 | (defconst bibtex-field-name "[^\"#%'(),={} \t\n0-9][^\"#%'(),={} \t\n]*") | 802 | (defconst bibtex-field-name "[^\"#%'(),={} \t\n0-9][^\"#%'(),={} \t\n]*") |
| 598 | ;; Regexp defining the name part of a BibTeX field. | 803 | ;; Regexp defining the name part of a BibTeX field (almost the same as |
| 804 | ;; bibtex-reference-type) | ||
| 599 | 805 | ||
| 600 | (defconst bibtex-field-const "[][A-Za-z0-9.:;?!`'()/*@_+=|<>-]+") | 806 | (defconst bibtex-field-const "[][a-z0-9.:;?!`'/*@+=|<>&_^$-]+") |
| 601 | ;; Format of a bibtex field constant (same as bibtex-reference-key (see below)) | 807 | ;; Regexp defining a bibtex field constant |
| 602 | 808 | ||
| 603 | (defconst bibtex-field-string-part-not-braced | 809 | (defconst bibtex-field-string-part-not-braced |
| 604 | "[^{}]") | 810 | "[^{}]") |
| @@ -607,7 +813,7 @@ See the documentation of function bibtex-generate-autokey for further detail.") | |||
| 607 | (defconst bibtex-field-string-part-no-inner-braces | 813 | (defconst bibtex-field-string-part-no-inner-braces |
| 608 | (concat | 814 | (concat |
| 609 | "{" | 815 | "{" |
| 610 | "\\(" bibtex-field-string-part-not-braced "\\)*" | 816 | bibtex-field-string-part-not-braced "*" |
| 611 | "}")) | 817 | "}")) |
| 612 | ;; Match field string part with no inner braces | 818 | ;; Match field string part with no inner braces |
| 613 | 819 | ||
| @@ -615,7 +821,7 @@ See the documentation of function bibtex-generate-autokey for further detail.") | |||
| 615 | (concat | 821 | (concat |
| 616 | "{" | 822 | "{" |
| 617 | "\\(" | 823 | "\\(" |
| 618 | "\\(" bibtex-field-string-part-not-braced "\\)" | 824 | bibtex-field-string-part-not-braced |
| 619 | "\\|" | 825 | "\\|" |
| 620 | "\\(" bibtex-field-string-part-no-inner-braces "\\)" | 826 | "\\(" bibtex-field-string-part-no-inner-braces "\\)" |
| 621 | "\\)*" | 827 | "\\)*" |
| @@ -626,9 +832,7 @@ See the documentation of function bibtex-generate-autokey for further detail.") | |||
| 626 | (concat | 832 | (concat |
| 627 | "{" | 833 | "{" |
| 628 | "\\(" | 834 | "\\(" |
| 629 | "\\(" bibtex-field-string-part-not-braced "\\)" | 835 | bibtex-field-string-part-not-braced |
| 630 | "\\|" | ||
| 631 | "\\(" bibtex-field-string-part-no-inner-braces "\\)" | ||
| 632 | "\\|" | 836 | "\\|" |
| 633 | "\\(" bibtex-field-string-part-1-inner-brace "\\)" | 837 | "\\(" bibtex-field-string-part-1-inner-brace "\\)" |
| 634 | "\\)*" | 838 | "\\)*" |
| @@ -639,11 +843,7 @@ See the documentation of function bibtex-generate-autokey for further detail.") | |||
| 639 | (concat | 843 | (concat |
| 640 | "{" | 844 | "{" |
| 641 | "\\(" | 845 | "\\(" |
| 642 | "\\(" bibtex-field-string-part-not-braced "\\)" | 846 | bibtex-field-string-part-not-braced |
| 643 | "\\|" | ||
| 644 | "\\(" bibtex-field-string-part-no-inner-braces "\\)" | ||
| 645 | "\\|" | ||
| 646 | "\\(" bibtex-field-string-part-1-inner-brace "\\)" | ||
| 647 | "\\|" | 847 | "\\|" |
| 648 | "\\(" bibtex-field-string-part-2-inner-braces "\\)" | 848 | "\\(" bibtex-field-string-part-2-inner-braces "\\)" |
| 649 | "\\)*" | 849 | "\\)*" |
| @@ -658,14 +858,14 @@ See the documentation of function bibtex-generate-autokey for further detail.") | |||
| 658 | (concat | 858 | (concat |
| 659 | "\"" | 859 | "\"" |
| 660 | "\\(" | 860 | "\\(" |
| 661 | "\\(" "[^\"\\]" "\\)" ;; every character except quote or backslash | 861 | "[^\"\\]" ;; every character except quote or backslash |
| 662 | "\\|" | 862 | "\\|" |
| 663 | ;; "\\(" "\"[A-Za-z-]" "\\)" ;; a quote followed by a letter or dash | 863 | ;; "\\(" "\"[a-z-]" "\\)" ;; a quote followed by a letter or dash |
| 664 | ;; "\\|" | 864 | ;; "\\|" |
| 665 | ;; last two lines commented out until lines like | 865 | ;; last two lines commented out until lines like |
| 666 | ;; author = "Stefan Sch"of" | 866 | ;; author = "Stefan Sch"of" |
| 667 | ;; are supported by BibTeX | 867 | ;; are supported by BibTeX |
| 668 | "\\(" "\\\\.\\|\n" "\\)" ;; a backslash followed by any character | 868 | "\\(" "\\\\\\(.\\|\n\\)" "\\)" ;; a backslash followed by any character |
| 669 | "\\)*" | 869 | "\\)*" |
| 670 | "\"")) | 870 | "\"")) |
| 671 | ;; Match quoted field string | 871 | ;; Match quoted field string |
| @@ -699,13 +899,6 @@ See the documentation of function bibtex-generate-autokey for further detail.") | |||
| 699 | (defconst bibtex-text-in-field bibtex-text-in-cfield) | 899 | (defconst bibtex-text-in-field bibtex-text-in-cfield) |
| 700 | ;; The regexp subexpression number of the text part in BibTeX-field. | 900 | ;; The regexp subexpression number of the text part in BibTeX-field. |
| 701 | 901 | ||
| 702 | (defconst bibtex-reference-type "@[A-Za-z]+") | ||
| 703 | ;; Regexp defining the type part of a BibTeX reference entry. | ||
| 704 | |||
| 705 | (defconst bibtex-reference-key "[][A-Za-z0-9.:;?!`'()/*@_+=|<>-]+") | ||
| 706 | ;; Regexp defining the label part of a BibTeX reference entry (same as | ||
| 707 | ;; bibtex-field-const (see above)) | ||
| 708 | |||
| 709 | (defconst bibtex-reference-head | 902 | (defconst bibtex-reference-head |
| 710 | (concat "^[ \t]*\\(" | 903 | (concat "^[ \t]*\\(" |
| 711 | bibtex-reference-type | 904 | bibtex-reference-type |
| @@ -728,22 +921,18 @@ See the documentation of function bibtex-generate-autokey for further detail.") | |||
| 728 | ;; The regexp subexpression number of the key part in | 921 | ;; The regexp subexpression number of the key part in |
| 729 | ;; bibtex-reference-head. | 922 | ;; bibtex-reference-head. |
| 730 | 923 | ||
| 731 | (defconst bibtex-reference | 924 | (defconst bibtex-reference-infix (concat "[ \t\n]*" bibtex-field)) |
| 732 | (concat bibtex-reference-head | 925 | ;; Regexp defining the (repeatable) infix of a bibtex reference |
| 733 | "\\([ \t\n]*" bibtex-field "\\)*" | ||
| 734 | "[ \t\n]*,?[ \t\n]*[})]")) | ||
| 735 | ;; Regexp defining the format of a BibTeX reference entry. | ||
| 736 | 926 | ||
| 737 | (defconst bibtex-type-in-reference bibtex-type-in-head) | 927 | (defconst bibtex-reference-postfix "[ \t\n]*,?[ \t\n]*[})]") |
| 738 | ;; The regexp subexpression number of the type part in | 928 | ;; Regexp defining the postfix of a bibtex reference |
| 739 | ;; bibtex-reference. | ||
| 740 | 929 | ||
| 741 | (defconst bibtex-key-in-reference bibtex-key-in-head) | 930 | (defconst bibtex-key-in-reference bibtex-key-in-head) |
| 742 | ;; The regexp subexpression number of the key part in | 931 | ;; The regexp subexpression number of the key part in |
| 743 | ;; bibtex-reference. | 932 | ;; bibtex-reference. |
| 744 | 933 | ||
| 745 | (defconst bibtex-string | 934 | (defconst bibtex-string |
| 746 | (concat "^[ \t]*@[sS][tT][rR][iI][nN][gG][ \t\n]*[({][ \t\n]*\\(" | 935 | (concat "^[ \t]*@string[ \t\n]*[({][ \t\n]*\\(" |
| 747 | bibtex-reference-key | 936 | bibtex-reference-key |
| 748 | "\\)[ \t\n]*=[ \t\n]*\\(" | 937 | "\\)[ \t\n]*=[ \t\n]*\\(" |
| 749 | bibtex-field-text | 938 | bibtex-field-text |
| @@ -762,8 +951,9 @@ See the documentation of function bibtex-generate-autokey for further detail.") | |||
| 762 | (list bibtex-type-in-head 'font-lock-function-name-face) | 951 | (list bibtex-type-in-head 'font-lock-function-name-face) |
| 763 | (list bibtex-key-in-head 'font-lock-reference-face nil t)) | 952 | (list bibtex-key-in-head 'font-lock-reference-face nil t)) |
| 764 | ;; reference type and reference label | 953 | ;; reference type and reference label |
| 765 | (list (concat "^[ \t]*\\(OPT" bibtex-field-name "\\)[ \t]*=") | 954 | (list |
| 766 | 1 'font-lock-comment-face) | 955 | (concat "^[ \t]*\\(OPT" bibtex-field-name "\\)[ \t]*=") |
| 956 | 1 'font-lock-comment-face) | ||
| 767 | ;; optional field names (treated as comments) | 957 | ;; optional field names (treated as comments) |
| 768 | (list (concat "^[ \t]*\\(" bibtex-field-name "\\)[ \t]*=") | 958 | (list (concat "^[ \t]*\\(" bibtex-field-name "\\)[ \t]*=") |
| 769 | 1 'font-lock-variable-name-face) | 959 | 1 'font-lock-variable-name-face) |
| @@ -771,83 +961,245 @@ See the documentation of function bibtex-generate-autokey for further detail.") | |||
| 771 | "*Default expressions to highlight in BibTeX mode.")) | 961 | "*Default expressions to highlight in BibTeX mode.")) |
| 772 | ;; now all needed patterns are defined | 962 | ;; now all needed patterns are defined |
| 773 | 963 | ||
| 774 | (defconst bibtex-name-alignment 2) | ||
| 775 | ;; Alignment for the name part in BibTeX fields. Chosen on aesthetic | ||
| 776 | ;; grounds only. | ||
| 777 | |||
| 778 | (defconst bibtex-text-alignment (length " organization = ")) | ||
| 779 | ;; Alignment for the text part in BibTeX fields. Equal to the space | ||
| 780 | ;; needed for the longest name part. | ||
| 781 | |||
| 782 | 964 | ||
| 783 | ;; Helper Functions | 965 | ;; Helper Functions |
| 784 | 966 | ||
| 967 | (defun delete-whitespace () | ||
| 968 | ;; Delete all whitespace starting at point | ||
| 969 | (if (looking-at "[ \t\n]+") | ||
| 970 | (delete-region (point) (match-end 0)))) | ||
| 971 | |||
| 972 | (defun current-line () | ||
| 973 | ;; this computes line number of point regardless whether the buffer | ||
| 974 | ;; is narrowed | ||
| 975 | (+ (count-lines 1 (point)) | ||
| 976 | (if (equal (current-column) 0) 1 0))) | ||
| 977 | |||
| 785 | (defun bibtex-member-of-regexp (string list) | 978 | (defun bibtex-member-of-regexp (string list) |
| 786 | ;; Return non-nil if STRING is exactly matched by an element of | 979 | ;; Return non-nil if STRING is exactly matched by an element of |
| 787 | ;; LIST. This function is influenced by the actual value of | 980 | ;; LIST (case ignored). The value is actually the tail of LIST whose |
| 788 | ;; `case-fold-search'. The value is actually the tail of LIST whose | ||
| 789 | ;; car matches STRING. | 981 | ;; car matches STRING. |
| 790 | (while | 982 | (let ((case-fold-search t)) |
| 791 | (and | 983 | (while |
| 792 | list | 984 | (and list (not (string-match (concat "^" (car list) "$") string))) |
| 793 | (not | 985 | (setq list (cdr list))) |
| 794 | (string-match | 986 | list)) |
| 795 | (concat "^" (car list) "$") | ||
| 796 | string))) | ||
| 797 | (setq list (cdr list))) | ||
| 798 | list) | ||
| 799 | 987 | ||
| 800 | (defun assoc-of-regexp (string alist) | 988 | (defun assoc-of-regexp (string alist) |
| 801 | ;; Return non-nil if STRING is exactly matched by the car of an | 989 | ;; Return non-nil if STRING is exactly matched by the car of an |
| 802 | ;; element of LIST. This function is influenced by the actual value | 990 | ;; element of LIST (case ignored). The value is actually the element |
| 803 | ;; of `case-fold-search'. The value is actually the element of LIST | 991 | ;; of LIST whose car matches STRING. |
| 804 | ;; whose car matches STRING. | 992 | (let ((case-fold-search t)) |
| 805 | (while | 993 | (while |
| 806 | (and | 994 | (and alist |
| 807 | alist | 995 | (not (string-match (concat "^" (car (car alist)) "$") string))) |
| 808 | (not | 996 | (setq alist (cdr alist))) |
| 809 | (string-match | 997 | (car alist))) |
| 810 | (concat "^" (car (car alist)) "$") | 998 | |
| 811 | string))) | 999 | (defun skip-to-valid-bibtex-entry (&optional backward) |
| 812 | (setq alist (cdr alist))) | 1000 | ;; If not at beginning of valid BibTeX entry, move to beginning of |
| 813 | (car alist)) | 1001 | ;; the next valid one. With argument backward non-nil, move backward |
| 814 | 1002 | ;; to beginning of previous valid one. A valid entry is a | |
| 815 | (defun skip-whitespace-and-comments () | 1003 | ;; syntactical correct one with type contained in |
| 816 | (let ((md (match-data))) | 1004 | ;; bibtex-entry-field-alist or, if bibtex-sort-ignore-string-entries |
| 817 | (unwind-protect | 1005 | ;; is nil, a syntactical correct string entry. |
| 818 | (while (cond ((looking-at "\\s>+\\|\\s +") | 1006 | (let ((case-fold-search t) |
| 819 | ;; was whitespace | 1007 | (valid-bibtex-entry |
| 820 | ;; NOTE: also checked end-comment. In latex and | 1008 | (concat |
| 821 | ;; lisp modes, newline is an end comment, but it | 1009 | "@[ \t]*\\(" |
| 822 | ;; should also be a whitespace char. | 1010 | (mapconcat |
| 823 | (goto-char (match-end 0))) | 1011 | (lambda (type) |
| 824 | ;; If looking at beginning of comment, skip to end. | 1012 | (concat "\\(" (car type) "\\)")) |
| 825 | ((looking-at "\\s<") | 1013 | bibtex-entry-field-alist |
| 826 | (re-search-forward "\\s>")))) | 1014 | "\\|") |
| 827 | (store-match-data md)))) | 1015 | "\\)")) |
| 1016 | found) | ||
| 1017 | (while (and (not found) | ||
| 1018 | (not (if backward | ||
| 1019 | (bobp) | ||
| 1020 | (eobp)))) | ||
| 1021 | (let ((pnt (point))) | ||
| 1022 | (cond | ||
| 1023 | ((looking-at valid-bibtex-entry) | ||
| 1024 | (if (and | ||
| 1025 | (bibtex-search-reference nil nil t) | ||
| 1026 | (equal (match-beginning 0) pnt)) | ||
| 1027 | (setq found t))) | ||
| 1028 | ((and (not bibtex-sort-ignore-string-entries) | ||
| 1029 | (looking-at bibtex-string)) | ||
| 1030 | (setq found t))) | ||
| 1031 | (if found | ||
| 1032 | (goto-char pnt) | ||
| 1033 | (if backward | ||
| 1034 | (progn | ||
| 1035 | (goto-char (1- pnt)) | ||
| 1036 | (if (re-search-backward "^[ \t]*\\(@\\)" nil 'move) | ||
| 1037 | (goto-char (match-beginning 1)))) | ||
| 1038 | (goto-char (1+ pnt)) | ||
| 1039 | (if (re-search-forward "^[ \t]*@" nil 'move) | ||
| 1040 | (forward-char -1)))))))) | ||
| 828 | 1041 | ||
| 829 | (defun map-bibtex-entries (fun) | 1042 | (defun map-bibtex-entries (fun) |
| 830 | ;; Call FUN for each BibTeX entry starting with the current. Do this | 1043 | ;; Call FUN for each BibTeX entry starting with the current. Do this |
| 831 | ;; to the end of the file. FUN is called with one argument, the key | 1044 | ;; to the end of the file. FUN is called with one argument, the key |
| 832 | ;; of the entry, and with point inside the entry. If | 1045 | ;; of the entry, and with point inside the entry. If |
| 833 | ;; bibtex-sort-ignore-string-entries is non-nil, FUN will not be called | 1046 | ;; bibtex-sort-ignore-string-entries is non-nil, FUN will not be |
| 834 | ;; for @string entries. | 1047 | ;; called for @String entries. |
| 835 | (bibtex-beginning-of-entry) | 1048 | (let ((case-fold-search t)) |
| 836 | (while (re-search-forward bibtex-reference-head nil t) | 1049 | (bibtex-beginning-of-entry) |
| 837 | (if (and bibtex-sort-ignore-string-entries | 1050 | (while (re-search-forward bibtex-reference-maybe-empty-head nil t) |
| 838 | (string-equal "@string" | 1051 | (let ((pnt (point)) |
| 839 | (downcase (buffer-substring-no-properties | 1052 | (reference-type |
| 840 | (match-beginning bibtex-type-in-head) | 1053 | (downcase (buffer-substring-no-properties |
| 841 | (match-end bibtex-type-in-head))))) | 1054 | (1+ (match-beginning bibtex-type-in-head)) |
| 842 | nil | 1055 | (match-end bibtex-type-in-head)))) |
| 843 | (funcall fun (buffer-substring-no-properties | 1056 | (reference-key |
| 844 | (match-beginning bibtex-key-in-head) | 1057 | (if (match-beginning bibtex-key-in-head) |
| 845 | (match-end bibtex-key-in-head)))))) | 1058 | (buffer-substring-no-properties |
| 1059 | (match-beginning bibtex-key-in-head) | ||
| 1060 | (match-end bibtex-key-in-head)) | ||
| 1061 | ""))) | ||
| 1062 | (if (or | ||
| 1063 | (and | ||
| 1064 | (not bibtex-sort-ignore-string-entries) | ||
| 1065 | (string-equal "string" (downcase reference-type))) | ||
| 1066 | (assoc-ignore-case reference-type bibtex-entry-field-alist)) | ||
| 1067 | (funcall fun reference-key)) | ||
| 1068 | (goto-char pnt) | ||
| 1069 | (bibtex-end-of-entry))))) | ||
| 1070 | |||
| 1071 | (defun bibtex-progress-message (&optional flag interval) | ||
| 1072 | ;; echos a message about progress of current buffer | ||
| 1073 | ;; if flag is a string, the message is initialized (in this case a | ||
| 1074 | ;; value for INTERVAL may be given as well (if not this is set to 5)) | ||
| 1075 | ;; if flag is done, the message is deinitialized | ||
| 1076 | ;; if flag is absent, a message is echoed if point was incremented | ||
| 1077 | ;; at least INTERVAL percent since last message was echoed | ||
| 1078 | (let* ((size (- (point-max) (point-min))) | ||
| 1079 | (perc (if (= size 0) | ||
| 1080 | 100 | ||
| 1081 | (/ (* 100 (- (point) (point-min))) size)))) | ||
| 1082 | (if (or (and (not flag) | ||
| 1083 | (>= perc | ||
| 1084 | (+ bibtex-progress-interval bibtex-progress-lastperc))) | ||
| 1085 | (stringp flag)) | ||
| 1086 | (progn | ||
| 1087 | (if (stringp flag) | ||
| 1088 | (progn | ||
| 1089 | (setq bibtex-progress-lastmes flag) | ||
| 1090 | (if interval | ||
| 1091 | (setq bibtex-progress-interval interval) | ||
| 1092 | (setq bibtex-progress-interval 5)))) | ||
| 1093 | (setq bibtex-progress-lastperc perc) | ||
| 1094 | (message (concat bibtex-progress-lastmes " (%d%%)") perc)) | ||
| 1095 | (if (equal flag 'done) | ||
| 1096 | (progn | ||
| 1097 | (message (concat bibtex-progress-lastmes " (done)")) | ||
| 1098 | (setq bibtex-progress-lastmes nil)))))) | ||
| 1099 | |||
| 1100 | |||
| 1101 | (defun bibtex-field-left-delimiter () | ||
| 1102 | ;; returns a string dependent on bibtex-field-delimiters | ||
| 1103 | (if (equal bibtex-field-delimiters 'braces) | ||
| 1104 | "{" | ||
| 1105 | "\"")) | ||
| 1106 | |||
| 1107 | (defun bibtex-field-right-delimiter () | ||
| 1108 | ;; returns a string dependent on bibtex-field-delimiters | ||
| 1109 | (if (equal bibtex-field-delimiters 'braces) | ||
| 1110 | "}" | ||
| 1111 | "\"")) | ||
| 1112 | |||
| 1113 | (defun bibtex-entry-left-delimiter () | ||
| 1114 | ;; returns a string dependent on bibtex-field-delimiters | ||
| 1115 | (if (equal bibtex-entry-delimiters 'braces) | ||
| 1116 | "{" | ||
| 1117 | "(")) | ||
| 1118 | |||
| 1119 | (defun bibtex-entry-right-delimiter () | ||
| 1120 | ;; returns a string dependent on bibtex-field-delimiters | ||
| 1121 | (if (equal bibtex-entry-delimiters 'braces) | ||
| 1122 | "}" | ||
| 1123 | ")")) | ||
| 1124 | |||
| 1125 | (defun bibtex-search-reference | ||
| 1126 | (empty-head &optional bound noerror backward) | ||
| 1127 | ;; A helper function necessary since the failure stack size limit for | ||
| 1128 | ;; regexps was reduced in emacs 19.32. | ||
| 1129 | ;; It searches for a BibTeX reference (maybe with an empty head if | ||
| 1130 | ;; EMPTY-HEAD is t). | ||
| 1131 | ;; BOUND and NOERROR are exactly as in re-search-forward. If | ||
| 1132 | ;; BACKWARD is non-nil, search is done in reverse direction. After | ||
| 1133 | ;; call to this function MATCH-BEGINNING and MATCH-END functions are | ||
| 1134 | ;; defined, but only for the head part of the reference (especially | ||
| 1135 | ;; (match-end 0) just gives the end of the head part). | ||
| 1136 | (let ((pnt (point)) | ||
| 1137 | (prefix (if empty-head | ||
| 1138 | bibtex-reference-maybe-empty-head | ||
| 1139 | bibtex-reference-head)) | ||
| 1140 | (infix bibtex-reference-infix) | ||
| 1141 | (postfix bibtex-reference-postfix)) | ||
| 1142 | (if backward | ||
| 1143 | (let (found) | ||
| 1144 | (while (and (not found) | ||
| 1145 | (re-search-backward prefix bound noerror)) | ||
| 1146 | (setq found (bibtex-search-reference empty-head pnt t))) | ||
| 1147 | (if found | ||
| 1148 | (goto-char (match-beginning 0)) | ||
| 1149 | (if (equal noerror nil) | ||
| 1150 | ;; yell | ||
| 1151 | (error "Search of BibTeX reference failed.")) | ||
| 1152 | (if (equal noerror t) | ||
| 1153 | ;; don't move | ||
| 1154 | (goto-char pnt)) | ||
| 1155 | nil)) | ||
| 1156 | (let ((limit (if bound bound (point-max))) | ||
| 1157 | md | ||
| 1158 | found) | ||
| 1159 | (while (and (not found) | ||
| 1160 | (re-search-forward prefix bound noerror)) | ||
| 1161 | (setq md (match-data)) | ||
| 1162 | ;; save match-data of prefix regexp | ||
| 1163 | (let ((entry-closer | ||
| 1164 | (if (save-excursion | ||
| 1165 | (goto-char (match-end bibtex-type-in-head)) | ||
| 1166 | (looking-at "[ \t]*(")) | ||
| 1167 | ;; entry opened with parenthesis | ||
| 1168 | ")" | ||
| 1169 | "}"))) | ||
| 1170 | (while (and | ||
| 1171 | (looking-at infix) | ||
| 1172 | (<= (match-end 0) limit)) | ||
| 1173 | (goto-char (match-end 0))) | ||
| 1174 | ;; This matches the infix* part. The AND construction assures | ||
| 1175 | ;; that BOUND is respected. | ||
| 1176 | (if (and (looking-at postfix) | ||
| 1177 | (string-equal | ||
| 1178 | (buffer-substring-no-properties | ||
| 1179 | (1- (match-end 0)) (match-end 0)) | ||
| 1180 | entry-closer) | ||
| 1181 | (<= (match-end 0) limit)) | ||
| 1182 | (progn | ||
| 1183 | (re-search-forward postfix) | ||
| 1184 | (setq found t))))) | ||
| 1185 | (if found | ||
| 1186 | (progn | ||
| 1187 | (store-match-data md) | ||
| 1188 | ;; to set match-beginning/end again | ||
| 1189 | (point)) | ||
| 1190 | (if (equal noerror nil) | ||
| 1191 | ;; yell | ||
| 1192 | (error "Search of BibTeX reference failed.")) | ||
| 1193 | (if (equal noerror t) | ||
| 1194 | ;; don't move | ||
| 1195 | (goto-char pnt)) | ||
| 1196 | nil))))) | ||
| 846 | 1197 | ||
| 847 | (defun bibtex-flash-head () | 1198 | (defun bibtex-flash-head () |
| 848 | ;; Flash at BibTeX reference head before point, if exists. | 1199 | ;; Flash at BibTeX reference head before point, if exists. |
| 849 | (let ((flash)) | 1200 | (let ((case-fold-search t) |
| 850 | (cond ((re-search-backward bibtex-reference-head (point-min) t) | 1201 | flash) |
| 1202 | (cond ((re-search-backward bibtex-reference-head nil t) | ||
| 851 | (goto-char (match-beginning bibtex-type-in-head)) | 1203 | (goto-char (match-beginning bibtex-type-in-head)) |
| 852 | (setq flash (match-end bibtex-key-in-reference))) | 1204 | (setq flash (match-end bibtex-key-in-reference))) |
| 853 | (t | 1205 | (t |
| @@ -861,29 +1213,31 @@ See the documentation of function bibtex-generate-autokey for further detail.") | |||
| 861 | (message "From: %s" | 1213 | (message "From: %s" |
| 862 | (buffer-substring (point) flash))))) | 1214 | (buffer-substring (point) flash))))) |
| 863 | 1215 | ||
| 1216 | (defun bibtex-make-optional-field (e-t) | ||
| 1217 | "Makes an optional field named E-T in current BibTeX entry." | ||
| 1218 | (if (consp e-t) | ||
| 1219 | (bibtex-make-field (cons (concat "OPT" (car e-t)) (cdr e-t))) | ||
| 1220 | (bibtex-make-field (concat "OPT" e-t)))) | ||
| 1221 | |||
| 864 | (defun bibtex-move-outside-of-entry () | 1222 | (defun bibtex-move-outside-of-entry () |
| 865 | ;; Make sure we are outside of a BibTeX entry. | 1223 | ;; Make sure we are outside of a BibTeX entry. |
| 866 | (cond ((or | 1224 | (bibtex-end-of-entry) |
| 867 | (= (point) (point-max)) | 1225 | (skip-chars-forward " \t\n")) |
| 868 | (= (point) (point-min)) | 1226 | |
| 869 | (looking-at "[ \n]*@") | 1227 | (defun bibtex-beginning-of-first-entry () |
| 870 | ) | 1228 | ;; Go to the beginning of the first BibTeX entry in buffer. Return |
| 871 | t) | 1229 | ;; point. |
| 872 | (t | ||
| 873 | (backward-paragraph) | ||
| 874 | (forward-paragraph))) | ||
| 875 | (re-search-forward "[ \t\n]*" (point-max) t)) | ||
| 876 | |||
| 877 | (defun beginning-of-first-bibtex-entry () | ||
| 878 | ;; Go to the beginning of the first BibTeX entry in buffer. | ||
| 879 | (goto-char (point-min)) | 1230 | (goto-char (point-min)) |
| 880 | (cond | 1231 | (if (re-search-forward "^[ \t]*@" nil 'move) |
| 881 | ((re-search-forward "^@" nil 'move) | 1232 | (beginning-of-line)) |
| 882 | (beginning-of-line)) | 1233 | (point)) |
| 883 | ((and (bobp) (eobp)) | 1234 | |
| 884 | nil) | 1235 | (defun bibtex-beginning-of-last-entry () |
| 885 | (t | 1236 | ;; Go to the beginning of the last BibTeX entry in buffer. |
| 886 | (message "Warning: No BibTeX entries found!")))) | 1237 | (goto-char (point-max)) |
| 1238 | (if (re-search-backward "^[ \t]*@" nil 'move) | ||
| 1239 | (beginning-of-line)) | ||
| 1240 | (point)) | ||
| 887 | 1241 | ||
| 888 | (defun bibtex-inside-field () | 1242 | (defun bibtex-inside-field () |
| 889 | ;; Try to avoid point being at end of a BibTeX field. | 1243 | ;; Try to avoid point being at end of a BibTeX field. |
| @@ -896,95 +1250,337 @@ See the documentation of function bibtex-generate-autokey for further detail.") | |||
| 896 | (= (preceding-char) ?\")) | 1250 | (= (preceding-char) ?\")) |
| 897 | (forward-char -1)))) | 1251 | (forward-char -1)))) |
| 898 | 1252 | ||
| 899 | (defun bibtex-enclosing-field () | 1253 | (defun bibtex-enclosing-field (&optional noerr) |
| 900 | ;; Search for BibTeX field enclosing point. Point moves to end of | 1254 | ;; Search for BibTeX field enclosing point. Point moves to end of |
| 901 | ;; field; also, use match-beginning and match-end to parse the field. | 1255 | ;; field. Use match-beginning and match-end to parse the field. If |
| 902 | ;; sct@dcs.edinburgh.ac.uk | 1256 | ;; NOERR is non-nil, no error is signalled. In this case, t is |
| 903 | (let ((old-point (point))) | 1257 | ;; returned on success, nil otherwise. |
| 904 | (condition-case errname | 1258 | (let ((case-fold-search t) |
| 905 | (bibtex-enclosing-regexp bibtex-field) | 1259 | (old-point (point)) |
| 906 | (search-failed | 1260 | (boe (bibtex-beginning-of-entry)) |
| 907 | (goto-char old-point) | 1261 | (success t)) |
| 908 | (error "Can't find enclosing BibTeX field."))))) | 1262 | (goto-char old-point) |
| 909 | 1263 | (if (not (re-search-backward | |
| 910 | (defun bibtex-enclosing-reference () | 1264 | (bibtex-cfield bibtex-field-name "") |
| 911 | ;; Search for BibTeX reference enclosing point. Point moves to | 1265 | boe t)) |
| 912 | ;; beginning of reference. Beginning/end of reference is given by | 1266 | ;; Search possible beginning of field |
| 913 | ;; (match-beginning/match-end 0). | ||
| 914 | (let ((old-point (point))) | ||
| 915 | (if (not | ||
| 916 | (re-search-backward bibtex-reference-head (point-min) t)) | ||
| 917 | (progn | 1267 | (progn |
| 918 | (error "Can't find enclosing BibTeX reference.") | 1268 | (goto-char old-point) |
| 919 | (goto-char old-point))) | 1269 | (if noerr |
| 920 | (goto-char (match-beginning bibtex-type-in-head)) | 1270 | (setq success nil) |
| 921 | (let ((pnt (point))) | 1271 | (error "Can't find enclosing BibTeX field."))) |
| 922 | (if (not | 1272 | (if (or (not (re-search-forward bibtex-field nil t)) |
| 923 | (re-search-forward bibtex-reference (point-max) t)) | 1273 | (< (match-end 0) old-point) |
| 1274 | (> (match-beginning 0) old-point)) | ||
| 924 | (progn | 1275 | (progn |
| 925 | (error "Can't find enclosing BibTeX reference.") | 1276 | (goto-char old-point) |
| 926 | (goto-char old-point)) | 1277 | (if noerr |
| 927 | (goto-char pnt))))) | 1278 | (setq success nil) |
| 1279 | (error "Can't find enclosing BibTeX field."))))) | ||
| 1280 | success)) | ||
| 928 | 1281 | ||
| 929 | (defun bibtex-enclosing-reference-maybe-empty-head () | 1282 | (defun bibtex-enclosing-reference-maybe-empty-head () |
| 930 | ;; Search for BibTeX reference enclosing point. Point moves to | 1283 | ;; Search for BibTeX reference enclosing point. Point moves to |
| 931 | ;; beginning of reference. Beginning/end of reference is given by | 1284 | ;; end of reference. Beginning (but not end) of reference is given |
| 932 | ;; (match-beginning/match-end 0). | 1285 | ;; by (match-beginning 0). |
| 933 | (let ((old-point (point))) | 1286 | (let ((case-fold-search t) |
| 1287 | (old-point (point))) | ||
| 934 | (if (not | 1288 | (if (not |
| 935 | (re-search-backward | 1289 | (re-search-backward |
| 936 | bibtex-reference-maybe-empty-head (point-min) t)) | 1290 | bibtex-reference-maybe-empty-head nil t)) |
| 937 | (progn | 1291 | (progn |
| 938 | (error "Can't find enclosing BibTeX reference.") | 1292 | (error "Can't find enclosing BibTeX reference.") |
| 939 | (goto-char old-point))) | 1293 | (goto-char old-point))) |
| 940 | (goto-char (match-beginning bibtex-type-in-head)) | 1294 | (goto-char (match-beginning bibtex-type-in-head)) |
| 941 | (let ((pnt (point))) | 1295 | (if (not |
| 942 | (if (not | 1296 | (bibtex-search-reference t nil t)) |
| 943 | (re-search-forward | 1297 | (progn |
| 944 | (concat | 1298 | (error "Can't find enclosing BibTeX reference.") |
| 945 | bibtex-reference-maybe-empty-head | 1299 | (goto-char old-point))))) |
| 946 | "\\([ \t\n]*" bibtex-field "\\)*" | 1300 | |
| 947 | "[ \t\n]*,?[ \t\n]*[})]") | 1301 | (defun bibtex-insert-current-kill (n) |
| 948 | (point-max) t)) | 1302 | (if (not bibtex-last-kill-command) |
| 949 | (progn | 1303 | (error "BibTeX kill ring is empty.") |
| 950 | (error "Can't find enclosing BibTeX reference.") | 1304 | (let* ((kr (if (equal bibtex-last-kill-command 'field) |
| 951 | (goto-char old-point)) | 1305 | 'bibtex-field-kill-ring |
| 952 | (goto-char pnt))))) | 1306 | 'bibtex-entry-kill-ring)) |
| 953 | 1307 | (kryp (if (equal bibtex-last-kill-command 'field) | |
| 954 | (defun bibtex-enclosing-regexp (regexp) | 1308 | 'bibtex-field-kill-ring-yank-pointer |
| 955 | ;; Search for REGEXP enclosing point. Point moves to end of | 1309 | 'bibtex-entry-kill-ring-yank-pointer)) |
| 956 | ;; REGEXP. See also match-beginning and match-end. If an enclosing | 1310 | (ARGth-kill-element |
| 957 | ;; REGEXP is not found, signals search-failed; point is left in an | 1311 | (nthcdr |
| 958 | ;; undefined location. | 1312 | (mod (- n (length (eval kryp))) (length (eval kr))) |
| 959 | ;; Doesn't something like this exist already? | 1313 | (eval kr))) |
| 960 | ;; compute reasonable limits for the loop | 1314 | (current (car (set kryp ARGth-kill-element)))) |
| 961 | (let* ((initial (point)) | 1315 | (cond |
| 962 | (right (if (re-search-forward regexp (point-max) t) | 1316 | ((equal bibtex-last-kill-command 'field) |
| 963 | (match-end 0) | 1317 | (let (bibtex-help-message) |
| 964 | (point-max))) | 1318 | (bibtex-find-text nil t) |
| 965 | (left | 1319 | (if (looking-at "[}\"]") |
| 966 | (progn | 1320 | (forward-char))) |
| 967 | (goto-char initial) | 1321 | (set-mark (point)) |
| 968 | (if (re-search-backward regexp (point-min) t) | 1322 | (message "Mark set") |
| 969 | (match-beginning 0) | 1323 | (bibtex-make-field (list (elt current 1) nil (elt current 2)) t)) |
| 970 | (point-min))))) | 1324 | ((equal bibtex-last-kill-command 'entry) |
| 971 | ; within the prescribed limits, loop until a match is found | 1325 | (if (not (eobp)) |
| 972 | (goto-char left) | 1326 | (bibtex-beginning-of-entry)) |
| 973 | (re-search-forward regexp right nil 1) | 1327 | (set-mark (point)) |
| 974 | (if (> (match-beginning 0) initial) | 1328 | (message "Mark set") |
| 975 | (signal 'search-failed (list regexp))) | 1329 | (insert (elt current 1))) |
| 976 | (while (<= (match-end 0) initial) | 1330 | (t |
| 977 | (re-search-forward regexp right nil 1) | 1331 | (error |
| 978 | (if (> (match-beginning 0) initial) | 1332 | "Unknown tag field: %s. Please submit a bug report." |
| 979 | (signal 'search-failed (list regexp)))) | 1333 | bibtex-last-kill-command)))))) |
| 980 | )) | 1334 | |
| 1335 | (defun bibtex-format-entry () | ||
| 1336 | ;; Helper function for bibtex-clean-entry. Formats current entry | ||
| 1337 | ;; according to variable bibtex-entry-format. | ||
| 1338 | (let ((case-fold-search t) | ||
| 1339 | (beg (point)) | ||
| 1340 | (start (bibtex-beginning-of-entry)) | ||
| 1341 | crossref-there | ||
| 1342 | alternatives-there | ||
| 1343 | non-empty-alternative) | ||
| 1344 | (let ((end (copy-marker (bibtex-end-of-entry)))) | ||
| 1345 | (if (equal start (marker-position end)) | ||
| 1346 | (error "Not on a known BibTeX entry.") | ||
| 1347 | (goto-char start) | ||
| 1348 | (while (re-search-forward bibtex-field end t) | ||
| 1349 | ;; determine if reference has crossref entry and if at least | ||
| 1350 | ;; one alternative is non-empty | ||
| 1351 | (let ((begin-name (match-beginning bibtex-name-in-field)) | ||
| 1352 | (end-name (match-end bibtex-name-in-field)) | ||
| 1353 | (begin-text (match-beginning bibtex-text-in-field)) | ||
| 1354 | (end-text (match-end bibtex-text-in-field))) | ||
| 1355 | (goto-char begin-name) | ||
| 1356 | (if (looking-at "ALT") | ||
| 1357 | (progn | ||
| 1358 | (setq alternatives-there t) | ||
| 1359 | (goto-char begin-text) | ||
| 1360 | (if (not (looking-at "\\(\"\"\\)\\|\\({}\\)")) | ||
| 1361 | (setq non-empty-alternative t)))) | ||
| 1362 | (if (string-match | ||
| 1363 | "\\(OPT\\)?crossref" | ||
| 1364 | (buffer-substring-no-properties begin-name end-name)) | ||
| 1365 | (progn | ||
| 1366 | (setq | ||
| 1367 | crossref-there | ||
| 1368 | (buffer-substring-no-properties | ||
| 1369 | (1+ begin-text) (1- end-text))) | ||
| 1370 | (if (equal crossref-there "") | ||
| 1371 | (setq crossref-there nil)))))) | ||
| 1372 | (if (and alternatives-there | ||
| 1373 | (not non-empty-alternative)) | ||
| 1374 | (progn | ||
| 1375 | (goto-char beg) | ||
| 1376 | (error "All alternatives are empty."))) | ||
| 1377 | (goto-char start) | ||
| 1378 | (re-search-forward bibtex-reference-type end) | ||
| 1379 | (let* ((begin-type (1+ (match-beginning 0))) | ||
| 1380 | (end-type (match-end 0)) | ||
| 1381 | (reference-type | ||
| 1382 | (downcase | ||
| 1383 | (buffer-substring-no-properties begin-type end-type))) | ||
| 1384 | (entry-list | ||
| 1385 | (assoc-ignore-case reference-type bibtex-entry-field-alist)) | ||
| 1386 | (req (elt (elt entry-list 1) 0)) | ||
| 1387 | (creq (elt (elt entry-list 2) 0)) | ||
| 1388 | (format (if (equal bibtex-entry-format t) | ||
| 1389 | '(realign opts-or-alts numerical-fields | ||
| 1390 | last-comma page-dashes delimiters | ||
| 1391 | unify-case inherit-booktitle) | ||
| 1392 | bibtex-entry-format)) | ||
| 1393 | field-done) | ||
| 1394 | (if (memq 'unify-case format) | ||
| 1395 | (progn | ||
| 1396 | (delete-region begin-type end-type) | ||
| 1397 | (insert (car entry-list)))) | ||
| 1398 | (if (memq 'delimiters format) | ||
| 1399 | (progn | ||
| 1400 | (goto-char end-type) | ||
| 1401 | (skip-chars-forward " \t\n") | ||
| 1402 | (delete-char 1) | ||
| 1403 | (insert (bibtex-entry-left-delimiter)))) | ||
| 1404 | (goto-char start) | ||
| 1405 | (while (re-search-forward bibtex-field end t) | ||
| 1406 | (let* ((begin-field | ||
| 1407 | (copy-marker (match-beginning 0))) | ||
| 1408 | (end-field | ||
| 1409 | (copy-marker (match-end 0))) | ||
| 1410 | (begin-name | ||
| 1411 | (copy-marker (match-beginning bibtex-name-in-field))) | ||
| 1412 | (end-name | ||
| 1413 | (copy-marker (match-end bibtex-name-in-field))) | ||
| 1414 | (begin-text | ||
| 1415 | (copy-marker (match-beginning bibtex-text-in-field))) | ||
| 1416 | (end-text | ||
| 1417 | (copy-marker (match-end bibtex-text-in-field))) | ||
| 1418 | (field-name | ||
| 1419 | (buffer-substring-no-properties | ||
| 1420 | (if (string-match | ||
| 1421 | "^OPT\\|ALT$" | ||
| 1422 | (buffer-substring-no-properties | ||
| 1423 | begin-name (+ begin-name 3))) | ||
| 1424 | (+ begin-name 3) | ||
| 1425 | begin-name) | ||
| 1426 | end-name))) | ||
| 1427 | (cond | ||
| 1428 | ((and | ||
| 1429 | (memq 'opts-or-alts format) | ||
| 1430 | (progn (goto-char begin-name) | ||
| 1431 | (looking-at "OPT\\|ALT"))) | ||
| 1432 | (goto-char begin-text) | ||
| 1433 | (if (looking-at "\\(\"\"\\)\\|\\({}\\)") | ||
| 1434 | ;; empty: delete whole field if really optional | ||
| 1435 | ;; (missing crossref handled) or complain | ||
| 1436 | (if (and | ||
| 1437 | (progn | ||
| 1438 | (goto-char begin-name) | ||
| 1439 | (looking-at "OPT")) | ||
| 1440 | (not crossref-there) | ||
| 1441 | (assoc-ignore-case field-name req)) | ||
| 1442 | ;; field is not really optional | ||
| 1443 | (progn | ||
| 1444 | (goto-char begin-name) | ||
| 1445 | (bibtex-remove-OPT-or-ALT) | ||
| 1446 | (error | ||
| 1447 | "Mandatory field ``%s'' is empty." field-name)) | ||
| 1448 | ;; field is optional | ||
| 1449 | (delete-region begin-field end-field)) | ||
| 1450 | ;; otherwise: not empty, delete "OPT" | ||
| 1451 | (goto-char begin-name) | ||
| 1452 | (bibtex-remove-OPT-or-ALT))) | ||
| 1453 | ((and | ||
| 1454 | (memq 'numerical-fields format) | ||
| 1455 | (progn | ||
| 1456 | (goto-char begin-text) | ||
| 1457 | (looking-at "\\(\"[0-9]+\"\\)\\|\\({[0-9]+}\\)"))) | ||
| 1458 | (goto-char end-text) | ||
| 1459 | (delete-char -1) | ||
| 1460 | (goto-char begin-text) | ||
| 1461 | (delete-char 1)) | ||
| 1462 | (t | ||
| 1463 | (if (memq 'delimiters format) | ||
| 1464 | (progn | ||
| 1465 | (goto-char begin-text) | ||
| 1466 | (while (and | ||
| 1467 | (<= (point) end-text) | ||
| 1468 | (re-search-forward | ||
| 1469 | bibtex-field-string-or-const end-text t)) | ||
| 1470 | (let ((end (point))) | ||
| 1471 | (goto-char (match-beginning 0)) | ||
| 1472 | (if (or | ||
| 1473 | (and | ||
| 1474 | (equal bibtex-field-delimiters 'double-quotes) | ||
| 1475 | (looking-at bibtex-field-string-braced)) | ||
| 1476 | (and | ||
| 1477 | (equal bibtex-field-delimiters 'braces) | ||
| 1478 | (looking-at bibtex-field-string-quoted))) | ||
| 1479 | (progn | ||
| 1480 | (goto-char (match-end 0)) | ||
| 1481 | (delete-backward-char 1) | ||
| 1482 | (insert (bibtex-field-right-delimiter)) | ||
| 1483 | (goto-char (match-beginning 0)) | ||
| 1484 | (delete-char 1) | ||
| 1485 | (insert (bibtex-field-left-delimiter)))) | ||
| 1486 | (goto-char end))))) | ||
| 1487 | (if (and | ||
| 1488 | (memq 'page-dashes format) | ||
| 1489 | (string-match "^\\(OPT\\)?pages$" (downcase field-name)) | ||
| 1490 | (progn | ||
| 1491 | (goto-char begin-text) | ||
| 1492 | (looking-at | ||
| 1493 | "\\([\"{][0-9]+\\)[ \t\n]*--?[ \t\n]*\\([0-9]+[\"}]\\)"))) | ||
| 1494 | (replace-match "\\1-\\2")) | ||
| 1495 | (if (and | ||
| 1496 | (memq 'inherit-booktitle format) | ||
| 1497 | (equal (downcase field-name) "booktitle") | ||
| 1498 | (progn | ||
| 1499 | (goto-char begin-text) | ||
| 1500 | (looking-at "\\(\"\"\\)\\|\\({}\\)")) | ||
| 1501 | crossref-there | ||
| 1502 | (not (bibtex-find-entry-location crossref-there t))) | ||
| 1503 | ;; booktitle field empty and crossref entry found | ||
| 1504 | ;; --> insert title field of crossreferenced entry if there | ||
| 1505 | (let ((end-of-crefd-entry (bibtex-end-of-entry))) | ||
| 1506 | (bibtex-beginning-of-entry) | ||
| 1507 | (if (re-search-forward | ||
| 1508 | (bibtex-cfield "title" bibtex-field-text) | ||
| 1509 | end-of-crefd-entry t) | ||
| 1510 | (progn | ||
| 1511 | (goto-char begin-text) | ||
| 1512 | (forward-char) | ||
| 1513 | (insert | ||
| 1514 | (buffer-substring-no-properties | ||
| 1515 | (1+ (match-beginning bibtex-text-in-field)) | ||
| 1516 | (1- (match-end bibtex-text-in-field)))))))) | ||
| 1517 | (if (progn | ||
| 1518 | (goto-char begin-text) | ||
| 1519 | (looking-at "\\(\"\"\\)\\|\\({}\\)")) | ||
| 1520 | ;; if empty field, complain | ||
| 1521 | (progn | ||
| 1522 | (forward-char) | ||
| 1523 | (if (or (and | ||
| 1524 | crossref-there | ||
| 1525 | (assoc-ignore-case | ||
| 1526 | field-name creq)) | ||
| 1527 | (and | ||
| 1528 | (not crossref-there) | ||
| 1529 | (assoc-ignore-case | ||
| 1530 | field-name req))) | ||
| 1531 | (error | ||
| 1532 | "Mandatory field ``%s'' is empty." field-name)))) | ||
| 1533 | (if (memq 'unify-case format) | ||
| 1534 | (let* ((fl | ||
| 1535 | (car (cdr (assoc-ignore-case | ||
| 1536 | reference-type | ||
| 1537 | bibtex-entry-field-alist)))) | ||
| 1538 | (field-list | ||
| 1539 | (append | ||
| 1540 | (elt fl 0) | ||
| 1541 | (elt fl 1) | ||
| 1542 | bibtex-user-optional-fields)) | ||
| 1543 | (new-field-name | ||
| 1544 | (car | ||
| 1545 | (assoc-ignore-case field-name field-list)))) | ||
| 1546 | (goto-char begin-name) | ||
| 1547 | (if new-field-name | ||
| 1548 | (progn | ||
| 1549 | (delete-region begin-name end-name) | ||
| 1550 | (insert new-field-name)) | ||
| 1551 | (downcase-region begin-name end-name)))) | ||
| 1552 | (setq field-done t))) | ||
| 1553 | (if (not field-done) | ||
| 1554 | (goto-char begin-field) | ||
| 1555 | (setq field-done nil) | ||
| 1556 | (goto-char end-field)))) | ||
| 1557 | (if (looking-at (bibtex-field-right-delimiter)) | ||
| 1558 | (forward-char)) | ||
| 1559 | (if (memq 'last-comma format) | ||
| 1560 | (cond ((and | ||
| 1561 | bibtex-comma-after-last-field | ||
| 1562 | (not (looking-at ","))) | ||
| 1563 | (insert ",")) | ||
| 1564 | ((and | ||
| 1565 | (not bibtex-comma-after-last-field) | ||
| 1566 | (looking-at ",")) | ||
| 1567 | (delete-char 1)))) | ||
| 1568 | (if (looking-at ",") | ||
| 1569 | (forward-char)) | ||
| 1570 | (if (memq 'delimiters format) | ||
| 1571 | (progn | ||
| 1572 | (skip-chars-forward " \t\n") | ||
| 1573 | (delete-char 1) | ||
| 1574 | (insert (bibtex-entry-right-delimiter)))) | ||
| 1575 | (if (memq 'realign format) | ||
| 1576 | (bibtex-fill-entry))))))) | ||
| 981 | 1577 | ||
| 982 | (defun bibtex-autokey-change (string change-list) | 1578 | (defun bibtex-autokey-change (string change-list) |
| 983 | ;; Returns a string where some regexps are changed according to | 1579 | ;; Returns a string where some regexps are changed according to |
| 984 | ;; change-list. Every item of change-list is an (old-regexp | 1580 | ;; change-list. Every item of change-list is an (old-regexp |
| 985 | ;; new-string) pair. | 1581 | ;; new-string) pair. |
| 986 | (let ((return-string string) | 1582 | (let (case-fold-search |
| 987 | case-fold-search | 1583 | (return-string string) |
| 988 | (index 0) | 1584 | (index 0) |
| 989 | (len (length change-list)) | 1585 | (len (length change-list)) |
| 990 | change-item) | 1586 | change-item) |
| @@ -1003,243 +1599,348 @@ See the documentation of function bibtex-generate-autokey for further detail.") | |||
| 1003 | ;; Returns an abbreviation of string with at least len | 1599 | ;; Returns an abbreviation of string with at least len |
| 1004 | ;; characters. String is aborted only after a consonant or at the | 1600 | ;; characters. String is aborted only after a consonant or at the |
| 1005 | ;; word end. If len is not a number, string is returned unchanged. | 1601 | ;; word end. If len is not a number, string is returned unchanged. |
| 1006 | (let* ((string-length (length string)) | 1602 | (cond ((or |
| 1007 | (len (if (numberp len) | 1603 | (not (numberp len)) |
| 1008 | (min len string-length) | 1604 | (<= (length string) len)) |
| 1009 | len)) | 1605 | string) |
| 1010 | (return-string (if (numberp len) | 1606 | ((equal len 0) |
| 1011 | (substring string 0 len))) | 1607 | "") |
| 1012 | (index len) | 1608 | (t |
| 1013 | (vowels '(?a ?e ?i ?o ?u ?A ?E ?I ?O ?U))) | 1609 | (let* ((case-fold-search t) |
| 1014 | (if (numberp len) | 1610 | (abort-char |
| 1015 | (progn | 1611 | (string-match "[^aeiou]" string (1- len)))) |
| 1016 | (while (and | 1612 | (if abort-char |
| 1017 | (< index string-length) | 1613 | (substring string 0 (1+ abort-char)) |
| 1018 | (member (elt return-string | 1614 | string))))) |
| 1019 | (1- (length return-string))) | 1615 | |
| 1020 | vowels)) | 1616 | (defun bibtex-autokey-get-namefield (min max) |
| 1021 | (setq return-string (concat return-string | 1617 | ;; returns the contents of the name field of the current entry |
| 1022 | (substring | 1618 | ;; does some modifications based on |
| 1023 | string index (1+ index))) | 1619 | ;; `bibtex-autokey-name-change-strings' |
| 1024 | index (1+ index))) | 1620 | (goto-char min) |
| 1025 | return-string) | 1621 | (let ((case-fold-search t)) |
| 1026 | string))) | 1622 | (if (re-search-forward |
| 1623 | (bibtex-cfield "\\(author\\)\\|\\(editor\\)" bibtex-field-text) | ||
| 1624 | max t) | ||
| 1625 | (bibtex-autokey-change | ||
| 1626 | (buffer-substring-no-properties | ||
| 1627 | (1+ (match-beginning (+ bibtex-text-in-cfield 2))) | ||
| 1628 | (1- (match-end (+ bibtex-text-in-cfield 2)))) | ||
| 1629 | bibtex-autokey-name-change-strings) | ||
| 1630 | ""))) | ||
| 1631 | |||
| 1632 | (defun bibtex-autokey-get-names (namefield) | ||
| 1633 | ;; gathers all names in namefield into a list | ||
| 1634 | (let ((case-fold-search t) | ||
| 1635 | names) | ||
| 1636 | (while (not (equal namefield "")) | ||
| 1637 | (let (name) | ||
| 1638 | (if (string-match "[ \t\n]and[ \t\n]" namefield) | ||
| 1639 | (setq name (substring namefield 0 (match-beginning 0)) | ||
| 1640 | namefield (substring namefield (match-end 0))) | ||
| 1641 | (setq name namefield | ||
| 1642 | namefield "")) | ||
| 1643 | (setq names (append names (list name))))) | ||
| 1644 | names)) | ||
| 1645 | |||
| 1646 | (defun bibtex-autokey-demangle-name (fullname) | ||
| 1647 | ;; gets the `last' part from a well-formed name | ||
| 1648 | (let* (case-fold-search | ||
| 1649 | (lastname | ||
| 1650 | (if (string-match "," fullname) | ||
| 1651 | ;; name is of the form "von Last, First" or | ||
| 1652 | ;; "von Last, Jr, First" | ||
| 1653 | ;; --> take only the part before the comma | ||
| 1654 | (let ((von-last | ||
| 1655 | (substring fullname 0 (match-beginning 0)))) | ||
| 1656 | (if (string-match "^[a-z]" von-last) | ||
| 1657 | ;; von-last has a "von" part --> take the "last" part | ||
| 1658 | (if (string-match "[ \t][A-Z]" von-last) | ||
| 1659 | (substring von-last (1+ (match-beginning 0))) | ||
| 1660 | (error | ||
| 1661 | "Name %s is incorrectly formed" fullname)) | ||
| 1662 | ;; von-last has no "von" part --> take all | ||
| 1663 | von-last)) | ||
| 1664 | ;; name is of the form "First von Last" | ||
| 1665 | (if (string-match "[ \t]" fullname) | ||
| 1666 | ;; more than one token | ||
| 1667 | (if (string-match "[ \t][a-z]" fullname) | ||
| 1668 | ;; there is a "von" part | ||
| 1669 | ;; --> take everything after that | ||
| 1670 | (if (string-match | ||
| 1671 | "[ \t][A-Z]" fullname (match-end 0)) | ||
| 1672 | (substring fullname (1+ (match-beginning 0))) | ||
| 1673 | (error | ||
| 1674 | "Name %s is incorrectly formed" fullname)) | ||
| 1675 | ;; there is no "von" part --> take only the last token | ||
| 1676 | (if (string-match " [^ ]*$" fullname) | ||
| 1677 | (substring fullname (1+ (match-beginning 0))) | ||
| 1678 | (error "Name %s is incorrectly formed" fullname))) | ||
| 1679 | ;; only one token --> take it | ||
| 1680 | fullname))) | ||
| 1681 | (usename | ||
| 1682 | (if (string-match "[ \t]+" lastname) | ||
| 1683 | ;; lastname consists of two or more tokens | ||
| 1684 | ;; --> take only the first one | ||
| 1685 | (substring lastname 0 (match-beginning 0)) | ||
| 1686 | lastname))) | ||
| 1687 | (if bibtex-autokey-preserve-case | ||
| 1688 | usename | ||
| 1689 | (downcase usename)))) | ||
| 1690 | |||
| 1691 | (defun bibtex-autokey-get-namelist (namefield) | ||
| 1692 | ;; gets namefield, performs abbreviations on the last parts, and | ||
| 1693 | ;; return results as a list | ||
| 1694 | (mapcar | ||
| 1695 | (lambda (fullname) | ||
| 1696 | (setq | ||
| 1697 | fullname (substring fullname (string-match "[^ \t]" fullname))) | ||
| 1698 | (bibtex-autokey-abbrev | ||
| 1699 | (bibtex-autokey-demangle-name fullname) | ||
| 1700 | bibtex-autokey-name-length)) | ||
| 1701 | (bibtex-autokey-get-names namefield))) | ||
| 1702 | |||
| 1703 | (defun bibtex-autokey-get-yearfield (min max) | ||
| 1704 | ;; get year field from current or maybe crossreferenced entry | ||
| 1705 | (let ((case-fold-search t)) | ||
| 1706 | (goto-char min) | ||
| 1707 | (if (re-search-forward | ||
| 1708 | (bibtex-cfield "year" "[0-9]+") max t) | ||
| 1709 | (buffer-substring-no-properties | ||
| 1710 | (match-beginning bibtex-text-in-cfield) | ||
| 1711 | (match-end bibtex-text-in-cfield)) | ||
| 1712 | (if bibtex-autokey-year-use-crossref-entry | ||
| 1713 | (let ((crossref-field | ||
| 1714 | (progn | ||
| 1715 | (goto-char min) | ||
| 1716 | (if (re-search-forward | ||
| 1717 | (bibtex-cfield | ||
| 1718 | "\\(OPT\\)?crossref" bibtex-field-text) | ||
| 1719 | max t) | ||
| 1720 | (buffer-substring-no-properties | ||
| 1721 | (1+ | ||
| 1722 | (match-beginning (+ bibtex-text-in-cfield 1))) | ||
| 1723 | (1- | ||
| 1724 | (match-end (+ bibtex-text-in-cfield 1)))))))) | ||
| 1725 | (if (not (bibtex-find-entry-location crossref-field t)) | ||
| 1726 | (let ((end-of-crefd-entry (bibtex-end-of-entry))) | ||
| 1727 | (bibtex-beginning-of-entry) | ||
| 1728 | (if (re-search-forward | ||
| 1729 | (bibtex-cfield "year" "[0-9]+") | ||
| 1730 | end-of-crefd-entry t) | ||
| 1731 | (buffer-substring-no-properties | ||
| 1732 | (match-beginning bibtex-text-in-cfield) | ||
| 1733 | (match-end bibtex-text-in-cfield)) | ||
| 1734 | "")) | ||
| 1735 | "")) | ||
| 1736 | "")))) | ||
| 1737 | |||
| 1738 | (defun bibtex-autokey-get-titlestring (min max) | ||
| 1739 | ;; get title field contents up to a terminator | ||
| 1740 | (let ((case-fold-search t)) | ||
| 1741 | (let ((titlefield | ||
| 1742 | (progn | ||
| 1743 | (goto-char min) | ||
| 1744 | (if (re-search-forward | ||
| 1745 | (bibtex-cfield "title" bibtex-field-text) max t) | ||
| 1746 | (bibtex-autokey-change | ||
| 1747 | (buffer-substring-no-properties | ||
| 1748 | (match-beginning bibtex-text-in-cfield) | ||
| 1749 | (match-end bibtex-text-in-cfield)) | ||
| 1750 | bibtex-autokey-titleword-change-strings) | ||
| 1751 | ""))) | ||
| 1752 | (index 0) | ||
| 1753 | (numberofitems | ||
| 1754 | (length bibtex-autokey-title-terminators))) | ||
| 1755 | (while (< index numberofitems) | ||
| 1756 | (if (string-match | ||
| 1757 | (elt bibtex-autokey-title-terminators index) titlefield) | ||
| 1758 | (setq | ||
| 1759 | titlefield (substring titlefield 0 (match-beginning 0)))) | ||
| 1760 | (setq index (1+ index))) | ||
| 1761 | titlefield))) | ||
| 1762 | |||
| 1763 | (defun bibtex-autokey-get-titles (titlestring) | ||
| 1764 | ;; gathers capitalized words from titlestring into a list. Ignores | ||
| 1765 | ;; specific words at the beginning and use only a specific amount of | ||
| 1766 | ;; words | ||
| 1767 | (let (case-fold-search | ||
| 1768 | titlewords | ||
| 1769 | titlewords-extra | ||
| 1770 | (counter 0) | ||
| 1771 | (first t)) | ||
| 1772 | (while (and | ||
| 1773 | (not (equal titlestring "")) | ||
| 1774 | (or | ||
| 1775 | (not (numberp bibtex-autokey-titlewords)) | ||
| 1776 | (< counter | ||
| 1777 | (+ bibtex-autokey-titlewords | ||
| 1778 | bibtex-autokey-titlewords-stretch)))) | ||
| 1779 | (if (string-match "\\b[A-Z][A-Za-z0-9]*" titlestring) | ||
| 1780 | (let* ((end-match (match-end 0)) | ||
| 1781 | (titleword | ||
| 1782 | (if bibtex-autokey-preserve-case | ||
| 1783 | (substring | ||
| 1784 | titlestring (match-beginning 0) end-match) | ||
| 1785 | (downcase | ||
| 1786 | (substring | ||
| 1787 | titlestring (match-beginning 0) end-match))))) | ||
| 1788 | (if (or | ||
| 1789 | (not (numberp bibtex-autokey-titlewords)) | ||
| 1790 | (< counter bibtex-autokey-titlewords)) | ||
| 1791 | (if (and | ||
| 1792 | first | ||
| 1793 | (bibtex-member-of-regexp | ||
| 1794 | titleword | ||
| 1795 | bibtex-autokey-titleword-first-ignore)) | ||
| 1796 | (setq counter -1) | ||
| 1797 | (setq | ||
| 1798 | titlewords (append titlewords (list titleword)))) | ||
| 1799 | (setq | ||
| 1800 | titlewords-extra | ||
| 1801 | (append titlewords-extra (list titleword)))) | ||
| 1802 | (setq | ||
| 1803 | titlestring (substring titlestring end-match))) | ||
| 1804 | (setq titlestring "")) | ||
| 1805 | (setq first nil | ||
| 1806 | counter (1+ counter))) | ||
| 1807 | (if (string-match "\\b[A-Z][^ ]*\\b" titlestring) | ||
| 1808 | titlewords | ||
| 1809 | (append titlewords titlewords-extra)))) | ||
| 1810 | |||
| 1811 | (defun bibtex-autokey-get-titlelist (titlestring) | ||
| 1812 | ;; returns all capitalized words in titlestring as a list | ||
| 1813 | ;; does some abbreviation on the found words | ||
| 1814 | (mapcar | ||
| 1815 | (lambda (titleword) | ||
| 1816 | (let ((abbrev | ||
| 1817 | (assoc-of-regexp | ||
| 1818 | titleword bibtex-autokey-titleword-abbrevs))) | ||
| 1819 | (if abbrev | ||
| 1820 | (elt abbrev 1) | ||
| 1821 | (bibtex-autokey-abbrev | ||
| 1822 | titleword | ||
| 1823 | bibtex-autokey-titleword-length)))) | ||
| 1824 | (bibtex-autokey-get-titles titlestring))) | ||
| 1027 | 1825 | ||
| 1028 | (defun bibtex-generate-autokey () | 1826 | (defun bibtex-generate-autokey () |
| 1029 | "Generates automatically a key from the author/editor and the title field. | 1827 | ;; Generates automatically a key from the author/editor and the |
| 1030 | The generation algorithm works as follows: | 1828 | ;; title field. This will only work for entries where each field |
| 1031 | 1. If there is a non-empty author (preferred) or editor field, | 1829 | ;; begins on a separate line. |
| 1032 | use it for the name part of the key. | 1830 | ;; The generation algorithm works as follows: |
| 1033 | 2. Change any substring found in `bibtex-autokey-name-change-strings' | 1831 | ;; 1. Use the value of `bibtex-autokey-prefix-string' as a prefix. |
| 1034 | to the corresponding new one (see documentation of this variable | 1832 | ;; 2. If there is a non-empty author (preferred) or editor field, |
| 1035 | for further detail). | 1833 | ;; use it as the name part of the key. |
| 1036 | 3. For every of the first `bibtex-autokey-names' names in the | 1834 | ;; 3. Change any substring found in |
| 1037 | \"name\" field, determine the last name. | 1835 | ;; `bibtex-autokey-name-change-strings' to the corresponding new |
| 1038 | 4. From every last name, take at least `bibtex-autokey-name-length' | 1836 | ;; one (see documentation of this variable for further detail). |
| 1039 | characters (abort only after a consonant or at a word end). | 1837 | ;; 4. For every of at least first `bibtex-autokey-names' names in |
| 1040 | 5. Build the name part of the key by concatenating all abbreviated last | 1838 | ;; the name field, determine the last name. If there are maximal |
| 1041 | names with the string `bibtex-autokey-name-separator' between | 1839 | ;; `bibtex-autokey-names' + `bibtex-autokey-names-stretch' |
| 1042 | any two. | 1840 | ;; names, all names are used. |
| 1043 | 6. Build the year part of the key by truncating the contents of the | 1841 | ;; 5. From every last name, take at least |
| 1044 | \"year\" field to the rightmost `bibtex-autokey-year-length' | 1842 | ;; `bibtex-autokey-name-length' characters (abort only after a |
| 1045 | digits (useful values are 2 and 4). | 1843 | ;; consonant or at a word end). |
| 1046 | 7. For the title part of the key change the contents of the \"title\" | 1844 | ;; 6. Unless `bibtex-autokey-preserve-case' is non-nil, convert all |
| 1047 | field of the reference according to | 1845 | ;; last names to lowercase letters. |
| 1048 | `bibtex-autokey-titleword-change-strings' to the corresponding | 1846 | ;; 7. Build the name part of the key by concatenating all |
| 1049 | new one (see documentation of this variable for further detail). | 1847 | ;; abbreviated last names with the string |
| 1050 | 8. Abbreviate the result to the string up to (but not including) the | 1848 | ;; `bibtex-autokey-name-separator' between any two. If there are |
| 1051 | first occurrence of a regexp matched by the items of | 1849 | ;; more names than are used in the name part, prepend the string |
| 1052 | `bibtex-autokey-title-terminators' and delete the first | 1850 | ;; contained in `bibtex-autokey-additional-names'. |
| 1053 | word if it appears in `bibtex-autokey-titleword-first-ignore'. | 1851 | ;; 8. Build the year part of the key by truncating the contents of |
| 1054 | Build the title part of the key by using at least the first | 1852 | ;; the year field to the rightmost `bibtex-autokey-year-length' |
| 1055 | `bibtex-autokey-titlewords' capitalized words from this | 1853 | ;; digits (useful values are 2 and 4). If the year field is |
| 1056 | abbreviated title. If the abbreviated title ends after maximal | 1854 | ;; absent, but the entry has a valid crossref field and the |
| 1057 | `bibtex-autokey-titlewords' + `bibtex-autokey-titlewords-stretch' | 1855 | ;; variable `bibtex-autokey-year-use-crossref-entry' is non-nil, |
| 1058 | capitalized words, all capitalized words from the abbreviated title | 1856 | ;; use the year field of the crossreferenced entry instead. |
| 1059 | are used. | 1857 | ;; 9. For the title part of the key change the contents of the |
| 1060 | 9. For every used title word that appears in | 1858 | ;; title field of the reference according to |
| 1061 | `bibtex-autokey-titleword-abbrevs' use the corresponding abbreviation | 1859 | ;; `bibtex-autokey-titleword-change-strings' to the |
| 1062 | (see documentation of this variable for further detail). | 1860 | ;; corresponding new one (see documentation of this variable for |
| 1063 | 10. From every title word not generated by an abbreviation, take at | 1861 | ;; further detail). |
| 1064 | least `bibtex-autokey-titleword-length' characters (abort only after | 1862 | ;; 10. Abbreviate the result to the string up to (but not including) |
| 1065 | a consonant or at a word end). | 1863 | ;; the first occurrence of a regexp matched by the items of |
| 1066 | 11. Build the title part of the key by concatenating all abbreviated | 1864 | ;; `bibtex-autokey-title-terminators' and delete the first |
| 1067 | title words with the string `bibtex-autokey-titleword-separator' | 1865 | ;; word if it appears in |
| 1068 | between any two. | 1866 | ;; `bibtex-autokey-titleword-first-ignore'. Build the title part |
| 1069 | 12. At least, to get the key, concatenate the name part, the year part | 1867 | ;; of the key by using at least the first |
| 1070 | and the title part with `bibtex-autokey-name-year-separator' | 1868 | ;; `bibtex-autokey-titlewords' capitalized words from this |
| 1071 | between the name and the year if both are non-empty and | 1869 | ;; abbreviated title. If the abbreviated title ends after |
| 1072 | `bibtex-autokey-year-title-separator' between the year and | 1870 | ;; maximal `bibtex-autokey-titlewords' + |
| 1073 | the title if both are non-empty." | 1871 | ;; `bibtex-autokey-titlewords-stretch' capitalized words, all |
| 1872 | ;; capitalized words from the abbreviated title are used. | ||
| 1873 | ;; 11. Unless `bibtex-autokey-preserve-case' is non-nil, convert all | ||
| 1874 | ;; used titlewords to lowercase letters. | ||
| 1875 | ;; 12. For every used title word that appears in | ||
| 1876 | ;; `bibtex-autokey-titleword-abbrevs' use the corresponding | ||
| 1877 | ;; abbreviation (see documentation of this variable for further | ||
| 1878 | ;; detail). | ||
| 1879 | ;; 13. From every title word not generated by an abbreviation, take | ||
| 1880 | ;; at least `bibtex-autokey-titleword-length' characters (abort | ||
| 1881 | ;; only after a consonant or at a word end). | ||
| 1882 | ;; 14. Build the title part of the key by concatenating all | ||
| 1883 | ;; abbreviated title words with the string | ||
| 1884 | ;; `bibtex-autokey-titleword-separator' between any two. | ||
| 1885 | ;; 15. At least, to get the key, concatenate | ||
| 1886 | ;; `bibtex-autokey-prefix-string', the name part, the year part | ||
| 1887 | ;; and the title part with `bibtex-autokey-name-year-separator' | ||
| 1888 | ;; between the name part and the year part if both are non-empty | ||
| 1889 | ;; and `bibtex-autokey-year-title-separator' between the year | ||
| 1890 | ;; part and the title part if both are non-empty. If the year | ||
| 1891 | ;; part is empty, but not the other two parts, | ||
| 1892 | ;; `bibtex-autokey-year-title-separator' is used as well. | ||
| 1893 | ;; 16. If the value of `bibtex-autokey-before-presentation-hook' is | ||
| 1894 | ;; non-nil, it must be a function taking one argument. This | ||
| 1895 | ;; function is then called with the generated key as the | ||
| 1896 | ;; argument. The return value of this function (a string) is | ||
| 1897 | ;; used as the key. | ||
| 1898 | ;; 17. If the value of `bibtex-autokey-edit-before-use' is non-nil, | ||
| 1899 | ;; the key is then presented in the minibuffer to the user, | ||
| 1900 | ;; where it can be edited. The key given by the user is then | ||
| 1901 | ;; used. | ||
| 1074 | 1902 | ||
| 1075 | (let* ((pnt (point)) | 1903 | (let* ((pnt (point)) |
| 1076 | (min | 1904 | (min (bibtex-beginning-of-entry)) |
| 1077 | (progn | 1905 | (max (bibtex-end-of-entry)) |
| 1078 | (bibtex-beginning-of-entry) | 1906 | (namefield (bibtex-autokey-get-namefield min max)) |
| 1079 | (point))) | 1907 | (name-etal "") |
| 1080 | (max | ||
| 1081 | (progn | ||
| 1082 | (bibtex-end-of-entry) | ||
| 1083 | (point))) | ||
| 1084 | (namefield | ||
| 1085 | (progn | ||
| 1086 | (goto-char min) | ||
| 1087 | (if (or | ||
| 1088 | (re-search-forward "^[ \t]*author[ \t]*=" max t) | ||
| 1089 | (re-search-forward "^[ \t]*editor[ \t]*=" max t)) | ||
| 1090 | (let* (bibtex-help-message | ||
| 1091 | (start (progn | ||
| 1092 | (bibtex-find-text t) | ||
| 1093 | (point))) | ||
| 1094 | (end (progn | ||
| 1095 | (bibtex-find-text nil) | ||
| 1096 | (point)))) | ||
| 1097 | (bibtex-autokey-change | ||
| 1098 | (buffer-substring-no-properties start end) | ||
| 1099 | bibtex-autokey-name-change-strings)) | ||
| 1100 | ""))) | ||
| 1101 | (namelist | 1908 | (namelist |
| 1102 | (mapcar | 1909 | (let ((nl (bibtex-autokey-get-namelist namefield))) |
| 1103 | (function | 1910 | (if (or (not (numberp bibtex-autokey-names)) |
| 1104 | (lambda (fullname) | 1911 | (<= (length nl) |
| 1105 | (bibtex-autokey-abbrev | 1912 | (+ bibtex-autokey-names |
| 1106 | (if (string-match "," fullname) | 1913 | bibtex-autokey-names-stretch))) |
| 1107 | (substring fullname 0 (match-beginning 0)) | 1914 | nl |
| 1108 | (progn | 1915 | (setq name-etal bibtex-autokey-additional-names) |
| 1109 | (if (string-match " [^ ]*$" fullname) | 1916 | (let (nnl) |
| 1110 | (substring | 1917 | (while (< (length nnl) bibtex-autokey-names) |
| 1111 | fullname (1+ (match-beginning 0))) | 1918 | (setq nnl (append nnl (list (car nl))) |
| 1112 | fullname))) | 1919 | nl (cdr nl))) |
| 1113 | bibtex-autokey-name-length))) | 1920 | nnl)))) |
| 1114 | ;; Gather all names into a list | 1921 | (namepart |
| 1115 | (let (names | 1922 | (concat |
| 1116 | (counter 0)) | 1923 | (mapconcat (lambda (name) name) |
| 1117 | (while (and | 1924 | namelist |
| 1118 | (not (equal namefield "")) | 1925 | bibtex-autokey-name-separator) |
| 1119 | (or | 1926 | name-etal)) |
| 1120 | (not (numberp bibtex-autokey-names)) | 1927 | (yearfield (bibtex-autokey-get-yearfield min max)) |
| 1121 | (< counter bibtex-autokey-names))) | ||
| 1122 | (if (string-match " and " namefield) | ||
| 1123 | (progn | ||
| 1124 | (setq | ||
| 1125 | names | ||
| 1126 | (append names | ||
| 1127 | (list | ||
| 1128 | (downcase | ||
| 1129 | (substring | ||
| 1130 | namefield 0 (match-beginning 0))))) | ||
| 1131 | namefield | ||
| 1132 | (substring namefield (match-end 0)))) | ||
| 1133 | (setq names | ||
| 1134 | (append names (list (downcase namefield))) | ||
| 1135 | namefield "")) | ||
| 1136 | (setq counter (1+ counter))) | ||
| 1137 | names))) | ||
| 1138 | (namepart (mapconcat (function (lambda (name) name)) | ||
| 1139 | namelist | ||
| 1140 | bibtex-autokey-name-separator)) | ||
| 1141 | (yearfield | ||
| 1142 | (progn | ||
| 1143 | (goto-char min) | ||
| 1144 | (if (re-search-forward | ||
| 1145 | "^[ \t]*year[ \t]*=[ \t]*\\([0-9]*\\)" max t) | ||
| 1146 | (buffer-substring-no-properties | ||
| 1147 | (match-beginning 1) (match-end 1)) | ||
| 1148 | ""))) | ||
| 1149 | (yearpart | 1928 | (yearpart |
| 1150 | (if (equal yearfield "") | 1929 | (if (equal yearfield "") |
| 1151 | "" | 1930 | "" |
| 1152 | (substring yearfield | 1931 | (substring |
| 1153 | (- (length yearfield) | 1932 | yearfield |
| 1154 | bibtex-autokey-year-length)))) | 1933 | (- (length yearfield) bibtex-autokey-year-length)))) |
| 1155 | (titlestring | 1934 | (titlestring (bibtex-autokey-get-titlestring min max)) |
| 1156 | (let ((case-fold-search t) | 1935 | (titlelist (bibtex-autokey-get-titlelist titlestring)) |
| 1157 | (titlefield | 1936 | (titlepart |
| 1158 | (progn | 1937 | (mapconcat |
| 1159 | (goto-char min) | 1938 | (lambda (name) name) |
| 1160 | (if (re-search-forward | 1939 | titlelist |
| 1161 | "^[ \t]*title[ \t]*=" max t) | 1940 | bibtex-autokey-titleword-separator)) |
| 1162 | (let* (bibtex-help-message | ||
| 1163 | (start (progn | ||
| 1164 | (bibtex-find-text t) | ||
| 1165 | (point))) | ||
| 1166 | (end (progn | ||
| 1167 | (bibtex-find-text nil) | ||
| 1168 | (point)))) | ||
| 1169 | (bibtex-autokey-change | ||
| 1170 | (buffer-substring-no-properties start end) | ||
| 1171 | bibtex-autokey-titleword-change-strings)) | ||
| 1172 | ""))) | ||
| 1173 | case-fold-search | ||
| 1174 | (index 0) | ||
| 1175 | (numberofitems | ||
| 1176 | (length bibtex-autokey-title-terminators))) | ||
| 1177 | (while (< index numberofitems) | ||
| 1178 | (if (string-match | ||
| 1179 | (elt bibtex-autokey-title-terminators index) | ||
| 1180 | titlefield) | ||
| 1181 | (setq titlefield | ||
| 1182 | (substring titlefield 0 (match-beginning 0)))) | ||
| 1183 | (setq index (1+ index))) | ||
| 1184 | titlefield)) | ||
| 1185 | (titlelist | ||
| 1186 | (mapcar | ||
| 1187 | (function | ||
| 1188 | (lambda (titleword) | ||
| 1189 | (let ((abbrev | ||
| 1190 | (assoc-of-regexp | ||
| 1191 | titleword bibtex-autokey-titleword-abbrevs))) | ||
| 1192 | (if abbrev | ||
| 1193 | (elt abbrev 1) | ||
| 1194 | (bibtex-autokey-abbrev | ||
| 1195 | titleword | ||
| 1196 | bibtex-autokey-titleword-length))))) | ||
| 1197 | ;; Gather all titlewords into a list | ||
| 1198 | (let (titlewords | ||
| 1199 | titlewords-extra | ||
| 1200 | case-fold-search | ||
| 1201 | (counter 0) | ||
| 1202 | (first t)) | ||
| 1203 | (while (and | ||
| 1204 | (not (equal titlestring "")) | ||
| 1205 | (or | ||
| 1206 | (not (numberp bibtex-autokey-titlewords)) | ||
| 1207 | (< counter (+ | ||
| 1208 | bibtex-autokey-titlewords | ||
| 1209 | bibtex-autokey-titlewords-stretch)))) | ||
| 1210 | (if (string-match "\\b[A-Z][A-Za-z0-9]*" titlestring) | ||
| 1211 | (let* ((end-match (match-end 0)) | ||
| 1212 | (titleword | ||
| 1213 | (downcase (substring titlestring | ||
| 1214 | (match-beginning 0) | ||
| 1215 | end-match)))) | ||
| 1216 | (if (or | ||
| 1217 | (not (numberp bibtex-autokey-titlewords)) | ||
| 1218 | (< counter bibtex-autokey-titlewords)) | ||
| 1219 | (if (and | ||
| 1220 | first | ||
| 1221 | (bibtex-member-of-regexp | ||
| 1222 | titleword | ||
| 1223 | bibtex-autokey-titleword-first-ignore)) | ||
| 1224 | (setq counter -1) | ||
| 1225 | (setq titlewords | ||
| 1226 | (append titlewords (list titleword)))) | ||
| 1227 | (setq | ||
| 1228 | titlewords-extra | ||
| 1229 | (append titlewords-extra (list titleword)))) | ||
| 1230 | (setq titlestring | ||
| 1231 | (substring titlestring end-match))) | ||
| 1232 | (setq titlestring "")) | ||
| 1233 | (setq first nil | ||
| 1234 | counter (1+ counter))) | ||
| 1235 | (if (string-match "\\b[A-Z][^ ]*\\b" titlestring) | ||
| 1236 | titlewords | ||
| 1237 | (append titlewords titlewords-extra))))) | ||
| 1238 | (titlepart (mapconcat (function (lambda (name) name)) | ||
| 1239 | titlelist | ||
| 1240 | bibtex-autokey-titleword-separator)) | ||
| 1241 | (autokey | 1941 | (autokey |
| 1242 | (concat | 1942 | (concat |
| 1943 | bibtex-autokey-prefix-string | ||
| 1243 | namepart | 1944 | namepart |
| 1244 | (if (not | 1945 | (if (not |
| 1245 | (or | 1946 | (or |
| @@ -1255,105 +1956,327 @@ The generation algorithm works as follows: | |||
| 1255 | (equal titlepart ""))) | 1956 | (equal titlepart ""))) |
| 1256 | bibtex-autokey-year-title-separator) | 1957 | bibtex-autokey-year-title-separator) |
| 1257 | titlepart))) | 1958 | titlepart))) |
| 1959 | (if bibtex-autokey-before-presentation-hook | ||
| 1960 | (setq | ||
| 1961 | autokey | ||
| 1962 | (funcall bibtex-autokey-before-presentation-hook autokey))) | ||
| 1258 | (goto-char pnt) | 1963 | (goto-char pnt) |
| 1259 | autokey)) | 1964 | autokey)) |
| 1260 | 1965 | ||
| 1261 | (defun bibtex-parse-keys (add &optional abortable) | 1966 | (defun bibtex-parse-keys (add verbose &optional abortable) |
| 1262 | ;; Sets bibtex-keys to the keys used in the whole (possibly | 1967 | ;; Sets bibtex-keys to the keys used in the whole (possibly |
| 1263 | ;; restricted) buffer (either as entry keys or as crossref entries). | 1968 | ;; restricted) buffer (either as entry keys or as crossref entries). |
| 1264 | ;; If ADD is non-nil adds the new keys to bibtex-keys instead of | 1969 | ;; If ADD is non-nil adds the new keys to bibtex-keys instead of |
| 1265 | ;; simply resetting it. If ABORTABLE is non-nil abort on user input. | 1970 | ;; simply resetting it. If VERBOSE is non-nil gives messages about |
| 1971 | ;; progress. If ABORTABLE is non-nil abort on user input. | ||
| 1266 | (if bibtex-maintain-sorted-entries | 1972 | (if bibtex-maintain-sorted-entries |
| 1267 | (let ((labels (if add | 1973 | (let ((case-fold-search t) |
| 1268 | bibtex-keys)) | 1974 | (crossref-field |
| 1269 | label | 1975 | (bibtex-cfield |
| 1270 | (case-fold-search t)) | 1976 | "crossref" (concat "[{\"]" bibtex-reference-key "[}\"]"))) |
| 1977 | (labels (if add | ||
| 1978 | bibtex-keys))) | ||
| 1271 | (save-excursion | 1979 | (save-excursion |
| 1272 | (goto-char (point-min)) | 1980 | (goto-char (point-min)) |
| 1273 | (if (not add) | 1981 | (if verbose |
| 1274 | (message "Parsing reference keys...")) | 1982 | (bibtex-progress-message |
| 1275 | 1983 | (concat (buffer-name) ": parsing reference keys"))) | |
| 1276 | (if (not | 1984 | (if (catch 'userkey |
| 1277 | (catch 'userkey | 1985 | (skip-to-valid-bibtex-entry) |
| 1278 | (while | 1986 | (while (not (eobp)) |
| 1279 | (re-search-forward | 1987 | (if (and |
| 1280 | (concat | 1988 | abortable |
| 1281 | "\\(" bibtex-reference-head "\\)" | 1989 | (input-pending-p)) |
| 1282 | "\\|" | 1990 | (throw 'userkey t)) |
| 1283 | "\\(" | 1991 | (if verbose |
| 1284 | "^[ \t]*crossref[ \t\n]*=[ \t\n]*" | 1992 | (bibtex-progress-message)) |
| 1285 | "\\(" | 1993 | (let (label |
| 1286 | "\\({" | 1994 | label2) |
| 1287 | bibtex-reference-key | 1995 | (cond |
| 1288 | ;; every valid crossref entry must have the | 1996 | ((looking-at bibtex-reference-head) |
| 1289 | ;; form of a reference key, so we need no | 1997 | (setq |
| 1290 | ;; nesting of brace etc. here | 1998 | label |
| 1291 | "}\\)" | 1999 | (buffer-substring-no-properties |
| 1292 | "\\|" | 2000 | (match-beginning bibtex-key-in-head) |
| 1293 | "\\(\"" | 2001 | (match-end bibtex-key-in-head))) |
| 1294 | bibtex-reference-key | 2002 | (let ((p (point)) |
| 1295 | "\"\\)" | 2003 | (m (bibtex-end-of-entry))) |
| 1296 | "\\)" | 2004 | (goto-char p) |
| 1297 | ",?$" | 2005 | (if (re-search-forward crossref-field m t) |
| 1298 | "\\)") | 2006 | (setq |
| 1299 | nil t) | 2007 | label2 |
| 2008 | (buffer-substring-no-properties | ||
| 2009 | (1+ (match-beginning bibtex-text-in-cfield)) | ||
| 2010 | (1- (match-end bibtex-text-in-cfield))))) | ||
| 2011 | (goto-char p))) | ||
| 2012 | ((looking-at bibtex-string) | ||
| 2013 | (setq | ||
| 2014 | label | ||
| 2015 | (buffer-substring-no-properties | ||
| 2016 | (match-beginning bibtex-key-in-string) | ||
| 2017 | (match-end bibtex-key-in-string))))) | ||
| 2018 | (forward-char) | ||
| 2019 | (skip-to-valid-bibtex-entry) | ||
| 2020 | (if (not (assoc label labels)) | ||
| 2021 | (setq labels | ||
| 2022 | (cons (list label) labels))) | ||
| 2023 | (if (and label2 | ||
| 2024 | (not (assoc label2 labels))) | ||
| 2025 | (setq labels | ||
| 2026 | (cons (list label2) labels)))))) | ||
| 2027 | ;; user has aborted by typing a key --> return nil | ||
| 2028 | nil | ||
| 2029 | ;; successful operation --> return t | ||
| 2030 | (setq | ||
| 2031 | bibtex-buffer-last-parsed-tick (buffer-modified-tick) | ||
| 2032 | bibtex-keys labels) | ||
| 2033 | (if verbose | ||
| 2034 | (bibtex-progress-message 'done)) | ||
| 2035 | t))))) | ||
| 2036 | |||
| 2037 | (defun bibtex-parse-buffers-stealthily () | ||
| 2038 | ;; Called by run-with-idle-timer. Whenever emacs has been idle for | ||
| 2039 | ;; bibtex-parse-keys-timeout seconds, all BibTeX buffers (starting | ||
| 2040 | ;; with the current) are parsed. | ||
| 2041 | (let ((buffers (buffer-list))) | ||
| 2042 | (save-excursion | ||
| 2043 | (while (and buffers (not (input-pending-p))) | ||
| 2044 | (set-buffer (car buffers)) | ||
| 2045 | (save-restriction | ||
| 2046 | (widen) | ||
| 2047 | (if (and | ||
| 2048 | (eq major-mode 'bibtex-mode) | ||
| 2049 | bibtex-maintain-sorted-entries | ||
| 2050 | (not | ||
| 2051 | (eq (buffer-modified-tick) | ||
| 2052 | bibtex-buffer-last-parsed-tick))) | ||
| 2053 | (if (bibtex-parse-keys nil t t) | ||
| 2054 | ;; successful operation --> remove buffer from list | ||
| 2055 | (setq buffers (cdr buffers))) | ||
| 2056 | ;; buffer is no BibTeX buffer or needs no parsing | ||
| 2057 | (setq buffers (cdr buffers)))))))) | ||
| 2058 | |||
| 2059 | (defun bibtex-complete (string-list &optional complete-strings) | ||
| 2060 | ;; Complete word fragment before point to longest prefix of one | ||
| 2061 | ;; string defined in STRING-LIST. If point is not after the part of | ||
| 2062 | ;; a word, all strings are listed. If COMPLETE-STRINGS is non-nil, | ||
| 2063 | ;; add the strings defined in this buffer before cursor to | ||
| 2064 | ;; STRING-LIST and remove surrounding delimiters if complete string | ||
| 2065 | ;; could be expanded. | ||
| 2066 | (let* ((case-fold-search t) | ||
| 2067 | (end (point)) | ||
| 2068 | (beg (save-excursion | ||
| 2069 | (re-search-backward "[ \t{\"]") | ||
| 2070 | (forward-char) | ||
| 2071 | (point))) | ||
| 2072 | (part-of-word (buffer-substring-no-properties beg end)) | ||
| 2073 | (completions (copy-sequence string-list)) | ||
| 2074 | (completion (save-excursion | ||
| 2075 | (if complete-strings | ||
| 2076 | (while (re-search-backward | ||
| 2077 | bibtex-string nil t) | ||
| 2078 | (setq completions | ||
| 2079 | (cons | ||
| 2080 | (list | ||
| 2081 | (buffer-substring-no-properties | ||
| 2082 | (match-beginning bibtex-key-in-string) | ||
| 2083 | (match-end bibtex-key-in-string))) | ||
| 2084 | completions)))) | ||
| 2085 | (setq completions | ||
| 2086 | (sort completions | ||
| 2087 | (lambda(x y) | ||
| 2088 | (string-lessp | ||
| 2089 | (car x) | ||
| 2090 | (car y))))) | ||
| 2091 | (try-completion part-of-word completions)))) | ||
| 2092 | (cond ((eq completion t) | ||
| 2093 | (if complete-strings | ||
| 2094 | ;; remove double-quotes or braces if field is no concatenation | ||
| 2095 | (save-excursion | ||
| 2096 | (bibtex-inside-field) | ||
| 2097 | (bibtex-enclosing-field) | ||
| 2098 | (let ((end (match-end bibtex-text-in-field))) | ||
| 2099 | (goto-char (match-beginning bibtex-text-in-field)) | ||
| 1300 | (if (and | 2100 | (if (and |
| 1301 | abortable | 2101 | (looking-at bibtex-field-string) |
| 1302 | (input-pending-p)) | 2102 | (equal (match-end 0) end)) |
| 1303 | (throw 'userkey t)) | 2103 | (bibtex-remove-delimiters)))))) |
| 1304 | (if (match-beginning (1+ bibtex-key-in-head)) | 2104 | ((not completion) |
| 1305 | (setq | 2105 | (error "Can't find completion for \"%s\"." part-of-word)) |
| 1306 | label | 2106 | ((not (string= part-of-word completion)) |
| 1307 | (buffer-substring-no-properties | 2107 | (delete-region beg end) |
| 1308 | (match-beginning (1+ bibtex-key-in-head)) | 2108 | (insert completion) |
| 1309 | (match-end (1+ bibtex-key-in-head)))) | 2109 | (if (and (assoc completion completions) |
| 1310 | (setq | 2110 | complete-strings) |
| 1311 | label | 2111 | ;; remove double-quotes or braces if field is no concatenation |
| 1312 | (buffer-substring-no-properties | 2112 | (save-excursion |
| 1313 | (1+ (match-beginning (+ 3 bibtex-key-in-head))) | 2113 | (bibtex-inside-field) |
| 1314 | (1- (match-end (+ 3 bibtex-key-in-head)))))) | 2114 | (bibtex-enclosing-field) |
| 1315 | (if (not (assoc label labels)) | 2115 | (let ((end (match-end bibtex-text-in-field))) |
| 1316 | (setq labels | 2116 | (goto-char (match-beginning bibtex-text-in-field)) |
| 1317 | (cons (list label) labels)))))) | 2117 | (if (and |
| 1318 | (progn | 2118 | (looking-at bibtex-field-string) |
| 1319 | (setq | 2119 | (equal (match-end 0) end)) |
| 1320 | bibtex-buffer-last-parsed-for-keys-tick | 2120 | (bibtex-remove-delimiters)))))) |
| 1321 | (buffer-modified-tick)) | 2121 | (t |
| 1322 | (if (not add) | 2122 | (message "Making completion list...") |
| 1323 | (message "Parsing reference keys... done")) | 2123 | (let ((list (all-completions part-of-word completions))) |
| 1324 | (setq bibtex-keys labels))))))) | 2124 | (with-output-to-temp-buffer "*Completions*" |
| 1325 | 2125 | (display-completion-list list))) | |
| 1326 | (defun bibtex-auto-fill-function () | 2126 | (message "Making completion list...done"))))) |
| 1327 | (let ((fill-prefix (make-string (+ bibtex-text-alignment 1) ? ))) | 2127 | |
| 2128 | (defun bibtex-do-auto-fill () | ||
| 2129 | (let ((fill-prefix | ||
| 2130 | (make-string | ||
| 2131 | (+ bibtex-entry-offset bibtex-contline-indentation) ? ))) | ||
| 1328 | (do-auto-fill))) | 2132 | (do-auto-fill))) |
| 1329 | 2133 | ||
| 2134 | (defun bibtex-pop (arg direction) | ||
| 2135 | ;; generic function to be used by bibtex-pop-previous and bibtex-pop-next | ||
| 2136 | (let (bibtex-help-message) | ||
| 2137 | (bibtex-find-text nil)) | ||
| 2138 | (save-excursion | ||
| 2139 | ;; parse current field | ||
| 2140 | (bibtex-inside-field) | ||
| 2141 | (bibtex-enclosing-field) | ||
| 2142 | (let ((case-fold-search t) | ||
| 2143 | (start-old-text (match-beginning bibtex-text-in-field)) | ||
| 2144 | (stop-old-text (match-end bibtex-text-in-field)) | ||
| 2145 | (start-name (match-beginning bibtex-name-in-field)) | ||
| 2146 | (stop-name (match-end bibtex-name-in-field)) | ||
| 2147 | (new-text)) | ||
| 2148 | (goto-char start-name) | ||
| 2149 | ;; construct regexp for field with same name as this one, | ||
| 2150 | ;; ignoring possible OPT's or ALT's | ||
| 2151 | (let ((matching-entry | ||
| 2152 | (bibtex-cfield | ||
| 2153 | (buffer-substring-no-properties | ||
| 2154 | (if (looking-at "OPT\\|ALT") | ||
| 2155 | (+ (point) (length "OPT")) | ||
| 2156 | (point)) | ||
| 2157 | stop-name) | ||
| 2158 | bibtex-field-text))) | ||
| 2159 | ;; if executed several times in a row, start each search where | ||
| 2160 | ;; the last one was finished | ||
| 2161 | (cond ((eq last-command 'bibtex-pop) | ||
| 2162 | t | ||
| 2163 | ) | ||
| 2164 | (t | ||
| 2165 | (bibtex-enclosing-reference-maybe-empty-head) | ||
| 2166 | (setq | ||
| 2167 | bibtex-pop-previous-search-point (match-beginning 0) | ||
| 2168 | bibtex-pop-next-search-point (point)))) | ||
| 2169 | (if (eq direction 'previous) | ||
| 2170 | (goto-char bibtex-pop-previous-search-point) | ||
| 2171 | (goto-char bibtex-pop-next-search-point)) | ||
| 2172 | ;; Now search for arg'th previous/next similar field | ||
| 2173 | (cond | ||
| 2174 | ((if (eq direction 'previous) | ||
| 2175 | (re-search-backward matching-entry nil t arg) | ||
| 2176 | (re-search-forward matching-entry nil t arg)) | ||
| 2177 | ;; Found a matching field. Remember boundaries. | ||
| 2178 | (setq bibtex-pop-previous-search-point (match-beginning 0)) | ||
| 2179 | (setq bibtex-pop-next-search-point (match-end 0)) | ||
| 2180 | (setq new-text | ||
| 2181 | (buffer-substring-no-properties | ||
| 2182 | (match-beginning bibtex-text-in-field) | ||
| 2183 | (match-end bibtex-text-in-field))) | ||
| 2184 | ;; change delimiters, if any changes needed | ||
| 2185 | (let ((start 0) | ||
| 2186 | old-open | ||
| 2187 | new-open | ||
| 2188 | old-close | ||
| 2189 | new-close) | ||
| 2190 | (if (equal bibtex-field-delimiters 'braces) | ||
| 2191 | (setq old-open ?\" | ||
| 2192 | new-open ?\{ | ||
| 2193 | old-close ?\" | ||
| 2194 | new-close ?\}) | ||
| 2195 | (setq old-open ?\{ | ||
| 2196 | new-open ?\" | ||
| 2197 | old-close ?\} | ||
| 2198 | new-close ?\")) | ||
| 2199 | (while (string-match bibtex-field-string new-text start) | ||
| 2200 | (let ((beg (match-beginning 0)) | ||
| 2201 | (end (1- (match-end 0)))) | ||
| 2202 | (if (and | ||
| 2203 | (eq (aref new-text beg) old-open) | ||
| 2204 | (eq (aref new-text end) old-close)) | ||
| 2205 | (progn | ||
| 2206 | (aset new-text beg new-open) | ||
| 2207 | (aset new-text end new-close)))) | ||
| 2208 | (setq start (match-end 0)))) | ||
| 2209 | (bibtex-flash-head) | ||
| 2210 | ;; Go back to where we started, delete old text, and pop new. | ||
| 2211 | (goto-char stop-old-text) | ||
| 2212 | (delete-region start-old-text stop-old-text) | ||
| 2213 | (insert new-text)) | ||
| 2214 | (t | ||
| 2215 | ;; search failed | ||
| 2216 | (error (concat "No " | ||
| 2217 | (if (eq direction 'previous) | ||
| 2218 | "previous" | ||
| 2219 | "next") | ||
| 2220 | " matching BibTeX field."))))))) | ||
| 2221 | (let (bibtex-help-message) | ||
| 2222 | (bibtex-find-text nil)) | ||
| 2223 | (setq this-command 'bibtex-pop)) | ||
| 2224 | |||
| 1330 | 2225 | ||
| 1331 | ;; Interactive Functions: | 2226 | ;; Interactive Functions: |
| 1332 | 2227 | ||
| 1333 | ;;;###autoload | 2228 | ;;;###autoload |
| 1334 | (defun bibtex-mode () | 2229 | (defun bibtex-mode () |
| 1335 | "Major mode for editing BibTeX files. | 2230 | "Major mode for editing BibTeX files. |
| 1336 | To submit a problem report, enter `\\[bibtex-submit-bug-report]' from a | 2231 | |
| 2232 | To submit a problem report, enter \\[bibtex-submit-bug-report] from a | ||
| 1337 | bibtex-mode buffer. This automatically sets up a mail buffer with | 2233 | bibtex-mode buffer. This automatically sets up a mail buffer with |
| 1338 | version information already added. You just need to add a description | 2234 | version information already added. You just need to add a description |
| 1339 | of the problem, including a reproducable test case and send the | 2235 | of the problem, including a reproducable test case and send the |
| 1340 | message. | 2236 | message. |
| 1341 | 2237 | ||
| 1342 | \\{bibtex-mode-map} | ||
| 1343 | 2238 | ||
| 1344 | A command such as \\[bibtex-Book] will outline the fields for a BibTeX book entry. | 2239 | General information on working with BibTeX mode: |
| 2240 | |||
| 2241 | You should use commands as \\[bibtex-Book] to get a template for a | ||
| 2242 | specific entry. You should then fill in all desired fields using | ||
| 2243 | \\[bibtex-next-field] to jump from field to field. After having filled | ||
| 2244 | in all desired fields in the entry, you should clean the new entry | ||
| 2245 | with command \\[bibtex-clean-entry]. | ||
| 2246 | |||
| 2247 | Some features of BibTeX mode are available only by setting variable | ||
| 2248 | bibtex-maintain-sorted-entries to t. However, then BibTeX mode will | ||
| 2249 | work with buffer containing only valid (syntactical correct) entries | ||
| 2250 | and with entries being sorted. This is usually the case, if you have | ||
| 2251 | created a buffer completely with BibTeX mode and finished every new | ||
| 2252 | entry with \\[bibtex-clean-entry]. | ||
| 2253 | |||
| 2254 | For third party BibTeX buffers, please call the function | ||
| 2255 | `bibtex-convert-alien' to fully take advantage of all features of | ||
| 2256 | BibTeX mode. | ||
| 1345 | 2257 | ||
| 1346 | The optional fields start with the string OPT, and thus ignored by BibTeX. | ||
| 1347 | The OPT string may be removed from a field with \\[bibtex-remove-OPT]. | ||
| 1348 | \\[bibtex-kill-optional-field] kills the current optional field entirely. | ||
| 1349 | \\[bibtex-remove-double-quotes-or-braces] removes the double-quotes or | ||
| 1350 | braces around the text of the current field. \\[bibtex-empty-field] | ||
| 1351 | replaces the text of the current field with the default \"\" or {}. | ||
| 1352 | 2258 | ||
| 1353 | The command \\[bibtex-clean-entry] cleans the current entry, i.e. (i) removes | 2259 | Special information: |
| 1354 | double-quotes or braces from entirely numerical fields, (ii) removes | 2260 | |
| 1355 | OPT from all non-empty optional fields, (iii) removes all empty | 2261 | A command such as \\[bibtex-Book] will outline the fields for a BibTeX book entry. |
| 1356 | optional fields, and (iv) checks that no non-optional fields are empty. | 2262 | |
| 2263 | The optional fields start with the string OPT, and are thus ignored by BibTeX. | ||
| 2264 | Alternatives from which only one is required start with the string ALT. | ||
| 2265 | The OPT or ALT string may be removed from a field with \\[bibtex-remove-OPT-or-ALT]. | ||
| 2266 | \\[bibtex-make-field] inserts a new field after the current one. | ||
| 2267 | \\[bibtex-kill-field] kills the current field entirely. | ||
| 2268 | \\[bibtex-yank] will yank the last recently killed field after the | ||
| 2269 | current field. | ||
| 2270 | \\[bibtex-remove-delimiters] removes the double-quotes or braces around the text of the current field. | ||
| 2271 | \\[bibtex-empty-field] replaces the text of the current field with the default \"\" or {}. | ||
| 2272 | |||
| 2273 | The command \\[bibtex-clean-entry] cleans the current entry, i.e. it removes OPT/ALT | ||
| 2274 | from all non-empty optional or alternative fields, checks that no required | ||
| 2275 | fields are empty, and does some formatting dependent on the value of | ||
| 2276 | bibtex-entry-format. | ||
| 2277 | Note: some functions in BibTeX mode depend on entries being in a special | ||
| 2278 | format (all fields beginning on separate lines), so it is usually a bad | ||
| 2279 | idea to remove `realign' from bibtex-entry-format. | ||
| 1357 | 2280 | ||
| 1358 | Use \\[bibtex-find-text] to position the cursor at the end of the current field. | 2281 | Use \\[bibtex-find-text] to position the cursor at the end of the current field. |
| 1359 | Use \\[bibtex-next-field] to move to end of the next field. | 2282 | Use \\[bibtex-next-field] to move to end of the next field. |
| @@ -1362,26 +2285,35 @@ The following may be of interest as well: | |||
| 1362 | 2285 | ||
| 1363 | Functions: | 2286 | Functions: |
| 1364 | bibtex-entry | 2287 | bibtex-entry |
| 2288 | bibtex-kill-entry | ||
| 2289 | bibtex-yank-pop | ||
| 2290 | bibtex-pop-previous | ||
| 2291 | bibtex-pop-next | ||
| 2292 | bibtex-complete-string | ||
| 2293 | bibtex-complete-key | ||
| 1365 | bibtex-print-help-message | 2294 | bibtex-print-help-message |
| 2295 | bibtex-generate-autokey | ||
| 1366 | bibtex-beginning-of-entry | 2296 | bibtex-beginning-of-entry |
| 1367 | bibtex-end-of-entry | 2297 | bibtex-end-of-entry |
| 2298 | bibtex-reposition-window | ||
| 2299 | bibtex-mark-entry | ||
| 1368 | bibtex-ispell-abstract | 2300 | bibtex-ispell-abstract |
| 2301 | bibtex-ispell-entry | ||
| 1369 | bibtex-narrow-to-entry | 2302 | bibtex-narrow-to-entry |
| 1370 | bibtex-hide-entry-bodies | 2303 | bibtex-hide-entry-bodies |
| 1371 | bibtex-sort-entries | 2304 | bibtex-sort-buffer |
| 1372 | bibtex-validate-buffer | 2305 | bibtex-validate |
| 1373 | bibtex-pop-previous | 2306 | bibtex-count |
| 1374 | bibtex-pop-next | 2307 | bibtex-fill-entry |
| 1375 | bibtex-complete-string | 2308 | bibtex-reformat |
| 2309 | bibtex-convert-alien | ||
| 1376 | 2310 | ||
| 1377 | Variables: | 2311 | Variables: |
| 1378 | bibtex-field-left-delimiter | 2312 | bibtex-field-delimiters |
| 1379 | bibtex-field-right-delimiter | ||
| 1380 | bibtex-include-OPTcrossref | 2313 | bibtex-include-OPTcrossref |
| 1381 | bibtex-include-OPTkey | 2314 | bibtex-include-OPTkey |
| 1382 | bibtex-include-OPTannote | 2315 | bibtex-user-optional-fields |
| 1383 | bibtex-mode-user-optional-fields | 2316 | bibtex-entry-format |
| 1384 | bibtex-clean-entry-zap-empty-opts | ||
| 1385 | bibtex-sort-ignore-string-entries | 2317 | bibtex-sort-ignore-string-entries |
| 1386 | bibtex-maintain-sorted-entries | 2318 | bibtex-maintain-sorted-entries |
| 1387 | bibtex-entry-field-alist | 2319 | bibtex-entry-field-alist |
| @@ -1389,94 +2321,94 @@ The following may be of interest as well: | |||
| 1389 | bibtex-string-files | 2321 | bibtex-string-files |
| 1390 | 2322 | ||
| 1391 | --------------------------------------------------------- | 2323 | --------------------------------------------------------- |
| 1392 | Entry to this mode calls the value of bibtex-mode-hook if that value is | 2324 | Entry to BibTeX mode calls the value of bibtex-mode-hook if that value is |
| 1393 | non-nil." | 2325 | non-nil. |
| 2326 | |||
| 2327 | \\{bibtex-mode-map} | ||
| 2328 | " | ||
| 1394 | (interactive) | 2329 | (interactive) |
| 1395 | (kill-all-local-variables) | 2330 | (kill-all-local-variables) |
| 1396 | (use-local-map bibtex-mode-map) | 2331 | (use-local-map bibtex-mode-map) |
| 1397 | (setq major-mode 'bibtex-mode) | 2332 | (setq major-mode 'bibtex-mode) |
| 1398 | (setq mode-name "BibTeX") | 2333 | (setq mode-name "BibTeX") |
| 1399 | (set-syntax-table bibtex-mode-syntax-table) | 2334 | (set-syntax-table bibtex-mode-syntax-table) |
| 1400 | (setq bibtex-completion-candidates bibtex-predefined-strings) | 2335 | (setq bibtex-strings bibtex-predefined-strings) |
| 1401 | (mapcar | 2336 | (mapcar |
| 1402 | (function | 2337 | (lambda (filename) |
| 1403 | (lambda (filename) | 2338 | ;; collect pathnames |
| 1404 | ;; collect pathnames | 2339 | (let* ((path (if bibtex-string-file-path |
| 1405 | (let* ((bib (getenv "BIBINPUTS")) | 2340 | bibtex-string-file-path |
| 1406 | (path (if bib | 2341 | ".")) |
| 1407 | bib | 2342 | (dirs |
| 1408 | ".")) | 2343 | (mapcar |
| 1409 | (dirs | 2344 | (lambda (dirname) ;; strips off trailing slashes |
| 1410 | (mapcar | 2345 | (let ((len (length dirname))) |
| 1411 | (function | 2346 | (if (equal (elt dirname (1- len)) "/") |
| 1412 | (lambda (dirname) ;; strips off trailing slashes | 2347 | (substring dirname 0 (1- (1- len))) |
| 1413 | (let ((len (length dirname))) | 2348 | dirname))) |
| 1414 | (if (equal (elt dirname (1- len)) "/") | 2349 | (let (actdirs) |
| 1415 | (substring dirname 0 (1- (1- len))) | 2350 | (while (string-match ":" path) |
| 1416 | dirname)))) | 2351 | (setq actdirs |
| 1417 | (let (actdirs) | 2352 | (append actdirs |
| 1418 | (while (string-match ":" path) | 2353 | (list (substring path 0 (1- (match-end 0))))) |
| 1419 | (setq actdirs | 2354 | path (substring path (match-end 0)))) |
| 1420 | (append actdirs | 2355 | (append actdirs (list path))))) |
| 1421 | (list (substring | 2356 | (filename (if (string-match "\.bib$" filename) |
| 1422 | path 0 | 2357 | filename |
| 1423 | (1- (match-end 0))))) | 2358 | (concat filename ".bib"))) |
| 1424 | path (substring path (match-end 0)))) | 2359 | fullfilename |
| 1425 | (append actdirs (list path))))) | 2360 | (item 0) |
| 1426 | (filename (if (string-match "\.bib$" filename) | 2361 | (size (length dirs))) |
| 1427 | filename | 2362 | ;; test filenames |
| 1428 | (concat filename ".bib"))) | 2363 | (while (and |
| 1429 | fullfilename | 2364 | (< item size) |
| 1430 | (item 0) | 2365 | (not (file-readable-p |
| 1431 | (size (length dirs))) | 2366 | (setq fullfilename |
| 1432 | ;; test filenames | 2367 | (concat (elt dirs item) "/" filename))))) |
| 1433 | (while (and | 2368 | (setq item (1+ item))) |
| 1434 | (< item size) | 2369 | (if (< item size) |
| 1435 | (not (file-readable-p | 2370 | ;; file was found |
| 1436 | (setq fullfilename | 2371 | (let ((case-fold-search t) |
| 1437 | (concat (elt dirs item) "/" filename))))) | 2372 | (curbuf (current-buffer)) |
| 1438 | (setq item (1+ item))) | 2373 | (bufname (make-temp-name "")) |
| 1439 | (if (< item size) | 2374 | (compl bibtex-strings)) |
| 1440 | ;; file was found | 2375 | (create-file-buffer bufname) |
| 1441 | (let ((curbuf (current-buffer)) | 2376 | (set-buffer bufname) |
| 1442 | (bufname (make-temp-name "")) | 2377 | (insert-file-contents fullfilename) |
| 1443 | (compl bibtex-completion-candidates)) | 2378 | (goto-char (point-min)) |
| 1444 | (create-file-buffer bufname) | 2379 | (while (re-search-forward bibtex-string nil t) |
| 1445 | (set-buffer bufname) | 2380 | (setq compl |
| 1446 | (insert-file-contents fullfilename) | 2381 | (append compl |
| 1447 | (goto-char (point-min)) | 2382 | (list |
| 1448 | (while (re-search-forward bibtex-string nil t) | 2383 | (list (buffer-substring-no-properties |
| 1449 | (setq | 2384 | (match-beginning bibtex-key-in-string) |
| 1450 | compl | 2385 | (match-end bibtex-key-in-string))))))) |
| 1451 | (append | 2386 | (kill-buffer bufname) |
| 1452 | compl | 2387 | (set-buffer curbuf) |
| 1453 | (list | 2388 | (setq bibtex-strings compl)) |
| 1454 | (list (buffer-substring-no-properties | 2389 | (error |
| 1455 | (match-beginning bibtex-key-in-string) | 2390 | "File %s not in paths defined by bibtex-string-file-path variable." |
| 1456 | (match-end bibtex-key-in-string))))))) | 2391 | filename)))) |
| 1457 | (kill-buffer bufname) | ||
| 1458 | (set-buffer curbuf) | ||
| 1459 | (setq bibtex-completion-candidates compl)) | ||
| 1460 | (error "File %s not in $BIBINPUTS paths" filename))))) | ||
| 1461 | bibtex-string-files) | 2392 | bibtex-string-files) |
| 1462 | (run-with-idle-timer | 2393 | (if bibtex-maintain-sorted-entries |
| 1463 | bibtex-parse-keys-timeout bibtex-parse-keys-timeout | 2394 | (run-with-idle-timer |
| 1464 | (function | 2395 | 0 nil |
| 1465 | (lambda () | 2396 | (lambda () |
| 1466 | (if (and | 2397 | (bibtex-parse-keys nil t t)))) |
| 1467 | bibtex-maintain-sorted-entries | 2398 | ;; to get buffer parsed once if everything else (including things |
| 1468 | (eq major-mode 'bibtex-mode) | 2399 | ;; installed in bibtex-mode-hook) has done its work |
| 1469 | (not | 2400 | (if (not bibtex-parse-idle-timer) |
| 1470 | (eq (buffer-modified-tick) | 2401 | (setq bibtex-parse-idle-timer |
| 1471 | bibtex-buffer-last-parsed-for-keys-tick))) | 2402 | (run-with-idle-timer |
| 1472 | (bibtex-parse-keys nil t))))) | 2403 | bibtex-parse-keys-timeout t |
| 1473 | (bibtex-parse-keys nil) | 2404 | 'bibtex-parse-buffers-stealthily))) |
| 1474 | (make-local-variable 'paragraph-start) | 2405 | ;; Install stealthy parse function if not already installed |
| 1475 | (setq paragraph-start "[ \f\n\t]*$") | 2406 | (set (make-local-variable 'paragraph-start) "[ \f\n\t]*$") |
| 1476 | (make-local-variable 'comment-start) | 2407 | (set (make-local-variable 'comment-start) "@Comment ") |
| 1477 | (setq comment-start "%") | 2408 | (set (make-local-variable 'comment-start-skip) "@Comment ") |
| 1478 | (make-local-variable 'normal-auto-fill-function) | 2409 | (set (make-local-variable 'comment-column) 0) |
| 1479 | (setq normal-auto-fill-function 'bibtex-auto-fill-function) | 2410 | (set (make-local-variable 'normal-auto-fill-function) |
| 2411 | 'bibtex-do-auto-fill) | ||
| 1480 | (set (make-local-variable 'font-lock-defaults) | 2412 | (set (make-local-variable 'font-lock-defaults) |
| 1481 | '(bibtex-font-lock-keywords | 2413 | '(bibtex-font-lock-keywords |
| 1482 | nil t ((?$ . "\"") | 2414 | nil t ((?$ . "\"") |
| @@ -1486,6 +2418,12 @@ non-nil." | |||
| 1486 | ;; entries should be fontified in the same way as | 2418 | ;; entries should be fontified in the same way as |
| 1487 | ;; brace-delimited ones | 2419 | ;; brace-delimited ones |
| 1488 | ))) | 2420 | ))) |
| 2421 | (setq font-lock-mark-block-function | ||
| 2422 | (lambda () | ||
| 2423 | (set-mark (bibtex-end-of-entry)) | ||
| 2424 | (bibtex-beginning-of-entry))) | ||
| 2425 | (setq imenu-generic-expression | ||
| 2426 | (list (list nil bibtex-reference-head bibtex-key-in-head))) | ||
| 1489 | (run-hooks 'bibtex-mode-hook)) | 2427 | (run-hooks 'bibtex-mode-hook)) |
| 1490 | 2428 | ||
| 1491 | (defun bibtex-submit-bug-report () | 2429 | (defun bibtex-submit-bug-report () |
| @@ -1497,27 +2435,47 @@ non-nil." | |||
| 1497 | (let ((reporter-prompt-for-summary-p t)) | 2435 | (let ((reporter-prompt-for-summary-p t)) |
| 1498 | (reporter-submit-bug-report | 2436 | (reporter-submit-bug-report |
| 1499 | bibtex-maintainer-address | 2437 | bibtex-maintainer-address |
| 1500 | "bibtex.el" | 2438 | (concat "bibtex.el " "(emacs 19.35)") |
| 1501 | (list | 2439 | (list |
| 1502 | 'system-configuration | 2440 | 'system-configuration |
| 1503 | 'system-configuration-options | 2441 | 'system-configuration-options |
| 2442 | 'bibtex-mode-hook | ||
| 2443 | 'bibtex-parse-keys-timeout | ||
| 2444 | ;; possible general errors | ||
| 1504 | 'bibtex-sort-ignore-string-entries | 2445 | 'bibtex-sort-ignore-string-entries |
| 1505 | 'bibtex-maintain-sorted-entries | 2446 | 'bibtex-maintain-sorted-entries |
| 1506 | 'bibtex-field-left-delimiter | 2447 | 'bibtex-entry-delimiters |
| 1507 | 'bibtex-field-right-delimiter | 2448 | 'bibtex-field-delimiters |
| 1508 | ;; Possible sorting and parsing bugs | 2449 | 'bibtex-comma-after-last-field |
| 1509 | 'bibtex-mode-user-optional-fields | 2450 | 'bibtex-entry-offset |
| 1510 | ;; Possible format error | 2451 | 'bibtex-field-indentation |
| 2452 | 'bibtex-text-indentation | ||
| 2453 | 'bibtex-contline-indentation | ||
| 2454 | 'bibtex-align-at-equal-sign | ||
| 2455 | ;; possible sorting and parsing bugs | ||
| 2456 | 'bibtex-entry-format | ||
| 2457 | 'bibtex-add-entry-hook | ||
| 2458 | 'bibtex-clean-entry-hook | ||
| 2459 | ;; possible cleaning error | ||
| 2460 | 'bibtex-user-optional-fields | ||
| 2461 | ;; possible format error | ||
| 2462 | 'bibtex-predefined-month-strings | ||
| 1511 | 'bibtex-predefined-strings | 2463 | 'bibtex-predefined-strings |
| 1512 | 'bibtex-string-files | 2464 | 'bibtex-string-files |
| 1513 | ;; Possible format error | 2465 | 'bibtex-string-file-path |
| 2466 | ;; possible format error | ||
| 1514 | 'bibtex-font-lock-keywords | 2467 | 'bibtex-font-lock-keywords |
| 1515 | ;; Possible bugs regarding fontlocking | 2468 | ;; possible bugs regarding fontlocking |
| 2469 | 'bibtex-autokey-prefix-string | ||
| 1516 | 'bibtex-autokey-names | 2470 | 'bibtex-autokey-names |
| 2471 | 'bibtex-autokey-names-stretch | ||
| 2472 | 'bibtex-autokey-additional-names | ||
| 2473 | 'bibtex-autokey-transcriptions | ||
| 1517 | 'bibtex-autokey-name-change-strings | 2474 | 'bibtex-autokey-name-change-strings |
| 1518 | 'bibtex-autokey-name-length | 2475 | 'bibtex-autokey-name-length |
| 1519 | 'bibtex-autokey-name-separator | 2476 | 'bibtex-autokey-name-separator |
| 1520 | 'bibtex-autokey-year-length | 2477 | 'bibtex-autokey-year-length |
| 2478 | 'bibtex-autokey-year-use-crossref-entry | ||
| 1521 | 'bibtex-autokey-titlewords | 2479 | 'bibtex-autokey-titlewords |
| 1522 | 'bibtex-autokey-title-terminators | 2480 | 'bibtex-autokey-title-terminators |
| 1523 | 'bibtex-autokey-titlewords-stretch | 2481 | 'bibtex-autokey-titlewords-stretch |
| @@ -1528,16 +2486,18 @@ non-nil." | |||
| 1528 | 'bibtex-autokey-titleword-separator | 2486 | 'bibtex-autokey-titleword-separator |
| 1529 | 'bibtex-autokey-name-year-separator | 2487 | 'bibtex-autokey-name-year-separator |
| 1530 | 'bibtex-autokey-year-title-separator | 2488 | 'bibtex-autokey-year-title-separator |
| 2489 | 'bibtex-autokey-preserve-case | ||
| 1531 | 'bibtex-autokey-edit-before-use | 2490 | 'bibtex-autokey-edit-before-use |
| 1532 | ;; Possible bugs regarding automatic labels | 2491 | 'bibtex-autokey-before-presentation-hook |
| 2492 | ;; possible bugs regarding automatic labels | ||
| 1533 | 'bibtex-entry-field-alist | 2493 | 'bibtex-entry-field-alist |
| 1534 | ;; Possible format error | 2494 | ;; possible format error |
| 1535 | 'bibtex-help-message | 2495 | 'bibtex-help-message |
| 1536 | 'bibtex-include-OPTcrossref | 2496 | 'bibtex-include-OPTcrossref |
| 1537 | 'bibtex-include-OPTkey | 2497 | 'bibtex-include-OPTkey |
| 1538 | 'bibtex-include-OPTannote | 2498 | 'bibtex-field-kill-ring-max |
| 1539 | 'bibtex-clean-entry-zap-empty-opts | 2499 | 'bibtex-entry-kill-ring-max |
| 1540 | ;; User variables which shouldn't cause any errors | 2500 | ;; user variables which shouldn't cause any errors |
| 1541 | ) | 2501 | ) |
| 1542 | nil nil | 2502 | nil nil |
| 1543 | (concat "Hi Stefan, | 2503 | (concat "Hi Stefan, |
| @@ -1552,37 +2512,41 @@ of `bibtex.el' with `M-x load-file', and then, to produce the buggy | |||
| 1552 | behaviour, I did the following:"))) | 2512 | behaviour, I did the following:"))) |
| 1553 | (message nil)))) | 2513 | (message nil)))) |
| 1554 | 2514 | ||
| 1555 | (defun bibtex-entry (entry-type &optional required optional) | 2515 | (defun bibtex-entry (entry-type) |
| 1556 | "Inserts a new BibTeX entry. | 2516 | "Inserts a new BibTeX entry. |
| 1557 | Calls the value of bibtex-add-entry-hook if that value is non-nil." | 2517 | After insertion it calls the functions in bibtex-add-entry-hook." |
| 1558 | (interactive (let* ((completion-ignore-case t) | 2518 | (interactive (let* ((completion-ignore-case t) |
| 1559 | (e-t (completing-read | 2519 | (e-t (completing-read |
| 1560 | "Entry Type: " | 2520 | "Entry Type: " |
| 1561 | bibtex-entry-field-alist | 2521 | bibtex-entry-field-alist |
| 1562 | nil t))) | 2522 | nil t nil 'bibtex-entry-type-history))) |
| 1563 | (list e-t))) | 2523 | (list e-t))) |
| 1564 | (if (and (null required) (null optional)) | 2524 | (if (not bibtex-keys) |
| 1565 | (let* ((e (assoc-ignore-case entry-type bibtex-entry-field-alist)) | 2525 | (bibtex-parse-keys nil t)) |
| 1566 | (r-n-o (elt e 1)) | 2526 | (let* (required |
| 1567 | (c-ref (elt e 2))) | 2527 | optional |
| 1568 | (if (null e) | 2528 | (key |
| 1569 | (error "Bibtex entry type %s not defined!" entry-type)) | 2529 | (if bibtex-maintain-sorted-entries |
| 1570 | (if (and | 2530 | (completing-read |
| 1571 | (member entry-type bibtex-include-OPTcrossref) | 2531 | (format "%s key: " entry-type) |
| 1572 | c-ref) | 2532 | bibtex-keys nil nil nil 'bibtex-key-history))) |
| 1573 | (setq required (elt c-ref 0) | 2533 | (e (assoc-ignore-case entry-type bibtex-entry-field-alist)) |
| 1574 | optional (elt c-ref 1)) | 2534 | (r-n-o (elt e 1)) |
| 1575 | (setq required (elt r-n-o 0) | 2535 | (c-ref (elt e 2))) |
| 1576 | optional (elt r-n-o 1))))) | 2536 | (if (not e) |
| 1577 | (let ((key | 2537 | (error "Bibtex entry type %s not defined." entry-type)) |
| 1578 | (if bibtex-maintain-sorted-entries | 2538 | (if (and |
| 1579 | (completing-read | 2539 | (member entry-type bibtex-include-OPTcrossref) |
| 1580 | (format "%s key: " entry-type) | 2540 | c-ref) |
| 1581 | bibtex-keys)))) | 2541 | (setq required (elt c-ref 0) |
| 2542 | optional (elt c-ref 1)) | ||
| 2543 | (setq required (elt r-n-o 0) | ||
| 2544 | optional (elt r-n-o 1))) | ||
| 1582 | (if bibtex-maintain-sorted-entries | 2545 | (if bibtex-maintain-sorted-entries |
| 1583 | (bibtex-find-entry-location key) | 2546 | (bibtex-find-entry-location key) |
| 1584 | (bibtex-move-outside-of-entry)) | 2547 | (bibtex-move-outside-of-entry)) |
| 1585 | (insert "@" entry-type "{") | 2548 | (indent-to-column bibtex-entry-offset) |
| 2549 | (insert "@" entry-type (bibtex-entry-left-delimiter)) | ||
| 1586 | (if key | 2550 | (if key |
| 1587 | (insert key)) | 2551 | (insert key)) |
| 1588 | (save-excursion | 2552 | (save-excursion |
| @@ -1590,33 +2554,39 @@ Calls the value of bibtex-add-entry-hook if that value is non-nil." | |||
| 1590 | (if (member entry-type bibtex-include-OPTcrossref) | 2554 | (if (member entry-type bibtex-include-OPTcrossref) |
| 1591 | (bibtex-make-optional-field '("crossref"))) | 2555 | (bibtex-make-optional-field '("crossref"))) |
| 1592 | (if bibtex-include-OPTkey | 2556 | (if bibtex-include-OPTkey |
| 1593 | (bibtex-make-optional-field '("key"))) | 2557 | (if (or |
| 2558 | (stringp bibtex-include-OPTkey) | ||
| 2559 | (fboundp bibtex-include-OPTkey)) | ||
| 2560 | (bibtex-make-optional-field | ||
| 2561 | (list "key" nil bibtex-include-OPTkey)) | ||
| 2562 | (bibtex-make-optional-field '("key")))) | ||
| 1594 | (mapcar 'bibtex-make-optional-field optional) | 2563 | (mapcar 'bibtex-make-optional-field optional) |
| 1595 | (mapcar 'bibtex-make-optional-field | 2564 | (mapcar 'bibtex-make-optional-field bibtex-user-optional-fields) |
| 1596 | bibtex-mode-user-optional-fields) | 2565 | (if bibtex-comma-after-last-field |
| 1597 | (if bibtex-include-OPTannote | 2566 | (insert ",")) |
| 1598 | (bibtex-make-optional-field '("annote"))) | 2567 | (insert "\n") |
| 1599 | (insert "\n}\n\n")) | 2568 | (indent-to-column bibtex-entry-offset) |
| 2569 | (insert (bibtex-entry-right-delimiter) "\n\n")) | ||
| 1600 | (bibtex-next-field t) | 2570 | (bibtex-next-field t) |
| 1601 | (run-hooks 'bibtex-add-entry-hook))) | 2571 | (run-hooks 'bibtex-add-entry-hook))) |
| 1602 | 2572 | ||
| 1603 | (defun bibtex-print-help-message () | 2573 | (defun bibtex-print-help-message () |
| 1604 | "Prints helpful information about current field in current BibTeX entry." | 2574 | "Prints helpful information about current field in current BibTeX entry." |
| 1605 | (interactive) | 2575 | (interactive) |
| 1606 | (let* ((pnt (point)) | 2576 | (let* ((case-fold-search t) |
| 2577 | (pnt (point)) | ||
| 1607 | (field-name | 2578 | (field-name |
| 1608 | (progn | 2579 | (progn |
| 1609 | (beginning-of-line) | ||
| 1610 | (condition-case errname | 2580 | (condition-case errname |
| 1611 | (bibtex-enclosing-regexp bibtex-field) | 2581 | (bibtex-enclosing-field) |
| 1612 | (search-failed | 2582 | (search-failed |
| 1613 | (goto-char pnt) | 2583 | (goto-char pnt) |
| 1614 | (error "Not on BibTeX field"))) | 2584 | (error "Not on BibTeX field."))) |
| 1615 | (let ((mb (match-beginning bibtex-name-in-field)) | 2585 | (let ((mb (match-beginning bibtex-name-in-field)) |
| 1616 | (me (match-end bibtex-name-in-field))) | 2586 | (me (match-end bibtex-name-in-field))) |
| 1617 | (goto-char mb) | 2587 | (goto-char mb) |
| 1618 | (buffer-substring-no-properties | 2588 | (buffer-substring-no-properties |
| 1619 | (if (looking-at "OPT") | 2589 | (if (looking-at "OPT\\|ALT") |
| 1620 | (+ 3 mb) | 2590 | (+ 3 mb) |
| 1621 | mb) | 2591 | mb) |
| 1622 | me)))) | 2592 | me)))) |
| @@ -1640,15 +2610,12 @@ Calls the value of bibtex-add-entry-hook if that value is non-nil." | |||
| 1640 | (list-of-entries (append | 2610 | (list-of-entries (append |
| 1641 | (elt req-opt-list 0) | 2611 | (elt req-opt-list 0) |
| 1642 | (elt req-opt-list 1) | 2612 | (elt req-opt-list 1) |
| 1643 | bibtex-mode-user-optional-fields | 2613 | bibtex-user-optional-fields |
| 1644 | (if (member | 2614 | (if (member |
| 1645 | reference-type | 2615 | reference-type |
| 1646 | bibtex-include-OPTcrossref) | 2616 | bibtex-include-OPTcrossref) |
| 1647 | '(("crossref" | 2617 | '(("crossref" |
| 1648 | "Label of the crossreferenced entry"))) | 2618 | "Label of the crossreferenced entry"))) |
| 1649 | (if bibtex-include-OPTannote | ||
| 1650 | '(("annote" | ||
| 1651 | "Personal annotation (ignored)"))) | ||
| 1652 | (if bibtex-include-OPTkey | 2619 | (if bibtex-include-OPTkey |
| 1653 | '(("key" | 2620 | '(("key" |
| 1654 | "Key used for label creation if author and editor fields are missing")))))) | 2621 | "Key used for label creation if author and editor fields are missing")))))) |
| @@ -1658,163 +2625,273 @@ Calls the value of bibtex-add-entry-hook if that value is non-nil." | |||
| 1658 | (message (elt comment 1)) | 2625 | (message (elt comment 1)) |
| 1659 | (message "NO COMMENT AVAILABLE"))))) | 2626 | (message "NO COMMENT AVAILABLE"))))) |
| 1660 | 2627 | ||
| 1661 | (defun bibtex-make-field (e-t) | 2628 | (defun bibtex-make-field (e-t &optional called-by-yank) |
| 1662 | "Makes a field named E-T in current BibTeX entry." | 2629 | "Makes a field named E-T in current BibTeX entry. |
| 1663 | (interactive "sBibTeX field name: ") | 2630 | This function is for interactive and non-interactive purposes. To call |
| 1664 | (let ((name (if (consp e-t) | 2631 | it interactively, just give it no arguments and enter the field name |
| 1665 | (elt e-t 0) | 2632 | using the minibuffer." |
| 1666 | e-t))) | 2633 | (interactive "*P") |
| 1667 | (if (interactive-p) | 2634 | (if (not e-t) |
| 1668 | (progn | 2635 | (setq |
| 1669 | (bibtex-find-text nil) | 2636 | e-t |
| 2637 | (let* ((reference-type | ||
| 2638 | (save-excursion | ||
| 2639 | (bibtex-enclosing-reference-maybe-empty-head) | ||
| 2640 | (buffer-substring-no-properties | ||
| 2641 | (1+ (match-beginning bibtex-type-in-head)) | ||
| 2642 | (match-end bibtex-type-in-head)))) | ||
| 2643 | (fl | ||
| 2644 | (car (cdr (assoc-ignore-case | ||
| 2645 | reference-type bibtex-entry-field-alist)))) | ||
| 2646 | (field-list | ||
| 2647 | (append | ||
| 2648 | (elt fl 0) (elt fl 1) bibtex-user-optional-fields | ||
| 2649 | (if bibtex-include-OPTcrossref '(("crossref" nil))) | ||
| 2650 | (if bibtex-include-OPTkey '(("key" nil))))) | ||
| 2651 | (completion-ignore-case t)) | ||
| 2652 | (completing-read | ||
| 2653 | "BibTeX field name: " field-list | ||
| 2654 | nil nil nil bibtex-field-history)))) | ||
| 2655 | (if (not (consp e-t)) | ||
| 2656 | (setq e-t (list e-t))) | ||
| 2657 | (if (equal (length e-t) 1) | ||
| 2658 | (setq e-t (append e-t (list "")))) | ||
| 2659 | (if (equal (length e-t) 2) | ||
| 2660 | (setq e-t (append e-t (list "")))) | ||
| 2661 | (let ((name (if (elt e-t 3) | ||
| 2662 | (concat "ALT" (car e-t)) | ||
| 2663 | (car e-t)))) | ||
| 2664 | (if (or (interactive-p) called-by-yank) | ||
| 2665 | (let (bibtex-help-message) | ||
| 2666 | (bibtex-find-text nil t) | ||
| 1670 | (if (looking-at "[}\"]") | 2667 | (if (looking-at "[}\"]") |
| 1671 | (forward-char 1)))) | 2668 | (forward-char)))) |
| 1672 | (insert ",\n") | 2669 | (insert ",\n") |
| 1673 | (indent-to-column bibtex-name-alignment) | 2670 | (indent-to-column |
| 1674 | (insert name " = ") | 2671 | (+ bibtex-entry-offset bibtex-field-indentation)) |
| 1675 | (indent-to-column bibtex-text-alignment) | 2672 | (insert name " ") |
| 1676 | (insert bibtex-field-left-delimiter bibtex-field-right-delimiter) | 2673 | (if bibtex-align-at-equal-sign |
| 2674 | (indent-to-column | ||
| 2675 | (+ bibtex-entry-offset (- bibtex-text-indentation 2)))) | ||
| 2676 | (insert "= ") | ||
| 2677 | (if (not bibtex-align-at-equal-sign) | ||
| 2678 | (indent-to-column | ||
| 2679 | (+ bibtex-entry-offset bibtex-text-indentation))) | ||
| 2680 | (insert (if called-by-yank | ||
| 2681 | "" | ||
| 2682 | (bibtex-field-left-delimiter)) | ||
| 2683 | (let ((init (elt e-t 2))) | ||
| 2684 | (cond | ||
| 2685 | ((stringp init) | ||
| 2686 | init) | ||
| 2687 | ((fboundp init) | ||
| 2688 | (funcall init)) | ||
| 2689 | (t | ||
| 2690 | (error "%s is neither a string nor a function." init)))) | ||
| 2691 | (if called-by-yank | ||
| 2692 | "" | ||
| 2693 | (bibtex-field-right-delimiter))) | ||
| 1677 | (if (interactive-p) | 2694 | (if (interactive-p) |
| 1678 | (forward-char -1)))) | 2695 | (forward-char -1)))) |
| 1679 | 2696 | ||
| 1680 | (defun bibtex-make-optional-field (e-t) | ||
| 1681 | "Makes an optional field named E-T in current BibTeX entry." | ||
| 1682 | (if (consp e-t) | ||
| 1683 | (setq e-t (cons (concat "OPT" (car e-t)) (cdr e-t))) | ||
| 1684 | (setq e-t (concat "OPT" e-t))) | ||
| 1685 | (bibtex-make-field e-t)) | ||
| 1686 | |||
| 1687 | (defun bibtex-beginning-of-entry () | 2697 | (defun bibtex-beginning-of-entry () |
| 1688 | "Move to beginning of BibTeX entry. | 2698 | "Move to beginning of BibTeX entry. |
| 1689 | If inside an entry, move to the beginning of it, otherwise move to the | 2699 | If inside an entry, move to the beginning of it, otherwise move to the |
| 1690 | beginning of the previous entry." | 2700 | beginning of the previous entry. |
| 2701 | If called from a program returns point." | ||
| 1691 | (interactive) | 2702 | (interactive) |
| 1692 | (if (looking-at "^@") | 2703 | (skip-chars-forward " \t") |
| 2704 | (if (looking-at "@") | ||
| 1693 | (forward-char)) | 2705 | (forward-char)) |
| 1694 | (re-search-backward "^@" nil 'move)) | 2706 | (re-search-backward "^[ \t]*@" nil 'move)) |
| 1695 | 2707 | ||
| 1696 | (defun bibtex-end-of-entry () | 2708 | (defun bibtex-end-of-entry () |
| 1697 | "Move to end of BibTeX entry. | 2709 | "Move to end of BibTeX entry. |
| 1698 | If inside an entry, move to the end of it, otherwise move to the end | 2710 | If inside an entry, move to the end of it, otherwise move to the end |
| 1699 | of the previous entry." | 2711 | of the previous entry. |
| 2712 | If called from a program returns point." | ||
| 1700 | (interactive) | 2713 | (interactive) |
| 1701 | (bibtex-beginning-of-entry) | 2714 | (let ((case-fold-search t) |
| 1702 | (let ((parse-sexp-ignore-comments t)) | 2715 | (valid-entry-head |
| 1703 | (forward-sexp 2) ;; skip entry type and body | 2716 | (concat "[ \t]*@[ \t]*\\(" |
| 1704 | )) | 2717 | (mapconcat |
| 2718 | (lambda (type) | ||
| 2719 | (concat "\\(" (car type) "\\)")) | ||
| 2720 | bibtex-entry-field-alist | ||
| 2721 | "\\|") | ||
| 2722 | "\\)")) | ||
| 2723 | (org (point)) | ||
| 2724 | (pnt (bibtex-beginning-of-entry)) | ||
| 2725 | err) | ||
| 2726 | (cond | ||
| 2727 | ((looking-at "[ \t]*@[ \t]*string[ \t\n]*[({]") | ||
| 2728 | (if (not (and | ||
| 2729 | (re-search-forward bibtex-string nil t) | ||
| 2730 | (equal (match-beginning 0) pnt))) | ||
| 2731 | (setq err t))) | ||
| 2732 | ((looking-at "[ \t]*@[ \t]*preamble[ \t\n]*") | ||
| 2733 | (goto-char (match-end 0)) | ||
| 2734 | (cond | ||
| 2735 | ((looking-at "(") | ||
| 2736 | (if (not (re-search-forward ")[ \t]*\n\n" nil 'move)) | ||
| 2737 | (setq err t))) | ||
| 2738 | ((looking-at "{") | ||
| 2739 | (if (not (re-search-forward "}[ \t]*\n\n" nil 'move)) | ||
| 2740 | (setq err t))) | ||
| 2741 | (t | ||
| 2742 | (setq err t))) | ||
| 2743 | (if (not err) | ||
| 2744 | (progn | ||
| 2745 | (goto-char (match-beginning 0)) | ||
| 2746 | (forward-char)))) | ||
| 2747 | ((looking-at valid-entry-head) | ||
| 2748 | (bibtex-search-reference t nil t) | ||
| 2749 | (if (not (equal (match-beginning 0) pnt)) | ||
| 2750 | (setq err t))) | ||
| 2751 | (t | ||
| 2752 | (if (interactive-p) | ||
| 2753 | (message "Not on a known BibTeX entry.")) | ||
| 2754 | (goto-char org))) | ||
| 2755 | (if err | ||
| 2756 | (progn | ||
| 2757 | (goto-char pnt) | ||
| 2758 | (error "Syntactical incorrect entry starts here.")))) | ||
| 2759 | (point)) | ||
| 1705 | 2760 | ||
| 2761 | (defun bibtex-reposition-window (arg) | ||
| 2762 | "Make the current BibTeX entry visible." | ||
| 2763 | (interactive "P") | ||
| 2764 | (save-excursion | ||
| 2765 | (goto-char | ||
| 2766 | (/ (+ (bibtex-beginning-of-entry) (bibtex-end-of-entry)) 2)) | ||
| 2767 | (recenter arg))) | ||
| 2768 | |||
| 2769 | (defun bibtex-mark-entry () | ||
| 2770 | "Put mark at beginning, point at end of current BibTeX entry." | ||
| 2771 | (interactive) | ||
| 2772 | (set-mark (bibtex-beginning-of-entry)) | ||
| 2773 | (bibtex-end-of-entry)) | ||
| 2774 | |||
| 2775 | (defun bibtex-count-entries (&optional count-string-entries) | ||
| 2776 | "Count number of entries in current buffer or region. | ||
| 2777 | With prefix argument it counts all entries, otherwise it counts all | ||
| 2778 | except Strings. | ||
| 2779 | If mark is active it counts entries in region, if not in whole buffer." | ||
| 2780 | (interactive "P") | ||
| 2781 | (let ((pnt (point)) | ||
| 2782 | (start-point | ||
| 2783 | (if mark-active | ||
| 2784 | (region-beginning) | ||
| 2785 | (bibtex-beginning-of-first-entry))) | ||
| 2786 | (end-point | ||
| 2787 | (if mark-active | ||
| 2788 | (region-end) | ||
| 2789 | (point-max))) | ||
| 2790 | (number 0) | ||
| 2791 | (bibtex-sort-ignore-string-entries | ||
| 2792 | (not count-string-entries))) | ||
| 2793 | (save-restriction | ||
| 2794 | (narrow-to-region start-point end-point) | ||
| 2795 | (goto-char start-point) | ||
| 2796 | (map-bibtex-entries | ||
| 2797 | (lambda (current) | ||
| 2798 | (setq number (1+ number))))) | ||
| 2799 | (message (concat (if mark-active "Region" "Buffer") | ||
| 2800 | " contains %d entries.") number) | ||
| 2801 | (goto-char pnt))) | ||
| 2802 | |||
| 1706 | (defun bibtex-ispell-entry () | 2803 | (defun bibtex-ispell-entry () |
| 1707 | "Spell whole BibTeX entry." | 2804 | "Spell whole BibTeX entry." |
| 1708 | (interactive) | 2805 | (interactive) |
| 1709 | (ispell-region (progn (bibtex-beginning-of-entry) (point)) | 2806 | (ispell-region (bibtex-beginning-of-entry) (bibtex-end-of-entry))) |
| 1710 | (progn (bibtex-end-of-entry) (point)))) | ||
| 1711 | 2807 | ||
| 1712 | (defun bibtex-ispell-abstract () | 2808 | (defun bibtex-ispell-abstract () |
| 1713 | "Spell abstract of BibTeX entry." | 2809 | "Spell abstract of BibTeX entry." |
| 1714 | (interactive) | 2810 | (interactive) |
| 1715 | (let ((pnt (bibtex-end-of-entry))) | 2811 | (let ((case-fold-search t) |
| 2812 | (pnt (bibtex-end-of-entry))) | ||
| 1716 | (bibtex-beginning-of-entry) | 2813 | (bibtex-beginning-of-entry) |
| 1717 | (if (null | 2814 | (if (not |
| 1718 | (re-search-forward "^[ \t]*[OPT]*abstract[ \t]*=" pnt)) | 2815 | (re-search-forward |
| 2816 | (bibtex-cfield "abstract" bibtex-field-text) pnt t)) | ||
| 1719 | (error "No abstract in entry."))) | 2817 | (error "No abstract in entry."))) |
| 1720 | (ispell-region (point) | 2818 | (ispell-region (match-beginning bibtex-text-in-cfield) |
| 1721 | (save-excursion (forward-sexp) (point)))) | 2819 | (match-end bibtex-text-in-cfield))) |
| 1722 | 2820 | ||
| 1723 | (defun bibtex-narrow-to-entry () | 2821 | (defun bibtex-narrow-to-entry () |
| 1724 | "Narrow buffer to current BibTeX entry." | 2822 | "Narrow buffer to current BibTeX entry." |
| 1725 | (interactive) | 2823 | (interactive) |
| 1726 | (save-excursion | 2824 | (save-excursion |
| 1727 | (narrow-to-region (progn (bibtex-beginning-of-entry) (point)) | 2825 | (narrow-to-region |
| 1728 | (progn (bibtex-end-of-entry) (point))))) | 2826 | (bibtex-beginning-of-entry) (bibtex-end-of-entry)))) |
| 1729 | 2827 | ||
| 1730 | (defun bibtex-hide-entry-bodies (&optional arg) | 2828 | (defun bibtex-hide-entry-bodies (&optional arg) |
| 1731 | "Hide all lines between first and last BibTeX entries not beginning with @. | 2829 | "Hide all lines between first and last BibTeX entries not beginning with @. |
| 1732 | With argument, show all text." | 2830 | With argument, show all text." |
| 1733 | (interactive "P") | 2831 | (interactive "P") |
| 1734 | (save-excursion | 2832 | (save-excursion |
| 1735 | (beginning-of-first-bibtex-entry) | 2833 | (bibtex-beginning-of-first-entry) |
| 1736 | ;; subst-char-in-region modifies the buffer, despite what the | 2834 | (let ((buffer-read-only nil)) |
| 1737 | ;; documentation says... | ||
| 1738 | (let ((modifiedp (buffer-modified-p)) | ||
| 1739 | (buffer-read-only nil)) | ||
| 1740 | (if arg | 2835 | (if arg |
| 1741 | (subst-char-in-region (point) (point-max) ?\r ?\n t) | 2836 | (subst-char-in-region (point) (point-max) ?\r ?\n t) |
| 1742 | (while (save-excursion (re-search-forward "\n[^@]" (point-max) t)) | 2837 | (while (not (eobp)) |
| 1743 | ;; (save-excursion (replace-regexp "\n\\([^@]\\)" "\r\\1")) | 2838 | (subst-char-in-region |
| 1744 | (save-excursion | 2839 | (point) |
| 1745 | (while (re-search-forward "\n\\([^@]\\)" nil t) | 2840 | (progn |
| 1746 | (replace-match "\r\\1" nil nil))))) | 2841 | (re-search-forward "[\n\r]@" nil t) |
| 1747 | (setq selective-display (not arg)) | 2842 | (forward-line -1) |
| 1748 | (set-buffer-modified-p modifiedp)))) | 2843 | (point)) |
| 1749 | 2844 | ?\n ?\r t) | |
| 1750 | (defun bibtex-sort-entries () | 2845 | (forward-line 1))) |
| 1751 | "Sort BibTeX entries alphabetically by key. | 2846 | (setq selective-display (not arg))))) |
| 2847 | |||
| 2848 | (defun bibtex-sort-buffer () | ||
| 2849 | "Sort BibTeX buffer alphabetically by key. | ||
| 1752 | Text outside of BibTeX entries is not affected. If | 2850 | Text outside of BibTeX entries is not affected. If |
| 1753 | bibtex-sort-ignore-string-entries is non-nil, @string entries will be | 2851 | bibtex-sort-ignore-string-entries is non-nil, @String entries will be |
| 1754 | ignored." | 2852 | ignored." |
| 1755 | (interactive) | 2853 | (interactive) |
| 1756 | (save-restriction | 2854 | (save-restriction |
| 1757 | (beginning-of-first-bibtex-entry) | ||
| 1758 | (narrow-to-region | 2855 | (narrow-to-region |
| 1759 | (point) | 2856 | (bibtex-beginning-of-first-entry) |
| 1760 | (save-excursion | 2857 | (save-excursion |
| 1761 | (goto-char (point-max)) | 2858 | (goto-char (point-max)) |
| 1762 | (bibtex-end-of-entry) | 2859 | (bibtex-end-of-entry))) |
| 1763 | (point))) | 2860 | (skip-to-valid-bibtex-entry) |
| 1764 | (if bibtex-sort-ignore-string-entries | ||
| 1765 | (if (re-search-forward bibtex-reference nil 'move) | ||
| 1766 | (goto-char (match-beginning 0)))) | ||
| 1767 | (sort-subr | 2861 | (sort-subr |
| 1768 | nil | 2862 | nil |
| 1769 | ;; NEXTREC function | 2863 | ;; NEXTREC function |
| 1770 | (function | 2864 | 'skip-to-valid-bibtex-entry |
| 1771 | (lambda () | ||
| 1772 | (if bibtex-sort-ignore-string-entries | ||
| 1773 | (if (re-search-forward bibtex-reference nil 'move) | ||
| 1774 | (goto-char (match-beginning 0))) | ||
| 1775 | (if (re-search-forward bibtex-reference-head nil 'move) | ||
| 1776 | (goto-char (match-beginning 0)))))) | ||
| 1777 | ;; ENDREC function | 2865 | ;; ENDREC function |
| 1778 | 'bibtex-end-of-entry | 2866 | 'bibtex-end-of-entry |
| 1779 | ;; STARTKEY function | 2867 | ;; STARTKEY function |
| 1780 | (function | 2868 | (lambda () |
| 1781 | (lambda () | 2869 | (let ((case-fold-search t)) |
| 1782 | (if bibtex-sort-ignore-string-entries | 2870 | (re-search-forward bibtex-reference-head) |
| 1783 | (progn | 2871 | (buffer-substring-no-properties |
| 1784 | (re-search-forward bibtex-reference) | 2872 | (match-beginning bibtex-key-in-head) |
| 1785 | (buffer-substring-no-properties | 2873 | (match-end bibtex-key-in-head))))))) |
| 1786 | (match-beginning bibtex-key-in-reference) | ||
| 1787 | (match-end bibtex-key-in-reference))) | ||
| 1788 | (re-search-forward bibtex-reference-head) | ||
| 1789 | (buffer-substring-no-properties | ||
| 1790 | (match-beginning bibtex-key-in-head) | ||
| 1791 | (match-end bibtex-key-in-head))))) | ||
| 1792 | ;; ENDKEY function | ||
| 1793 | nil))) | ||
| 1794 | 2874 | ||
| 1795 | (defun bibtex-find-entry-location (entry-name &optional ignore-dups) | 2875 | (defun bibtex-find-entry-location (entry-name &optional ignore-dups) |
| 1796 | "Looking for place to put the BibTeX entry named ENTRY-NAME. | 2876 | "Looking for place to put the BibTeX entry named ENTRY-NAME. |
| 1797 | Performs a binary search (therefore, buffer is assumed to be in sorted | 2877 | Performs a binary search (therefore, buffer is assumed to be in sorted |
| 1798 | order, without duplicates (see \\[bibtex-validate-buffer]), if it is | 2878 | order, without duplicates (see \\[bibtex-validate]), if it is |
| 1799 | not, bibtex-find-entry-location will fail). If entry-name is already | 2879 | not, bibtex-find-entry-location will fail). If entry-name is already |
| 1800 | used as a reference key, an error is signaled. However, if optional | 2880 | used as a reference key, an error is signaled. However, if optional |
| 1801 | variable IGNORE-DUPS is non-nil, no error messages about duplicate | 2881 | variable IGNORE-DUPS is non-nil, no error messages about duplicate |
| 1802 | entries are signaled, but the error handling is assumed to be made in | 2882 | entries are signaled, but the error handling is assumed to be made in |
| 1803 | the calling function. Nil is returned, if an duplicate entry error | 2883 | the calling function. Nil is returned, if an duplicate entry error |
| 1804 | occurred, and t in all other cases." | 2884 | occurred, and t in all other cases." |
| 1805 | (let* ((left | 2885 | (let* ((case-fold-search t) |
| 2886 | (left | ||
| 1806 | (progn | 2887 | (progn |
| 1807 | (beginning-of-first-bibtex-entry) | 2888 | (bibtex-beginning-of-first-entry) |
| 1808 | (if bibtex-sort-ignore-string-entries | 2889 | (skip-to-valid-bibtex-entry) |
| 1809 | (re-search-forward bibtex-reference nil `move) | 2890 | (bibtex-end-of-entry))) |
| 1810 | (bibtex-end-of-entry)) | ||
| 1811 | (point))) | ||
| 1812 | (right | 2891 | (right |
| 1813 | (progn | 2892 | (progn |
| 1814 | (goto-char (point-max)) | 2893 | (bibtex-beginning-of-last-entry) |
| 1815 | (if bibtex-sort-ignore-string-entries | 2894 | (skip-to-valid-bibtex-entry t) |
| 1816 | (re-search-backward bibtex-reference nil `move) | ||
| 1817 | (bibtex-beginning-of-entry)) | ||
| 1818 | (point))) | 2895 | (point))) |
| 1819 | actual-point | 2896 | actual-point |
| 1820 | actual-key | 2897 | actual-key |
| @@ -1824,26 +2901,21 @@ occurred, and t in all other cases." | |||
| 1824 | (while (not done) | 2901 | (while (not done) |
| 1825 | (setq actual-point (/ (+ left right) 2)) | 2902 | (setq actual-point (/ (+ left right) 2)) |
| 1826 | (goto-char actual-point) | 2903 | (goto-char actual-point) |
| 1827 | (bibtex-beginning-of-entry) | 2904 | (skip-to-valid-bibtex-entry t) |
| 1828 | (setq actual-key | 2905 | (setq actual-key |
| 1829 | (if bibtex-sort-ignore-string-entries | 2906 | (progn |
| 1830 | (progn | ||
| 1831 | (re-search-forward bibtex-reference) | ||
| 1832 | (buffer-substring-no-properties | ||
| 1833 | (match-beginning bibtex-key-in-reference) | ||
| 1834 | (match-end bibtex-key-in-reference))) | ||
| 1835 | (re-search-forward bibtex-reference-head) | 2907 | (re-search-forward bibtex-reference-head) |
| 1836 | (buffer-substring-no-properties | 2908 | (buffer-substring-no-properties |
| 1837 | (match-beginning bibtex-key-in-head) | 2909 | (match-beginning bibtex-key-in-head) |
| 1838 | (match-end bibtex-key-in-head)))) | 2910 | (match-end bibtex-key-in-head)))) |
| 1839 | (cond | 2911 | (cond |
| 1840 | ((string-lessp entry-name actual-key) | 2912 | ((string-lessp entry-name actual-key) |
| 1841 | (setq new (match-beginning 0)) | 2913 | (setq new (bibtex-beginning-of-entry)) |
| 1842 | (if (equal right new) | 2914 | (if (equal right new) |
| 1843 | (setq done t) | 2915 | (setq done t) |
| 1844 | (setq right new))) | 2916 | (setq right new))) |
| 1845 | ((string-lessp actual-key entry-name) | 2917 | ((string-lessp actual-key entry-name) |
| 1846 | (setq new (match-end 0)) | 2918 | (setq new (bibtex-end-of-entry)) |
| 1847 | (if (equal left new) | 2919 | (if (equal left new) |
| 1848 | (setq done t) | 2920 | (setq done t) |
| 1849 | (setq left new))) | 2921 | (setq left new))) |
| @@ -1851,82 +2923,240 @@ occurred, and t in all other cases." | |||
| 1851 | (setq dup t | 2923 | (setq dup t |
| 1852 | done t) | 2924 | done t) |
| 1853 | (if (not ignore-dups) | 2925 | (if (not ignore-dups) |
| 1854 | (error "Entry with key `%s' already exists!" entry-name))))) | 2926 | (progn |
| 2927 | (bibtex-beginning-of-entry) | ||
| 2928 | (error "Entry with key `%s' already exists." entry-name)))))) | ||
| 1855 | (if dup | 2929 | (if dup |
| 1856 | nil | 2930 | (progn |
| 2931 | (bibtex-beginning-of-entry) | ||
| 2932 | nil) | ||
| 1857 | (goto-char right) | 2933 | (goto-char right) |
| 1858 | (if (re-search-forward bibtex-reference nil t) | 2934 | (setq actual-key |
| 2935 | (if (looking-at bibtex-reference-head) | ||
| 2936 | (buffer-substring-no-properties | ||
| 2937 | (match-beginning bibtex-key-in-reference) | ||
| 2938 | (match-end bibtex-key-in-reference)))) | ||
| 2939 | (if (or | ||
| 2940 | (not actual-key) | ||
| 2941 | (string-lessp actual-key entry-name)) | ||
| 2942 | ;; buffer contains no valid entries or | ||
| 2943 | ;; greater than last entry --> append | ||
| 1859 | (progn | 2944 | (progn |
| 1860 | (setq actual-key | 2945 | (bibtex-end-of-entry) |
| 1861 | (buffer-substring-no-properties | 2946 | (if (not (bobp)) |
| 1862 | (match-beginning bibtex-key-in-reference) | 2947 | (newline (forward-line 2))) |
| 1863 | (match-end bibtex-key-in-reference))) | 2948 | (beginning-of-line)) |
| 1864 | (if (string-lessp actual-key entry-name) | 2949 | (goto-char right)) |
| 1865 | ;; even greater than last entry --> we must append | ||
| 1866 | (progn | ||
| 1867 | (goto-char (match-end 0)) | ||
| 1868 | (newline (forward-line 2)) | ||
| 1869 | (beginning-of-line)) | ||
| 1870 | (goto-char right)))) | ||
| 1871 | t))) | 2950 | t))) |
| 1872 | 2951 | ||
| 1873 | (defun bibtex-validate-buffer (&optional from-point) | 2952 | (defun bibtex-validate (&optional test-thoroughly) |
| 1874 | "Validate if the current BibTeX buffer is syntactically correct. | 2953 | "Validate if buffer or region is syntactically correct. |
| 1875 | Any garbage (e.g. comments) before the first \"@\" is not tested (so | 2954 | Only known reference types are checked, so you can put comments |
| 1876 | you can put comments here). | 2955 | outside of entries. |
| 1877 | With non-nil FROM-POINT it starts with entry enclosing point." | 2956 | With optional argument TEST-THOROUGHLY non-nil it checks for absence of |
| 2957 | required fields and questionable month fields as well. | ||
| 2958 | If mark is active, it validates current region, if not whole buffer. | ||
| 2959 | Returns t if test was successful, nil otherwise." | ||
| 1878 | (interactive "P") | 2960 | (interactive "P") |
| 1879 | (let ((pnt (point)) | 2961 | (let (error-list |
| 1880 | (starting-point | 2962 | syntax-error |
| 1881 | (progn | 2963 | (case-fold-search t) |
| 1882 | (if from-point | 2964 | (valid-bibtex-entry |
| 1883 | (bibtex-beginning-of-entry) | 2965 | (concat |
| 1884 | (beginning-of-first-bibtex-entry)) | 2966 | "@[ \t]*\\(\\(string\\)\\|" |
| 1885 | (point)))) | 2967 | (mapconcat |
| 1886 | ;; looking if entries fit syntactical structure | 2968 | (lambda (type) |
| 1887 | (goto-char starting-point) | 2969 | (concat "\\(" (car type) "\\)")) |
| 1888 | (while (re-search-forward "^@" nil t) | 2970 | bibtex-entry-field-alist |
| 1889 | (forward-char -1) | 2971 | "\\|") |
| 1890 | (let ((p (point))) | 2972 | "\\)")) |
| 1891 | (if (or | 2973 | (pnt (point)) |
| 1892 | (looking-at "@string") | 2974 | (start-point |
| 1893 | (looking-at "@preamble")) | 2975 | (if mark-active |
| 1894 | (forward-char) | 2976 | (region-beginning) |
| 1895 | (if (not (and | 2977 | (bibtex-beginning-of-first-entry))) |
| 1896 | (re-search-forward bibtex-reference nil t) | 2978 | (end-point |
| 1897 | (equal p (match-beginning 0)))) | 2979 | (if mark-active |
| 1898 | (progn | 2980 | (region-end) |
| 1899 | (goto-char p) | 2981 | (point-max)))) |
| 1900 | (error "Bad entry begins here")))))) | 2982 | (save-restriction |
| 1901 | ;; looking if entries are balanced (a single non-escaped quote | 2983 | (narrow-to-region start-point end-point) |
| 1902 | ;; inside braces is not detected by the former check, but | 2984 | ;; looking if entries fit syntactical structure |
| 1903 | ;; bibtex-sort-entries stumbles about it | 2985 | (goto-char start-point) |
| 1904 | (goto-char starting-point) | 2986 | (bibtex-progress-message "Checking syntactical structure") |
| 1905 | (map-bibtex-entries | 2987 | (while (re-search-forward "^[ \t]*@" nil t) |
| 1906 | (function | 2988 | (bibtex-progress-message) |
| 1907 | (lambda (current) | 2989 | (forward-char -1) |
| 1908 | (bibtex-beginning-of-entry) | 2990 | (let ((p (point)) |
| 1909 | (forward-sexp 2)))) | 2991 | (must-match |
| 1910 | ;; looking for correct sort order and duplicates | 2992 | (looking-at valid-bibtex-entry))) |
| 1911 | (if bibtex-maintain-sorted-entries | 2993 | (if (not must-match) |
| 1912 | (let (previous | 2994 | (forward-char) |
| 1913 | point) | 2995 | (let (bibtex-sort-ignore-string-entries) |
| 1914 | (goto-char starting-point) | 2996 | (skip-to-valid-bibtex-entry)) |
| 1915 | (map-bibtex-entries | 2997 | (if (equal (point) p) |
| 1916 | (function | 2998 | (forward-char) |
| 1917 | (lambda (current) | 2999 | (goto-char p) |
| 1918 | (cond ((or (null previous) | 3000 | (setq |
| 1919 | (string< previous current)) | 3001 | error-list |
| 1920 | (setq previous current | 3002 | (cons (list |
| 1921 | point (point))) | 3003 | (current-line) |
| 1922 | ((string-equal previous current) | 3004 | "Syntax error (check esp. commas, braces, and quotes)") |
| 1923 | (error "Duplicate here with previous!")) | 3005 | error-list)) |
| 1924 | (t | 3006 | (forward-char))))) |
| 1925 | (error "Entries out of order here!")))))))) | 3007 | (bibtex-progress-message 'done) |
| 3008 | (if error-list | ||
| 3009 | (setq syntax-error t) | ||
| 3010 | ;; looking for correct sort order and duplicates (only if | ||
| 3011 | ;; there were no syntax errors) | ||
| 3012 | (if bibtex-maintain-sorted-entries | ||
| 3013 | (let (previous) | ||
| 3014 | (goto-char start-point) | ||
| 3015 | (bibtex-progress-message "Checking correct sort order") | ||
| 3016 | (map-bibtex-entries | ||
| 3017 | (lambda (current) | ||
| 3018 | (bibtex-progress-message) | ||
| 3019 | (cond ((or (not previous) | ||
| 3020 | (string< previous current)) | ||
| 3021 | (setq previous current)) | ||
| 3022 | ((string-equal previous current) | ||
| 3023 | (setq | ||
| 3024 | error-list | ||
| 3025 | (cons (list (current-line) | ||
| 3026 | "Duplicate key with previous") | ||
| 3027 | error-list))) | ||
| 3028 | (t | ||
| 3029 | (setq previous current | ||
| 3030 | error-list | ||
| 3031 | (cons (list (current-line) | ||
| 3032 | "Entries out of order") | ||
| 3033 | error-list)))))) | ||
| 3034 | (bibtex-progress-message 'done))) | ||
| 3035 | (if test-thoroughly | ||
| 3036 | (progn | ||
| 3037 | (goto-char start-point) | ||
| 3038 | (bibtex-progress-message | ||
| 3039 | "Checking required fields and month fields") | ||
| 3040 | (let ((bibtex-sort-ignore-string-entries t) | ||
| 3041 | (questionable-month | ||
| 3042 | (concat | ||
| 3043 | "[{\"]\\(" | ||
| 3044 | (mapconcat | ||
| 3045 | (lambda (mon) | ||
| 3046 | (concat "\\(" (car mon) "\\)")) | ||
| 3047 | bibtex-predefined-month-strings | ||
| 3048 | "\\|") | ||
| 3049 | "\\)[}\"]"))) | ||
| 3050 | (map-bibtex-entries | ||
| 3051 | (lambda (current) | ||
| 3052 | (bibtex-progress-message) | ||
| 3053 | (let* ((beg (bibtex-beginning-of-entry)) | ||
| 3054 | (end (bibtex-end-of-entry)) | ||
| 3055 | (entry-list | ||
| 3056 | (progn | ||
| 3057 | (goto-char beg) | ||
| 3058 | (bibtex-search-reference nil end) | ||
| 3059 | (assoc-ignore-case | ||
| 3060 | (buffer-substring-no-properties | ||
| 3061 | (1+ (match-beginning bibtex-type-in-head)) | ||
| 3062 | (match-end bibtex-type-in-head)) | ||
| 3063 | bibtex-entry-field-alist))) | ||
| 3064 | (req (copy-sequence (elt (elt entry-list 1) 0))) | ||
| 3065 | (creq (copy-sequence (elt (elt entry-list 2) 0))) | ||
| 3066 | crossref-there) | ||
| 3067 | (goto-char beg) | ||
| 3068 | (while (re-search-forward bibtex-field end t) | ||
| 3069 | (let ((field-name | ||
| 3070 | (buffer-substring-no-properties | ||
| 3071 | (match-beginning bibtex-name-in-field) | ||
| 3072 | (match-end bibtex-name-in-field)))) | ||
| 3073 | (if (and (equal (downcase field-name) "month") | ||
| 3074 | (string-match | ||
| 3075 | questionable-month | ||
| 3076 | (buffer-substring-no-properties | ||
| 3077 | (match-beginning bibtex-text-in-field) | ||
| 3078 | (match-end bibtex-text-in-field)))) | ||
| 3079 | (setq | ||
| 3080 | error-list | ||
| 3081 | (cons | ||
| 3082 | (list | ||
| 3083 | (current-line) | ||
| 3084 | "Questionable month field (delimited string)") | ||
| 3085 | error-list))) | ||
| 3086 | (setq | ||
| 3087 | req | ||
| 3088 | (delete (assoc-ignore-case field-name req) req) | ||
| 3089 | creq | ||
| 3090 | (delete (assoc-ignore-case field-name creq) creq)) | ||
| 3091 | (if (equal (downcase field-name) "crossref") | ||
| 3092 | (setq crossref-there t)))) | ||
| 3093 | (if crossref-there | ||
| 3094 | (setq req creq)) | ||
| 3095 | (if (or (> (length req) 1) | ||
| 3096 | (and (= (length req) 1) | ||
| 3097 | (not (elt (car req) 3)))) | ||
| 3098 | ;; two (or more) fields missed or one field | ||
| 3099 | ;; missed and this isn't flagged alternative | ||
| 3100 | ;; (notice that this fails if there are more | ||
| 3101 | ;; than two alternatives in a BibTeX entry, | ||
| 3102 | ;; which isn't the case momentarily) | ||
| 3103 | (setq | ||
| 3104 | error-list | ||
| 3105 | (cons | ||
| 3106 | (list (save-excursion | ||
| 3107 | (bibtex-beginning-of-entry) | ||
| 3108 | (current-line)) | ||
| 3109 | (concat | ||
| 3110 | "Required field \"" | ||
| 3111 | (car (car req)) | ||
| 3112 | "\" missing")) | ||
| 3113 | error-list))))))) | ||
| 3114 | (bibtex-progress-message 'done))))) | ||
| 1926 | (goto-char pnt) | 3115 | (goto-char pnt) |
| 1927 | (if from-point | 3116 | (if error-list |
| 1928 | (message "Part of BibTeX buffer starting at point is syntactically correct") | 3117 | (let ((bufnam (buffer-name)) |
| 1929 | (message "BibTeX buffer is syntactically correct")))) | 3118 | (dir default-directory)) |
| 3119 | (setq error-list | ||
| 3120 | (sort error-list | ||
| 3121 | (lambda (a b) | ||
| 3122 | (< (car a) (car b))))) | ||
| 3123 | (let ((pop-up-windows t)) | ||
| 3124 | (pop-to-buffer nil t)) | ||
| 3125 | (switch-to-buffer | ||
| 3126 | (get-buffer-create "*BibTeX validation errors*") t) | ||
| 3127 | ;; don't use switch-to-buffer-other-window, since this | ||
| 3128 | ;; doesn't allow the second parameter NORECORD | ||
| 3129 | (setq default-directory dir) | ||
| 3130 | (toggle-read-only -1) | ||
| 3131 | (compilation-mode) | ||
| 3132 | (delete-region (point-min) (point-max)) | ||
| 3133 | (goto-char (point-min)) | ||
| 3134 | (insert | ||
| 3135 | "BibTeX mode command `bibtex-validate'\n" | ||
| 3136 | (if syntax-error | ||
| 3137 | "Maybe undetected errors due to syntax errors. Correct and validate again." | ||
| 3138 | "") | ||
| 3139 | "\n") | ||
| 3140 | (while error-list | ||
| 3141 | (insert | ||
| 3142 | bufnam ":" (number-to-string (elt (car error-list) 0)) | ||
| 3143 | ": " (elt (car error-list) 1) "\n") | ||
| 3144 | (setq error-list (cdr error-list))) | ||
| 3145 | (compilation-parse-errors nil nil) | ||
| 3146 | (setq compilation-old-error-list compilation-error-list) | ||
| 3147 | ;; this is necessary to avoid reparsing of buffer if you | ||
| 3148 | ;; switch to compilation buffer and enter | ||
| 3149 | ;; `compile-goto-error' | ||
| 3150 | (set-buffer-modified-p nil) | ||
| 3151 | (toggle-read-only 1) | ||
| 3152 | (goto-char (point-min)) | ||
| 3153 | (other-window -1) | ||
| 3154 | ;; return nil | ||
| 3155 | nil) | ||
| 3156 | (if mark-active | ||
| 3157 | (message "Region is syntactically correct") | ||
| 3158 | (message "Buffer is syntactically correct")) | ||
| 3159 | t))) | ||
| 1930 | 3160 | ||
| 1931 | (defun bibtex-next-field (arg) | 3161 | (defun bibtex-next-field (arg) |
| 1932 | "Finds end of text of next BibTeX field; with arg, to its beginning." | 3162 | "Finds end of text of next BibTeX field; with arg, to its beginning." |
| @@ -1941,77 +3171,195 @@ With non-nil FROM-POINT it starts with entry enclosing point." | |||
| 1941 | (error | 3171 | (error |
| 1942 | (goto-char start) | 3172 | (goto-char start) |
| 1943 | (end-of-line) | 3173 | (end-of-line) |
| 1944 | (forward-char 1)))) | 3174 | (forward-char)))) |
| 1945 | (bibtex-find-text arg)) | 3175 | (bibtex-find-text arg t)) |
| 1946 | 3176 | ||
| 1947 | (defun bibtex-find-text (arg) | 3177 | (defun bibtex-find-text (arg &optional as-if-interactive) |
| 1948 | "Go to end of text of current field; with arg, go to beginning." | 3178 | "Go to end of text of current field; with ARG, go to beginning." |
| 1949 | (interactive "P") | 3179 | (interactive "P") |
| 1950 | (bibtex-inside-field) | 3180 | (bibtex-inside-field) |
| 1951 | (bibtex-enclosing-field) | 3181 | (if (bibtex-enclosing-field (or (interactive-p) as-if-interactive)) |
| 1952 | (if arg | ||
| 1953 | (progn | 3182 | (progn |
| 1954 | (goto-char (match-beginning bibtex-text-in-field)) | 3183 | (if arg |
| 1955 | (if (looking-at "[{\"]") | 3184 | (progn |
| 1956 | (forward-char 1))) | 3185 | (goto-char (match-beginning bibtex-text-in-field)) |
| 1957 | (goto-char (match-end bibtex-text-in-field)) | 3186 | (if (looking-at "[{\"]") |
| 1958 | (if (or | 3187 | (forward-char))) |
| 1959 | (= (preceding-char) ?}) | 3188 | (goto-char (match-end bibtex-text-in-field)) |
| 1960 | (= (preceding-char) ?\")) | 3189 | (if (or |
| 1961 | (forward-char -1))) | 3190 | (= (preceding-char) ?}) |
| 1962 | (if bibtex-help-message | 3191 | (= (preceding-char) ?\")) |
| 1963 | (bibtex-print-help-message))) | 3192 | (forward-char -1))) |
| 1964 | 3193 | (if bibtex-help-message | |
| 1965 | (defun bibtex-remove-OPT () | 3194 | (bibtex-print-help-message))) |
| 1966 | "Removes the 'OPT' starting optional arguments and goes to end of text." | 3195 | (beginning-of-line) |
| 3196 | (cond | ||
| 3197 | ((looking-at bibtex-string) | ||
| 3198 | (goto-char | ||
| 3199 | (if arg | ||
| 3200 | (match-beginning bibtex-text-in-string) | ||
| 3201 | (match-end bibtex-text-in-string)))) | ||
| 3202 | ((looking-at bibtex-reference-maybe-empty-head) | ||
| 3203 | (goto-char | ||
| 3204 | (if arg | ||
| 3205 | (match-beginning bibtex-key-in-head) | ||
| 3206 | (match-end 0)))) | ||
| 3207 | (t | ||
| 3208 | (error "Not on BibTeX field."))))) | ||
| 3209 | |||
| 3210 | (defun bibtex-remove-OPT-or-ALT () | ||
| 3211 | "Removes the string starting optional/alternative fields. | ||
| 3212 | Aligns text and goes thereafter to end of text." | ||
| 1967 | (interactive) | 3213 | (interactive) |
| 1968 | (bibtex-inside-field) | 3214 | (let ((case-fold-search t)) |
| 1969 | (bibtex-enclosing-field) | 3215 | (bibtex-inside-field) |
| 1970 | (save-excursion | 3216 | (bibtex-enclosing-field) |
| 1971 | (goto-char (match-beginning bibtex-name-in-field)) | 3217 | (save-excursion |
| 1972 | (if (looking-at "OPT") | 3218 | (goto-char (match-beginning bibtex-name-in-field)) |
| 1973 | ;; sct@dcs.edinburgh.ac.uk | 3219 | (if (looking-at "OPT\\|ALT") |
| 1974 | (progn | 3220 | (progn |
| 1975 | (delete-char (length "OPT")) | 3221 | (delete-char (length "OPT")) |
| 1976 | (search-forward "=") | 3222 | ;; make field non-OPT |
| 1977 | (delete-horizontal-space) | 3223 | (search-forward "=") |
| 1978 | (indent-to-column bibtex-text-alignment)))) | 3224 | (forward-char -1) |
| 1979 | (bibtex-inside-field)) | 3225 | (delete-horizontal-space) |
| 1980 | 3226 | (if bibtex-align-at-equal-sign | |
| 1981 | (defun bibtex-remove-double-quotes-or-braces () | 3227 | (indent-to-column (- bibtex-text-indentation 2)) |
| 3228 | (insert " ")) | ||
| 3229 | (search-forward "=") | ||
| 3230 | (delete-horizontal-space) | ||
| 3231 | (if bibtex-align-at-equal-sign | ||
| 3232 | (insert " ") | ||
| 3233 | (indent-to-column bibtex-text-indentation))))) | ||
| 3234 | (bibtex-inside-field))) | ||
| 3235 | |||
| 3236 | (defun bibtex-remove-delimiters () | ||
| 1982 | "Removes \"\" or {} around string." | 3237 | "Removes \"\" or {} around string." |
| 1983 | (interactive) | 3238 | (interactive) |
| 1984 | (save-excursion | 3239 | (let ((case-fold-search t)) |
| 3240 | (save-excursion | ||
| 3241 | (bibtex-inside-field) | ||
| 3242 | (bibtex-enclosing-field) | ||
| 3243 | (let ((start (match-beginning bibtex-text-in-field)) | ||
| 3244 | (stop (match-end bibtex-text-in-field))) | ||
| 3245 | (goto-char start) | ||
| 3246 | (while (re-search-forward bibtex-field-string stop t) | ||
| 3247 | (let ((beg (copy-marker (match-beginning 0))) | ||
| 3248 | (end (copy-marker (match-end 0)))) | ||
| 3249 | (goto-char beg) | ||
| 3250 | (if (looking-at "[{\"]") | ||
| 3251 | (delete-char 1)) | ||
| 3252 | (goto-char end) | ||
| 3253 | (forward-char -1) | ||
| 3254 | (if (looking-at "[}\"]") | ||
| 3255 | (delete-char 1)))))))) | ||
| 3256 | |||
| 3257 | (defun bibtex-kill-field (&optional copy-only) | ||
| 3258 | "Kills the entire enclosing BibTeX field. | ||
| 3259 | With prefix arg copy the current field to bibtex-field-kill-ring, but | ||
| 3260 | do not actually kill it." | ||
| 3261 | (interactive "P") | ||
| 3262 | (let ((pnt (point)) | ||
| 3263 | (case-fold-search t)) | ||
| 1985 | (bibtex-inside-field) | 3264 | (bibtex-inside-field) |
| 1986 | (bibtex-enclosing-field) | 3265 | (bibtex-enclosing-field) |
| 1987 | (let ((start (match-beginning bibtex-text-in-field)) | 3266 | (let ((the-end (match-end 0)) |
| 1988 | (stop (match-end bibtex-text-in-field))) | 3267 | (the-beginning (match-beginning 0))) |
| 1989 | (goto-char start) | 3268 | (goto-char the-end) |
| 1990 | (while (re-search-forward bibtex-field-string stop t) | 3269 | (skip-chars-forward " \t\n,") |
| 1991 | (let ((beg (match-beginning 0)) | 3270 | (setq |
| 1992 | (end (match-end 0))) | 3271 | bibtex-field-kill-ring |
| 1993 | (goto-char end) | 3272 | (cons |
| 1994 | (forward-char -1) | 3273 | (list |
| 1995 | (if (looking-at "[}\"]") | 3274 | 'field |
| 1996 | (delete-char 1)) | 3275 | (buffer-substring-no-properties |
| 1997 | (goto-char beg) | 3276 | (match-beginning bibtex-name-in-field) |
| 1998 | (if (looking-at "[{\"]") | 3277 | (match-end bibtex-name-in-field)) |
| 1999 | (delete-char 1))))))) | 3278 | (buffer-substring-no-properties |
| 3279 | (match-beginning bibtex-text-in-field) | ||
| 3280 | (match-end bibtex-text-in-field))) | ||
| 3281 | bibtex-field-kill-ring)) | ||
| 3282 | (if (> (length bibtex-field-kill-ring) bibtex-field-kill-ring-max) | ||
| 3283 | (setcdr | ||
| 3284 | (nthcdr (1- bibtex-field-kill-ring-max) bibtex-field-kill-ring) | ||
| 3285 | nil)) | ||
| 3286 | (setq bibtex-field-kill-ring-yank-pointer bibtex-field-kill-ring) | ||
| 3287 | (if copy-only | ||
| 3288 | (goto-char pnt) | ||
| 3289 | (delete-region the-beginning the-end) | ||
| 3290 | (goto-char the-beginning) | ||
| 3291 | (let (bibtex-help-message) | ||
| 3292 | (bibtex-find-text nil t))))) | ||
| 3293 | (setq bibtex-last-kill-command 'field)) | ||
| 3294 | |||
| 3295 | (defun bibtex-copy-field-as-kill () | ||
| 3296 | (interactive) | ||
| 3297 | (bibtex-kill-field t)) | ||
| 2000 | 3298 | ||
| 2001 | (defun bibtex-kill-optional-field () | 3299 | (defun bibtex-kill-entry (&optional copy-only) |
| 2002 | "Kill the entire enclosing optional BibTeX field." | 3300 | "Kills the entire enclosing BibTeX reference entry. |
| 3301 | With prefix arg copy the current reference entry to | ||
| 3302 | bibtex-entry-kill-ring, but do not actually kill it." | ||
| 3303 | (interactive "P") | ||
| 3304 | (let ((pnt (point)) | ||
| 3305 | (case-fold-search t) | ||
| 3306 | (beg (bibtex-beginning-of-entry)) | ||
| 3307 | (end | ||
| 3308 | (progn | ||
| 3309 | (bibtex-end-of-entry) | ||
| 3310 | (if (re-search-forward | ||
| 3311 | bibtex-reference-maybe-empty-head nil 'move) | ||
| 3312 | (goto-char (match-beginning 0))) | ||
| 3313 | (point)))) | ||
| 3314 | (setq | ||
| 3315 | bibtex-entry-kill-ring | ||
| 3316 | (cons | ||
| 3317 | (list 'entry (buffer-substring-no-properties beg end)) | ||
| 3318 | bibtex-entry-kill-ring)) | ||
| 3319 | (if (> (length bibtex-entry-kill-ring) bibtex-entry-kill-ring-max) | ||
| 3320 | (setcdr | ||
| 3321 | (nthcdr (1- bibtex-entry-kill-ring-max) bibtex-entry-kill-ring) | ||
| 3322 | nil)) | ||
| 3323 | (setq bibtex-entry-kill-ring-yank-pointer bibtex-entry-kill-ring) | ||
| 3324 | (if copy-only | ||
| 3325 | (goto-char pnt) | ||
| 3326 | (delete-region beg end))) | ||
| 3327 | (setq bibtex-last-kill-command 'entry)) | ||
| 3328 | |||
| 3329 | (defun bibtex-copy-entry-as-kill () | ||
| 2003 | (interactive) | 3330 | (interactive) |
| 2004 | (bibtex-inside-field) | 3331 | (bibtex-kill-entry t)) |
| 2005 | (bibtex-enclosing-field) | 3332 | |
| 2006 | (goto-char (match-beginning bibtex-name-in-field)) | 3333 | (defun bibtex-yank (&optional n) |
| 2007 | (let ((the-end (match-end 0)) | 3334 | "Reinsert the last BibTeX item. |
| 2008 | (the-beginning (match-beginning 0))) | 3335 | More precisely, reinsert the field or entry killed or yanked most recently. |
| 2009 | (if (looking-at "OPT") | 3336 | With argument N, reinsert the Nth most recently killed BibTeX item. |
| 2010 | (progn | 3337 | See also the command \\[bibtex-yank-pop]]." |
| 2011 | (goto-char the-end) | 3338 | (interactive "*p") |
| 2012 | (skip-chars-forward " \t\n,") | 3339 | (bibtex-insert-current-kill (1- n)) |
| 2013 | (kill-region the-beginning the-end)) | 3340 | (setq this-command 'bibtex-yank)) |
| 2014 | (error "Mandatory fields can't be killed")))) | 3341 | |
| 3342 | (defun bibtex-yank-pop (n) | ||
| 3343 | "Replace just-yanked killed BibTeX item with a different. | ||
| 3344 | This command is allowed only immediately after a `bibtex-yank' or a | ||
| 3345 | `bibtex-yank-pop'. | ||
| 3346 | At such a time, the region contains a reinserted previously killed | ||
| 3347 | BibTeX item. `bibtex-yank-pop' deletes that item and inserts in its | ||
| 3348 | place a different killed BibTeX item. | ||
| 3349 | |||
| 3350 | With no argument, the previous kill is inserted. | ||
| 3351 | With argument N, insert the Nth previous kill. | ||
| 3352 | If N is negative, this is a more recent kill. | ||
| 3353 | |||
| 3354 | The sequence of kills wraps around, so that after the oldest one | ||
| 3355 | comes the newest one." | ||
| 3356 | (interactive "*p") | ||
| 3357 | (if (not (eq last-command 'bibtex-yank)) | ||
| 3358 | (error "Previous command was not a BibTeX yank")) | ||
| 3359 | (setq this-command 'bibtex-yank) | ||
| 3360 | (let ((inhibit-read-only t)) | ||
| 3361 | (delete-region (point) (mark t)) | ||
| 3362 | (bibtex-insert-current-kill n))) | ||
| 2015 | 3363 | ||
| 2016 | (defun bibtex-empty-field () | 3364 | (defun bibtex-empty-field () |
| 2017 | "Delete the text part of the current field, replace with empty text." | 3365 | "Delete the text part of the current field, replace with empty text." |
| @@ -2019,99 +3367,11 @@ With non-nil FROM-POINT it starts with entry enclosing point." | |||
| 2019 | (bibtex-inside-field) | 3367 | (bibtex-inside-field) |
| 2020 | (bibtex-enclosing-field) | 3368 | (bibtex-enclosing-field) |
| 2021 | (goto-char (match-beginning bibtex-text-in-field)) | 3369 | (goto-char (match-beginning bibtex-text-in-field)) |
| 2022 | (kill-region (point) (match-end bibtex-text-in-field)) | 3370 | (delete-region (point) (match-end bibtex-text-in-field)) |
| 2023 | (insert (concat bibtex-field-left-delimiter | 3371 | (insert (concat (bibtex-field-left-delimiter) |
| 2024 | bibtex-field-right-delimiter)) | 3372 | (bibtex-field-right-delimiter)) ) |
| 2025 | (bibtex-find-text t)) | 3373 | (bibtex-find-text t)) |
| 2026 | 3374 | ||
| 2027 | (defun bibtex-pop (arg direction) | ||
| 2028 | ;; generic function to be used by bibtex-pop-previous and bibtex-pop-next | ||
| 2029 | (let (bibtex-help-message) | ||
| 2030 | (bibtex-find-text nil)) | ||
| 2031 | (save-excursion | ||
| 2032 | ;; parse current field | ||
| 2033 | (bibtex-inside-field) | ||
| 2034 | (bibtex-enclosing-field) | ||
| 2035 | (let ((start-old-text (match-beginning bibtex-text-in-field)) | ||
| 2036 | (stop-old-text (match-end bibtex-text-in-field)) | ||
| 2037 | (start-name (match-beginning bibtex-name-in-field)) | ||
| 2038 | (stop-name (match-end bibtex-name-in-field)) | ||
| 2039 | (new-text)) | ||
| 2040 | (goto-char start-name) | ||
| 2041 | ;; construct regexp for field with same name as this one, | ||
| 2042 | ;; ignoring possible OPT's | ||
| 2043 | (let ((matching-entry | ||
| 2044 | (bibtex-cfield | ||
| 2045 | (buffer-substring-no-properties (if (looking-at "OPT") | ||
| 2046 | (+ (point) (length "OPT")) | ||
| 2047 | (point)) | ||
| 2048 | stop-name) | ||
| 2049 | bibtex-field-text))) | ||
| 2050 | ;; if executed several times in a row, start each search where | ||
| 2051 | ;; the last one was finished | ||
| 2052 | (cond ((eq last-command 'bibtex-pop) | ||
| 2053 | t | ||
| 2054 | ) | ||
| 2055 | (t | ||
| 2056 | (bibtex-enclosing-reference-maybe-empty-head) | ||
| 2057 | (setq bibtex-pop-previous-search-point (point)) | ||
| 2058 | (setq bibtex-pop-next-search-point (match-end 0)))) | ||
| 2059 | (if (eq direction 'previous) | ||
| 2060 | (goto-char bibtex-pop-previous-search-point) | ||
| 2061 | (goto-char bibtex-pop-next-search-point)) | ||
| 2062 | ;; Now search for arg'th previous/next similar field | ||
| 2063 | (cond | ||
| 2064 | ((if (eq direction 'previous) | ||
| 2065 | (re-search-backward matching-entry (point-min) t arg) | ||
| 2066 | (re-search-forward matching-entry (point-max) t arg)) | ||
| 2067 | ;; Found a matching field. Remember boundaries. | ||
| 2068 | (setq bibtex-pop-previous-search-point (match-beginning 0)) | ||
| 2069 | (setq bibtex-pop-next-search-point (match-end 0)) | ||
| 2070 | (setq new-text | ||
| 2071 | (buffer-substring-no-properties | ||
| 2072 | (match-beginning bibtex-text-in-field) | ||
| 2073 | (match-end bibtex-text-in-field))) | ||
| 2074 | ;; change delimiters, if any changes needed | ||
| 2075 | (let ((start 0) | ||
| 2076 | old-open | ||
| 2077 | new-open | ||
| 2078 | old-close | ||
| 2079 | new-close) | ||
| 2080 | (if (equal bibtex-field-left-delimiter "{") | ||
| 2081 | (setq old-open ?\" | ||
| 2082 | new-open ?\{ | ||
| 2083 | old-close ?\" | ||
| 2084 | new-close ?\}) | ||
| 2085 | (setq old-open ?\{ | ||
| 2086 | new-open ?\" | ||
| 2087 | old-close ?\} | ||
| 2088 | new-close ?\")) | ||
| 2089 | (while (string-match bibtex-field-string new-text start) | ||
| 2090 | (let ((beg (match-beginning 0)) | ||
| 2091 | (end (1- (match-end 0)))) | ||
| 2092 | (if (and | ||
| 2093 | (eq (aref new-text beg) old-open) | ||
| 2094 | (eq (aref new-text end) old-close)) | ||
| 2095 | (progn | ||
| 2096 | (aset new-text beg new-open) | ||
| 2097 | (aset new-text end new-close)))) | ||
| 2098 | (setq start (match-end 0)))) | ||
| 2099 | (bibtex-flash-head) | ||
| 2100 | ;; Go back to where we started, delete old text, and pop new. | ||
| 2101 | (goto-char stop-old-text) | ||
| 2102 | (delete-region start-old-text stop-old-text) | ||
| 2103 | (insert new-text)) | ||
| 2104 | (t | ||
| 2105 | ;; search failed | ||
| 2106 | (error (concat "No " | ||
| 2107 | (if (eq direction 'previous) | ||
| 2108 | "previous" | ||
| 2109 | "next") | ||
| 2110 | " matching BibTeX field."))))))) | ||
| 2111 | (let (bibtex-help-message) | ||
| 2112 | (bibtex-find-text nil)) | ||
| 2113 | (setq this-command 'bibtex-pop)) | ||
| 2114 | |||
| 2115 | (defun bibtex-pop-previous (arg) | 3375 | (defun bibtex-pop-previous (arg) |
| 2116 | "Replace text of current field with the text of similar field in previous entry. | 3376 | "Replace text of current field with the text of similar field in previous entry. |
| 2117 | With arg, goes up ARG entries. Repeated, goes up so many times. May be | 3377 | With arg, goes up ARG entries. Repeated, goes up so many times. May be |
| @@ -2126,125 +3386,21 @@ intermixed with \\[bibtex-pop-previous] (bibtex-pop-previous)." | |||
| 2126 | (interactive "p") | 3386 | (interactive "p") |
| 2127 | (bibtex-pop arg 'next)) | 3387 | (bibtex-pop arg 'next)) |
| 2128 | 3388 | ||
| 2129 | (defun bibtex-clean-entry (&optional arg) | 3389 | (defun bibtex-clean-entry (&optional new-label called-by-reformat) |
| 2130 | "Finish editing the current BibTeX entry and clean it up. | 3390 | "Finish editing the current BibTeX entry and clean it up. |
| 2131 | For all optional fields of current BibTeX entry: if empty, kill the | 3391 | Checks that no required fields are empty and formats entry dependent |
| 2132 | whole field; otherwise, remove the \"OPT\" string in the name; if text | 3392 | on the value of bibtex-entry-format. |
| 2133 | numerical, remove double-quotes. For all mandatory fields: if empty, | 3393 | If label of entry is empty or a prefix argument is given, calculate a |
| 2134 | signal error. If label of entry is empty or a prefix argument was | 3394 | new entry label (note: this only will work if fields in entry begin on |
| 2135 | given, calculate a new entry label." | 3395 | separate lines prior to calling bibtex-clean-entry or if 'realign is |
| 3396 | contained in bibtex-entry-format). | ||
| 3397 | Don't call this on `string' or `preamble' entries. | ||
| 3398 | At end of the cleaning process, the functions in | ||
| 3399 | bibtex-clean-entry-hook are called with region narrowed to entry." | ||
| 2136 | (interactive "P") | 3400 | (interactive "P") |
| 2137 | (bibtex-beginning-of-entry) | 3401 | (bibtex-format-entry) |
| 2138 | (let ((start (point)) | 3402 | (let* ((case-fold-search t) |
| 2139 | crossref-there) | 3403 | (eob (bibtex-end-of-entry)) |
| 2140 | (save-restriction | ||
| 2141 | (narrow-to-region start (save-excursion (bibtex-end-of-entry) (point))) | ||
| 2142 | (while (and | ||
| 2143 | (re-search-forward bibtex-field (point-max) t 1) | ||
| 2144 | (not crossref-there)) | ||
| 2145 | ;; determine if reference has crossref entry | ||
| 2146 | (let ((begin-name (match-beginning bibtex-name-in-field)) | ||
| 2147 | (begin-text (match-beginning bibtex-text-in-field))) | ||
| 2148 | (goto-char begin-name) | ||
| 2149 | (if (looking-at "\\(OPTcrossref\\)\\|\\(crossref\\)") | ||
| 2150 | (progn | ||
| 2151 | (goto-char begin-text) | ||
| 2152 | (if (not (looking-at "\\(\"\"\\)\\|\\({}\\)")) | ||
| 2153 | (setq crossref-there t)))))) | ||
| 2154 | (bibtex-enclosing-reference-maybe-empty-head) | ||
| 2155 | (re-search-forward bibtex-reference-type) | ||
| 2156 | (let ((begin-type (1+ (match-beginning 0))) | ||
| 2157 | (end-type (match-end 0))) | ||
| 2158 | (goto-char start) | ||
| 2159 | (while (re-search-forward bibtex-field (point-max) t 1) | ||
| 2160 | (let ((begin-field (match-beginning 0)) | ||
| 2161 | (end-field (match-end 0)) | ||
| 2162 | (begin-name (match-beginning bibtex-name-in-field)) | ||
| 2163 | (end-name (match-end bibtex-name-in-field)) | ||
| 2164 | (begin-text (match-beginning bibtex-text-in-field)) | ||
| 2165 | (end-text (match-end bibtex-text-in-field)) | ||
| 2166 | ) | ||
| 2167 | (goto-char begin-name) | ||
| 2168 | (cond ((and | ||
| 2169 | (looking-at "OPT") | ||
| 2170 | bibtex-clean-entry-zap-empty-opts) | ||
| 2171 | (goto-char begin-text) | ||
| 2172 | (if (looking-at "\\(\"\"\\)\\|\\({}\\)") | ||
| 2173 | ;; empty: delete whole field if really optional | ||
| 2174 | ;; (missing crossref handled) or complain | ||
| 2175 | (if (and | ||
| 2176 | (not crossref-there) | ||
| 2177 | (assoc | ||
| 2178 | (downcase | ||
| 2179 | (buffer-substring-no-properties | ||
| 2180 | (+ (length "OPT") begin-name) end-name)) | ||
| 2181 | (car (car (cdr | ||
| 2182 | (assoc-ignore-case | ||
| 2183 | (buffer-substring-no-properties | ||
| 2184 | begin-type end-type) | ||
| 2185 | bibtex-entry-field-alist)))))) | ||
| 2186 | ;; field is not really optional | ||
| 2187 | (progn | ||
| 2188 | (goto-char begin-name) | ||
| 2189 | (delete-char (length "OPT")) | ||
| 2190 | ;; make field non-OPT | ||
| 2191 | (search-forward "=") | ||
| 2192 | (delete-horizontal-space) | ||
| 2193 | (indent-to-column bibtex-text-alignment) | ||
| 2194 | (forward-char) | ||
| 2195 | ;; and loop to go through next test | ||
| 2196 | (error "Mandatory field ``%s'' is empty" | ||
| 2197 | (buffer-substring-no-properties | ||
| 2198 | begin-name | ||
| 2199 | end-name))) | ||
| 2200 | ;; field is optional | ||
| 2201 | (delete-region begin-field end-field)) | ||
| 2202 | ;; otherwise: not empty, delete "OPT" | ||
| 2203 | (goto-char begin-name) | ||
| 2204 | (delete-char (length "OPT")) | ||
| 2205 | (progn | ||
| 2206 | ;; fixup alignment. [alarson:19920309.2047CST] | ||
| 2207 | (search-forward "=") | ||
| 2208 | (delete-horizontal-space) | ||
| 2209 | (indent-to-column bibtex-text-alignment)) | ||
| 2210 | (goto-char begin-field) | ||
| 2211 | ;; and loop to go through next test | ||
| 2212 | )) | ||
| 2213 | (t | ||
| 2214 | (goto-char begin-text) | ||
| 2215 | (cond ((looking-at "\\(\"[0-9]+\"\\)\\|\\({[0-9]+}\\)") | ||
| 2216 | ;; if numerical, | ||
| 2217 | (goto-char end-text) | ||
| 2218 | (delete-char -1) | ||
| 2219 | (goto-char begin-text) | ||
| 2220 | (delete-char 1) | ||
| 2221 | ;; delete enclosing delimiters | ||
| 2222 | (goto-char end-field) | ||
| 2223 | ;; go to end for next search | ||
| 2224 | (forward-char -2) | ||
| 2225 | ;; to compensate for the 2 delimiters deleted | ||
| 2226 | ) | ||
| 2227 | ((looking-at "\\(\"\"\\)\\|\\({}\\)") | ||
| 2228 | ;; if empty field, complain | ||
| 2229 | (forward-char 1) | ||
| 2230 | (if (not (or (equal (buffer-substring-no-properties | ||
| 2231 | begin-name | ||
| 2232 | (+ begin-name 3)) | ||
| 2233 | "OPT") | ||
| 2234 | (equal (buffer-substring-no-properties | ||
| 2235 | begin-name | ||
| 2236 | (+ begin-name 3)) | ||
| 2237 | "opt"))) | ||
| 2238 | (error "Mandatory field ``%s'' is empty" | ||
| 2239 | (buffer-substring-no-properties | ||
| 2240 | begin-name end-name)))) | ||
| 2241 | (t | ||
| 2242 | (goto-char end-field))))))))) | ||
| 2243 | (goto-char start) | ||
| 2244 | (bibtex-end-of-entry)) | ||
| 2245 | (let* ((eob (progn | ||
| 2246 | (bibtex-end-of-entry) | ||
| 2247 | (point))) | ||
| 2248 | (key (progn | 3404 | (key (progn |
| 2249 | (bibtex-beginning-of-entry) | 3405 | (bibtex-beginning-of-entry) |
| 2250 | (if (re-search-forward | 3406 | (if (re-search-forward |
| @@ -2253,13 +3409,14 @@ given, calculate a new entry label." | |||
| 2253 | (match-beginning bibtex-key-in-head) | 3409 | (match-beginning bibtex-key-in-head) |
| 2254 | (match-end bibtex-key-in-head)))))) | 3410 | (match-end bibtex-key-in-head)))))) |
| 2255 | (if (or | 3411 | (if (or |
| 2256 | arg | 3412 | new-label |
| 2257 | (not key)) | 3413 | (not key)) |
| 2258 | (progn | 3414 | (progn |
| 2259 | (let ((autokey | 3415 | (let ((autokey |
| 2260 | (if bibtex-autokey-edit-before-use | 3416 | (if bibtex-autokey-edit-before-use |
| 2261 | (read-from-minibuffer "Key to use: " | 3417 | (read-from-minibuffer |
| 2262 | (bibtex-generate-autokey)) | 3418 | "Key to use: " (bibtex-generate-autokey) nil nil |
| 3419 | 'bibtex-key-history) | ||
| 2263 | (bibtex-generate-autokey)))) | 3420 | (bibtex-generate-autokey)))) |
| 2264 | (bibtex-beginning-of-entry) | 3421 | (bibtex-beginning-of-entry) |
| 2265 | (re-search-forward bibtex-reference-maybe-empty-head) | 3422 | (re-search-forward bibtex-reference-maybe-empty-head) |
| @@ -2267,97 +3424,239 @@ given, calculate a new entry label." | |||
| 2267 | (delete-region (match-beginning bibtex-key-in-head) | 3424 | (delete-region (match-beginning bibtex-key-in-head) |
| 2268 | (match-end bibtex-key-in-head))) | 3425 | (match-end bibtex-key-in-head))) |
| 2269 | (insert autokey) | 3426 | (insert autokey) |
| 2270 | (let ((start (progn | 3427 | (let* ((start (bibtex-beginning-of-entry)) |
| 2271 | (bibtex-beginning-of-entry) | 3428 | (end (progn |
| 2272 | (point))) | 3429 | (bibtex-end-of-entry) |
| 2273 | (end (progn | 3430 | (if (re-search-forward |
| 2274 | (bibtex-end-of-entry) | 3431 | bibtex-reference-maybe-empty-head nil 'move) |
| 2275 | (re-search-forward "^@" nil 'move) | 3432 | (goto-char (match-beginning 0))) |
| 2276 | (beginning-of-line) | 3433 | (point))) |
| 2277 | (point))) | 3434 | (entry (buffer-substring start end))) |
| 2278 | last-command) | 3435 | (delete-region start end) |
| 2279 | (kill-region start end) | ||
| 2280 | (let ((success | 3436 | (let ((success |
| 2281 | (or | 3437 | (or |
| 3438 | called-by-reformat | ||
| 2282 | (not bibtex-maintain-sorted-entries) | 3439 | (not bibtex-maintain-sorted-entries) |
| 2283 | (bibtex-find-entry-location autokey t)))) | 3440 | (bibtex-find-entry-location autokey t)))) |
| 2284 | (yank) | 3441 | (insert entry) |
| 2285 | (setq kill-ring (cdr kill-ring)) | ||
| 2286 | (forward-char -1) | 3442 | (forward-char -1) |
| 2287 | (bibtex-beginning-of-entry) | 3443 | (bibtex-beginning-of-entry) |
| 2288 | (re-search-forward bibtex-reference-head) | 3444 | (re-search-forward bibtex-reference-head) |
| 2289 | (if (not success) | 3445 | (if (not success) |
| 2290 | (error | 3446 | (error |
| 2291 | "New inserted reference may be a duplicate.")))))))) | 3447 | "New inserted reference yields duplicate key.")))))))) |
| 2292 | (save-excursion | 3448 | (if (not called-by-reformat) |
| 2293 | (let ((start (progn (bibtex-beginning-of-entry) (point))) | 3449 | (save-excursion |
| 2294 | (end (progn (bibtex-end-of-entry) (point)))) | 3450 | (save-restriction |
| 2295 | (save-restriction | 3451 | (narrow-to-region |
| 2296 | (narrow-to-region start end) | 3452 | (bibtex-beginning-of-entry) (bibtex-end-of-entry)) |
| 2297 | (bibtex-parse-keys t))))) | 3453 | (bibtex-parse-keys t nil) |
| 3454 | (run-hooks 'bibtex-clean-entry-hook))))) | ||
| 3455 | |||
| 3456 | (defun bibtex-fill-entry () | ||
| 3457 | "Fill current entry. | ||
| 3458 | Realigns entry, so that every field starts on a separate line. Field | ||
| 3459 | names appear in column bibtex-field-indentation, field text starts in | ||
| 3460 | column bibtex-text-indentation and continuation lines start here, too. | ||
| 3461 | If bibtex-align-at-equal-sign is non-nil, equal signs are aligned as | ||
| 3462 | well." | ||
| 3463 | (interactive "*") | ||
| 3464 | (let ((pnt (copy-marker (point))) | ||
| 3465 | (end (copy-marker (bibtex-end-of-entry)))) | ||
| 3466 | (bibtex-beginning-of-entry) | ||
| 3467 | (delete-whitespace) | ||
| 3468 | (indent-to-column bibtex-entry-offset) | ||
| 3469 | (while (re-search-forward bibtex-field end t) | ||
| 3470 | (let* ((begin-field | ||
| 3471 | (copy-marker (match-beginning 0))) | ||
| 3472 | (end-field | ||
| 3473 | (copy-marker (match-end 0))) | ||
| 3474 | (begin-name | ||
| 3475 | (copy-marker (match-beginning bibtex-name-in-field))) | ||
| 3476 | (end-name | ||
| 3477 | (copy-marker (match-end bibtex-name-in-field)))) | ||
| 3478 | (goto-char begin-field) | ||
| 3479 | (forward-char) | ||
| 3480 | (delete-whitespace) | ||
| 3481 | (open-line 1) | ||
| 3482 | (forward-char) | ||
| 3483 | (indent-to-column | ||
| 3484 | (+ bibtex-entry-offset bibtex-field-indentation)) | ||
| 3485 | (re-search-forward "[ \t\n]*=" end) | ||
| 3486 | (replace-match "=") | ||
| 3487 | (forward-char -1) | ||
| 3488 | (if bibtex-align-at-equal-sign | ||
| 3489 | (indent-to-column | ||
| 3490 | (+ bibtex-entry-offset (- bibtex-text-indentation 2))) | ||
| 3491 | (insert " ")) | ||
| 3492 | (forward-char) | ||
| 3493 | (delete-whitespace) | ||
| 3494 | (if bibtex-align-at-equal-sign | ||
| 3495 | (insert " ") | ||
| 3496 | (indent-to-column bibtex-text-indentation)) | ||
| 3497 | (while (re-search-forward "[ \t\n]+" end-field 'move) | ||
| 3498 | (replace-match " ")) | ||
| 3499 | (bibtex-do-auto-fill))) | ||
| 3500 | (if (looking-at ",") | ||
| 3501 | (forward-char)) | ||
| 3502 | (delete-whitespace) | ||
| 3503 | (open-line 1) | ||
| 3504 | (forward-char) | ||
| 3505 | (indent-to-column bibtex-entry-offset) | ||
| 3506 | (goto-char pnt))) | ||
| 3507 | |||
| 3508 | (defun bibtex-reformat (&optional additional-options called-by-convert-alien) | ||
| 3509 | "Reformats entries in buffer or region. | ||
| 3510 | Refills all entries. With prefix argument, read options for | ||
| 3511 | reformatting entries from minibuffer. With double prefix argument, | ||
| 3512 | reuse previous answers (if any) again. | ||
| 3513 | If mark is active it reformats entries in region, if not in whole buffer." | ||
| 3514 | (interactive "*P") | ||
| 3515 | (let* ((pnt (point)) | ||
| 3516 | (use-previous-options | ||
| 3517 | (and (equal (prefix-numeric-value additional-options) 16) | ||
| 3518 | (or bibtex-reformat-previous-options | ||
| 3519 | bibtex-reformat-previous-labels))) | ||
| 3520 | (bibtex-entry-format | ||
| 3521 | (if additional-options | ||
| 3522 | (if use-previous-options | ||
| 3523 | bibtex-reformat-previous-options | ||
| 3524 | (setq | ||
| 3525 | bibtex-reformat-previous-options | ||
| 3526 | (delq | ||
| 3527 | nil | ||
| 3528 | (list | ||
| 3529 | (if (or | ||
| 3530 | called-by-convert-alien | ||
| 3531 | (y-or-n-p | ||
| 3532 | "Realign entries (recommended for files not created by BibTeX mode)? ")) | ||
| 3533 | 'realign) | ||
| 3534 | (if (y-or-n-p | ||
| 3535 | "Remove empty optional and alternative fields? ") | ||
| 3536 | 'opts-or-alts) | ||
| 3537 | (if (y-or-n-p | ||
| 3538 | "Remove delimiters around pure numerical fields? ") | ||
| 3539 | 'numerical-fields) | ||
| 3540 | (if (y-or-n-p (concat | ||
| 3541 | (if bibtex-comma-after-last-field | ||
| 3542 | "Insert" | ||
| 3543 | "Remove") | ||
| 3544 | " comma at end of entry? ")) | ||
| 3545 | 'last-comma) | ||
| 3546 | (if (y-or-n-p | ||
| 3547 | "Substitute double page dashes by single ones? ") | ||
| 3548 | 'page-dashes) | ||
| 3549 | (if (y-or-n-p | ||
| 3550 | "Force delimiters? ") | ||
| 3551 | 'delimiters) | ||
| 3552 | (if (y-or-n-p | ||
| 3553 | "Unify case of entry types and field names? ") | ||
| 3554 | 'unify-case))))) | ||
| 3555 | '(realign))) | ||
| 3556 | (labels | ||
| 3557 | (if additional-options | ||
| 3558 | (if use-previous-options | ||
| 3559 | bibtex-reformat-previous-labels | ||
| 3560 | (setq | ||
| 3561 | bibtex-reformat-previous-labels | ||
| 3562 | (y-or-n-p "Generate automatically new reference labels? "))))) | ||
| 3563 | bibtex-autokey-edit-before-use | ||
| 3564 | (bibtex-sort-ignore-string-entries t) | ||
| 3565 | (start-point | ||
| 3566 | (if mark-active | ||
| 3567 | (region-beginning) | ||
| 3568 | (progn | ||
| 3569 | (bibtex-beginning-of-first-entry) | ||
| 3570 | (skip-to-valid-bibtex-entry) | ||
| 3571 | (point)))) | ||
| 3572 | (end-point | ||
| 3573 | (if mark-active | ||
| 3574 | (region-end) | ||
| 3575 | (point-max))) | ||
| 3576 | (valid-bibtex-entry | ||
| 3577 | (concat | ||
| 3578 | "[ \t\n]+\\(@[ \t]*\\(" | ||
| 3579 | (mapconcat | ||
| 3580 | (lambda (type) | ||
| 3581 | (concat "\\(" (car type) "\\)")) | ||
| 3582 | bibtex-entry-field-alist | ||
| 3583 | "\\|") | ||
| 3584 | "\\)\\)"))) | ||
| 3585 | (save-restriction | ||
| 3586 | (narrow-to-region start-point end-point) | ||
| 3587 | (if (memq 'realign bibtex-entry-format) | ||
| 3588 | (progn | ||
| 3589 | (goto-char (point-min)) | ||
| 3590 | (while (re-search-forward valid-bibtex-entry nil t) | ||
| 3591 | (replace-match "\n\\1")))) | ||
| 3592 | (goto-char start-point) | ||
| 3593 | (bibtex-progress-message "Formatting" 1) | ||
| 3594 | (map-bibtex-entries | ||
| 3595 | (lambda (current) | ||
| 3596 | (bibtex-progress-message) | ||
| 3597 | (bibtex-clean-entry labels labels) | ||
| 3598 | (if (memq 'realign bibtex-entry-format) | ||
| 3599 | (progn | ||
| 3600 | (bibtex-end-of-entry) | ||
| 3601 | (delete-whitespace) | ||
| 3602 | (open-line 2))))) | ||
| 3603 | (bibtex-progress-message 'done)) | ||
| 3604 | (if (and | ||
| 3605 | labels | ||
| 3606 | bibtex-maintain-sorted-entries | ||
| 3607 | (not called-by-convert-alien)) | ||
| 3608 | (progn | ||
| 3609 | (bibtex-sort-buffer) | ||
| 3610 | (setq bibtex-keys nil) | ||
| 3611 | (bibtex-parse-keys nil t t))) | ||
| 3612 | (goto-char pnt))) | ||
| 3613 | |||
| 3614 | (defun bibtex-convert-alien (&optional do-additional-reformatting) | ||
| 3615 | "Converts an alien BibTeX buffer to be fully usable by BibTeX mode. | ||
| 3616 | If a file doesn't confirm with some standards used by BibTeX mode, | ||
| 3617 | some of the high-level features of BibTeX mode won't be available. | ||
| 3618 | This function tries to convert current buffer to confirm with these | ||
| 3619 | standards. | ||
| 3620 | With prefix argument DO-ADDITIONAL-REFORMATTING | ||
| 3621 | non-nil, read options for reformatting entries from minibuffer." | ||
| 3622 | (interactive "*P") | ||
| 3623 | (message "Starting to validate buffer...") | ||
| 3624 | (sit-for 1 nil t) | ||
| 3625 | (goto-char (point-min)) | ||
| 3626 | (while (re-search-forward "[ \t\n]+@" nil t) | ||
| 3627 | (replace-match "\n@")) | ||
| 3628 | (message | ||
| 3629 | "If errors occur, correct them and call `bibtex-convert-alien' again") | ||
| 3630 | (sit-for 5 nil t) | ||
| 3631 | (if (let (mark-active | ||
| 3632 | bibtex-maintain-sorted-entries) | ||
| 3633 | (bibtex-validate)) | ||
| 3634 | (progn | ||
| 3635 | (message "Starting to reformat entries...") | ||
| 3636 | (sit-for 2 nil t) | ||
| 3637 | (bibtex-reformat do-additional-reformatting t) | ||
| 3638 | (if bibtex-maintain-sorted-entries | ||
| 3639 | (progn | ||
| 3640 | (message "Starting to sort buffer...") | ||
| 3641 | (bibtex-sort-buffer))) | ||
| 3642 | (goto-char (point-max)) | ||
| 3643 | (message "Buffer is now parsable. Please save it.")))) | ||
| 2298 | 3644 | ||
| 2299 | (defun bibtex-complete-string () | 3645 | (defun bibtex-complete-string () |
| 2300 | "Complete word fragment before point to longest prefix of a defined string. | 3646 | "Complete word fragment before point to longest prefix of a defined string. |
| 2301 | If point is not after the part of a word, all strings are listed." | 3647 | If point is not after the part of a word, all strings are listed. |
| 3648 | Remove surrounding delimiters if complete string could be expanded." | ||
| 2302 | (interactive "*") | 3649 | (interactive "*") |
| 2303 | (let* ((end (point)) | 3650 | (bibtex-complete bibtex-strings t)) |
| 2304 | (beg (save-excursion | 3651 | |
| 2305 | (re-search-backward "[ \t{\"]") | 3652 | (defun bibtex-complete-key () |
| 2306 | (forward-char 1) | 3653 | "Complete word fragment before point to longest prefix of a defined key. |
| 2307 | (point))) | 3654 | If point is not after the part of a word, all keys are listed. This |
| 2308 | (part-of-word (buffer-substring-no-properties beg end)) | 3655 | function is most useful in completing crossref entries." |
| 2309 | (string-list (copy-sequence bibtex-completion-candidates)) | 3656 | (interactive "*") |
| 2310 | (case-fold-search t) | 3657 | (if (not bibtex-keys) |
| 2311 | (completion (save-excursion | 3658 | (bibtex-parse-keys nil t)) |
| 2312 | (while (re-search-backward | 3659 | (bibtex-complete bibtex-keys)) |
| 2313 | bibtex-string (point-min) t) | ||
| 2314 | (setq string-list | ||
| 2315 | (cons | ||
| 2316 | (list | ||
| 2317 | (buffer-substring-no-properties | ||
| 2318 | (match-beginning bibtex-key-in-string) | ||
| 2319 | (match-end bibtex-key-in-string))) | ||
| 2320 | string-list))) | ||
| 2321 | (setq string-list | ||
| 2322 | (sort string-list | ||
| 2323 | (lambda(x y) | ||
| 2324 | (string-lessp | ||
| 2325 | (car x) | ||
| 2326 | (car y))))) | ||
| 2327 | (try-completion part-of-word string-list)))) | ||
| 2328 | (cond ((eq completion t) | ||
| 2329 | ;; remove double-quotes or braces if field is no concatenation | ||
| 2330 | (save-excursion | ||
| 2331 | (bibtex-inside-field) | ||
| 2332 | (bibtex-enclosing-field) | ||
| 2333 | (let ((end (match-end bibtex-text-in-field))) | ||
| 2334 | (goto-char (match-beginning bibtex-text-in-field)) | ||
| 2335 | (if (and | ||
| 2336 | (looking-at bibtex-field-string) | ||
| 2337 | (equal (match-end 0) end)) | ||
| 2338 | (bibtex-remove-double-quotes-or-braces))))) | ||
| 2339 | ((null completion) | ||
| 2340 | (error "Can't find completion for \"%s\"" part-of-word)) | ||
| 2341 | ((not (string= part-of-word completion)) | ||
| 2342 | (delete-region beg end) | ||
| 2343 | (insert completion) | ||
| 2344 | (if (assoc completion string-list) | ||
| 2345 | ;; remove double-quotes or braces if field is no concatenation | ||
| 2346 | (save-excursion | ||
| 2347 | (bibtex-inside-field) | ||
| 2348 | (bibtex-enclosing-field) | ||
| 2349 | (let ((end (match-end bibtex-text-in-field))) | ||
| 2350 | (goto-char (match-beginning bibtex-text-in-field)) | ||
| 2351 | (if (and | ||
| 2352 | (looking-at bibtex-field-string) | ||
| 2353 | (equal (match-end 0) end)) | ||
| 2354 | (bibtex-remove-double-quotes-or-braces)))))) | ||
| 2355 | (t | ||
| 2356 | (message "Making completion list...") | ||
| 2357 | (let ((list (all-completions part-of-word string-list))) | ||
| 2358 | (with-output-to-temp-buffer "*Completions*" | ||
| 2359 | (display-completion-list list))) | ||
| 2360 | (message "Making completion list...done"))))) | ||
| 2361 | 3660 | ||
| 2362 | (defun bibtex-Article () | 3661 | (defun bibtex-Article () |
| 2363 | (interactive) | 3662 | (interactive) |
| @@ -2411,22 +3710,52 @@ If point is not after the part of a word, all strings are listed." | |||
| 2411 | (interactive) | 3710 | (interactive) |
| 2412 | (bibtex-entry "Unpublished")) | 3711 | (bibtex-entry "Unpublished")) |
| 2413 | 3712 | ||
| 2414 | (defun bibtex-string () | 3713 | (defun bibtex-String () |
| 2415 | (interactive) | 3714 | (interactive) |
| 2416 | (bibtex-move-outside-of-entry) | 3715 | (if (not bibtex-keys) |
| 2417 | (insert | 3716 | (bibtex-parse-keys nil t)) |
| 2418 | (concat | 3717 | (let ((key |
| 2419 | "@string{ = " | 3718 | (if (and |
| 2420 | bibtex-field-left-delimiter | 3719 | bibtex-maintain-sorted-entries |
| 2421 | bibtex-field-right-delimiter | 3720 | (not bibtex-sort-ignore-string-entries)) |
| 2422 | "}\n")) | 3721 | (completing-read |
| 3722 | "String key: " bibtex-keys nil nil nil 'bibtex-key-history)))) | ||
| 3723 | (if (and | ||
| 3724 | bibtex-maintain-sorted-entries | ||
| 3725 | (not bibtex-sort-ignore-string-entries)) | ||
| 3726 | (bibtex-find-entry-location key) | ||
| 3727 | (bibtex-move-outside-of-entry)) | ||
| 3728 | (indent-to-column bibtex-entry-offset) | ||
| 3729 | (insert | ||
| 3730 | (concat | ||
| 3731 | "@String" | ||
| 3732 | (bibtex-entry-left-delimiter) | ||
| 3733 | (if (and | ||
| 3734 | bibtex-maintain-sorted-entries | ||
| 3735 | (not bibtex-sort-ignore-string-entries)) | ||
| 3736 | key) | ||
| 3737 | " = " | ||
| 3738 | (bibtex-field-left-delimiter) | ||
| 3739 | (bibtex-field-right-delimiter) | ||
| 3740 | (bibtex-entry-right-delimiter) | ||
| 3741 | "\n")) | ||
| 2423 | (forward-line -1) | 3742 | (forward-line -1) |
| 2424 | (forward-char 8)) | 3743 | (forward-char |
| 2425 | 3744 | (if (and | |
| 2426 | (defun bibtex-preamble () | 3745 | bibtex-maintain-sorted-entries |
| 3746 | (not bibtex-sort-ignore-string-entries)) | ||
| 3747 | (+ (length "@String{") (length key) (length " = {")) | ||
| 3748 | (length "@String{"))))) | ||
| 3749 | |||
| 3750 | (defun bibtex-Preamble () | ||
| 2427 | (interactive) | 3751 | (interactive) |
| 2428 | (bibtex-move-outside-of-entry) | 3752 | (bibtex-move-outside-of-entry) |
| 2429 | (insert "@Preamble{}\n") | 3753 | (indent-to-column bibtex-entry-offset) |
| 3754 | (insert | ||
| 3755 | "@Preamble" | ||
| 3756 | (bibtex-entry-left-delimiter) | ||
| 3757 | (bibtex-entry-right-delimiter) | ||
| 3758 | "\n") | ||
| 2430 | (forward-line -1) | 3759 | (forward-line -1) |
| 2431 | (forward-char 10)) | 3760 | (forward-char 10)) |
| 2432 | 3761 | ||