annotate lisp/textmodes/refer.el @ 12413:a580af99789c

Update copyright year in message.
author Richard M. Stallman <rms@gnu.org>
date Wed, 28 Jun 1995 10:41:05 +0000
parents fb6479579c0b
children 0ad88e6d8ef1
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
7638
fb6479579c0b entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1 ;;; refer.el --- look up references in bibliography files.
fb6479579c0b entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2
fb6479579c0b entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
3 ;; Copyright (C) 1992 Free Software Foundation, Inc.
fb6479579c0b entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
4
fb6479579c0b entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
5 ;; Author: Ashwin Ram <Ram-Ashwin@cs.yale.edu>
fb6479579c0b entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
6 ;; Adapted-By: ESR
fb6479579c0b entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
7 ;; Keywords: bib
fb6479579c0b entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
8
fb6479579c0b entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
9 ;; This file is part of GNU Emacs.
fb6479579c0b entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
10
fb6479579c0b entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
11 ;; GNU Emacs is free software; you can redistribute it and/or modify
fb6479579c0b entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
12 ;; it under the terms of the GNU General Public License as published by
fb6479579c0b entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
13 ;; the Free Software Foundation; either version 2, or (at your option)
fb6479579c0b entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
14 ;; any later version.
fb6479579c0b entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
15
fb6479579c0b entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
16 ;; GNU Emacs is distributed in the hope that it will be useful,
fb6479579c0b entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
17 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
fb6479579c0b entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
18 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
fb6479579c0b entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
19 ;; GNU General Public License for more details.
fb6479579c0b entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
20
fb6479579c0b entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
21 ;; You should have received a copy of the GNU General Public License
fb6479579c0b entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
22 ;; along with GNU Emacs; see the file COPYING. If not, write to
fb6479579c0b entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
23 ;; the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
fb6479579c0b entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
24
fb6479579c0b entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
25 ;;; Commentary:
fb6479579c0b entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
26 ;;
fb6479579c0b entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
27 ;; Functions to look up references in bibliography files given lists of
fb6479579c0b entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
28 ;; keywords, similar to refer(1). I don't use tags since tags on .bib files
fb6479579c0b entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
29 ;; only picks up the cite key, where as refer-find-entry looks for occurrences
fb6479579c0b entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
30 ;; of keywords anywhere in the bibliography entry.
fb6479579c0b entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
31 ;;
fb6479579c0b entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
32 ;; To use:
fb6479579c0b entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
33 ;; (autoload 'refer-find-entry "refer" nil t)
fb6479579c0b entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
34 ;; or (require 'refer)
fb6479579c0b entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
35 ;;
fb6479579c0b entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
36 ;; To look for an article by Knuth about semaphores:
fb6479579c0b entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
37 ;; Invoke refer-find-entry, then in response to the Keywords: prompt,
fb6479579c0b entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
38 ;; say: Knuth semaphores (a blank-separated list of keywords to be used
fb6479579c0b entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
39 ;; as search strings).
fb6479579c0b entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
40 ;;
fb6479579c0b entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
41 ;; To continue the previous search, i.e., to search for the next occurrence
fb6479579c0b entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
42 ;; of the keywords, use refer-find-next-entry, or invoke refer-find-entry
fb6479579c0b entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
43 ;; with a prefix argument.
fb6479579c0b entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
44 ;;
fb6479579c0b entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
45 ;; If the list of bibliography files changes, reinitialize the variable
fb6479579c0b entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
46 ;; refer-bib-files.
fb6479579c0b entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
47 ;;
fb6479579c0b entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
48 ;; To customize:
fb6479579c0b entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
49 ;; See variables refer-bib-files, refer-cache-bib-files and
fb6479579c0b entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
50 ;; refer-bib-files-regexp. By default, these are set up so that refer
fb6479579c0b entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
51 ;; looks for the keywords you specify in all the .bib files in the current
fb6479579c0b entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
52 ;; directory.
fb6479579c0b entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
53 ;;
fb6479579c0b entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
54 ;; The only assumption I make about bib files is that they contain a bunch
fb6479579c0b entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
55 ;; of entries, one to a paragraph. refer-find-entry searches paragraph by
fb6479579c0b entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
56 ;; paragraph, looking for a paragraph containing all the keywords
fb6479579c0b entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
57 ;; specified. So you should be able to use pretty much any bib file with
fb6479579c0b entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
58 ;; this code. If your bib file does not use paragraphs to separate
fb6479579c0b entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
59 ;; entries, try setting the paragraph-start/separate variables, or changing
fb6479579c0b entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
60 ;; the (forward-paragraph 1) call in refer-find-entry-in-file.
fb6479579c0b entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
61
fb6479579c0b entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
62 ;;; ChangeLog:
fb6479579c0b entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
63 ;;
fb6479579c0b entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
64 ;; 01/08/89 Ashwin Ram <Ram-Ashwin@cs.yale.edu>
fb6479579c0b entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
65 ;; Initial release.
fb6479579c0b entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
66 ;;
fb6479579c0b entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
67
fb6479579c0b entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
68 ;;; Code:
fb6479579c0b entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
69
fb6479579c0b entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
70 (provide 'refer)
fb6479579c0b entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
71
fb6479579c0b entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
72 (defvar refer-bib-files 'dir
fb6479579c0b entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
73 "*List of \\.bib files to search for references,
fb6479579c0b entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
74 or one of the following special values:
fb6479579c0b entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
75 nil = prompt for \\.bib file (if visiting a \\.bib file, use it as default)
fb6479579c0b entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
76 auto = read \\.bib file names from appropriate command in buffer (see refer-bib-files-regexp)
fb6479579c0b entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
77 dir = use all \\.bib files in current directory.
fb6479579c0b entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
78
fb6479579c0b entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
79 If a specified file doesn't exist and has no extension, a \\.bib extension
fb6479579c0b entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
80 is automatically tried.
fb6479579c0b entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
81
fb6479579c0b entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
82 If refer-bib-files is nil, auto or dir, it is setq'd to the appropriate
fb6479579c0b entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
83 list of files when it is first used if refer-cache-bib-files is t. If
fb6479579c0b entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
84 refer-cache-bib-files is nil, the list of \\.bib files to use is re-read
fb6479579c0b entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
85 each time it is needed.")
fb6479579c0b entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
86
fb6479579c0b entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
87 (defvar refer-cache-bib-files t
fb6479579c0b entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
88 "*Variable determining whether the value of refer-bib-files should be cached.
fb6479579c0b entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
89 If t, initialize the value of refer-bib-files the first time it is used. If
fb6479579c0b entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
90 nil, re-read the list of \\.bib files depending on the value of refer-bib-files
fb6479579c0b entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
91 each time it is needed.")
fb6479579c0b entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
92
fb6479579c0b entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
93 (defvar refer-bib-files-regexp "\\\\bibliography"
fb6479579c0b entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
94 "*Regexp matching a bibliography file declaration.
fb6479579c0b entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
95 The current buffer is expected to contain a line such as
fb6479579c0b entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
96 \\bibliography{file1,file2,file3}
fb6479579c0b entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
97 which is read to set up refer-bib-files. The regexp must specify the command
fb6479579c0b entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
98 \(such as \\bibliography) that is used to specify the list of bib files. The
fb6479579c0b entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
99 command is expected to specify a file name, or a list of comma-separated file
fb6479579c0b entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
100 names, within curly braces.
fb6479579c0b entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
101 If a specified file doesn't exist and has no extension, a \\.bib extension
fb6479579c0b entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
102 is automatically tried.")
fb6479579c0b entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
103
fb6479579c0b entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
104 (make-variable-buffer-local 'refer-bib-files)
fb6479579c0b entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
105 (make-variable-buffer-local 'refer-cache-bib-files)
fb6479579c0b entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
106
fb6479579c0b entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
107 (defun refer-find-entry (keywords &optional continue)
fb6479579c0b entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
108 "Find entry in refer-bib-files containing KEYWORDS.
fb6479579c0b entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
109 If KEYWORDS is nil, prompt user for blank-separated list of keywords.
fb6479579c0b entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
110 If CONTINUE is t, or if called interactively with a prefix arg, look for next
fb6479579c0b entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
111 entry by continuing search from previous point."
fb6479579c0b entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
112 (interactive (list nil current-prefix-arg))
fb6479579c0b entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
113 (or keywords (setq keywords (if continue
fb6479579c0b entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
114 refer-previous-keywords
fb6479579c0b entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
115 (read-string "Keywords: "))))
fb6479579c0b entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
116 (setq refer-previous-keywords keywords)
fb6479579c0b entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
117 (refer-find-entry-internal keywords continue))
fb6479579c0b entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
118
fb6479579c0b entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
119 (defun refer-find-next-entry ()
fb6479579c0b entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
120 "Find next occurrence of entry in refer-bib-files. See refer-find-entry."
fb6479579c0b entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
121 (interactive)
fb6479579c0b entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
122 (refer-find-entry-internal refer-previous-keywords t))
fb6479579c0b entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
123
fb6479579c0b entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
124 (defun refer-find-entry-internal (keywords continue)
fb6479579c0b entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
125 (let ((keywords-list (convert-string-to-list-of-strings keywords))
fb6479579c0b entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
126 (files (if continue
fb6479579c0b entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
127 refer-saved-state
fb6479579c0b entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
128 (refer-get-bib-files))))
fb6479579c0b entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
129 (catch 'found
fb6479579c0b entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
130 (while files
fb6479579c0b entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
131 (let ((file (cond ((file-exists-p (car files)) (car files))
fb6479579c0b entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
132 ((file-exists-p (concat (car files) ".bib")) (concat (car files) ".bib")))))
fb6479579c0b entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
133 (setq refer-saved-state files)
fb6479579c0b entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
134 (if file
fb6479579c0b entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
135 (if (refer-find-entry-in-file keywords-list file continue)
fb6479579c0b entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
136 (throw 'found (find-file file))
fb6479579c0b entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
137 (setq files (cdr files)))
fb6479579c0b entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
138 (progn (message "Scanning %s... No such file" (car files) (ding))
fb6479579c0b entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
139 (sit-for 1)
fb6479579c0b entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
140 (setq files (cdr files))))))
fb6479579c0b entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
141 (message "Keywords \"%s\" not found in any \.bib file" keywords (ding)))))
fb6479579c0b entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
142
fb6479579c0b entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
143 (defun refer-find-entry-in-file (keywords-list file &optional continue)
fb6479579c0b entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
144 (message "Scanning %s..." file) ; (expand-file-name file)
fb6479579c0b entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
145 (set-buffer (find-file-noselect file))
fb6479579c0b entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
146 (if continue
fb6479579c0b entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
147 (forward-paragraph 1)
fb6479579c0b entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
148 (goto-char (point-min)))
fb6479579c0b entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
149 (let ((begin (point))
fb6479579c0b entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
150 (end 0)
fb6479579c0b entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
151 (found nil))
fb6479579c0b entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
152 (while (and (not found)
fb6479579c0b entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
153 (not (eobp)))
fb6479579c0b entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
154 (forward-paragraph 1)
fb6479579c0b entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
155 (setq end (point))
fb6479579c0b entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
156 (setq found
fb6479579c0b entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
157 (every (function (lambda (keyword)
fb6479579c0b entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
158 (goto-char begin)
fb6479579c0b entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
159 (re-search-forward keyword end t)))
fb6479579c0b entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
160 keywords-list))
fb6479579c0b entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
161 (if (not found)
fb6479579c0b entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
162 (progn
fb6479579c0b entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
163 (setq begin end)
fb6479579c0b entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
164 (goto-char begin))))
fb6479579c0b entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
165 (if found
fb6479579c0b entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
166 (progn (goto-char begin)
fb6479579c0b entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
167 (re-search-forward "\\W" nil t)
fb6479579c0b entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
168 (message "Scanning %s... found" file))
fb6479579c0b entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
169 (progn (message "Scanning %s... not found" file)
fb6479579c0b entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
170 nil))))
fb6479579c0b entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
171
fb6479579c0b entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
172 (defun every (pred l)
fb6479579c0b entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
173 (cond ((null l) nil)
fb6479579c0b entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
174 ((funcall pred (car l))
fb6479579c0b entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
175 (or (null (cdr l))
fb6479579c0b entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
176 (every pred (cdr l))))))
fb6479579c0b entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
177
fb6479579c0b entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
178 (defun convert-string-to-list-of-strings (s)
fb6479579c0b entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
179 (let ((current (current-buffer))
fb6479579c0b entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
180 (temp-buffer (get-buffer-create "*refer-temp*")))
fb6479579c0b entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
181 (set-buffer temp-buffer)
fb6479579c0b entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
182 (erase-buffer)
fb6479579c0b entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
183 (insert (regexp-quote s))
fb6479579c0b entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
184 (goto-char (point-min))
fb6479579c0b entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
185 (insert "(\"")
fb6479579c0b entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
186 (while (re-search-forward "[ \t]+" nil t)
fb6479579c0b entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
187 (replace-match "\" \"" t t))
fb6479579c0b entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
188 (goto-char (point-max))
fb6479579c0b entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
189 (insert "\")")
fb6479579c0b entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
190 (goto-char (point-min))
fb6479579c0b entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
191 (prog1 (read temp-buffer)
fb6479579c0b entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
192 (set-buffer current))))
fb6479579c0b entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
193
fb6479579c0b entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
194 (defun refer-get-bib-files ()
fb6479579c0b entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
195 (let ((files
fb6479579c0b entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
196 (cond ((null refer-bib-files)
fb6479579c0b entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
197 (list (expand-file-name
fb6479579c0b entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
198 (if (eq major-mode 'bibtex-mode)
fb6479579c0b entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
199 (read-file-name (format ".bib file: (default %s) " (file-name-nondirectory (buffer-file-name)))
fb6479579c0b entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
200 (file-name-directory (buffer-file-name))
fb6479579c0b entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
201 (file-name-nondirectory (buffer-file-name))
fb6479579c0b entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
202 t)
fb6479579c0b entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
203 (read-file-name ".bib file: " nil nil t)))))
fb6479579c0b entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
204 ((listp refer-bib-files) refer-bib-files)
fb6479579c0b entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
205 ((eq refer-bib-files 'auto)
fb6479579c0b entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
206 (save-excursion
fb6479579c0b entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
207 (if (progn (goto-char (point-min))
fb6479579c0b entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
208 (re-search-forward (concat refer-bib-files-regexp "\{") nil t))
fb6479579c0b entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
209 (let ((files (list (buffer-substring (point)
fb6479579c0b entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
210 (progn (re-search-forward "[,\}]" nil t)
fb6479579c0b entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
211 (backward-char 1)
fb6479579c0b entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
212 (point))))))
fb6479579c0b entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
213 (while (not (looking-at "\}"))
fb6479579c0b entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
214 (setq files (append files
fb6479579c0b entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
215 (list (buffer-substring (progn (forward-char 1)
fb6479579c0b entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
216 (point))
fb6479579c0b entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
217 (progn (re-search-forward "[,\}]" nil t)
fb6479579c0b entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
218 (backward-char 1)
fb6479579c0b entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
219 (point)))))))
fb6479579c0b entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
220 files)
fb6479579c0b entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
221 (error "No \\\\bibliography command in this buffer, can't read refer-bib-files"))))
fb6479579c0b entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
222 ((eq refer-bib-files 'dir)
fb6479579c0b entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
223 (directory-files "." t "\\.bib$"))
fb6479579c0b entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
224 (t (error "Illegal value for refer-bib-files: %s" refer-bib-files)))))
fb6479579c0b entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
225 (if refer-cache-bib-files
fb6479579c0b entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
226 (setq refer-bib-files files))
fb6479579c0b entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
227 files))
fb6479579c0b entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
228
fb6479579c0b entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
229 ;;; refer.el ends here