diff options
| author | Richard M. Stallman | 1995-07-27 22:52:02 +0000 |
|---|---|---|
| committer | Richard M. Stallman | 1995-07-27 22:52:02 +0000 |
| commit | 5c69dbfc013af5857e50f064ef62aeff7e7cbacc (patch) | |
| tree | a924d8fd6a35e33d82be26989d8913e75eaf5bc0 /lisp | |
| parent | cb26008f395fc3488550eb0b767e48618d38ba07 (diff) | |
| download | emacs-5c69dbfc013af5857e50f064ef62aeff7e7cbacc.tar.gz emacs-5c69dbfc013af5857e50f064ef62aeff7e7cbacc.zip | |
Add keywords and comments as per conventions.
Changed almost all occurences of buffer-substring to
buffer-substring-no-properties..
(bibtex-find-entry-location, bibtex-clean-entry):
Added support to handle invalidate buffers in a more friendly manner.
(bibtex-make-field): Changed to be called either interactively with a
string (field name) or from Lisp with a list of two strings (FIELDNAME
COMMENT).
Diffstat (limited to 'lisp')
| -rw-r--r-- | lisp/textmodes/bibtex.el | 163 |
1 files changed, 93 insertions, 70 deletions
diff --git a/lisp/textmodes/bibtex.el b/lisp/textmodes/bibtex.el index f5f6d707d13..6edc5990a54 100644 --- a/lisp/textmodes/bibtex.el +++ b/lisp/textmodes/bibtex.el | |||
| @@ -26,21 +26,17 @@ | |||
| 26 | ;; along with GNU Emacs; see the file COPYING. If not, write to | 26 | ;; along with GNU Emacs; see the file COPYING. If not, write to |
| 27 | ;; the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. | 27 | ;; the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. |
| 28 | 28 | ||
| 29 | ;;; TODO: | 29 | ;;; Commentary: |
| 30 | ;; Distribute texinfo file. | ||
| 31 | ;; A better concept for intermixing quote and brace delimiters is | ||
| 32 | ;; needed. | ||
| 33 | |||
| 34 | ;;; PURPOSE: | ||
| 35 | ;; Major mode for editing and validating BibTeX files. | 30 | ;; Major mode for editing and validating BibTeX files. |
| 36 | 31 | ||
| 37 | 32 | ;; Usage: | |
| 38 | ;;; USAGE: | ||
| 39 | ;; See documentation for function bibtex-mode (or type "\M-x describe-mode" | 33 | ;; See documentation for function bibtex-mode (or type "\M-x describe-mode" |
| 40 | ;; when you are in bibtex-mode). | 34 | ;; when you are in bibtex-mode). |
| 41 | 35 | ||
| 36 | ;; Todo: | ||
| 37 | ;; Distribute texinfo file. | ||
| 42 | 38 | ||
| 43 | ;;; KNOWN BUGS: | 39 | ;; Known Bugs: |
| 44 | ;; 1. using regular expressions to match the entire BibTeX entry dies | 40 | ;; 1. using regular expressions to match the entire BibTeX entry dies |
| 45 | ;; on long entries (e.g. those containing abstracts) since | 41 | ;; on long entries (e.g. those containing abstracts) since |
| 46 | ;; the length of regular expression matches is fairly limited. | 42 | ;; the length of regular expression matches is fairly limited. |
| @@ -48,10 +44,11 @@ | |||
| 48 | ;; error message "Can't find enclosing Bibtex field" instead of | 44 | ;; error message "Can't find enclosing Bibtex field" instead of |
| 49 | ;; moving to the empty string. [reported by gernot@cs.unsw.oz.au] | 45 | ;; moving to the empty string. [reported by gernot@cs.unsw.oz.au] |
| 50 | 46 | ||
| 51 | ;;; (current keeper: schoef@informatik.uni-oldenburg.de | 47 | ;; (current keeper: schoef@informatik.uni-oldenburg.de |
| 52 | ;;; previous: alarson@src.honeywell.com) | 48 | ;; previous: alarson@src.honeywell.com) |
| 53 | 49 | ||
| 54 | ;;; USER OPTIONS: | 50 | ;;; Code: |
| 51 | ;; User Options: | ||
| 55 | 52 | ||
| 56 | (defvar bibtex-field-left-delimiter "{" | 53 | (defvar bibtex-field-left-delimiter "{" |
| 57 | "*Set this to { or \" according to your personal preferences. | 54 | "*Set this to { or \" according to your personal preferences. |
| @@ -402,7 +399,7 @@ See the documentation of function bibtex-generate-autokey for further detail.") | |||
| 402 | 399 | ||
| 403 | 400 | ||
| 404 | 401 | ||
| 405 | ;;; SYNTAX TABLE, KEYBINDINGS and BIBTEX-ENTRY-LIST | 402 | ;; Syntax Table, Keybindings and BibTeX Entry List |
| 406 | (defvar bibtex-mode-syntax-table | 403 | (defvar bibtex-mode-syntax-table |
| 407 | (let ((st (make-syntax-table))) | 404 | (let ((st (make-syntax-table))) |
| 408 | ;; [alarson:19920214.1004CST] make double quote a string quote | 405 | ;; [alarson:19920214.1004CST] make double quote a string quote |
| @@ -522,7 +519,7 @@ See the documentation of function bibtex-generate-autokey for further detail.") | |||
| 522 | 519 | ||
| 523 | 520 | ||
| 524 | 521 | ||
| 525 | ;;; INTERNAL VARIABLES | 522 | ;; Internal Variables |
| 526 | 523 | ||
| 527 | (defvar bibtex-pop-previous-search-point nil) | 524 | (defvar bibtex-pop-previous-search-point nil) |
| 528 | ;; Next point where bibtex-pop-previous starts looking for a similar | 525 | ;; Next point where bibtex-pop-previous starts looking for a similar |
| @@ -538,7 +535,7 @@ See the documentation of function bibtex-generate-autokey for further detail.") | |||
| 538 | (make-variable-buffer-local 'bibtex-completion-candidates) | 535 | (make-variable-buffer-local 'bibtex-completion-candidates) |
| 539 | 536 | ||
| 540 | 537 | ||
| 541 | ;;; FUNCTIONS to parse the BibTeX entries | 538 | ;; Functions to Parse the BibTeX Entries |
| 542 | 539 | ||
| 543 | (defun bibtex-cfield (name text) | 540 | (defun bibtex-cfield (name text) |
| 544 | ;; Create a regexp for a BibTeX field of name NAME and text TEXT. | 541 | ;; Create a regexp for a BibTeX field of name NAME and text TEXT. |
| @@ -650,7 +647,7 @@ See the documentation of function bibtex-generate-autokey for further detail.") | |||
| 650 | 647 | ||
| 651 | 648 | ||
| 652 | 649 | ||
| 653 | ;;; HELPER FUNCTIONS | 650 | ;; Helper Functions |
| 654 | 651 | ||
| 655 | (defun assoc-ignore-case (string alist) | 652 | (defun assoc-ignore-case (string alist) |
| 656 | ;; Return non-nil if STRING is `equal' to the car of an element of | 653 | ;; Return non-nil if STRING is `equal' to the car of an element of |
| @@ -718,11 +715,12 @@ See the documentation of function bibtex-generate-autokey for further detail.") | |||
| 718 | (while (re-search-forward "^@[^{]*{[ \t]*\\([^, ]*\\)" nil t) | 715 | (while (re-search-forward "^@[^{]*{[ \t]*\\([^, ]*\\)" nil t) |
| 719 | (if (and bibtex-sort-ignore-string-entries | 716 | (if (and bibtex-sort-ignore-string-entries |
| 720 | (string-equal "@string{" | 717 | (string-equal "@string{" |
| 721 | (downcase (buffer-substring | 718 | (downcase (buffer-substring-no-properties |
| 722 | (match-beginning 0) | 719 | (match-beginning 0) |
| 723 | (match-beginning 1))))) | 720 | (match-beginning 1))))) |
| 724 | nil | 721 | nil |
| 725 | (funcall fun (buffer-substring (match-beginning 1) (match-end 1)))))) | 722 | (funcall fun (buffer-substring-no-properties |
| 723 | (match-beginning 1) (match-end 1)))))) | ||
| 726 | 724 | ||
| 727 | (defun bibtex-flash-head () | 725 | (defun bibtex-flash-head () |
| 728 | ;; Flash at BibTeX reference head before point, if exists. | 726 | ;; Flash at BibTeX reference head before point, if exists. |
| @@ -951,7 +949,7 @@ The generation algorithm works as follows: | |||
| 951 | (bibtex-find-text nil) | 949 | (bibtex-find-text nil) |
| 952 | (point)))) | 950 | (point)))) |
| 953 | (bibtex-autokey-change | 951 | (bibtex-autokey-change |
| 954 | (buffer-substring start end) | 952 | (buffer-substring-no-properties start end) |
| 955 | bibtex-autokey-name-change-strings)) | 953 | bibtex-autokey-name-change-strings)) |
| 956 | ""))) | 954 | ""))) |
| 957 | (namelist | 955 | (namelist |
| @@ -999,7 +997,8 @@ The generation algorithm works as follows: | |||
| 999 | (goto-char min) | 997 | (goto-char min) |
| 1000 | (if (search-forward-regexp | 998 | (if (search-forward-regexp |
| 1001 | "^[ \t]*year[ \t]*=[ \t]*\\([0-9]*\\)" max t) | 999 | "^[ \t]*year[ \t]*=[ \t]*\\([0-9]*\\)" max t) |
| 1002 | (buffer-substring (match-beginning 1) (match-end 1)) | 1000 | (buffer-substring-no-properties |
| 1001 | (match-beginning 1) (match-end 1)) | ||
| 1003 | ""))) | 1002 | ""))) |
| 1004 | (yearpart | 1003 | (yearpart |
| 1005 | (if (equal yearfield "") | 1004 | (if (equal yearfield "") |
| @@ -1022,7 +1021,7 @@ The generation algorithm works as follows: | |||
| 1022 | (bibtex-find-text nil) | 1021 | (bibtex-find-text nil) |
| 1023 | (point)))) | 1022 | (point)))) |
| 1024 | (bibtex-autokey-change | 1023 | (bibtex-autokey-change |
| 1025 | (buffer-substring start end) | 1024 | (buffer-substring-no-properties start end) |
| 1026 | bibtex-autokey-titleword-change-strings)) | 1025 | bibtex-autokey-titleword-change-strings)) |
| 1027 | ""))) | 1026 | ""))) |
| 1028 | case-fold-search | 1027 | case-fold-search |
| @@ -1115,7 +1114,7 @@ The generation algorithm works as follows: | |||
| 1115 | 1114 | ||
| 1116 | 1115 | ||
| 1117 | 1116 | ||
| 1118 | ;;; INTERACTIVE FUNCTIONS: | 1117 | ;; Interactive Functions: |
| 1119 | 1118 | ||
| 1120 | ;;;###autoload | 1119 | ;;;###autoload |
| 1121 | (defun bibtex-mode () | 1120 | (defun bibtex-mode () |
| @@ -1233,7 +1232,7 @@ non-nil." | |||
| 1233 | (append | 1232 | (append |
| 1234 | compl | 1233 | compl |
| 1235 | (list | 1234 | (list |
| 1236 | (list (buffer-substring | 1235 | (list (buffer-substring-no-properties |
| 1237 | (match-beginning bibtex-name-in-string) | 1236 | (match-beginning bibtex-name-in-string) |
| 1238 | (match-end bibtex-name-in-string))))))) | 1237 | (match-end bibtex-name-in-string))))))) |
| 1239 | (kill-buffer bufname) | 1238 | (kill-buffer bufname) |
| @@ -1283,9 +1282,9 @@ non-nil." | |||
| 1283 | "\\(^@[a-z]+[ \t\n]*[{(][ \t\n]*\\([^ ,\t\n]+\\)[ \t\n]*,\\)\\|\\(^[ \t\n]*crossref[ \t\n]*=[ \t\n]*[{\"]\\([^ ,\t\n]*\\)[}\"],$\\)" | 1282 | "\\(^@[a-z]+[ \t\n]*[{(][ \t\n]*\\([^ ,\t\n]+\\)[ \t\n]*,\\)\\|\\(^[ \t\n]*crossref[ \t\n]*=[ \t\n]*[{\"]\\([^ ,\t\n]*\\)[}\"],$\\)" |
| 1284 | nil t) | 1283 | nil t) |
| 1285 | (if (match-beginning 2) | 1284 | (if (match-beginning 2) |
| 1286 | (setq label (buffer-substring | 1285 | (setq label (buffer-substring-no-properties |
| 1287 | (match-beginning 2) (match-end 2))) | 1286 | (match-beginning 2) (match-end 2))) |
| 1288 | (setq label (buffer-substring | 1287 | (setq label (buffer-substring-no-properties |
| 1289 | (match-beginning 4) (match-end 4)))) | 1288 | (match-beginning 4) (match-end 4)))) |
| 1290 | (if (not (assoc label labels)) | 1289 | (if (not (assoc label labels)) |
| 1291 | (setq labels | 1290 | (setq labels |
| @@ -1331,7 +1330,7 @@ non-nil." | |||
| 1331 | "^[ \t]*\\([A-Za-z]+\\)[ \t\n]*=" nil t) | 1330 | "^[ \t]*\\([A-Za-z]+\\)[ \t\n]*=" nil t) |
| 1332 | (let ((mb (match-beginning 1)) | 1331 | (let ((mb (match-beginning 1)) |
| 1333 | (me (match-end 1))) | 1332 | (me (match-end 1))) |
| 1334 | (buffer-substring | 1333 | (buffer-substring-no-properties |
| 1335 | (if (looking-at "^[ \t]*OPT") | 1334 | (if (looking-at "^[ \t]*OPT") |
| 1336 | (+ 3 mb) | 1335 | (+ 3 mb) |
| 1337 | mb) | 1336 | mb) |
| @@ -1340,7 +1339,8 @@ non-nil." | |||
| 1340 | (progn | 1339 | (progn |
| 1341 | (re-search-backward | 1340 | (re-search-backward |
| 1342 | "^@\\([A-Za-z]+\\)[ \t\n]*[{(][^, \t\n]*[ \t\n]*," nil t) | 1341 | "^@\\([A-Za-z]+\\)[ \t\n]*[{(][^, \t\n]*[ \t\n]*," nil t) |
| 1343 | (buffer-substring (match-beginning 1) (match-end 1)))) | 1342 | (buffer-substring-no-properties |
| 1343 | (match-beginning 1) (match-end 1)))) | ||
| 1344 | (entry-list | 1344 | (entry-list |
| 1345 | (assoc-ignore-case reference-type | 1345 | (assoc-ignore-case reference-type |
| 1346 | bibtex-entry-field-alist)) | 1346 | bibtex-entry-field-alist)) |
| @@ -1374,7 +1374,11 @@ non-nil." | |||
| 1374 | (defun bibtex-make-field (e-t) | 1374 | (defun bibtex-make-field (e-t) |
| 1375 | "Makes a field named E-T in current BibTeX entry." | 1375 | "Makes a field named E-T in current BibTeX entry." |
| 1376 | (interactive "sBibTeX entry type: ") | 1376 | (interactive "sBibTeX entry type: ") |
| 1377 | (let ((name (elt e-t 0))) | 1377 | (let ((name (if (consp e-t) |
| 1378 | (elt e-t 0) | ||
| 1379 | e-t))) | ||
| 1380 | (bibtex-find-text nil) | ||
| 1381 | (forward-char 1) | ||
| 1378 | (insert ",\n") | 1382 | (insert ",\n") |
| 1379 | (indent-to-column bibtex-name-alignment) | 1383 | (indent-to-column bibtex-name-alignment) |
| 1380 | (insert name " = ") | 1384 | (insert name " = ") |
| @@ -1491,7 +1495,7 @@ Bugs: | |||
| 1491 | (string-equal | 1495 | (string-equal |
| 1492 | "@string" | 1496 | "@string" |
| 1493 | (downcase | 1497 | (downcase |
| 1494 | (buffer-substring | 1498 | (buffer-substring-no-properties |
| 1495 | (match-beginning 1) | 1499 | (match-beginning 1) |
| 1496 | (match-end 1)))))) | 1500 | (match-end 1)))))) |
| 1497 | nil)) | 1501 | nil)) |
| @@ -1503,18 +1507,20 @@ Bugs: | |||
| 1503 | (lambda () | 1507 | (lambda () |
| 1504 | (search-forward ",")))))) | 1508 | (search-forward ",")))))) |
| 1505 | 1509 | ||
| 1506 | (defun bibtex-find-entry-location (entry-name &optional maybedup) | 1510 | (defun bibtex-find-entry-location (entry-name &optional ignore-errors) |
| 1507 | "Looking for place to put the BibTeX entry named ENTRY-NAME. | 1511 | "Looking for place to put the BibTeX entry named ENTRY-NAME. |
| 1508 | Searches from beginning of buffer. Buffer is assumed to be in sorted | 1512 | Searches from beginning of buffer. Buffer is assumed to be in sorted |
| 1509 | order, without duplicates (see \\[bibtex-sort-entries]), if it is not, | 1513 | order, without duplicates (see \\[bibtex-sort-entries]), if it is not, |
| 1510 | an error will be signalled. If optional argument MAYBEDUP is non-nil | 1514 | an error will be signalled. However, if optional argument |
| 1511 | no error/warning messages about ENTRY-NAME being a (potential) | 1515 | IGNORE-ERRORS is non-nil, no error messages about duplicate entries or |
| 1512 | duplicate of an existing entry will be emitted. This function returns | 1516 | sort order violences are signalled, but the error handling is assumed |
| 1513 | `nil' if ENTRY-NAME is a duplicate of an existing entry and t in all | 1517 | to be made in the calling function. Nil is returned, if any error |
| 1514 | other cases." | 1518 | occured during search for location of the new entry, and t in all |
| 1519 | other cases. If an error occured, point is not moved." | ||
| 1515 | (interactive "sBibtex entry key: ") | 1520 | (interactive "sBibtex entry key: ") |
| 1516 | (let ((nodup t) | 1521 | (let ((noerr t) |
| 1517 | (previous nil) | 1522 | (previous nil) |
| 1523 | (pnt (point)) | ||
| 1518 | point) | 1524 | point) |
| 1519 | (beginning-of-first-bibtex-entry) | 1525 | (beginning-of-first-bibtex-entry) |
| 1520 | (or | 1526 | (or |
| @@ -1523,9 +1529,9 @@ other cases." | |||
| 1523 | (function | 1529 | (function |
| 1524 | (lambda (current) | 1530 | (lambda (current) |
| 1525 | (cond ((string-equal entry-name current) | 1531 | (cond ((string-equal entry-name current) |
| 1526 | (setq nodup nil) | 1532 | (setq noerr nil) |
| 1527 | (bibtex-beginning-of-entry) | 1533 | (bibtex-beginning-of-entry) |
| 1528 | (if maybedup | 1534 | (if ignore-errors |
| 1529 | (throw 'done t) | 1535 | (throw 'done t) |
| 1530 | (error "Entry duplicates existing!"))) | 1536 | (error "Entry duplicates existing!"))) |
| 1531 | ((or (null previous) | 1537 | ((or (null previous) |
| @@ -1545,7 +1551,7 @@ other cases." | |||
| 1545 | (if (and | 1551 | (if (and |
| 1546 | (integerp idx) | 1552 | (integerp idx) |
| 1547 | (zerop idx) | 1553 | (zerop idx) |
| 1548 | (not maybedup) | 1554 | ;; (not ignore-errors) |
| 1549 | (not (equal entry-name ""))) | 1555 | (not (equal entry-name ""))) |
| 1550 | (progn | 1556 | (progn |
| 1551 | (message | 1557 | (message |
| @@ -1554,10 +1560,19 @@ other cases." | |||
| 1554 | (ding t)))) | 1560 | (ding t)))) |
| 1555 | (throw 'done t)))) | 1561 | (throw 'done t)))) |
| 1556 | ((string-equal previous current) | 1562 | ((string-equal previous current) |
| 1557 | (error "Duplicate here with previous!")) | 1563 | (setq noerr nil) |
| 1558 | (t (error "Entries out of order here!"))))))) | 1564 | (if ignore-errors |
| 1565 | (throw 'done t) | ||
| 1566 | (error "Duplicate here with previous!"))) | ||
| 1567 | (t | ||
| 1568 | (setq noerr nil) | ||
| 1569 | (if ignore-errors | ||
| 1570 | (throw 'done t) | ||
| 1571 | (error "Entries out of order here!")))))))) | ||
| 1559 | (goto-char (point-max))) | 1572 | (goto-char (point-max))) |
| 1560 | nodup)) | 1573 | (if (not noerr) |
| 1574 | (goto-char pnt)) | ||
| 1575 | noerr)) | ||
| 1561 | 1576 | ||
| 1562 | (defun bibtex-validate-buffer () | 1577 | (defun bibtex-validate-buffer () |
| 1563 | "Validate if the current BibTeX buffer is syntactically correct. | 1578 | "Validate if the current BibTeX buffer is syntactically correct. |
| @@ -1693,10 +1708,10 @@ intermixed with \\[bibtex-pop-next] (bibtex-pop-next)." | |||
| 1693 | ; construct regexp for previous field with same name as this one | 1708 | ; construct regexp for previous field with same name as this one |
| 1694 | (let ((matching-entry | 1709 | (let ((matching-entry |
| 1695 | (bibtex-cfield | 1710 | (bibtex-cfield |
| 1696 | (buffer-substring (if (looking-at "OPT") | 1711 | (buffer-substring-no-properties (if (looking-at "OPT") |
| 1697 | (+ (point) (length "OPT")) | 1712 | (+ (point) (length "OPT")) |
| 1698 | (point)) | 1713 | (point)) |
| 1699 | stop-name) | 1714 | stop-name) |
| 1700 | bibtex-field-text))) | 1715 | bibtex-field-text))) |
| 1701 | ; if executed several times in a row, start each search where the | 1716 | ; if executed several times in a row, start each search where the |
| 1702 | ; last one finished | 1717 | ; last one finished |
| @@ -1713,8 +1728,9 @@ intermixed with \\[bibtex-pop-next] (bibtex-pop-next)." | |||
| 1713 | (cond | 1728 | (cond |
| 1714 | ((re-search-backward matching-entry (point-min) t arg) | 1729 | ((re-search-backward matching-entry (point-min) t arg) |
| 1715 | (setq new-text | 1730 | (setq new-text |
| 1716 | (buffer-substring (match-beginning bibtex-text-in-cfield) | 1731 | (buffer-substring-no-properties |
| 1717 | (match-end bibtex-text-in-cfield))) | 1732 | (match-beginning bibtex-text-in-cfield) |
| 1733 | (match-end bibtex-text-in-cfield))) | ||
| 1718 | ;; change delimiters, if any changes needed | 1734 | ;; change delimiters, if any changes needed |
| 1719 | (cond | 1735 | (cond |
| 1720 | ((and | 1736 | ((and |
| @@ -1768,10 +1784,10 @@ intermixed with \\[bibtex-pop-previous] (bibtex-pop-previous)." | |||
| 1768 | ; ignoring possible OPT's | 1784 | ; ignoring possible OPT's |
| 1769 | (let ((matching-entry | 1785 | (let ((matching-entry |
| 1770 | (bibtex-cfield | 1786 | (bibtex-cfield |
| 1771 | (buffer-substring (if (looking-at "OPT") | 1787 | (buffer-substring-no-properties (if (looking-at "OPT") |
| 1772 | (+ (point) (length "OPT")) | 1788 | (+ (point) (length "OPT")) |
| 1773 | (point)) | 1789 | (point)) |
| 1774 | stop-name) | 1790 | stop-name) |
| 1775 | bibtex-field-text))) | 1791 | bibtex-field-text))) |
| 1776 | 1792 | ||
| 1777 | ; if executed several times in a row, start each search where the | 1793 | ; if executed several times in a row, start each search where the |
| @@ -1790,8 +1806,9 @@ intermixed with \\[bibtex-pop-previous] (bibtex-pop-previous)." | |||
| 1790 | (cond | 1806 | (cond |
| 1791 | ((re-search-forward matching-entry (point-max) t arg) | 1807 | ((re-search-forward matching-entry (point-max) t arg) |
| 1792 | (setq new-text | 1808 | (setq new-text |
| 1793 | (buffer-substring (match-beginning bibtex-text-in-cfield) | 1809 | (buffer-substring-no-properties |
| 1794 | (match-end bibtex-text-in-cfield))) | 1810 | (match-beginning bibtex-text-in-cfield) |
| 1811 | (match-end bibtex-text-in-cfield))) | ||
| 1795 | ;; change delimiters, if any changes needed | 1812 | ;; change delimiters, if any changes needed |
| 1796 | (cond | 1813 | (cond |
| 1797 | ((and | 1814 | ((and |
| @@ -1882,11 +1899,12 @@ given, calculate a new entry label." | |||
| 1882 | (not crossref-there) | 1899 | (not crossref-there) |
| 1883 | (assoc | 1900 | (assoc |
| 1884 | (downcase | 1901 | (downcase |
| 1885 | (buffer-substring | 1902 | (buffer-substring-no-properties |
| 1886 | (+ (length "OPT") begin-name) end-name)) | 1903 | (+ (length "OPT") begin-name) end-name)) |
| 1887 | (car (car (cdr | 1904 | (car (car (cdr |
| 1888 | (assoc-ignore-case | 1905 | (assoc-ignore-case |
| 1889 | (buffer-substring begin-type end-type) | 1906 | (buffer-substring-no-properties |
| 1907 | begin-type end-type) | ||
| 1890 | bibtex-entry-field-alist)))))) | 1908 | bibtex-entry-field-alist)))))) |
| 1891 | ;; field is not really optional | 1909 | ;; field is not really optional |
| 1892 | (progn | 1910 | (progn |
| @@ -1899,8 +1917,9 @@ given, calculate a new entry label." | |||
| 1899 | (forward-char) | 1917 | (forward-char) |
| 1900 | ;; and loop to go through next test | 1918 | ;; and loop to go through next test |
| 1901 | (error "Mandatory field ``%s'' is empty" | 1919 | (error "Mandatory field ``%s'' is empty" |
| 1902 | (buffer-substring begin-name | 1920 | (buffer-substring-no-properties |
| 1903 | end-name))) | 1921 | begin-name |
| 1922 | end-name))) | ||
| 1904 | ;; field is optional | 1923 | ;; field is optional |
| 1905 | (delete-region begin-field end-field)) | 1924 | (delete-region begin-field end-field)) |
| 1906 | ;; otherwise: not empty, delete "OPT" | 1925 | ;; otherwise: not empty, delete "OPT" |
| @@ -1932,16 +1951,17 @@ given, calculate a new entry label." | |||
| 1932 | bibtex-field-right-delimiter)) | 1951 | bibtex-field-right-delimiter)) |
| 1933 | ;; if empty quotes, complain | 1952 | ;; if empty quotes, complain |
| 1934 | (forward-char 1) | 1953 | (forward-char 1) |
| 1935 | (if (not (or (equal (buffer-substring | 1954 | (if (not (or (equal (buffer-substring-no-properties |
| 1936 | begin-name | 1955 | begin-name |
| 1937 | (+ begin-name 3)) | 1956 | (+ begin-name 3)) |
| 1938 | "OPT") | 1957 | "OPT") |
| 1939 | (equal (buffer-substring | 1958 | (equal (buffer-substring-no-properties |
| 1940 | begin-name | 1959 | begin-name |
| 1941 | (+ begin-name 3)) | 1960 | (+ begin-name 3)) |
| 1942 | "opt"))) | 1961 | "opt"))) |
| 1943 | (error "Mandatory field ``%s'' is empty" | 1962 | (error "Mandatory field ``%s'' is empty" |
| 1944 | (buffer-substring begin-name end-name)))) | 1963 | (buffer-substring-no-properties |
| 1964 | begin-name end-name)))) | ||
| 1945 | (t | 1965 | (t |
| 1946 | (goto-char end-field))))))))) | 1966 | (goto-char end-field))))))))) |
| 1947 | (goto-char start) | 1967 | (goto-char start) |
| @@ -1959,7 +1979,7 @@ given, calculate a new entry label." | |||
| 1959 | (bibtex-beginning-of-entry) | 1979 | (bibtex-beginning-of-entry) |
| 1960 | (if (search-forward-regexp | 1980 | (if (search-forward-regexp |
| 1961 | bibtex-reference-head eob t) | 1981 | bibtex-reference-head eob t) |
| 1962 | (buffer-substring | 1982 | (buffer-substring-no-properties |
| 1963 | (match-beginning bibtex-key-in-head) | 1983 | (match-beginning bibtex-key-in-head) |
| 1964 | (match-end bibtex-key-in-head)))))) | 1984 | (match-end bibtex-key-in-head)))))) |
| 1965 | (if (or | 1985 | (if (or |
| @@ -1988,12 +2008,14 @@ given, calculate a new entry label." | |||
| 1988 | (kill-region start end) | 2008 | (kill-region start end) |
| 1989 | (let ((success (bibtex-find-entry-location autokey t))) | 2009 | (let ((success (bibtex-find-entry-location autokey t))) |
| 1990 | (yank) | 2010 | (yank) |
| 1991 | (bibtex-beginning-of-entry) | ||
| 1992 | (search-forward-regexp bibtex-reference-head) | ||
| 1993 | (setq kill-ring (cdr kill-ring)) | 2011 | (setq kill-ring (cdr kill-ring)) |
| 2012 | (if success | ||
| 2013 | (bibtex-beginning-of-entry) | ||
| 2014 | (goto-char start)) | ||
| 2015 | (search-forward-regexp bibtex-reference-head) | ||
| 1994 | (if (not success) | 2016 | (if (not success) |
| 1995 | (error | 2017 | (error |
| 1996 | "Duplicated key (change manually and enter `bibtex-sort-entries')"))))))))) | 2018 | "BibTeX buffer was or has become invalid (call `bibtex-validate-buffer')"))))))))) |
| 1997 | 2019 | ||
| 1998 | (defun bibtex-complete-string () | 2020 | (defun bibtex-complete-string () |
| 1999 | "Complete word fragment before point to longest prefix of a defined string. | 2021 | "Complete word fragment before point to longest prefix of a defined string. |
| @@ -2004,7 +2026,7 @@ If point is not after the part of a word, all strings are listed." | |||
| 2004 | (re-search-backward "[ \t{\"]") | 2026 | (re-search-backward "[ \t{\"]") |
| 2005 | (forward-char 1) | 2027 | (forward-char 1) |
| 2006 | (point))) | 2028 | (point))) |
| 2007 | (part-of-word (buffer-substring beg end)) | 2029 | (part-of-word (buffer-substring-no-properties beg end)) |
| 2008 | (string-list (copy-sequence bibtex-completion-candidates)) | 2030 | (string-list (copy-sequence bibtex-completion-candidates)) |
| 2009 | (case-fold-search t) | 2031 | (case-fold-search t) |
| 2010 | (completion (save-excursion | 2032 | (completion (save-excursion |
| @@ -2019,7 +2041,9 @@ If point is not after the part of a word, all strings are listed." | |||
| 2019 | (goto-char (match-beginning 0)) | 2041 | (goto-char (match-beginning 0)) |
| 2020 | (setq string-list | 2042 | (setq string-list |
| 2021 | (cons | 2043 | (cons |
| 2022 | (list (buffer-substring pnt (point))) | 2044 | (list |
| 2045 | (buffer-substring-no-properties | ||
| 2046 | pnt (point))) | ||
| 2023 | string-list)) | 2047 | string-list)) |
| 2024 | (goto-char strt))) | 2048 | (goto-char strt))) |
| 2025 | (setq string-list | 2049 | (setq string-list |
| @@ -2118,10 +2142,9 @@ If point is not after the part of a word, all strings are listed." | |||
| 2118 | 2142 | ||
| 2119 | 2143 | ||
| 2120 | 2144 | ||
| 2121 | ;;; MAKE BIBTEX a FEATURE | 2145 | ;; Make BibTeX a Feature |
| 2122 | 2146 | ||
| 2123 | (provide 'bibtex) | 2147 | (provide 'bibtex) |
| 2124 | 2148 | ||
| 2125 | 2149 | ||
| 2126 | ;;; bibtex.el ends here | 2150 | ;;; bibtex.el ends here |
| 2127 | |||