comparison lisp/textmodes/bibtex.el @ 90140:02f1dbc4a199

Revision: miles@gnu.org--gnu-2005/emacs--unicode--0--patch-35 Merge from emacs--cvs-trunk--0 Patches applied: * emacs--cvs-trunk--0 (patch 228-240) - Update from CVS - Merge from gnus--rel--5.10 * gnus--rel--5.10 (patch 53-58) - Merge from emacs--cvs-trunk--0 - Update from CVS - Collapse feature addition/removal within single ChangeLog entry
author Miles Bader <miles@gnu.org>
date Sat, 09 Apr 2005 02:16:29 +0000
parents f8a7a9ba3d08 d11749d2bcff
children 146c086df160
comparison
equal deleted inserted replaced
90139:e0d294b9b23e 90140:02f1dbc4a199
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>
7 ;; Bengt Martensson <bengt@mathematik.uni-Bremen.de> 7 ;; Bengt Martensson <bengt@mathematik.uni-Bremen.de>
8 ;; Mark Shapiro <shapiro@corto.inria.fr> 8 ;; Mark Shapiro <shapiro@corto.inria.fr>
782 :group 'bibtex 782 :group 'bibtex
783 :type '(choice (const :tag "Default" bibtex-summary) 783 :type '(choice (const :tag "Default" bibtex-summary)
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:
792
793 ((FIELD . REGEXP))
794 ((FIELD . REGEXP) STEP...)
795 ((FIELD . REGEXP) STRING STEP...)
800 796
801 FIELD is a field name as returned by `bibtex-parse-entry'. 797 FIELD is a field name as returned by `bibtex-parse-entry'.
802 REGEXP is matched against the text of FIELD. If the match succeeds, then 798 REGEXP is matched against the text of FIELD. If the match succeeds,
803 this scheme is used. If no STEPs are specified the matched text is used 799 then this scheme is used. If no STRING and STEPs are specified
804 as the URL, otherwise the URL is built by concatenating the STEPs. 800 the matched text is used as the URL, otherwise the URL is built
805 801 by evaluating STEPs. If no STRING is specified the STEPs must result
806 A STEP can be a string or a list (FIELD REGEXP REPLACE) in which case 802 in strings which are concatenated. Otherwise the resulting objects
807 the text of FIELD is matched against REGEXP, and is replaced with REPLACE. 803 are passed through `format' using STRING as format control string.
808 REPLACE can be a string, or a number (which selects the corresponding submatch) 804
809 or a function called with the field's text as argument and with the 805 A STEP is a list (FIELD REGEXP REPLACE). The text of FIELD
810 `match-data' properly set. 806 is matched against REGEXP, and is replaced with REPLACE.
811 807 REPLACE can be a string, or a number (which selects the corresponding
812 Case is always ignored. Always remove the field delimiters." 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")
825 (integer :tag "Sub-match") 840 (integer :tag "Sub-match")
826 (function :tag "Filter")))))))) 841 (function :tag "Filter"))))))))
2660 (setq start (1+ start))) 2675 (setq start (1+ start)))
2661 (>= bound start))) 2676 (>= bound start)))
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)))
2673 found)) 2687 found))
2674 2688
4281 (bibtex-beginning-of-entry) 4295 (bibtex-beginning-of-entry)
4282 (let ((fields-alist (bibtex-parse-entry)) 4296 (let ((fields-alist (bibtex-parse-entry))
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
4322 ;; Make BibTeX a Feature 4333 ;; Make BibTeX a Feature
4323 4334