diff options
| author | Stefan Monnier | 2004-09-12 19:52:15 +0000 |
|---|---|---|
| committer | Stefan Monnier | 2004-09-12 19:52:15 +0000 |
| commit | a9d77f1fbc53b28f0674f01f164d2a7ec2d97d8b (patch) | |
| tree | 69eac0f7d9f20227296b82d424ebc9a5597f4c1b /lisp/textmodes | |
| parent | 17aa33855f4600aa7ca9cf00f4cb9f98a9720c61 (diff) | |
| download | emacs-a9d77f1fbc53b28f0674f01f164d2a7ec2d97d8b.tar.gz emacs-a9d77f1fbc53b28f0674f01f164d2a7ec2d97d8b.zip | |
(bibtex-generate-url-list): Change format. Provide a sample complex default.
(bibtex-url, bibtex-font-lock-url): Adapt to new format.
(bibtex-entry): Use mapc.
Diffstat (limited to 'lisp/textmodes')
| -rw-r--r-- | lisp/textmodes/bibtex.el | 328 |
1 files changed, 162 insertions, 166 deletions
diff --git a/lisp/textmodes/bibtex.el b/lisp/textmodes/bibtex.el index d521a98b9b1..ddc1d4ecb62 100644 --- a/lisp/textmodes/bibtex.el +++ b/lisp/textmodes/bibtex.el | |||
| @@ -1,6 +1,6 @@ | |||
| 1 | ;;; bibtex.el --- BibTeX mode for GNU Emacs | 1 | ;;; bibtex.el --- BibTeX mode for GNU Emacs |
| 2 | 2 | ||
| 3 | ;; Copyright (C) 1992,94,95,96,97,98,1999,2003,2004 | 3 | ;; Copyright (C) 1992, 1994, 1995, 1996, 1997, 1998, 1999, 2003, 2004 |
| 4 | ;; Free Software Foundation, Inc. | 4 | ;; Free Software Foundation, Inc. |
| 5 | 5 | ||
| 6 | ;; Author: Stefan Schoef <schoef@offis.uni-oldenburg.de> | 6 | ;; Author: Stefan Schoef <schoef@offis.uni-oldenburg.de> |
| @@ -61,13 +61,13 @@ | |||
| 61 | :type 'hook) | 61 | :type 'hook) |
| 62 | 62 | ||
| 63 | (defcustom bibtex-field-delimiters 'braces | 63 | (defcustom bibtex-field-delimiters 'braces |
| 64 | "*Type of field delimiters. Allowed values are `braces' or `double-quotes'." | 64 | "*Type of field delimiters. Allowed values are `braces' or `double-quotes'." |
| 65 | :group 'bibtex | 65 | :group 'bibtex |
| 66 | :type '(choice (const braces) | 66 | :type '(choice (const braces) |
| 67 | (const double-quotes))) | 67 | (const double-quotes))) |
| 68 | 68 | ||
| 69 | (defcustom bibtex-entry-delimiters 'braces | 69 | (defcustom bibtex-entry-delimiters 'braces |
| 70 | "*Type of entry delimiters. Allowed values are `braces' or `parentheses'." | 70 | "*Type of entry delimiters. Allowed values are `braces' or `parentheses'." |
| 71 | :group 'bibtex | 71 | :group 'bibtex |
| 72 | :type '(choice (const braces) | 72 | :type '(choice (const braces) |
| 73 | (const parentheses))) | 73 | (const parentheses))) |
| @@ -154,10 +154,10 @@ narrowed to just the entry." | |||
| 154 | Allowed non-nil values are: | 154 | Allowed non-nil values are: |
| 155 | plain All entries are sorted alphabetically. | 155 | plain All entries are sorted alphabetically. |
| 156 | crossref All entries are sorted alphabetically unless an entry has a | 156 | crossref All entries are sorted alphabetically unless an entry has a |
| 157 | crossref field. These crossrefed entries are placed in | 157 | crossref field. These crossrefed entries are placed in |
| 158 | alphabetical order immediately preceding the main entry. | 158 | alphabetical order immediately preceding the main entry. |
| 159 | entry-class The entries are divided into classes according to their | 159 | entry-class The entries are divided into classes according to their |
| 160 | entry name, see `bibtex-sort-entry-class'. Within each class | 160 | entry name, see `bibtex-sort-entry-class'. Within each class |
| 161 | the entries are sorted alphabetically. | 161 | the entries are sorted alphabetically. |
| 162 | See also `bibtex-sort-ignore-string-entries'." | 162 | See also `bibtex-sort-ignore-string-entries'." |
| 163 | :group 'bibtex | 163 | :group 'bibtex |
| @@ -172,8 +172,8 @@ See also `bibtex-sort-ignore-string-entries'." | |||
| 172 | ("Book" "Proceedings")) | 172 | ("Book" "Proceedings")) |
| 173 | "*List of classes of BibTeX entry names, used for sorting entries. | 173 | "*List of classes of BibTeX entry names, used for sorting entries. |
| 174 | If value of `bibtex-maintain-sorted-entries' is `entry-class' | 174 | If value of `bibtex-maintain-sorted-entries' is `entry-class' |
| 175 | entries are ordered according to the classes they belong to. Each | 175 | entries are ordered according to the classes they belong to. Each |
| 176 | class contains a list of entry names. An entry `catch-all' applies | 176 | class contains a list of entry names. An entry `catch-all' applies |
| 177 | to all entries not explicitely mentioned.") | 177 | to all entries not explicitely mentioned.") |
| 178 | 178 | ||
| 179 | (defcustom bibtex-sort-ignore-string-entries t | 179 | (defcustom bibtex-sort-ignore-string-entries t |
| @@ -763,45 +763,46 @@ If non-nil, the column for the equal sign is the value of | |||
| 763 | :type '(repeat string)) | 763 | :type '(repeat string)) |
| 764 | 764 | ||
| 765 | (defcustom bibtex-generate-url-list | 765 | (defcustom bibtex-generate-url-list |
| 766 | '((("url" . t) ("url" t))) | 766 | '((("url" . ".*:.*")) |
| 767 | ;; Example of a complex setup. | ||
| 768 | (("journal" . "\\<\\(PR[ABCDEL]?\\|RMP\\)\\>") | ||
| 769 | "http://publish.aps.org/abstract/" | ||
| 770 | ("journal" ".*" downcase) | ||
| 771 | "/v" | ||
| 772 | ("volume" ".*" 0) | ||
| 773 | "/p" | ||
| 774 | ("pages" "\\`\\([0-9]+\\)" 1))) | ||
| 767 | "List of schemes for generating the URL of a BibTeX entry. | 775 | "List of schemes for generating the URL of a BibTeX entry. |
| 768 | These schemes are used by `bibtex-url'. | 776 | These schemes are used by `bibtex-url'. |
| 769 | 777 | ||
| 770 | Each scheme is of the form ((FIELD . REGEXP) STEPS). | 778 | Each scheme is of the form ((FIELD . REGEXP) STEP...). |
| 771 | 779 | ||
| 772 | FIELD is a field name as returned by `bibtex-parse-entry'. | 780 | FIELD is a field name as returned by `bibtex-parse-entry'. |
| 773 | REGEXP is matched against the text of FIELD. | 781 | REGEXP is matched against the text of FIELD. If the match succeed, then |
| 774 | If the match succeeds, the list STEPS is used to generate the URL. | 782 | this scheme will be used. If no STEPS are specified the matched text is used |
| 775 | If REGEXP is t, always generate the URL if FIELD is present. | 783 | as the URL, otherwise the URL is built by concatenating the STEPS. |
| 776 | 784 | ||
| 777 | If an element of STEPS is a list (FIELD MATCH FILTER), | 785 | A STEP can be a string or a list (FIELD REGEXP REPLACE) in which case |
| 778 | the text of FIELD is matched against MATCH. | 786 | the text of FIELD is matched against REGEXP, and is replaced with REPLACE. |
| 779 | If MATCH is t, the text of FIELD is accepted as is. | 787 | REPLACE can be a string, or a number (which selects the corresponding submatch) |
| 780 | If MATCH is a cons cell (REGEXP . REPLACE), the text is matched against REGEXP. | 788 | or a function called with the field's text as argument and with the |
| 781 | If REPLACE is a string, the text is replaced with REPLACE. If REPLACE is a | 789 | `match-data' properly set. |
| 782 | number, it specifies which parenthesized expression in the match is taken. | 790 | |
| 783 | The optional element FILTER is a function for piping the match through it. | 791 | Case is always ignored. Always remove the field delimiters." |
| 784 | The text strings are then concatenated to generate the URL. | ||
| 785 | |||
| 786 | If an element of STEPS is a string, it is simply added to the URL. | ||
| 787 | |||
| 788 | Case is always ignored. Always remove the field delimiters." | ||
| 789 | :group 'bibtex | 792 | :group 'bibtex |
| 790 | :type '(repeat | 793 | :type '(repeat |
| 791 | (list :tag "Scheme" | 794 | (list :tag "Scheme" |
| 792 | (cons :tag "Matcher" :extra-offset 4 | 795 | (cons :tag "Matcher" :extra-offset 4 |
| 793 | (string :tag "BibTeX field") | 796 | (string :tag "BibTeX field") |
| 794 | (choice (regexp :tag "Regexp") | 797 | (regexp :tag "Regexp")) |
| 795 | (const :tag "Accept as is" t))) | ||
| 796 | (repeat :tag "Steps to generate URL" :inline t | 798 | (repeat :tag "Steps to generate URL" :inline t |
| 797 | (choice | 799 | (choice |
| 798 | (string :tag "Literal text") | 800 | (string :tag "Literal text") |
| 799 | (list (string :tag "BibTeX field") | 801 | (list (string :tag "BibTeX field") |
| 800 | (choice (const :tag "Accept as is" t) | 802 | (regexp :tag "Regexp") |
| 801 | (cons (string :tag "Field") | 803 | (choice (string :tag "Replacement") |
| 802 | (choice (regexp :tag "Regexp") | 804 | (integer :tag "Sub-match") |
| 803 | (integer :tag "Matched parenthesis")))) | 805 | (function :tag "Filter")))))))) |
| 804 | (option (function :tag "Filter" :value ignore)))))))) | ||
| 805 | 806 | ||
| 806 | ;; bibtex-font-lock-keywords is a user option as well, but since the | 807 | ;; bibtex-font-lock-keywords is a user option as well, but since the |
| 807 | ;; patterns used to define this variable are defined in a later | 808 | ;; patterns used to define this variable are defined in a later |
| @@ -1000,8 +1001,7 @@ Initialized from `bibtex-predefined-strings' and `bibtex-string-files'.") | |||
| 1000 | (make-variable-buffer-local 'bibtex-reference-keys) | 1001 | (make-variable-buffer-local 'bibtex-reference-keys) |
| 1001 | 1002 | ||
| 1002 | (defvar bibtex-buffer-last-parsed-tick nil | 1003 | (defvar bibtex-buffer-last-parsed-tick nil |
| 1003 | "Last value returned by `buffer-modified-tick' when buffer | 1004 | "Value of `buffer-modified-tick' last time buffer was parsed for keys.") |
| 1004 | was parsed for keys the last time.") | ||
| 1005 | 1005 | ||
| 1006 | (defvar bibtex-parse-idle-timer nil | 1006 | (defvar bibtex-parse-idle-timer nil |
| 1007 | "Stores if timer is already installed.") | 1007 | "Stores if timer is already installed.") |
| @@ -1103,7 +1103,7 @@ was parsed for keys the last time.") | |||
| 1103 | (,(concat "^[ \t]*\\(" bibtex-field-name "\\)[ \t]*=") | 1103 | (,(concat "^[ \t]*\\(" bibtex-field-name "\\)[ \t]*=") |
| 1104 | 1 font-lock-variable-name-face) | 1104 | 1 font-lock-variable-name-face) |
| 1105 | ;; url | 1105 | ;; url |
| 1106 | (bibtex-font-lock-url 0 '(face nil mouse-face highlight | 1106 | (bibtex-font-lock-url 0 '(face nil mouse-face highlight |
| 1107 | keymap bibtex-url-map))) | 1107 | keymap bibtex-url-map))) |
| 1108 | "*Default expressions to highlight in BibTeX mode.") | 1108 | "*Default expressions to highlight in BibTeX mode.") |
| 1109 | 1109 | ||
| @@ -1113,8 +1113,8 @@ was parsed for keys the last time.") | |||
| 1113 | "Regexp for `bibtex-font-lock-url'.") | 1113 | "Regexp for `bibtex-font-lock-url'.") |
| 1114 | 1114 | ||
| 1115 | (defvar bibtex-field-name-for-parsing nil | 1115 | (defvar bibtex-field-name-for-parsing nil |
| 1116 | "Temporary variable storing the name string to be parsed by the callback | 1116 | "Regexp of field name to be parsed by function `bibtex-parse-field-name'. |
| 1117 | function `bibtex-parse-field-name'.") | 1117 | Passed by dynamic scoping.") |
| 1118 | 1118 | ||
| 1119 | (defvar bibtex-sort-entry-class-alist | 1119 | (defvar bibtex-sort-entry-class-alist |
| 1120 | (let ((i -1) alist) | 1120 | (let ((i -1) alist) |
| @@ -1123,8 +1123,9 @@ function `bibtex-parse-field-name'.") | |||
| 1123 | (dolist (entry class) | 1123 | (dolist (entry class) |
| 1124 | ;; all entry names should be downcase (for ease of comparison) | 1124 | ;; all entry names should be downcase (for ease of comparison) |
| 1125 | (push (cons (if (stringp entry) (downcase entry) entry) i) alist)))) | 1125 | (push (cons (if (stringp entry) (downcase entry) entry) i) alist)))) |
| 1126 | "Alist for the classes of the entry types if the value of | 1126 | "Alist mapping entry types to their sorting index. |
| 1127 | `bibtex-maintain-sorted-entries' is `entry-class'.") | 1127 | Auto-generated from `bibtex-sort-entry-class'. |
| 1128 | Used when `bibtex-maintain-sorted-entries' is `entry-class'.") | ||
| 1128 | 1129 | ||
| 1129 | 1130 | ||
| 1130 | ;; Special support taking care of variants | 1131 | ;; Special support taking care of variants |
| @@ -1149,15 +1150,11 @@ function `bibtex-parse-field-name'.") | |||
| 1149 | 1150 | ||
| 1150 | ;; Support for hideshow minor mode | 1151 | ;; Support for hideshow minor mode |
| 1151 | (defun bibtex-hs-forward-sexp (arg) | 1152 | (defun bibtex-hs-forward-sexp (arg) |
| 1152 | "Replacement for `forward-sexp' to be used by `hs-minor-mode'." | 1153 | "Replacement for `forward-sexp' to be used by `hs-minor-mode'. |
| 1153 | (if (< arg 0) | 1154 | ARG is ignored." |
| 1154 | (backward-sexp 1) | 1155 | (if (looking-at "@\\S(*\\s(") |
| 1155 | (if (looking-at "@\\S(*\\s(") | 1156 | (goto-char (1- (match-end 0)))) |
| 1156 | (progn | 1157 | (forward-sexp 1)) |
| 1157 | (goto-char (match-end 0)) | ||
| 1158 | (forward-char -1) | ||
| 1159 | (forward-sexp 1)) | ||
| 1160 | (forward-sexp 1)))) | ||
| 1161 | 1158 | ||
| 1162 | (add-to-list | 1159 | (add-to-list |
| 1163 | 'hs-special-modes-alist | 1160 | 'hs-special-modes-alist |
| @@ -1184,7 +1181,7 @@ values of the functions PARSE-LHS and PARSE-RHS is returned." | |||
| 1184 | "Parse the field name stored in `bibtex-field-name-for-parsing'. | 1181 | "Parse the field name stored in `bibtex-field-name-for-parsing'. |
| 1185 | If the field name is found, return a triple consisting of the position of the | 1182 | If the field name is found, return a triple consisting of the position of the |
| 1186 | very first character of the match, the actual starting position of the name | 1183 | very first character of the match, the actual starting position of the name |
| 1187 | part and end position of the match. Move point to end of field name. | 1184 | part and end position of the match. Move point to end of field name. |
| 1188 | If `bibtex-autoadd-commas' is non-nil add missing comma at end of preceeding | 1185 | If `bibtex-autoadd-commas' is non-nil add missing comma at end of preceeding |
| 1189 | BibTeX field as necessary." | 1186 | BibTeX field as necessary." |
| 1190 | (cond ((looking-at ",[ \t\n]*") | 1187 | (cond ((looking-at ",[ \t\n]*") |
| @@ -1246,7 +1243,7 @@ end position of the field string is returned, nil otherwise." | |||
| 1246 | The text part is either a string, or an empty string, or a constant followed | 1243 | The text part is either a string, or an empty string, or a constant followed |
| 1247 | by one or more <# (string|constant)> pairs. If a syntactically correct text | 1244 | by one or more <# (string|constant)> pairs. If a syntactically correct text |
| 1248 | is found, a pair containing the start and end position of the text is | 1245 | is found, a pair containing the start and end position of the text is |
| 1249 | returned, nil otherwise. Move point to end of field text." | 1246 | returned, nil otherwise. Move point to end of field text." |
| 1250 | (let ((starting-point (point)) | 1247 | (let ((starting-point (point)) |
| 1251 | end-point failure boundaries) | 1248 | end-point failure boundaries) |
| 1252 | (while (not (or end-point failure)) | 1249 | (while (not (or end-point failure)) |
| @@ -1274,8 +1271,8 @@ the name and text parts of the field is returned." | |||
| 1274 | "Search forward to find a field of name NAME. | 1271 | "Search forward to find a field of name NAME. |
| 1275 | If a syntactically correct field is found, a pair containing the boundaries of | 1272 | If a syntactically correct field is found, a pair containing the boundaries of |
| 1276 | the name and text parts of the field is returned. The search is limited by | 1273 | the name and text parts of the field is returned. The search is limited by |
| 1277 | optional arg BOUND. If BOUND is t the search is limited by the end of the current | 1274 | optional arg BOUND. If BOUND is t the search is limited by the end of the |
| 1278 | entry. Do not move point." | 1275 | current entry. Do not move point." |
| 1279 | (save-match-data | 1276 | (save-match-data |
| 1280 | (save-excursion | 1277 | (save-excursion |
| 1281 | (unless (integer-or-marker-p bound) | 1278 | (unless (integer-or-marker-p bound) |
| @@ -1301,8 +1298,8 @@ entry. Do not move point." | |||
| 1301 | "Search backward to find a field of name NAME. | 1298 | "Search backward to find a field of name NAME. |
| 1302 | If a syntactically correct field is found, a pair containing the boundaries of | 1299 | If a syntactically correct field is found, a pair containing the boundaries of |
| 1303 | the name and text parts of the field is returned. The search is limited by | 1300 | the name and text parts of the field is returned. The search is limited by |
| 1304 | optional arg BOUND. If BOUND is t the search is limited by the beginning of the | 1301 | optional arg BOUND. If BOUND is t the search is limited by the beginning of the |
| 1305 | current entry. Do not move point." | 1302 | current entry. Do not move point." |
| 1306 | (save-match-data | 1303 | (save-match-data |
| 1307 | (save-excursion | 1304 | (save-excursion |
| 1308 | (unless (integer-or-marker-p bound) | 1305 | (unless (integer-or-marker-p bound) |
| @@ -1356,7 +1353,7 @@ if present." | |||
| 1356 | content))) | 1353 | content))) |
| 1357 | 1354 | ||
| 1358 | (defun bibtex-text-in-field (field &optional follow-crossref) | 1355 | (defun bibtex-text-in-field (field &optional follow-crossref) |
| 1359 | "Get content of field FIELD of current BibTeX entry. Return nil if not found. | 1356 | "Get content of field FIELD of current BibTeX entry. Return nil if not found. |
| 1360 | If optional arg FOLLOW-CROSSREF is non-nil, follow crossref." | 1357 | If optional arg FOLLOW-CROSSREF is non-nil, follow crossref." |
| 1361 | (save-excursion | 1358 | (save-excursion |
| 1362 | (save-restriction | 1359 | (save-restriction |
| @@ -1396,7 +1393,7 @@ reference key and the end position of the match." | |||
| 1396 | "Parse the postfix part of a BibTeX string entry, including the text. | 1393 | "Parse the postfix part of a BibTeX string entry, including the text. |
| 1397 | If the string postfix is found, return a triple consisting of the position of | 1394 | If the string postfix is found, return a triple consisting of the position of |
| 1398 | the actual starting and ending position of the text and the very last | 1395 | the actual starting and ending position of the text and the very last |
| 1399 | character of the string entry. Move point past BibTeX string entry." | 1396 | character of the string entry. Move point past BibTeX string entry." |
| 1400 | (let* ((case-fold-search t) | 1397 | (let* ((case-fold-search t) |
| 1401 | (bounds (bibtex-parse-field-text))) | 1398 | (bounds (bibtex-parse-field-text))) |
| 1402 | (when bounds | 1399 | (when bounds |
| @@ -1418,7 +1415,7 @@ Move point past BibTeX string entry." | |||
| 1418 | (defun bibtex-search-forward-string () | 1415 | (defun bibtex-search-forward-string () |
| 1419 | "Search forward to find a BibTeX string entry. | 1416 | "Search forward to find a BibTeX string entry. |
| 1420 | If a syntactically correct entry is found, a pair containing the boundaries of | 1417 | If a syntactically correct entry is found, a pair containing the boundaries of |
| 1421 | the reference key and text parts of the string is returned. Do not move point." | 1418 | the reference key and text parts of the string is returned. Do not move point." |
| 1422 | (save-excursion | 1419 | (save-excursion |
| 1423 | (save-match-data | 1420 | (save-match-data |
| 1424 | (let ((case-fold-search t) | 1421 | (let ((case-fold-search t) |
| @@ -1434,7 +1431,7 @@ the reference key and text parts of the string is returned. Do not move point." | |||
| 1434 | (defun bibtex-search-backward-string () | 1431 | (defun bibtex-search-backward-string () |
| 1435 | "Search backward to find a BibTeX string entry. | 1432 | "Search backward to find a BibTeX string entry. |
| 1436 | If a syntactically correct entry is found, a pair containing the boundaries of | 1433 | If a syntactically correct entry is found, a pair containing the boundaries of |
| 1437 | the reference key and text parts of the field is returned. Do not move point." | 1434 | the reference key and text parts of the field is returned. Do not move point." |
| 1438 | (save-excursion | 1435 | (save-excursion |
| 1439 | (save-match-data | 1436 | (save-match-data |
| 1440 | (let ((case-fold-search t) | 1437 | (let ((case-fold-search t) |
| @@ -1475,7 +1472,7 @@ delimiters if present." | |||
| 1475 | (match-end bibtex-type-in-head))) | 1472 | (match-end bibtex-type-in-head))) |
| 1476 | 1473 | ||
| 1477 | (defun bibtex-key-in-head (&optional empty) | 1474 | (defun bibtex-key-in-head (&optional empty) |
| 1478 | "Extract BibTeX key in head. Return optional arg EMPTY if key is empty." | 1475 | "Extract BibTeX key in head. Return optional arg EMPTY if key is empty." |
| 1479 | (if (match-beginning bibtex-key-in-head) | 1476 | (if (match-beginning bibtex-key-in-head) |
| 1480 | (buffer-substring-no-properties (match-beginning bibtex-key-in-head) | 1477 | (buffer-substring-no-properties (match-beginning bibtex-key-in-head) |
| 1481 | (match-end bibtex-key-in-head)) | 1478 | (match-end bibtex-key-in-head)) |
| @@ -1484,7 +1481,7 @@ delimiters if present." | |||
| 1484 | ;; Helper Functions | 1481 | ;; Helper Functions |
| 1485 | 1482 | ||
| 1486 | (defsubst bibtex-string= (str1 str2) | 1483 | (defsubst bibtex-string= (str1 str2) |
| 1487 | "Return t if two strings are equal, ignoring case." | 1484 | "Return t if STR1 and STR2 are equal, ignoring case." |
| 1488 | (eq t (compare-strings str1 0 nil str2 0 nil t))) | 1485 | (eq t (compare-strings str1 0 nil str2 0 nil t))) |
| 1489 | 1486 | ||
| 1490 | (defun bibtex-delete-whitespace () | 1487 | (defun bibtex-delete-whitespace () |
| @@ -1498,12 +1495,13 @@ delimiters if present." | |||
| 1498 | (if (equal (current-column) 0) 1 0))) | 1495 | (if (equal (current-column) 0) 1 0))) |
| 1499 | 1496 | ||
| 1500 | (defun bibtex-skip-to-valid-entry (&optional backward) | 1497 | (defun bibtex-skip-to-valid-entry (&optional backward) |
| 1501 | "Unless at beginning of a valid BibTeX entry, move point to beginning of the | 1498 | "Move point to beginning of the next valid BibTeX entry. |
| 1502 | next valid one. With optional argument BACKWARD non-nil, move backward to | 1499 | Do not move if we are already at beginning of a valid BibTeX entry. |
| 1503 | beginning of previous valid one. A valid entry is a syntactical correct one | 1500 | With optional argument BACKWARD non-nil, move backward to |
| 1501 | beginning of previous valid one. A valid entry is a syntactical correct one | ||
| 1504 | with type contained in `bibtex-entry-field-alist' or, if | 1502 | with type contained in `bibtex-entry-field-alist' or, if |
| 1505 | `bibtex-sort-ignore-string-entries' is nil, a syntactical correct string | 1503 | `bibtex-sort-ignore-string-entries' is nil, a syntactical correct string |
| 1506 | entry. Return buffer position of beginning and ending of entry if a valid | 1504 | entry. Return buffer position of beginning and ending of entry if a valid |
| 1507 | entry is found, nil otherwise." | 1505 | entry is found, nil otherwise." |
| 1508 | (interactive "P") | 1506 | (interactive "P") |
| 1509 | (let ((case-fold-search t) | 1507 | (let ((case-fold-search t) |
| @@ -1528,9 +1526,9 @@ entry is found, nil otherwise." | |||
| 1528 | 1526 | ||
| 1529 | (defun bibtex-map-entries (fun) | 1527 | (defun bibtex-map-entries (fun) |
| 1530 | "Call FUN for each BibTeX entry starting with the current. | 1528 | "Call FUN for each BibTeX entry starting with the current. |
| 1531 | Do this to the end of the file. FUN is called with three arguments, the key of | 1529 | Do this to the end of the file. FUN is called with three arguments, the key of |
| 1532 | the entry and the buffer positions (marker) of beginning and end of entry. | 1530 | the entry and the buffer positions (marker) of beginning and end of entry. |
| 1533 | Point is inside the entry. If `bibtex-sort-ignore-string-entries' is non-nil, | 1531 | Point is inside the entry. If `bibtex-sort-ignore-string-entries' is non-nil, |
| 1534 | FUN will not be called for @String entries." | 1532 | FUN will not be called for @String entries." |
| 1535 | (let ((case-fold-search t)) | 1533 | (let ((case-fold-search t)) |
| 1536 | (bibtex-beginning-of-entry) | 1534 | (bibtex-beginning-of-entry) |
| @@ -1596,8 +1594,8 @@ If FLAG is nil, a message is echoed if point was incremented at least | |||
| 1596 | 1594 | ||
| 1597 | (defun bibtex-search-entry (empty-head &optional bound noerror backward) | 1595 | (defun bibtex-search-entry (empty-head &optional bound noerror backward) |
| 1598 | "Search for a BibTeX entry (maybe without reference key if EMPTY-HEAD is t). | 1596 | "Search for a BibTeX entry (maybe without reference key if EMPTY-HEAD is t). |
| 1599 | BOUND and NOERROR are exactly as in `re-search-forward'. If BACKWARD | 1597 | BOUND and NOERROR are exactly as in `re-search-forward'. If BACKWARD |
| 1600 | is non-nil, search is done in reverse direction. Point is moved past the | 1598 | is non-nil, search is done in reverse direction. Point is moved past the |
| 1601 | closing delimiter (at the beginning of entry if BACKWARD is non-nil). | 1599 | closing delimiter (at the beginning of entry if BACKWARD is non-nil). |
| 1602 | Return a cons pair with buffer positions of beginning and end of entry. | 1600 | Return a cons pair with buffer positions of beginning and end of entry. |
| 1603 | After call to this function MATCH-BEGINNING and MATCH-END functions | 1601 | After call to this function MATCH-BEGINNING and MATCH-END functions |
| @@ -1700,7 +1698,7 @@ are defined, but only for the head part of the entry | |||
| 1700 | (skip-chars-forward " \t\n"))) | 1698 | (skip-chars-forward " \t\n"))) |
| 1701 | 1699 | ||
| 1702 | (defun bibtex-beginning-of-first-entry () | 1700 | (defun bibtex-beginning-of-first-entry () |
| 1703 | "Go to the beginning of the first BibTeX entry in buffer. Return point." | 1701 | "Go to the beginning of the first BibTeX entry in buffer. Return point." |
| 1704 | (goto-char (point-min)) | 1702 | (goto-char (point-min)) |
| 1705 | (if (re-search-forward "^[ \t]*@" nil 'move) | 1703 | (if (re-search-forward "^[ \t]*@" nil 'move) |
| 1706 | (beginning-of-line)) | 1704 | (beginning-of-line)) |
| @@ -1725,9 +1723,9 @@ are defined, but only for the head part of the entry | |||
| 1725 | 1723 | ||
| 1726 | (defun bibtex-enclosing-field (&optional noerr) | 1724 | (defun bibtex-enclosing-field (&optional noerr) |
| 1727 | "Search for BibTeX field enclosing point. | 1725 | "Search for BibTeX field enclosing point. |
| 1728 | Use `match-beginning' and `match-end' to parse the field. If NOERR is non-nil, | 1726 | Use `match-beginning' and `match-end' to parse the field. If NOERR is non-nil, |
| 1729 | no error is signalled. In this case, bounds are returned on success, | 1727 | no error is signalled. In this case, bounds are returned on success, |
| 1730 | nil otherwise. Does not move point." | 1728 | nil otherwise. Does not move point." |
| 1731 | (let ((bounds (bibtex-search-backward-field bibtex-field-name t))) | 1729 | (let ((bounds (bibtex-search-backward-field bibtex-field-name t))) |
| 1732 | (if (and bounds | 1730 | (if (and bounds |
| 1733 | (<= (bibtex-start-of-field bounds) (point)) | 1731 | (<= (bibtex-start-of-field bounds) (point)) |
| @@ -1737,7 +1735,7 @@ nil otherwise. Does not move point." | |||
| 1737 | (error "Can't find enclosing BibTeX field"))))) | 1735 | (error "Can't find enclosing BibTeX field"))))) |
| 1738 | 1736 | ||
| 1739 | (defun bibtex-enclosing-entry-maybe-empty-head () | 1737 | (defun bibtex-enclosing-entry-maybe-empty-head () |
| 1740 | "Search for BibTeX entry enclosing point. Move point to end of entry. | 1738 | "Search for BibTeX entry enclosing point. Move point to end of entry. |
| 1741 | Beginning (but not end) of entry is given by (`match-beginning' 0)." | 1739 | Beginning (but not end) of entry is given by (`match-beginning' 0)." |
| 1742 | (let ((case-fold-search t) | 1740 | (let ((case-fold-search t) |
| 1743 | (old-point (point))) | 1741 | (old-point (point))) |
| @@ -2016,8 +2014,8 @@ Formats current entry according to variable `bibtex-entry-format'." | |||
| 2016 | (defun bibtex-autokey-abbrev (string len) | 2014 | (defun bibtex-autokey-abbrev (string len) |
| 2017 | "Return an abbreviation of STRING with at least LEN characters. | 2015 | "Return an abbreviation of STRING with at least LEN characters. |
| 2018 | If LEN is positive the abbreviation is terminated only after a consonant | 2016 | If LEN is positive the abbreviation is terminated only after a consonant |
| 2019 | or at the word end. If LEN is negative the abbreviation is strictly | 2017 | or at the word end. If LEN is negative the abbreviation is strictly |
| 2020 | enforced using abs (LEN) characters. If LEN is not a number, STRING | 2018 | enforced using abs (LEN) characters. If LEN is not a number, STRING |
| 2021 | is returned unchanged." | 2019 | is returned unchanged." |
| 2022 | (cond ((or (not (numberp len)) | 2020 | (cond ((or (not (numberp len)) |
| 2023 | (<= (length string) (abs len))) | 2021 | (<= (length string) (abs len))) |
| @@ -2033,9 +2031,9 @@ is returned unchanged." | |||
| 2033 | string))))) | 2031 | string))))) |
| 2034 | 2032 | ||
| 2035 | (defun bibtex-autokey-get-field (field &optional change-list) | 2033 | (defun bibtex-autokey-get-field (field &optional change-list) |
| 2036 | "Get content of BibTeX field FIELD. Return empty string if not found. | 2034 | "Get content of BibTeX field FIELD. Return empty string if not found. |
| 2037 | Optional arg CHANGE-LIST is a list of substitution patterns that is | 2035 | Optional arg CHANGE-LIST is a list of substitution patterns that is |
| 2038 | applied to the content of FIELD. It is an alist with pairs | 2036 | applied to the content of FIELD. It is an alist with pairs |
| 2039 | \(OLD-REGEXP . NEW-STRING\)." | 2037 | \(OLD-REGEXP . NEW-STRING\)." |
| 2040 | (let ((content (bibtex-text-in-field field bibtex-autokey-use-crossref)) | 2038 | (let ((content (bibtex-text-in-field field bibtex-autokey-use-crossref)) |
| 2041 | case-fold-search) | 2039 | case-fold-search) |
| @@ -2058,7 +2056,7 @@ and return results as a list." | |||
| 2058 | (split-string names "[ \t\n]+and[ \t\n]+"))))) | 2056 | (split-string names "[ \t\n]+and[ \t\n]+"))))) |
| 2059 | 2057 | ||
| 2060 | (defun bibtex-autokey-demangle-name (fullname) | 2058 | (defun bibtex-autokey-demangle-name (fullname) |
| 2061 | "Get the last part from a well-formed name and perform abbreviations." | 2059 | "Get the last part from a well-formed FULLNAME and perform abbreviations." |
| 2062 | (let* (case-fold-search | 2060 | (let* (case-fold-search |
| 2063 | (name (cond ((string-match "\\([A-Z][^, ]*\\)[^,]*," fullname) | 2061 | (name (cond ((string-match "\\([A-Z][^, ]*\\)[^,]*," fullname) |
| 2064 | ;; Name is of the form "von Last, First" or | 2062 | ;; Name is of the form "von Last, First" or |
| @@ -2150,7 +2148,7 @@ The generation algorithm works as follows: | |||
| 2150 | `bibtex-autokey-name-change-strings' to the corresponding new | 2148 | `bibtex-autokey-name-change-strings' to the corresponding new |
| 2151 | one (see documentation of this variable for further detail). | 2149 | one (see documentation of this variable for further detail). |
| 2152 | 4. For every of at least first `bibtex-autokey-names' names in | 2150 | 4. For every of at least first `bibtex-autokey-names' names in |
| 2153 | the name field, determine the last name. If there are maximal | 2151 | the name field, determine the last name. If there are maximal |
| 2154 | `bibtex-autokey-names' + `bibtex-autokey-names-stretch' | 2152 | `bibtex-autokey-names' + `bibtex-autokey-names-stretch' |
| 2155 | names, all names are used. | 2153 | names, all names are used. |
| 2156 | 5. From every last name, take at least `bibtex-autokey-name-length' | 2154 | 5. From every last name, take at least `bibtex-autokey-name-length' |
| @@ -2159,12 +2157,12 @@ The generation algorithm works as follows: | |||
| 2159 | `bibtex-autokey-name-case-convert'. | 2157 | `bibtex-autokey-name-case-convert'. |
| 2160 | 7. Build the name part of the key by concatenating all | 2158 | 7. Build the name part of the key by concatenating all |
| 2161 | abbreviated last names with the string | 2159 | abbreviated last names with the string |
| 2162 | `bibtex-autokey-name-separator' between any two. If there are | 2160 | `bibtex-autokey-name-separator' between any two. If there are |
| 2163 | more names than are used in the name part, prepend the string | 2161 | more names than are used in the name part, prepend the string |
| 2164 | contained in `bibtex-autokey-additional-names'. | 2162 | contained in `bibtex-autokey-additional-names'. |
| 2165 | 8. Build the year part of the key by truncating the contents of | 2163 | 8. Build the year part of the key by truncating the contents of |
| 2166 | the year field to the rightmost `bibtex-autokey-year-length' | 2164 | the year field to the rightmost `bibtex-autokey-year-length' |
| 2167 | digits (useful values are 2 and 4). If the year field (or any | 2165 | digits (useful values are 2 and 4). If the year field (or any |
| 2168 | other field required to generate the key) is absent, but the entry | 2166 | other field required to generate the key) is absent, but the entry |
| 2169 | has a valid crossref field and the variable | 2167 | has a valid crossref field and the variable |
| 2170 | `bibtex-autokey-use-crossref' is non-nil, use the field of the | 2168 | `bibtex-autokey-use-crossref' is non-nil, use the field of the |
| @@ -2180,7 +2178,7 @@ The generation algorithm works as follows: | |||
| 2180 | appear in `bibtex-autokey-titleword-ignore'. | 2178 | appear in `bibtex-autokey-titleword-ignore'. |
| 2181 | Build the title part of the key by using at least the first | 2179 | Build the title part of the key by using at least the first |
| 2182 | `bibtex-autokey-titlewords' words from this | 2180 | `bibtex-autokey-titlewords' words from this |
| 2183 | abbreviated title. If the abbreviated title ends after | 2181 | abbreviated title. If the abbreviated title ends after |
| 2184 | maximal `bibtex-autokey-titlewords' + | 2182 | maximal `bibtex-autokey-titlewords' + |
| 2185 | `bibtex-autokey-titlewords-stretch' words, all | 2183 | `bibtex-autokey-titlewords-stretch' words, all |
| 2186 | words from the abbreviated title are used. | 2184 | words from the abbreviated title are used. |
| @@ -2201,13 +2199,13 @@ The generation algorithm works as follows: | |||
| 2201 | and the title part with `bibtex-autokey-name-year-separator' | 2199 | and the title part with `bibtex-autokey-name-year-separator' |
| 2202 | between the name part and the year part if both are non-empty | 2200 | between the name part and the year part if both are non-empty |
| 2203 | and `bibtex-autokey-year-title-separator' between the year | 2201 | and `bibtex-autokey-year-title-separator' between the year |
| 2204 | part and the title part if both are non-empty. If the year | 2202 | part and the title part if both are non-empty. If the year |
| 2205 | part is empty, but not the other two parts, | 2203 | part is empty, but not the other two parts, |
| 2206 | `bibtex-autokey-year-title-separator' is used as well. | 2204 | `bibtex-autokey-year-title-separator' is used as well. |
| 2207 | 16. If the value of `bibtex-autokey-before-presentation-function' | 2205 | 16. If the value of `bibtex-autokey-before-presentation-function' |
| 2208 | is non-nil, it must be a function taking one argument. This | 2206 | is non-nil, it must be a function taking one argument. This |
| 2209 | function is then called with the generated key as the | 2207 | function is then called with the generated key as the |
| 2210 | argument. The return value of this function (a string) is | 2208 | argument. The return value of this function (a string) is |
| 2211 | used as the key. | 2209 | used as the key. |
| 2212 | 17. If the value of `bibtex-autokey-edit-before-use' is non-nil, | 2210 | 17. If the value of `bibtex-autokey-edit-before-use' is non-nil, |
| 2213 | the key is then presented in the minibuffer to the user, | 2211 | the key is then presented in the minibuffer to the user, |
| @@ -2261,9 +2259,9 @@ The generation algorithm works as follows: | |||
| 2261 | The buffer might possibly be restricted. | 2259 | The buffer might possibly be restricted. |
| 2262 | Find both entry keys and crossref entries. | 2260 | Find both entry keys and crossref entries. |
| 2263 | If ADD is non-nil add the new keys to `bibtex-reference-keys' instead of | 2261 | If ADD is non-nil add the new keys to `bibtex-reference-keys' instead of |
| 2264 | simply resetting it. If ADD is an alist of keys, also add ADD to | 2262 | simply resetting it. If ADD is an alist of keys, also add ADD to |
| 2265 | `bibtex-reference-keys'. If ABORTABLE is non-nil abort on user | 2263 | `bibtex-reference-keys'. If ABORTABLE is non-nil abort on user |
| 2266 | input. If VERBOSE is non-nil gives messages about progress. | 2264 | input. If VERBOSE is non-nil gives messages about progress. |
| 2267 | Return alist of keys if parsing was completed, `aborted' otherwise." | 2265 | Return alist of keys if parsing was completed, `aborted' otherwise." |
| 2268 | (let ((reference-keys (if (and add | 2266 | (let ((reference-keys (if (and add |
| 2269 | (listp bibtex-reference-keys)) | 2267 | (listp bibtex-reference-keys)) |
| @@ -2327,8 +2325,8 @@ Return alist of keys if parsing was completed, `aborted' otherwise." | |||
| 2327 | "Set `bibtex-strings' to the string definitions in the whole buffer. | 2325 | "Set `bibtex-strings' to the string definitions in the whole buffer. |
| 2328 | The buffer might possibly be restricted. | 2326 | The buffer might possibly be restricted. |
| 2329 | If ADD is non-nil add the new strings to `bibtex-strings' instead of | 2327 | If ADD is non-nil add the new strings to `bibtex-strings' instead of |
| 2330 | simply resetting it. If ADD is an alist of strings, also add ADD to | 2328 | simply resetting it. If ADD is an alist of strings, also add ADD to |
| 2331 | `bibtex-strings'. If ABORTABLE is non-nil abort on user input. | 2329 | `bibtex-strings'. If ABORTABLE is non-nil abort on user input. |
| 2332 | Return alist of strings if parsing was completed, `aborted' otherwise." | 2330 | Return alist of strings if parsing was completed, `aborted' otherwise." |
| 2333 | (save-excursion | 2331 | (save-excursion |
| 2334 | (save-match-data | 2332 | (save-match-data |
| @@ -2388,7 +2386,8 @@ Use `bibtex-predefined-strings' and bib files `bibtex-string-files'." | |||
| 2388 | (append bibtex-predefined-strings (nreverse compl))))) | 2386 | (append bibtex-predefined-strings (nreverse compl))))) |
| 2389 | 2387 | ||
| 2390 | (defun bibtex-parse-buffers-stealthily () | 2388 | (defun bibtex-parse-buffers-stealthily () |
| 2391 | "Called by `bibtex-run-with-idle-timer'. Whenever emacs has been idle | 2389 | "Parse buffer in the background during idle time. |
| 2390 | Called by `bibtex-run-with-idle-timer'. Whenever Emacs has been idle | ||
| 2392 | for `bibtex-parse-keys-timeout' seconds, all BibTeX buffers (starting | 2391 | for `bibtex-parse-keys-timeout' seconds, all BibTeX buffers (starting |
| 2393 | with the current) are parsed." | 2392 | with the current) are parsed." |
| 2394 | (save-excursion | 2393 | (save-excursion |
| @@ -2412,9 +2411,9 @@ with the current) are parsed." | |||
| 2412 | (setq buffers (cdr buffers)))))) | 2411 | (setq buffers (cdr buffers)))))) |
| 2413 | 2412 | ||
| 2414 | (defun bibtex-complete-internal (completions) | 2413 | (defun bibtex-complete-internal (completions) |
| 2415 | "Complete word fragment before point to longest prefix of one | 2414 | "Complete word fragment before point to longest prefix of COMPLETIONS. |
| 2416 | string defined in list COMPLETIONS. If point is not after the part | 2415 | COMPLETIONS should be a list of strings. If point is not after the part |
| 2417 | of a word, all strings are listed. Return completion." | 2416 | of a word, all strings are listed. Return completion." |
| 2418 | (let* ((case-fold-search t) | 2417 | (let* ((case-fold-search t) |
| 2419 | (beg (save-excursion | 2418 | (beg (save-excursion |
| 2420 | (re-search-backward "[ \t{\"]") | 2419 | (re-search-backward "[ \t{\"]") |
| @@ -2514,7 +2513,8 @@ expansion of STR using expansion list STRINGS-ALIST." | |||
| 2514 | (set-window-point window (point)))) | 2513 | (set-window-point window (point)))) |
| 2515 | 2514 | ||
| 2516 | (defun bibtex-pop (arg direction) | 2515 | (defun bibtex-pop (arg direction) |
| 2517 | "Generic function used by `bibtex-pop-previous' and `bibtex-pop-next'." | 2516 | "Fill current field from the ARG'th same field's text in DIRECTION. |
| 2517 | Generic function used by `bibtex-pop-previous' and `bibtex-pop-next'." | ||
| 2518 | (let (bibtex-help-message) | 2518 | (let (bibtex-help-message) |
| 2519 | (bibtex-find-text nil)) | 2519 | (bibtex-find-text nil)) |
| 2520 | (save-excursion | 2520 | (save-excursion |
| @@ -2577,15 +2577,15 @@ expansion of STR using expansion list STRINGS-ALIST." | |||
| 2577 | General information on working with BibTeX mode: | 2577 | General information on working with BibTeX mode: |
| 2578 | 2578 | ||
| 2579 | You should use commands such as \\[bibtex-Book] to get a template for a | 2579 | You should use commands such as \\[bibtex-Book] to get a template for a |
| 2580 | specific entry. You should then fill in all desired fields using | 2580 | specific entry. You should then fill in all desired fields using |
| 2581 | \\[bibtex-next-field] to jump from field to field. After having filled | 2581 | \\[bibtex-next-field] to jump from field to field. After having filled |
| 2582 | in all desired fields in the entry, you should clean the new entry | 2582 | in all desired fields in the entry, you should clean the new entry |
| 2583 | with the command \\[bibtex-clean-entry]. | 2583 | with the command \\[bibtex-clean-entry]. |
| 2584 | 2584 | ||
| 2585 | Some features of BibTeX mode are available only by setting the variable | 2585 | Some features of BibTeX mode are available only by setting the variable |
| 2586 | `bibtex-maintain-sorted-entries' to non-nil. However, then BibTeX mode will | 2586 | `bibtex-maintain-sorted-entries' to non-nil. However, then BibTeX mode will |
| 2587 | work only with buffers containing valid (syntactical correct) entries | 2587 | work only with buffers containing valid (syntactical correct) entries |
| 2588 | and with entries being sorted. This is usually the case, if you have | 2588 | and with entries being sorted. This is usually the case, if you have |
| 2589 | created a buffer completely with BibTeX mode and finished every new | 2589 | created a buffer completely with BibTeX mode and finished every new |
| 2590 | entry with \\[bibtex-clean-entry]. | 2590 | entry with \\[bibtex-clean-entry]. |
| 2591 | 2591 | ||
| @@ -2736,7 +2736,7 @@ names for ENTRY-TYPE according to `bibtex-entry-field-alist'." | |||
| 2736 | (cons required optional))) | 2736 | (cons required optional))) |
| 2737 | 2737 | ||
| 2738 | (defun bibtex-entry (entry-type) | 2738 | (defun bibtex-entry (entry-type) |
| 2739 | "Insert a new BibTeX entry. | 2739 | "Insert a new BibTeX entry of type ENTRY-TYPE. |
| 2740 | After insertion it calls the functions in `bibtex-add-entry-hook'." | 2740 | After insertion it calls the functions in `bibtex-add-entry-hook'." |
| 2741 | (interactive (let* ((completion-ignore-case t) | 2741 | (interactive (let* ((completion-ignore-case t) |
| 2742 | (e-t (completing-read | 2742 | (e-t (completing-read |
| @@ -2753,8 +2753,8 @@ After insertion it calls the functions in `bibtex-add-entry-hook'." | |||
| 2753 | (insert "@" entry-type (bibtex-entry-left-delimiter)) | 2753 | (insert "@" entry-type (bibtex-entry-left-delimiter)) |
| 2754 | (if key (insert key)) | 2754 | (if key (insert key)) |
| 2755 | (save-excursion | 2755 | (save-excursion |
| 2756 | (mapcar 'bibtex-make-field (car field-list)) | 2756 | (mapc 'bibtex-make-field (car field-list)) |
| 2757 | (mapcar 'bibtex-make-optional-field (cdr field-list)) | 2757 | (mapc 'bibtex-make-optional-field (cdr field-list)) |
| 2758 | (if bibtex-comma-after-last-field | 2758 | (if bibtex-comma-after-last-field |
| 2759 | (insert ",")) | 2759 | (insert ",")) |
| 2760 | (insert "\n") | 2760 | (insert "\n") |
| @@ -2887,7 +2887,8 @@ Move point to the end of the last field." | |||
| 2887 | "Make a field named FIELD in current BibTeX entry. | 2887 | "Make a field named FIELD in current BibTeX entry. |
| 2888 | FIELD is either a string or a list of the form | 2888 | FIELD is either a string or a list of the form |
| 2889 | \(FIELD-NAME COMMENT-STRING INIT ALTERNATIVE-FLAG) as in | 2889 | \(FIELD-NAME COMMENT-STRING INIT ALTERNATIVE-FLAG) as in |
| 2890 | `bibtex-entry-field-alist'." | 2890 | `bibtex-entry-field-alist'. |
| 2891 | If CALLED-BY-YANK is non-nil, don't insert delimiters." | ||
| 2891 | (interactive | 2892 | (interactive |
| 2892 | (list (let ((completion-ignore-case t) | 2893 | (list (let ((completion-ignore-case t) |
| 2893 | (field-list (bibtex-field-list | 2894 | (field-list (bibtex-field-list |
| @@ -2929,8 +2930,8 @@ FIELD is either a string or a list of the form | |||
| 2929 | (defun bibtex-beginning-of-entry () | 2930 | (defun bibtex-beginning-of-entry () |
| 2930 | "Move to beginning of BibTeX entry (beginning of line). | 2931 | "Move to beginning of BibTeX entry (beginning of line). |
| 2931 | If inside an entry, move to the beginning of it, otherwise move to the | 2932 | If inside an entry, move to the beginning of it, otherwise move to the |
| 2932 | beginning of the previous entry. If point is ahead of all BibTeX entries | 2933 | beginning of the previous entry. If point is ahead of all BibTeX entries |
| 2933 | move point to the beginning of buffer. Return the new location of point." | 2934 | move point to the beginning of buffer. Return the new location of point." |
| 2934 | (interactive) | 2935 | (interactive) |
| 2935 | (skip-chars-forward " \t") | 2936 | (skip-chars-forward " \t") |
| 2936 | (if (looking-at "@") | 2937 | (if (looking-at "@") |
| @@ -2941,7 +2942,7 @@ move point to the beginning of buffer. Return the new location of point." | |||
| 2941 | (defun bibtex-end-of-entry () | 2942 | (defun bibtex-end-of-entry () |
| 2942 | "Move to end of BibTeX entry (past the closing brace). | 2943 | "Move to end of BibTeX entry (past the closing brace). |
| 2943 | If inside an entry, move to the end of it, otherwise move to the end | 2944 | If inside an entry, move to the end of it, otherwise move to the end |
| 2944 | of the previous entry. Do not move if ahead of first entry. | 2945 | of the previous entry. Do not move if ahead of first entry. |
| 2945 | Return the new location of point." | 2946 | Return the new location of point." |
| 2946 | (interactive) | 2947 | (interactive) |
| 2947 | (let ((case-fold-search t) | 2948 | (let ((case-fold-search t) |
| @@ -3041,9 +3042,9 @@ If mark is active it counts entries in region, if not in whole buffer." | |||
| 3041 | (bibtex-end-of-entry)))) | 3042 | (bibtex-end-of-entry)))) |
| 3042 | 3043 | ||
| 3043 | (defun bibtex-entry-index () | 3044 | (defun bibtex-entry-index () |
| 3044 | "Return the index of the BibTeX entry at point. Move point. | 3045 | "Return the index of the BibTeX entry at point. Move point. |
| 3045 | The index is a list (KEY CROSSREF-KEY ENTRY-NAME) that is used for sorting | 3046 | The index is a list (KEY CROSSREF-KEY ENTRY-NAME) that is used for sorting |
| 3046 | the entries of the BibTeX buffer. Return nil if no entry found." | 3047 | the entries of the BibTeX buffer. Return nil if no entry found." |
| 3047 | (let ((case-fold-search t)) | 3048 | (let ((case-fold-search t)) |
| 3048 | (if (re-search-forward bibtex-entry-maybe-empty-head nil t) | 3049 | (if (re-search-forward bibtex-entry-maybe-empty-head nil t) |
| 3049 | (let ((key (bibtex-key-in-head)) | 3050 | (let ((key (bibtex-key-in-head)) |
| @@ -3093,8 +3094,8 @@ If its value is nil use plain sorting." | |||
| 3093 | (defun bibtex-sort-buffer () | 3094 | (defun bibtex-sort-buffer () |
| 3094 | "Sort BibTeX buffer alphabetically by key. | 3095 | "Sort BibTeX buffer alphabetically by key. |
| 3095 | The predicate for sorting is defined via `bibtex-maintain-sorted-entries'. | 3096 | The predicate for sorting is defined via `bibtex-maintain-sorted-entries'. |
| 3096 | If its value is nil use plain sorting. Text outside of BibTeX entries is not | 3097 | If its value is nil use plain sorting. Text outside of BibTeX entries is not |
| 3097 | affected. If `bibtex-sort-ignore-string-entries' is non-nil, @String entries | 3098 | affected. If `bibtex-sort-ignore-string-entries' is non-nil, @String entries |
| 3098 | will be ignored." | 3099 | will be ignored." |
| 3099 | (interactive) | 3100 | (interactive) |
| 3100 | (save-restriction | 3101 | (save-restriction |
| @@ -3156,7 +3157,7 @@ With prefix arg, the value of START is position of point." | |||
| 3156 | INDEX is a list (KEY CROSSREF-KEY ENTRY-NAME). | 3157 | INDEX is a list (KEY CROSSREF-KEY ENTRY-NAME). |
| 3157 | Move point where the entry KEY should be placed. | 3158 | Move point where the entry KEY should be placed. |
| 3158 | If `bibtex-maintain-sorted-entries' is non-nil, perform a binary | 3159 | If `bibtex-maintain-sorted-entries' is non-nil, perform a binary |
| 3159 | search to look for place for KEY. This will fail if buffer is not in | 3160 | search to look for place for KEY. This will fail if buffer is not in |
| 3160 | sorted order, see \\[bibtex-validate].) | 3161 | sorted order, see \\[bibtex-validate].) |
| 3161 | Return t if preparation was successful or nil if entry KEY already exists." | 3162 | Return t if preparation was successful or nil if entry KEY already exists." |
| 3162 | (let ((key (nth 0 index)) | 3163 | (let ((key (nth 0 index)) |
| @@ -3562,7 +3563,7 @@ intermixed with \\[bibtex-pop-previous] (bibtex-pop-previous)." | |||
| 3562 | Check that no required fields are empty and formats entry dependent | 3563 | Check that no required fields are empty and formats entry dependent |
| 3563 | on the value of `bibtex-entry-format'. | 3564 | on the value of `bibtex-entry-format'. |
| 3564 | If the reference key of the entry is empty or a prefix argument is given, | 3565 | If the reference key of the entry is empty or a prefix argument is given, |
| 3565 | calculate a new reference key. (Note: this will only work if fields in entry | 3566 | calculate a new reference key. (Note: this will only work if fields in entry |
| 3566 | begin on separate lines prior to calling `bibtex-clean-entry' or if | 3567 | begin on separate lines prior to calling `bibtex-clean-entry' or if |
| 3567 | 'realign is contained in `bibtex-entry-format'.) | 3568 | 'realign is contained in `bibtex-entry-format'.) |
| 3568 | Don't call `bibtex-clean-entry' on @Preamble entries. | 3569 | Don't call `bibtex-clean-entry' on @Preamble entries. |
| @@ -3962,7 +3963,7 @@ signaled if point is outside key or BibTeX field." | |||
| 3962 | (defun bibtex-url (&optional event) | 3963 | (defun bibtex-url (&optional event) |
| 3963 | "Browse a URL for the BibTeX entry at position PNT. | 3964 | "Browse a URL for the BibTeX entry at position PNT. |
| 3964 | The URL is generated using the schemes defined in `bibtex-generate-url-list' | 3965 | The URL is generated using the schemes defined in `bibtex-generate-url-list' |
| 3965 | \(see there\). Then the URL is passed to `browse-url'." | 3966 | \(see there\). Then the URL is passed to `browse-url'." |
| 3966 | (interactive (list last-input-event)) | 3967 | (interactive (list last-input-event)) |
| 3967 | (save-excursion | 3968 | (save-excursion |
| 3968 | (if event (posn-set-point (event-end event))) | 3969 | (if event (posn-set-point (event-end event))) |
| @@ -3972,39 +3973,40 @@ The URL is generated using the schemes defined in `bibtex-generate-url-list' | |||
| 3972 | (lst bibtex-generate-url-list) | 3973 | (lst bibtex-generate-url-list) |
| 3973 | field url scheme) | 3974 | field url scheme) |
| 3974 | (while (setq scheme (car lst)) | 3975 | (while (setq scheme (car lst)) |
| 3975 | (when (and (setq field (assoc-string (caar scheme) fields-alist t)) | 3976 | (when (and (setq field (cdr (assoc-string (caar scheme) |
| 3976 | (or (eq t (cdar scheme)) | 3977 | fields-alist t))) |
| 3977 | (string-match (cdar scheme) (cdr field)))) | 3978 | (progn |
| 3978 | (setq lst nil) | 3979 | (if (string-match "\\`[{\"]\\(.*\\)[}\"]\\'" field) |
| 3980 | (setq field (match-string 1 field))) | ||
| 3981 | (string-match (cdar scheme) field))) | ||
| 3982 | (setq lst nil) | ||
| 3983 | (if (null (cdr scheme)) | ||
| 3984 | (setq url (match-string 0 field))) | ||
| 3979 | (dolist (step (cdr scheme)) | 3985 | (dolist (step (cdr scheme)) |
| 3980 | (cond ((stringp step) | 3986 | (cond ((stringp step) |
| 3981 | (setq url (concat url step))) | 3987 | (setq url (concat url step))) |
| 3982 | ((setq field (assoc-string (car step) fields-alist t)) | 3988 | ((setq field (assoc-string (car step) fields-alist t)) |
| 3983 | ;; always remove field delimiters | 3989 | ;; always remove field delimiters |
| 3984 | (let* ((text (if (string-match "\\`[{\"]\\(.*\\)[}\"]\\'" | 3990 | (let* ((text (if (string-match "\\`[{\"]\\(.*\\)[}\"]\\'" |
| 3985 | (cdr field)) | 3991 | (cdr field)) |
| 3986 | (match-string 1 (cdr field)) | 3992 | (match-string 1 (cdr field)) |
| 3987 | (cdr field))) | 3993 | (cdr field))) |
| 3988 | (str (cond ((eq t (nth 1 step)) | 3994 | (str (if (string-match (nth 1 step) text) |
| 3989 | text) | 3995 | (cond |
| 3990 | ((and (consp (nth 1 step)) | 3996 | ((functionp (nth 2 step)) |
| 3991 | (string-match (car (nth 1 step)) | 3997 | (funcall (nth 2 step) text)) |
| 3992 | text)) | 3998 | ((numberp (nth 2 step)) |
| 3993 | (if (numberp (cdr (nth 1 step))) | 3999 | (match-string (nth 2 step) text)) |
| 3994 | (match-string (cdr (nth 1 step)) | 4000 | (t |
| 3995 | text) | 4001 | (replace-match (nth 2 step) nil nil text))) |
| 3996 | (replace-match (cdr (nth 1 step)) | 4002 | ;; If the scheme is set up correctly, |
| 3997 | nil nil text))) | 4003 | ;; we should never reach this point |
| 3998 | ;; If the scheme is set up correctly, | 4004 | (error "Match failed: %s" text)))) |
| 3999 | ;; we should never reach this point | 4005 | (setq url (concat url str)))) |
| 4000 | (t (error "Match failed: %s" text))))) | 4006 | ;; If the scheme is set up correctly, |
| 4001 | (setq url (concat url (if (fboundp (nth 2 step)) | 4007 | ;; we should never reach this point |
| 4002 | (funcall (nth 2 step) str) | 4008 | (t (error "Step failed: %s" step)))) |
| 4003 | str))))) | 4009 | (message "%s" url) |
| 4004 | ;; If the scheme is set up correctly, | ||
| 4005 | ;; we should never reach this point | ||
| 4006 | (t (error "Step failed: %s" step)))) | ||
| 4007 | (message "%s" url) | ||
| 4008 | (browse-url url)) | 4010 | (browse-url url)) |
| 4009 | (setq lst (cdr lst))) | 4011 | (setq lst (cdr lst))) |
| 4010 | (unless url (message "No URL known."))))) | 4012 | (unless url (message "No URL known."))))) |
| @@ -4014,29 +4016,23 @@ The URL is generated using the schemes defined in `bibtex-generate-url-list' | |||
| 4014 | (let ((case-fold-search t) | 4016 | (let ((case-fold-search t) |
| 4015 | (bounds (bibtex-enclosing-field t)) | 4017 | (bounds (bibtex-enclosing-field t)) |
| 4016 | (pnt (point)) | 4018 | (pnt (point)) |
| 4017 | found url) | 4019 | found field) |
| 4018 | ;; We use start-of-field as syntax-begin | 4020 | ;; We use start-of-field as syntax-begin |
| 4019 | (goto-char (if bounds (bibtex-start-of-field bounds) pnt)) | 4021 | (goto-char (if bounds (bibtex-start-of-field bounds) pnt)) |
| 4020 | (while (and (not found) | 4022 | (while (and (not found) |
| 4021 | (search-forward-regexp bibtex-font-lock-url-regexp bound t) | 4023 | (prog1 (re-search-forward bibtex-font-lock-url-regexp bound t) |
| 4022 | (save-match-data (setq bounds (bibtex-parse-field-text))) | 4024 | (setq field (match-string-no-properties 1))) |
| 4023 | (>= bound (car bounds))) | 4025 | (setq bounds (bibtex-parse-field-text)) |
| 4024 | (let ((field (match-string-no-properties 1)) | 4026 | (>= bound (car bounds)) |
| 4025 | (lst bibtex-generate-url-list)) | 4027 | (>= (car bounds) pnt)) |
| 4026 | (while (and (not found) | 4028 | (let ((lst bibtex-generate-url-list) url) |
| 4027 | (setq url (caar lst))) | 4029 | (goto-char (car bounds)) |
| 4028 | (when (bibtex-string= field (car url)) | 4030 | (while (and (not found) |
| 4029 | (if (eq t (cdr url)) | 4031 | (setq url (caar lst))) |
| 4030 | (progn | 4032 | (when (bibtex-string= field (car url)) |
| 4031 | (goto-char (min bound (cdr bounds))) | 4033 | (setq found (re-search-forward (cdr url) (cdr bounds) t))) |
| 4032 | (set-match-data (list (car bounds) (point))) | 4034 | (setq lst (cdr lst)))) |
| 4033 | (setq found t)) | 4035 | (goto-char (cdr bounds))) |
| 4034 | (goto-char (car bounds)) | ||
| 4035 | (setq found (search-forward-regexp (cdr url) | ||
| 4036 | (min bound (cdr bounds)) t))) | ||
| 4037 | (if (< (match-beginning 0) pnt) | ||
| 4038 | (setq found nil))) | ||
| 4039 | (setq lst (cdr lst))))) | ||
| 4040 | found)) | 4036 | found)) |
| 4041 | 4037 | ||
| 4042 | 4038 | ||