diff options
| author | Stefan Monnier | 2005-04-03 21:26:11 +0000 |
|---|---|---|
| committer | Stefan Monnier | 2005-04-03 21:26:11 +0000 |
| commit | 63d516ce90e226c6ab730e1441e8d175e121d37f (patch) | |
| tree | 96492a84b0c25e3d0c5f38f203d74c6c397dea6f | |
| parent | 4c5113c76b804c4fcd3935e0b2c4858cd503c194 (diff) | |
| download | emacs-63d516ce90e226c6ab730e1441e8d175e121d37f.tar.gz emacs-63d516ce90e226c6ab730e1441e8d175e121d37f.zip | |
(bibtex-url): Use format to generate the url.
(bibtex-generate-url-list): Update docstring accordingly. Put the
complex example in the docstring.
(bibtex-font-lock-url): Use pop.
| -rw-r--r-- | lisp/ChangeLog | 7 | ||||
| -rw-r--r-- | lisp/textmodes/bibtex.el | 123 |
2 files changed, 74 insertions, 56 deletions
diff --git a/lisp/ChangeLog b/lisp/ChangeLog index 9af0def37ec..3ad59c9ed07 100644 --- a/lisp/ChangeLog +++ b/lisp/ChangeLog | |||
| @@ -1,3 +1,10 @@ | |||
| 1 | 2005-04-03 Roland Winkler <Roland.Winkler@physik.uni-erlangen.de> | ||
| 2 | |||
| 3 | * textmodes/bibtex.el (bibtex-url): Use format to generate the url. | ||
| 4 | (bibtex-generate-url-list): Update docstring accordingly. Put the | ||
| 5 | complex example in the docstring. | ||
| 6 | (bibtex-font-lock-url): Use pop. | ||
| 7 | |||
| 1 | 2005-04-03 Stefan Monnier <monnier@iro.umontreal.ca> | 8 | 2005-04-03 Stefan Monnier <monnier@iro.umontreal.ca> |
| 2 | 9 | ||
| 3 | * progmodes/tcl.el (tcl-set-font-lock-keywords): Use new \_< ops. | 10 | * progmodes/tcl.el (tcl-set-font-lock-keywords): Use new \_< ops. |
diff --git a/lisp/textmodes/bibtex.el b/lisp/textmodes/bibtex.el index fc677b3de44..3e5b77d8baa 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, 1994, 1995, 1996, 1997, 1998, 1999, 2003, 2004 | 3 | ;; Copyright (C) 1992, 1994, 1995, 1996, 1997, 1998, 1999, 2003, 2004, 2005 |
| 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> |
| @@ -784,41 +784,56 @@ Used by `bibtex-complete-crossref-cleanup' and `bibtex-copy-summary-as-kill'." | |||
| 784 | (function :tag "Personalized function"))) | 784 | (function :tag "Personalized function"))) |
| 785 | 785 | ||
| 786 | (defcustom bibtex-generate-url-list | 786 | (defcustom bibtex-generate-url-list |
| 787 | '((("url" . ".*:.*")) | 787 | '((("url" . ".*:.*"))) |
| 788 | ;; Example of a complex setup. | ||
| 789 | (("journal" . "\\<\\(PR[ABCDEL]?\\|RMP\\)\\>") | ||
| 790 | "http://link.aps.org/abstract/" | ||
| 791 | ("journal" ".*" downcase) | ||
| 792 | "/v" | ||
| 793 | ("volume" ".*" 0) | ||
| 794 | "/p" | ||
| 795 | ("pages" "\\`\\([0-9]+\\)" 1))) | ||
| 796 | "List of schemes for generating the URL of a BibTeX entry. | 788 | "List of schemes for generating the URL of a BibTeX entry. |
| 797 | These schemes are used by `bibtex-url'. | 789 | These schemes are used by `bibtex-url'. |
| 798 | 790 | ||
| 799 | Each scheme is of the form ((FIELD . REGEXP) STEP...). | 791 | Each scheme should have one of these forms: |
| 800 | 792 | ||
| 801 | FIELD is a field name as returned by `bibtex-parse-entry'. | 793 | ((FIELD . REGEXP)) |
| 802 | REGEXP is matched against the text of FIELD. If the match succeeds, then | 794 | ((FIELD . REGEXP) STEP...) |
| 803 | this scheme is used. If no STEPs are specified the matched text is used | 795 | ((FIELD . REGEXP) STRING STEP...) |
| 804 | as the URL, otherwise the URL is built by concatenating the STEPs. | ||
| 805 | |||
| 806 | A STEP can be a string or a list (FIELD REGEXP REPLACE) in which case | ||
| 807 | the text of FIELD is matched against REGEXP, and is replaced with REPLACE. | ||
| 808 | REPLACE can be a string, or a number (which selects the corresponding submatch) | ||
| 809 | or a function called with the field's text as argument and with the | ||
| 810 | `match-data' properly set. | ||
| 811 | 796 | ||
| 812 | Case is always ignored. Always remove the field delimiters." | 797 | FIELD is a field name as returned by `bibtex-parse-entry'. |
| 798 | REGEXP is matched against the text of FIELD. If the match succeeds, | ||
| 799 | then this scheme is used. If no STRING and STEPs are specified | ||
| 800 | the matched text is used as the URL, otherwise the URL is built | ||
| 801 | by evaluating STEPs. If no STRING is specified the STEPs must result | ||
| 802 | in strings which are concatenated. Otherwise the resulting objects | ||
| 803 | are passed through `format' using STRING as format control string. | ||
| 804 | |||
| 805 | A STEP is a list (FIELD REGEXP REPLACE). The text of FIELD | ||
| 806 | is matched against REGEXP, and is replaced with REPLACE. | ||
| 807 | REPLACE can be a string, or a number (which selects the corresponding | ||
| 808 | submatch), or a function called with the field's text as argument | ||
| 809 | and with the `match-data' properly set. | ||
| 810 | |||
| 811 | Case is always ignored. Always remove the field delimiters. | ||
| 812 | |||
| 813 | The following is a complex example, see http://link.aps.org/linkfaq.html. | ||
| 814 | |||
| 815 | (((\"journal\" . \"\\\\=<\\(PR[ABCDEL]?\\|RMP\\)\\\\=>\") | ||
| 816 | \"http://link.aps.org/abstract/%s/v%s/p%s\" | ||
| 817 | (\"journal\" \".*\" downcase) | ||
| 818 | (\"volume\" \".*\" 0) | ||
| 819 | (\"pages\" \"\\`[A-Z]?[0-9]+\" 0)))" | ||
| 813 | :group 'bibtex | 820 | :group 'bibtex |
| 814 | :type '(repeat | 821 | :type '(repeat |
| 815 | (list :tag "Scheme" | 822 | (cons :tag "Scheme" |
| 816 | (cons :tag "Matcher" :extra-offset 4 | 823 | (cons :tag "Matcher" :extra-offset 4 |
| 817 | (string :tag "BibTeX field") | 824 | (string :tag "BibTeX field") |
| 818 | (regexp :tag "Regexp")) | 825 | (regexp :tag "Regexp")) |
| 819 | (repeat :tag "Steps to generate URL" :inline t | 826 | (choice |
| 820 | (choice | 827 | (const :tag "Take match as is" nil) |
| 821 | (string :tag "Literal text") | 828 | (cons :tag "Formatted" |
| 829 | (string :tag "Format control string") | ||
| 830 | (repeat :tag "Steps to generate URL" | ||
| 831 | (list (string :tag "BibTeX field") | ||
| 832 | (regexp :tag "Regexp") | ||
| 833 | (choice (string :tag "Replacement") | ||
| 834 | (integer :tag "Sub-match") | ||
| 835 | (function :tag "Filter"))))) | ||
| 836 | (repeat :tag "Concatenated" | ||
| 822 | (list (string :tag "BibTeX field") | 837 | (list (string :tag "BibTeX field") |
| 823 | (regexp :tag "Regexp") | 838 | (regexp :tag "Regexp") |
| 824 | (choice (string :tag "Replacement") | 839 | (choice (string :tag "Replacement") |
| @@ -2662,11 +2677,10 @@ begins at the beginning of a line. We use this function for font-locking." | |||
| 2662 | (let ((lst bibtex-generate-url-list) url) | 2677 | (let ((lst bibtex-generate-url-list) url) |
| 2663 | (goto-char start) | 2678 | (goto-char start) |
| 2664 | (while (and (not found) | 2679 | (while (and (not found) |
| 2665 | (setq url (caar lst))) | 2680 | (setq url (car (pop lst)))) |
| 2666 | (setq found (and (bibtex-string= field (car url)) | 2681 | (setq found (and (bibtex-string= field (car url)) |
| 2667 | (re-search-forward (cdr url) end t) | 2682 | (re-search-forward (cdr url) end t) |
| 2668 | (>= (match-beginning 0) pnt)) | 2683 | (>= (match-beginning 0) pnt))))) |
| 2669 | lst (cdr lst)))) | ||
| 2670 | (goto-char end)) | 2684 | (goto-char end)) |
| 2671 | (if found (bibtex-button (match-beginning 0) (match-end 0) | 2685 | (if found (bibtex-button (match-beginning 0) (match-end 0) |
| 2672 | 'bibtex-url (match-beginning 0))) | 2686 | 'bibtex-url (match-beginning 0))) |
| @@ -4283,39 +4297,36 @@ The URL is generated using the schemes defined in `bibtex-generate-url-list' | |||
| 4283 | ;; Always ignore case, | 4297 | ;; Always ignore case, |
| 4284 | (case-fold-search t) | 4298 | (case-fold-search t) |
| 4285 | (lst bibtex-generate-url-list) | 4299 | (lst bibtex-generate-url-list) |
| 4286 | field url scheme) | 4300 | field url scheme obj fmt) |
| 4287 | (while (setq scheme (pop lst)) | 4301 | (while (setq scheme (pop lst)) |
| 4288 | (when (and (setq field (cdr (assoc-string (caar scheme) | 4302 | (when (and (setq field (cdr (assoc-string (caar scheme) |
| 4289 | fields-alist t))) | 4303 | fields-alist t))) |
| 4290 | ;; Always remove field delimiters | 4304 | ;; Always remove field delimiters |
| 4291 | (progn (setq field (bibtex-remove-delimiters-string field)) | 4305 | (progn (setq field (bibtex-remove-delimiters-string field)) |
| 4292 | (string-match (cdar scheme) field))) | 4306 | (string-match (cdar scheme) field))) |
| 4293 | (setq lst nil) | 4307 | (setq lst nil |
| 4294 | (if (null (cdr scheme)) | 4308 | scheme (cdr scheme) |
| 4295 | (setq url (match-string 0 field))) | 4309 | url (if (null scheme) (match-string 0 field) |
| 4296 | (dolist (step (cdr scheme)) | 4310 | (if (stringp (car scheme)) |
| 4297 | (cond ((stringp step) | 4311 | (setq fmt (pop scheme))) |
| 4298 | (setq url (concat url step))) | 4312 | (dolist (step scheme) |
| 4299 | ((setq field (cdr (assoc-string (car step) fields-alist t))) | 4313 | ;; Always remove field delimiters |
| 4300 | ;; Always remove field delimiters | 4314 | (setq field (bibtex-remove-delimiters-string |
| 4301 | (setq field (bibtex-remove-delimiters-string field)) | 4315 | (cdr (assoc-string (car step) fields-alist t)))) |
| 4302 | (if (string-match (nth 1 step) field) | 4316 | (if (string-match (nth 1 step) field) |
| 4303 | (setq field (cond | 4317 | (setq field (cond ((functionp (nth 2 step)) |
| 4304 | ((functionp (nth 2 step)) | 4318 | (funcall (nth 2 step) field)) |
| 4305 | (funcall (nth 2 step) field)) | 4319 | ((numberp (nth 2 step)) |
| 4306 | ((numberp (nth 2 step)) | 4320 | (match-string (nth 2 step) field)) |
| 4307 | (match-string (nth 2 step) field)) | 4321 | (t |
| 4308 | (t | 4322 | (replace-match (nth 2 step) t nil field)))) |
| 4309 | (replace-match (nth 2 step) t nil field)))) | 4323 | ;; If the scheme is set up correctly, |
| 4310 | ;; If the scheme is set up correctly, | 4324 | ;; we should never reach this point |
| 4311 | ;; we should never reach this point | 4325 | (error "Match failed: %s" field)) |
| 4312 | (error "Match failed: %s" field)) | 4326 | (push field obj)) |
| 4313 | (setq url (concat url field))) | 4327 | (if fmt (apply 'format fmt (nreverse obj)) |
| 4314 | ;; If the scheme is set up correctly, | 4328 | (apply 'concat (nreverse obj))))) |
| 4315 | ;; we should never reach this point | 4329 | (browse-url (message "%s" url)))) |
| 4316 | (t (error "Step failed: %s" step)))) | ||
| 4317 | (message "%s" url) | ||
| 4318 | (browse-url url))) | ||
| 4319 | (unless url (message "No URL known."))))) | 4330 | (unless url (message "No URL known."))))) |
| 4320 | 4331 | ||
| 4321 | 4332 | ||