annotate lisp/textmodes/refer.el @ 18494:c64480c04c07

(Fcall_process): Fix previous change.
author Richard M. Stallman <rms@gnu.org>
date Sun, 29 Jun 1997 03:39:02 +0000
parents 4ef76e689d69
children 9b831f34ff7d
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
16473
4ef76e689d69 (refer-bib-directory): New variable, list of
Richard M. Stallman <rms@gnu.org>
parents: 14169
diff changeset
3 ;; Copyright (C) 1992, 1996 Free Software Foundation, Inc.
7638
fb6479579c0b entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
4
16473
4ef76e689d69 (refer-bib-directory): New variable, list of
Richard M. Stallman <rms@gnu.org>
parents: 14169
diff changeset
5 ;; Author: Ashwin Ram <ashwin@cc.gatech.edu>
4ef76e689d69 (refer-bib-directory): New variable, list of
Richard M. Stallman <rms@gnu.org>
parents: 14169
diff changeset
6 ;; Maintainer: Gernot Heiser <gernot@jungfrau.disy.cse.unsw.EDU.AU>
7638
fb6479579c0b entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
7 ;; Adapted-By: ESR
fb6479579c0b entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
8 ;; Keywords: bib
fb6479579c0b entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
9
fb6479579c0b entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
10 ;; This file is part of GNU Emacs.
fb6479579c0b entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
11
fb6479579c0b entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
12 ;; 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
13 ;; 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
14 ;; the Free Software Foundation; either version 2, or (at your option)
fb6479579c0b entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
15 ;; any later version.
fb6479579c0b entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
16
fb6479579c0b entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
17 ;; 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
18 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
fb6479579c0b entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
19 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
fb6479579c0b entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
20 ;; GNU General Public License for more details.
fb6479579c0b entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
21
fb6479579c0b entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
22 ;; You should have received a copy of the GNU General Public License
14169
83f275dcd93a Update FSF's address.
Erik Naggum <erik@naggum.no>
parents: 12952
diff changeset
23 ;; along with GNU Emacs; see the file COPYING. If not, write to the
83f275dcd93a Update FSF's address.
Erik Naggum <erik@naggum.no>
parents: 12952
diff changeset
24 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
83f275dcd93a Update FSF's address.
Erik Naggum <erik@naggum.no>
parents: 12952
diff changeset
25 ;; Boston, MA 02111-1307, USA.
7638
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 ;;; Commentary:
14169
83f275dcd93a Update FSF's address.
Erik Naggum <erik@naggum.no>
parents: 12952
diff changeset
28
7638
fb6479579c0b entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
29 ;; Functions to look up references in bibliography files given lists of
fb6479579c0b entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
30 ;; 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
31 ;; 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
32 ;; of keywords anywhere in the bibliography entry.
fb6479579c0b entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
33 ;;
fb6479579c0b entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
34 ;; To use:
fb6479579c0b entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
35 ;; (autoload 'refer-find-entry "refer" nil t)
fb6479579c0b entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
36 ;; or (require 'refer)
fb6479579c0b entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
37 ;;
fb6479579c0b entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
38 ;; To look for an article by Knuth about semaphores:
fb6479579c0b entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
39 ;; Invoke refer-find-entry, then in response to the Keywords: prompt,
fb6479579c0b entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
40 ;; 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
41 ;; as search strings).
fb6479579c0b entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
42 ;;
fb6479579c0b entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
43 ;; 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
44 ;; 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
45 ;; with a prefix argument.
fb6479579c0b entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
46 ;;
16473
4ef76e689d69 (refer-bib-directory): New variable, list of
Richard M. Stallman <rms@gnu.org>
parents: 14169
diff changeset
47 ;; Once you've found the entry you want to reference, invoke
4ef76e689d69 (refer-bib-directory): New variable, list of
Richard M. Stallman <rms@gnu.org>
parents: 14169
diff changeset
48 ;; refer-yank-key to insert it at point in the current buffer
4ef76e689d69 (refer-bib-directory): New variable, list of
Richard M. Stallman <rms@gnu.org>
parents: 14169
diff changeset
49 ;; (typically as the argument of a \cite{} command).
4ef76e689d69 (refer-bib-directory): New variable, list of
Richard M. Stallman <rms@gnu.org>
parents: 14169
diff changeset
50 ;;
4ef76e689d69 (refer-bib-directory): New variable, list of
Richard M. Stallman <rms@gnu.org>
parents: 14169
diff changeset
51 ;; I use (define-key tex-mode-map "\C-c\C-y" 'refer-yank-key)
4ef76e689d69 (refer-bib-directory): New variable, list of
Richard M. Stallman <rms@gnu.org>
parents: 14169
diff changeset
52 ;; to bind this often-used function to a key in (la)tex-mode.
4ef76e689d69 (refer-bib-directory): New variable, list of
Richard M. Stallman <rms@gnu.org>
parents: 14169
diff changeset
53 ;;
7638
fb6479579c0b entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
54 ;; If the list of bibliography files changes, reinitialize the variable
fb6479579c0b entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
55 ;; refer-bib-files.
fb6479579c0b entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
56 ;;
fb6479579c0b entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
57 ;; To customize:
fb6479579c0b entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
58 ;; See variables refer-bib-files, refer-cache-bib-files and
fb6479579c0b entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
59 ;; 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
60 ;; 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
61 ;; directory.
fb6479579c0b entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
62 ;;
fb6479579c0b entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
63 ;; 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
64 ;; 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
65 ;; paragraph, looking for a paragraph containing all the keywords
fb6479579c0b entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
66 ;; 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
67 ;; 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
68 ;; entries, try setting the paragraph-start/separate variables, or changing
fb6479579c0b entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
69 ;; the (forward-paragraph 1) call in refer-find-entry-in-file.
fb6479579c0b entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
70
fb6479579c0b entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
71 ;;; Code:
fb6479579c0b entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
72
fb6479579c0b entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
73 (provide 'refer)
fb6479579c0b entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
74
16473
4ef76e689d69 (refer-bib-directory): New variable, list of
Richard M. Stallman <rms@gnu.org>
parents: 14169
diff changeset
75 (defvar refer-bib-directory nil
4ef76e689d69 (refer-bib-directory): New variable, list of
Richard M. Stallman <rms@gnu.org>
parents: 14169
diff changeset
76 "Directory, or list of directories, to search for \\.bib files. Can
4ef76e689d69 (refer-bib-directory): New variable, list of
Richard M. Stallman <rms@gnu.org>
parents: 14169
diff changeset
77 be set to 'bibinputs or 'texinputs, in which case the environment
4ef76e689d69 (refer-bib-directory): New variable, list of
Richard M. Stallman <rms@gnu.org>
parents: 14169
diff changeset
78 variable BIBINPUTS or TEXINPUTS, respectively, is used to obtain a
4ef76e689d69 (refer-bib-directory): New variable, list of
Richard M. Stallman <rms@gnu.org>
parents: 14169
diff changeset
79 list of directories. Useful only if refer-bib-files is set to 'dir or
4ef76e689d69 (refer-bib-directory): New variable, list of
Richard M. Stallman <rms@gnu.org>
parents: 14169
diff changeset
80 a list of file names (without directory). A value of nil indicates the
4ef76e689d69 (refer-bib-directory): New variable, list of
Richard M. Stallman <rms@gnu.org>
parents: 14169
diff changeset
81 current working directory.
4ef76e689d69 (refer-bib-directory): New variable, list of
Richard M. Stallman <rms@gnu.org>
parents: 14169
diff changeset
82
4ef76e689d69 (refer-bib-directory): New variable, list of
Richard M. Stallman <rms@gnu.org>
parents: 14169
diff changeset
83 If refer-bib-directory is 'bibinputs or 'texinputs, it is setq'd to
4ef76e689d69 (refer-bib-directory): New variable, list of
Richard M. Stallman <rms@gnu.org>
parents: 14169
diff changeset
84 the appropriate list of directories when it is first used.
4ef76e689d69 (refer-bib-directory): New variable, list of
Richard M. Stallman <rms@gnu.org>
parents: 14169
diff changeset
85
4ef76e689d69 (refer-bib-directory): New variable, list of
Richard M. Stallman <rms@gnu.org>
parents: 14169
diff changeset
86 Note that an empty directory is interpreted by BibTeX as indicating
4ef76e689d69 (refer-bib-directory): New variable, list of
Richard M. Stallman <rms@gnu.org>
parents: 14169
diff changeset
87 the default search path. Since Refer does not know that default path,
4ef76e689d69 (refer-bib-directory): New variable, list of
Richard M. Stallman <rms@gnu.org>
parents: 14169
diff changeset
88 it cannot search it. Include that path explicitly in your BIBINPUTS
4ef76e689d69 (refer-bib-directory): New variable, list of
Richard M. Stallman <rms@gnu.org>
parents: 14169
diff changeset
89 environment if you really want it searched (which is not likely to
4ef76e689d69 (refer-bib-directory): New variable, list of
Richard M. Stallman <rms@gnu.org>
parents: 14169
diff changeset
90 happen anyway).")
4ef76e689d69 (refer-bib-directory): New variable, list of
Richard M. Stallman <rms@gnu.org>
parents: 14169
diff changeset
91
7638
fb6479579c0b entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
92 (defvar refer-bib-files 'dir
fb6479579c0b entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
93 "*List of \\.bib files to search for references,
fb6479579c0b entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
94 or one of the following special values:
fb6479579c0b entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
95 nil = prompt for \\.bib file (if visiting a \\.bib file, use it as default)
16473
4ef76e689d69 (refer-bib-directory): New variable, list of
Richard M. Stallman <rms@gnu.org>
parents: 14169
diff changeset
96 auto = read \\.bib file names from appropriate command in buffer (see
4ef76e689d69 (refer-bib-directory): New variable, list of
Richard M. Stallman <rms@gnu.org>
parents: 14169
diff changeset
97 refer-bib-files-regexp) unless the buffer's mode is bibtex-mode,
4ef76e689d69 (refer-bib-directory): New variable, list of
Richard M. Stallman <rms@gnu.org>
parents: 14169
diff changeset
98 in which case only the buffer is searched
4ef76e689d69 (refer-bib-directory): New variable, list of
Richard M. Stallman <rms@gnu.org>
parents: 14169
diff changeset
99 dir = use all \\.bib files in directories referenced by refer-bib-directory.
7638
fb6479579c0b entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
100
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 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
105 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
106 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
107 each time it is needed.")
fb6479579c0b entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
108
fb6479579c0b entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
109 (defvar refer-cache-bib-files t
fb6479579c0b entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
110 "*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
111 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
112 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
113 each time it is needed.")
fb6479579c0b entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
114
fb6479579c0b entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
115 (defvar refer-bib-files-regexp "\\\\bibliography"
fb6479579c0b entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
116 "*Regexp matching a bibliography file declaration.
fb6479579c0b entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
117 The current buffer is expected to contain a line such as
fb6479579c0b entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
118 \\bibliography{file1,file2,file3}
fb6479579c0b entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
119 which is read to set up refer-bib-files. The regexp must specify the command
16473
4ef76e689d69 (refer-bib-directory): New variable, list of
Richard M. Stallman <rms@gnu.org>
parents: 14169
diff changeset
120 (such as \\bibliography) that is used to specify the list of bib files. The
7638
fb6479579c0b entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
121 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
122 names, within curly braces.
fb6479579c0b entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
123 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
124 is automatically tried.")
fb6479579c0b entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
125
fb6479579c0b entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
126 (make-variable-buffer-local 'refer-bib-files)
fb6479579c0b entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
127 (make-variable-buffer-local 'refer-cache-bib-files)
16473
4ef76e689d69 (refer-bib-directory): New variable, list of
Richard M. Stallman <rms@gnu.org>
parents: 14169
diff changeset
128 (make-variable-buffer-local 'refer-bib-directory)
4ef76e689d69 (refer-bib-directory): New variable, list of
Richard M. Stallman <rms@gnu.org>
parents: 14169
diff changeset
129
4ef76e689d69 (refer-bib-directory): New variable, list of
Richard M. Stallman <rms@gnu.org>
parents: 14169
diff changeset
130 ;;; Internal variables
4ef76e689d69 (refer-bib-directory): New variable, list of
Richard M. Stallman <rms@gnu.org>
parents: 14169
diff changeset
131 (defvar refer-saved-state nil)
4ef76e689d69 (refer-bib-directory): New variable, list of
Richard M. Stallman <rms@gnu.org>
parents: 14169
diff changeset
132 (defvar refer-previous-keywords nil)
4ef76e689d69 (refer-bib-directory): New variable, list of
Richard M. Stallman <rms@gnu.org>
parents: 14169
diff changeset
133 (defvar refer-saved-pos nil)
4ef76e689d69 (refer-bib-directory): New variable, list of
Richard M. Stallman <rms@gnu.org>
parents: 14169
diff changeset
134 (defvar refer-same-file nil)
7638
fb6479579c0b entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
135
fb6479579c0b entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
136 (defun refer-find-entry (keywords &optional continue)
fb6479579c0b entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
137 "Find entry in refer-bib-files containing KEYWORDS.
fb6479579c0b entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
138 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
139 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
140 entry by continuing search from previous point."
fb6479579c0b entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
141 (interactive (list nil current-prefix-arg))
fb6479579c0b entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
142 (or keywords (setq keywords (if continue
fb6479579c0b entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
143 refer-previous-keywords
16473
4ef76e689d69 (refer-bib-directory): New variable, list of
Richard M. Stallman <rms@gnu.org>
parents: 14169
diff changeset
144 (read-string "Keywords: "))))
7638
fb6479579c0b entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
145 (setq refer-previous-keywords keywords)
fb6479579c0b entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
146 (refer-find-entry-internal keywords continue))
fb6479579c0b entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
147
fb6479579c0b entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
148 (defun refer-find-next-entry ()
fb6479579c0b entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
149 "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
150 (interactive)
fb6479579c0b entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
151 (refer-find-entry-internal refer-previous-keywords t))
fb6479579c0b entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
152
16473
4ef76e689d69 (refer-bib-directory): New variable, list of
Richard M. Stallman <rms@gnu.org>
parents: 14169
diff changeset
153 (defun refer-yank-key ()
4ef76e689d69 (refer-bib-directory): New variable, list of
Richard M. Stallman <rms@gnu.org>
parents: 14169
diff changeset
154 "Inserts at point in current buffer the \"key\" field of the entry
4ef76e689d69 (refer-bib-directory): New variable, list of
Richard M. Stallman <rms@gnu.org>
parents: 14169
diff changeset
155 found on the last refer-find-entry or refer-find-next-entry."
4ef76e689d69 (refer-bib-directory): New variable, list of
Richard M. Stallman <rms@gnu.org>
parents: 14169
diff changeset
156 (interactive)
4ef76e689d69 (refer-bib-directory): New variable, list of
Richard M. Stallman <rms@gnu.org>
parents: 14169
diff changeset
157 (let ((old-point (point)))
4ef76e689d69 (refer-bib-directory): New variable, list of
Richard M. Stallman <rms@gnu.org>
parents: 14169
diff changeset
158 (insert
4ef76e689d69 (refer-bib-directory): New variable, list of
Richard M. Stallman <rms@gnu.org>
parents: 14169
diff changeset
159 (save-window-excursion
4ef76e689d69 (refer-bib-directory): New variable, list of
Richard M. Stallman <rms@gnu.org>
parents: 14169
diff changeset
160 (save-excursion
4ef76e689d69 (refer-bib-directory): New variable, list of
Richard M. Stallman <rms@gnu.org>
parents: 14169
diff changeset
161 (find-file (car refer-saved-state))
4ef76e689d69 (refer-bib-directory): New variable, list of
Richard M. Stallman <rms@gnu.org>
parents: 14169
diff changeset
162 (if (looking-at
4ef76e689d69 (refer-bib-directory): New variable, list of
Richard M. Stallman <rms@gnu.org>
parents: 14169
diff changeset
163 "[ \t\n]*@\\s-*[a-zA-Z][a-zA-Z0-9]*\\s-*{\\s-*\\([^ \t\n,]+\\)\\s-*,")
4ef76e689d69 (refer-bib-directory): New variable, list of
Richard M. Stallman <rms@gnu.org>
parents: 14169
diff changeset
164 (buffer-substring (match-beginning 1) (match-end 1))
4ef76e689d69 (refer-bib-directory): New variable, list of
Richard M. Stallman <rms@gnu.org>
parents: 14169
diff changeset
165 (error "Cannot find key for entry in file %s."
4ef76e689d69 (refer-bib-directory): New variable, list of
Richard M. Stallman <rms@gnu.org>
parents: 14169
diff changeset
166 (car refer-saved-state))))))
4ef76e689d69 (refer-bib-directory): New variable, list of
Richard M. Stallman <rms@gnu.org>
parents: 14169
diff changeset
167 (if (not (= (point) old-point))
4ef76e689d69 (refer-bib-directory): New variable, list of
Richard M. Stallman <rms@gnu.org>
parents: 14169
diff changeset
168 (set-mark old-point))))
4ef76e689d69 (refer-bib-directory): New variable, list of
Richard M. Stallman <rms@gnu.org>
parents: 14169
diff changeset
169
7638
fb6479579c0b entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
170 (defun refer-find-entry-internal (keywords continue)
12952
0ad88e6d8ef1 (refer-every): Renamed from every.
Richard M. Stallman <rms@gnu.org>
parents: 7638
diff changeset
171 (let ((keywords-list (refer-convert-string-to-list-of-strings keywords))
16473
4ef76e689d69 (refer-bib-directory): New variable, list of
Richard M. Stallman <rms@gnu.org>
parents: 14169
diff changeset
172 (old-buffer (current-buffer))
4ef76e689d69 (refer-bib-directory): New variable, list of
Richard M. Stallman <rms@gnu.org>
parents: 14169
diff changeset
173 (old-window (selected-window))
4ef76e689d69 (refer-bib-directory): New variable, list of
Richard M. Stallman <rms@gnu.org>
parents: 14169
diff changeset
174 (new-window (selected-window))
7638
fb6479579c0b entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
175 (files (if continue
fb6479579c0b entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
176 refer-saved-state
16473
4ef76e689d69 (refer-bib-directory): New variable, list of
Richard M. Stallman <rms@gnu.org>
parents: 14169
diff changeset
177 (setq refer-saved-pos nil)
4ef76e689d69 (refer-bib-directory): New variable, list of
Richard M. Stallman <rms@gnu.org>
parents: 14169
diff changeset
178 (refer-get-bib-files)))
4ef76e689d69 (refer-bib-directory): New variable, list of
Richard M. Stallman <rms@gnu.org>
parents: 14169
diff changeset
179 (n 0)
4ef76e689d69 (refer-bib-directory): New variable, list of
Richard M. Stallman <rms@gnu.org>
parents: 14169
diff changeset
180 (found nil)
4ef76e689d69 (refer-bib-directory): New variable, list of
Richard M. Stallman <rms@gnu.org>
parents: 14169
diff changeset
181 (file nil))
4ef76e689d69 (refer-bib-directory): New variable, list of
Richard M. Stallman <rms@gnu.org>
parents: 14169
diff changeset
182 ;; find window in which to display bibliography file.
4ef76e689d69 (refer-bib-directory): New variable, list of
Richard M. Stallman <rms@gnu.org>
parents: 14169
diff changeset
183 ;; if a bibliography file is already displayed in a window, use
4ef76e689d69 (refer-bib-directory): New variable, list of
Richard M. Stallman <rms@gnu.org>
parents: 14169
diff changeset
184 ;; that one, otherwise use any window other than the current one
4ef76e689d69 (refer-bib-directory): New variable, list of
Richard M. Stallman <rms@gnu.org>
parents: 14169
diff changeset
185 (while (not found)
4ef76e689d69 (refer-bib-directory): New variable, list of
Richard M. Stallman <rms@gnu.org>
parents: 14169
diff changeset
186 (while (and (not (null (setq file (nth n files))))
4ef76e689d69 (refer-bib-directory): New variable, list of
Richard M. Stallman <rms@gnu.org>
parents: 14169
diff changeset
187 (setq n (1+ n))
4ef76e689d69 (refer-bib-directory): New variable, list of
Richard M. Stallman <rms@gnu.org>
parents: 14169
diff changeset
188 (not (string-equal file
4ef76e689d69 (refer-bib-directory): New variable, list of
Richard M. Stallman <rms@gnu.org>
parents: 14169
diff changeset
189 (buffer-file-name
4ef76e689d69 (refer-bib-directory): New variable, list of
Richard M. Stallman <rms@gnu.org>
parents: 14169
diff changeset
190 (window-buffer new-window))))))
4ef76e689d69 (refer-bib-directory): New variable, list of
Richard M. Stallman <rms@gnu.org>
parents: 14169
diff changeset
191 (setq found
4ef76e689d69 (refer-bib-directory): New variable, list of
Richard M. Stallman <rms@gnu.org>
parents: 14169
diff changeset
192 (if (null file)
4ef76e689d69 (refer-bib-directory): New variable, list of
Richard M. Stallman <rms@gnu.org>
parents: 14169
diff changeset
193 (eq (setq new-window (next-window new-window 'nomini))
4ef76e689d69 (refer-bib-directory): New variable, list of
Richard M. Stallman <rms@gnu.org>
parents: 14169
diff changeset
194 old-window)
4ef76e689d69 (refer-bib-directory): New variable, list of
Richard M. Stallman <rms@gnu.org>
parents: 14169
diff changeset
195 't)))
4ef76e689d69 (refer-bib-directory): New variable, list of
Richard M. Stallman <rms@gnu.org>
parents: 14169
diff changeset
196 (if (null file) ; didn't find bib file in any window:
4ef76e689d69 (refer-bib-directory): New variable, list of
Richard M. Stallman <rms@gnu.org>
parents: 14169
diff changeset
197 (progn (if (one-window-p 'nomini)
4ef76e689d69 (refer-bib-directory): New variable, list of
Richard M. Stallman <rms@gnu.org>
parents: 14169
diff changeset
198 (setq old-window (split-window)))
4ef76e689d69 (refer-bib-directory): New variable, list of
Richard M. Stallman <rms@gnu.org>
parents: 14169
diff changeset
199 (setq new-window (next-window old-window 'nomini))))
4ef76e689d69 (refer-bib-directory): New variable, list of
Richard M. Stallman <rms@gnu.org>
parents: 14169
diff changeset
200 (select-window (if refer-same-file
4ef76e689d69 (refer-bib-directory): New variable, list of
Richard M. Stallman <rms@gnu.org>
parents: 14169
diff changeset
201 old-window
4ef76e689d69 (refer-bib-directory): New variable, list of
Richard M. Stallman <rms@gnu.org>
parents: 14169
diff changeset
202 new-window)) ; the window in which to show the bib file
4ef76e689d69 (refer-bib-directory): New variable, list of
Richard M. Stallman <rms@gnu.org>
parents: 14169
diff changeset
203 (catch 'found
4ef76e689d69 (refer-bib-directory): New variable, list of
Richard M. Stallman <rms@gnu.org>
parents: 14169
diff changeset
204 (while files
4ef76e689d69 (refer-bib-directory): New variable, list of
Richard M. Stallman <rms@gnu.org>
parents: 14169
diff changeset
205 (let ((file (cond ((file-exists-p (car files)) (car files))
4ef76e689d69 (refer-bib-directory): New variable, list of
Richard M. Stallman <rms@gnu.org>
parents: 14169
diff changeset
206 ((file-exists-p (concat (car files) ".bib"))
4ef76e689d69 (refer-bib-directory): New variable, list of
Richard M. Stallman <rms@gnu.org>
parents: 14169
diff changeset
207 (concat (car files) ".bib")))))
4ef76e689d69 (refer-bib-directory): New variable, list of
Richard M. Stallman <rms@gnu.org>
parents: 14169
diff changeset
208 (setq refer-saved-state files)
4ef76e689d69 (refer-bib-directory): New variable, list of
Richard M. Stallman <rms@gnu.org>
parents: 14169
diff changeset
209 (if file
4ef76e689d69 (refer-bib-directory): New variable, list of
Richard M. Stallman <rms@gnu.org>
parents: 14169
diff changeset
210 (if (refer-find-entry-in-file keywords-list file refer-saved-pos)
4ef76e689d69 (refer-bib-directory): New variable, list of
Richard M. Stallman <rms@gnu.org>
parents: 14169
diff changeset
211 (progn
4ef76e689d69 (refer-bib-directory): New variable, list of
Richard M. Stallman <rms@gnu.org>
parents: 14169
diff changeset
212 (setq refer-saved-pos (point))
4ef76e689d69 (refer-bib-directory): New variable, list of
Richard M. Stallman <rms@gnu.org>
parents: 14169
diff changeset
213 (recenter 0)
4ef76e689d69 (refer-bib-directory): New variable, list of
Richard M. Stallman <rms@gnu.org>
parents: 14169
diff changeset
214 (throw 'found (find-file file)))
4ef76e689d69 (refer-bib-directory): New variable, list of
Richard M. Stallman <rms@gnu.org>
parents: 14169
diff changeset
215 (setq refer-saved-pos nil
4ef76e689d69 (refer-bib-directory): New variable, list of
Richard M. Stallman <rms@gnu.org>
parents: 14169
diff changeset
216 files (cdr files)))
4ef76e689d69 (refer-bib-directory): New variable, list of
Richard M. Stallman <rms@gnu.org>
parents: 14169
diff changeset
217 (progn (message "Scanning %s... No such file" (car files) (ding))
4ef76e689d69 (refer-bib-directory): New variable, list of
Richard M. Stallman <rms@gnu.org>
parents: 14169
diff changeset
218 (sit-for 1)
4ef76e689d69 (refer-bib-directory): New variable, list of
Richard M. Stallman <rms@gnu.org>
parents: 14169
diff changeset
219 (setq files (cdr files))))))
4ef76e689d69 (refer-bib-directory): New variable, list of
Richard M. Stallman <rms@gnu.org>
parents: 14169
diff changeset
220 (message "Keywords \"%s\" not found in any \.bib file" keywords (ding)))
4ef76e689d69 (refer-bib-directory): New variable, list of
Richard M. Stallman <rms@gnu.org>
parents: 14169
diff changeset
221 (select-window old-window)))
7638
fb6479579c0b entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
222
16473
4ef76e689d69 (refer-bib-directory): New variable, list of
Richard M. Stallman <rms@gnu.org>
parents: 14169
diff changeset
223 (defun refer-find-entry-in-file (keywords-list file &optional old-pos)
4ef76e689d69 (refer-bib-directory): New variable, list of
Richard M. Stallman <rms@gnu.org>
parents: 14169
diff changeset
224 (message "Scanning %s..." file)
4ef76e689d69 (refer-bib-directory): New variable, list of
Richard M. Stallman <rms@gnu.org>
parents: 14169
diff changeset
225 (expand-file-name file)
7638
fb6479579c0b entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
226 (set-buffer (find-file-noselect file))
16473
4ef76e689d69 (refer-bib-directory): New variable, list of
Richard M. Stallman <rms@gnu.org>
parents: 14169
diff changeset
227 (find-file file)
4ef76e689d69 (refer-bib-directory): New variable, list of
Richard M. Stallman <rms@gnu.org>
parents: 14169
diff changeset
228 (if (not old-pos)
4ef76e689d69 (refer-bib-directory): New variable, list of
Richard M. Stallman <rms@gnu.org>
parents: 14169
diff changeset
229 (goto-char (point-min))
4ef76e689d69 (refer-bib-directory): New variable, list of
Richard M. Stallman <rms@gnu.org>
parents: 14169
diff changeset
230 (goto-char old-pos)
4ef76e689d69 (refer-bib-directory): New variable, list of
Richard M. Stallman <rms@gnu.org>
parents: 14169
diff changeset
231 (forward-paragraph 1))
7638
fb6479579c0b entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
232 (let ((begin (point))
fb6479579c0b entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
233 (end 0)
fb6479579c0b entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
234 (found nil))
16473
4ef76e689d69 (refer-bib-directory): New variable, list of
Richard M. Stallman <rms@gnu.org>
parents: 14169
diff changeset
235 (while (and (not found)
4ef76e689d69 (refer-bib-directory): New variable, list of
Richard M. Stallman <rms@gnu.org>
parents: 14169
diff changeset
236 (not (eobp)))
4ef76e689d69 (refer-bib-directory): New variable, list of
Richard M. Stallman <rms@gnu.org>
parents: 14169
diff changeset
237 (forward-paragraph 1)
4ef76e689d69 (refer-bib-directory): New variable, list of
Richard M. Stallman <rms@gnu.org>
parents: 14169
diff changeset
238 (setq end (point))
4ef76e689d69 (refer-bib-directory): New variable, list of
Richard M. Stallman <rms@gnu.org>
parents: 14169
diff changeset
239 (setq found
4ef76e689d69 (refer-bib-directory): New variable, list of
Richard M. Stallman <rms@gnu.org>
parents: 14169
diff changeset
240 (refer-every (function (lambda (keyword)
4ef76e689d69 (refer-bib-directory): New variable, list of
Richard M. Stallman <rms@gnu.org>
parents: 14169
diff changeset
241 (goto-char begin)
4ef76e689d69 (refer-bib-directory): New variable, list of
Richard M. Stallman <rms@gnu.org>
parents: 14169
diff changeset
242 (re-search-forward keyword end t)))
4ef76e689d69 (refer-bib-directory): New variable, list of
Richard M. Stallman <rms@gnu.org>
parents: 14169
diff changeset
243 keywords-list))
4ef76e689d69 (refer-bib-directory): New variable, list of
Richard M. Stallman <rms@gnu.org>
parents: 14169
diff changeset
244 (if (not found)
4ef76e689d69 (refer-bib-directory): New variable, list of
Richard M. Stallman <rms@gnu.org>
parents: 14169
diff changeset
245 (progn
4ef76e689d69 (refer-bib-directory): New variable, list of
Richard M. Stallman <rms@gnu.org>
parents: 14169
diff changeset
246 (setq begin end)
4ef76e689d69 (refer-bib-directory): New variable, list of
Richard M. Stallman <rms@gnu.org>
parents: 14169
diff changeset
247 (goto-char begin))))
4ef76e689d69 (refer-bib-directory): New variable, list of
Richard M. Stallman <rms@gnu.org>
parents: 14169
diff changeset
248 (if found
4ef76e689d69 (refer-bib-directory): New variable, list of
Richard M. Stallman <rms@gnu.org>
parents: 14169
diff changeset
249 (progn (goto-char begin)
4ef76e689d69 (refer-bib-directory): New variable, list of
Richard M. Stallman <rms@gnu.org>
parents: 14169
diff changeset
250 (re-search-forward "\\W" nil t)
4ef76e689d69 (refer-bib-directory): New variable, list of
Richard M. Stallman <rms@gnu.org>
parents: 14169
diff changeset
251 (message "Scanning %s... found" file))
4ef76e689d69 (refer-bib-directory): New variable, list of
Richard M. Stallman <rms@gnu.org>
parents: 14169
diff changeset
252 (progn (message "Scanning %s... not found" file)
4ef76e689d69 (refer-bib-directory): New variable, list of
Richard M. Stallman <rms@gnu.org>
parents: 14169
diff changeset
253 nil))))
7638
fb6479579c0b entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
254
12952
0ad88e6d8ef1 (refer-every): Renamed from every.
Richard M. Stallman <rms@gnu.org>
parents: 7638
diff changeset
255 (defun refer-every (pred l)
16473
4ef76e689d69 (refer-bib-directory): New variable, list of
Richard M. Stallman <rms@gnu.org>
parents: 14169
diff changeset
256 (cond ((null l) nil)
4ef76e689d69 (refer-bib-directory): New variable, list of
Richard M. Stallman <rms@gnu.org>
parents: 14169
diff changeset
257 ((funcall pred (car l))
4ef76e689d69 (refer-bib-directory): New variable, list of
Richard M. Stallman <rms@gnu.org>
parents: 14169
diff changeset
258 (or (null (cdr l))
4ef76e689d69 (refer-bib-directory): New variable, list of
Richard M. Stallman <rms@gnu.org>
parents: 14169
diff changeset
259 (refer-every pred (cdr l))))))
7638
fb6479579c0b entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
260
12952
0ad88e6d8ef1 (refer-every): Renamed from every.
Richard M. Stallman <rms@gnu.org>
parents: 7638
diff changeset
261 (defun refer-convert-string-to-list-of-strings (s)
7638
fb6479579c0b entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
262 (let ((current (current-buffer))
fb6479579c0b entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
263 (temp-buffer (get-buffer-create "*refer-temp*")))
fb6479579c0b entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
264 (set-buffer temp-buffer)
fb6479579c0b entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
265 (erase-buffer)
fb6479579c0b entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
266 (insert (regexp-quote s))
fb6479579c0b entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
267 (goto-char (point-min))
fb6479579c0b entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
268 (insert "(\"")
fb6479579c0b entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
269 (while (re-search-forward "[ \t]+" nil t)
fb6479579c0b entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
270 (replace-match "\" \"" t t))
fb6479579c0b entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
271 (goto-char (point-max))
fb6479579c0b entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
272 (insert "\")")
fb6479579c0b entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
273 (goto-char (point-min))
fb6479579c0b entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
274 (prog1 (read temp-buffer)
fb6479579c0b entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
275 (set-buffer current))))
fb6479579c0b entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
276
16473
4ef76e689d69 (refer-bib-directory): New variable, list of
Richard M. Stallman <rms@gnu.org>
parents: 14169
diff changeset
277 (defun refer-expand-files (file-list dir-list)
4ef76e689d69 (refer-bib-directory): New variable, list of
Richard M. Stallman <rms@gnu.org>
parents: 14169
diff changeset
278 (let (file files dir dirs)
4ef76e689d69 (refer-bib-directory): New variable, list of
Richard M. Stallman <rms@gnu.org>
parents: 14169
diff changeset
279 (while (setq file (car file-list))
4ef76e689d69 (refer-bib-directory): New variable, list of
Richard M. Stallman <rms@gnu.org>
parents: 14169
diff changeset
280 (setq dirs (copy-alist dir-list))
4ef76e689d69 (refer-bib-directory): New variable, list of
Richard M. Stallman <rms@gnu.org>
parents: 14169
diff changeset
281 (while (setq dir (car dirs))
4ef76e689d69 (refer-bib-directory): New variable, list of
Richard M. Stallman <rms@gnu.org>
parents: 14169
diff changeset
282 (if (file-exists-p (expand-file-name file dir))
4ef76e689d69 (refer-bib-directory): New variable, list of
Richard M. Stallman <rms@gnu.org>
parents: 14169
diff changeset
283 (setq files (append files (list (expand-file-name file dir)))
4ef76e689d69 (refer-bib-directory): New variable, list of
Richard M. Stallman <rms@gnu.org>
parents: 14169
diff changeset
284 dirs nil)
4ef76e689d69 (refer-bib-directory): New variable, list of
Richard M. Stallman <rms@gnu.org>
parents: 14169
diff changeset
285 (if (file-exists-p (expand-file-name (concat file ".bib") dir))
4ef76e689d69 (refer-bib-directory): New variable, list of
Richard M. Stallman <rms@gnu.org>
parents: 14169
diff changeset
286 (setq files (append files (list (expand-file-name (concat file ".bib")
4ef76e689d69 (refer-bib-directory): New variable, list of
Richard M. Stallman <rms@gnu.org>
parents: 14169
diff changeset
287 dir)))
4ef76e689d69 (refer-bib-directory): New variable, list of
Richard M. Stallman <rms@gnu.org>
parents: 14169
diff changeset
288 dirs nil)
4ef76e689d69 (refer-bib-directory): New variable, list of
Richard M. Stallman <rms@gnu.org>
parents: 14169
diff changeset
289 (setq dirs (cdr dirs)))))
4ef76e689d69 (refer-bib-directory): New variable, list of
Richard M. Stallman <rms@gnu.org>
parents: 14169
diff changeset
290 (setq file-list (cdr file-list)))
4ef76e689d69 (refer-bib-directory): New variable, list of
Richard M. Stallman <rms@gnu.org>
parents: 14169
diff changeset
291 files))
4ef76e689d69 (refer-bib-directory): New variable, list of
Richard M. Stallman <rms@gnu.org>
parents: 14169
diff changeset
292
7638
fb6479579c0b entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
293 (defun refer-get-bib-files ()
16473
4ef76e689d69 (refer-bib-directory): New variable, list of
Richard M. Stallman <rms@gnu.org>
parents: 14169
diff changeset
294 (let* ((dir-list
4ef76e689d69 (refer-bib-directory): New variable, list of
Richard M. Stallman <rms@gnu.org>
parents: 14169
diff changeset
295 (cond
4ef76e689d69 (refer-bib-directory): New variable, list of
Richard M. Stallman <rms@gnu.org>
parents: 14169
diff changeset
296 ((null refer-bib-directory)
4ef76e689d69 (refer-bib-directory): New variable, list of
Richard M. Stallman <rms@gnu.org>
parents: 14169
diff changeset
297 '("."))
4ef76e689d69 (refer-bib-directory): New variable, list of
Richard M. Stallman <rms@gnu.org>
parents: 14169
diff changeset
298 ((or (eq refer-bib-directory 'texinputs)
4ef76e689d69 (refer-bib-directory): New variable, list of
Richard M. Stallman <rms@gnu.org>
parents: 14169
diff changeset
299 (eq refer-bib-directory 'bibinputs))
4ef76e689d69 (refer-bib-directory): New variable, list of
Richard M. Stallman <rms@gnu.org>
parents: 14169
diff changeset
300 (let ((envvar (getenv (if (eq refer-bib-directory 'texinputs)
4ef76e689d69 (refer-bib-directory): New variable, list of
Richard M. Stallman <rms@gnu.org>
parents: 14169
diff changeset
301 "TEXINPUTS"
4ef76e689d69 (refer-bib-directory): New variable, list of
Richard M. Stallman <rms@gnu.org>
parents: 14169
diff changeset
302 "BIBINPUTS")))
4ef76e689d69 (refer-bib-directory): New variable, list of
Richard M. Stallman <rms@gnu.org>
parents: 14169
diff changeset
303 (dirs nil))
4ef76e689d69 (refer-bib-directory): New variable, list of
Richard M. Stallman <rms@gnu.org>
parents: 14169
diff changeset
304 (if (null envvar)
4ef76e689d69 (refer-bib-directory): New variable, list of
Richard M. Stallman <rms@gnu.org>
parents: 14169
diff changeset
305 (setq envvar "."))
4ef76e689d69 (refer-bib-directory): New variable, list of
Richard M. Stallman <rms@gnu.org>
parents: 14169
diff changeset
306 (while (string-match ":" envvar)
4ef76e689d69 (refer-bib-directory): New variable, list of
Richard M. Stallman <rms@gnu.org>
parents: 14169
diff changeset
307 (let ((dir (substring envvar 0 (match-beginning 0))))
4ef76e689d69 (refer-bib-directory): New variable, list of
Richard M. Stallman <rms@gnu.org>
parents: 14169
diff changeset
308 (if (and (not (string-equal "" dir))
4ef76e689d69 (refer-bib-directory): New variable, list of
Richard M. Stallman <rms@gnu.org>
parents: 14169
diff changeset
309 (file-directory-p dir))
4ef76e689d69 (refer-bib-directory): New variable, list of
Richard M. Stallman <rms@gnu.org>
parents: 14169
diff changeset
310 (setq dirs (append (list (expand-file-name dir nil))
4ef76e689d69 (refer-bib-directory): New variable, list of
Richard M. Stallman <rms@gnu.org>
parents: 14169
diff changeset
311 dirs))))
4ef76e689d69 (refer-bib-directory): New variable, list of
Richard M. Stallman <rms@gnu.org>
parents: 14169
diff changeset
312 (setq envvar (substring envvar (match-end 0))))
4ef76e689d69 (refer-bib-directory): New variable, list of
Richard M. Stallman <rms@gnu.org>
parents: 14169
diff changeset
313 (if (and (not (string-equal "" envvar))
4ef76e689d69 (refer-bib-directory): New variable, list of
Richard M. Stallman <rms@gnu.org>
parents: 14169
diff changeset
314 (file-directory-p envvar))
4ef76e689d69 (refer-bib-directory): New variable, list of
Richard M. Stallman <rms@gnu.org>
parents: 14169
diff changeset
315 (setq dirs (append (list envvar) dirs)))
4ef76e689d69 (refer-bib-directory): New variable, list of
Richard M. Stallman <rms@gnu.org>
parents: 14169
diff changeset
316 (setq dirs (nreverse dirs))))
4ef76e689d69 (refer-bib-directory): New variable, list of
Richard M. Stallman <rms@gnu.org>
parents: 14169
diff changeset
317 ((listp refer-bib-directory)
4ef76e689d69 (refer-bib-directory): New variable, list of
Richard M. Stallman <rms@gnu.org>
parents: 14169
diff changeset
318 refer-bib-directory)
4ef76e689d69 (refer-bib-directory): New variable, list of
Richard M. Stallman <rms@gnu.org>
parents: 14169
diff changeset
319 (t
4ef76e689d69 (refer-bib-directory): New variable, list of
Richard M. Stallman <rms@gnu.org>
parents: 14169
diff changeset
320 (list refer-bib-directory))))
4ef76e689d69 (refer-bib-directory): New variable, list of
Richard M. Stallman <rms@gnu.org>
parents: 14169
diff changeset
321 (files
4ef76e689d69 (refer-bib-directory): New variable, list of
Richard M. Stallman <rms@gnu.org>
parents: 14169
diff changeset
322 (cond
4ef76e689d69 (refer-bib-directory): New variable, list of
Richard M. Stallman <rms@gnu.org>
parents: 14169
diff changeset
323 ((null refer-bib-files)
4ef76e689d69 (refer-bib-directory): New variable, list of
Richard M. Stallman <rms@gnu.org>
parents: 14169
diff changeset
324 (list (expand-file-name
4ef76e689d69 (refer-bib-directory): New variable, list of
Richard M. Stallman <rms@gnu.org>
parents: 14169
diff changeset
325 (if (eq major-mode 'bibtex-mode)
4ef76e689d69 (refer-bib-directory): New variable, list of
Richard M. Stallman <rms@gnu.org>
parents: 14169
diff changeset
326 (read-file-name
4ef76e689d69 (refer-bib-directory): New variable, list of
Richard M. Stallman <rms@gnu.org>
parents: 14169
diff changeset
327 (format ".bib file: (default %s) "
4ef76e689d69 (refer-bib-directory): New variable, list of
Richard M. Stallman <rms@gnu.org>
parents: 14169
diff changeset
328 (file-name-nondirectory
4ef76e689d69 (refer-bib-directory): New variable, list of
Richard M. Stallman <rms@gnu.org>
parents: 14169
diff changeset
329 (buffer-file-name)))
4ef76e689d69 (refer-bib-directory): New variable, list of
Richard M. Stallman <rms@gnu.org>
parents: 14169
diff changeset
330 (file-name-directory (buffer-file-name))
4ef76e689d69 (refer-bib-directory): New variable, list of
Richard M. Stallman <rms@gnu.org>
parents: 14169
diff changeset
331 (file-name-nondirectory (buffer-file-name))
4ef76e689d69 (refer-bib-directory): New variable, list of
Richard M. Stallman <rms@gnu.org>
parents: 14169
diff changeset
332 t)
4ef76e689d69 (refer-bib-directory): New variable, list of
Richard M. Stallman <rms@gnu.org>
parents: 14169
diff changeset
333 (read-file-name ".bib file: " nil nil t)))))
4ef76e689d69 (refer-bib-directory): New variable, list of
Richard M. Stallman <rms@gnu.org>
parents: 14169
diff changeset
334 ((eq refer-bib-files 'auto)
4ef76e689d69 (refer-bib-directory): New variable, list of
Richard M. Stallman <rms@gnu.org>
parents: 14169
diff changeset
335 (let ((files
4ef76e689d69 (refer-bib-directory): New variable, list of
Richard M. Stallman <rms@gnu.org>
parents: 14169
diff changeset
336 (save-excursion
4ef76e689d69 (refer-bib-directory): New variable, list of
Richard M. Stallman <rms@gnu.org>
parents: 14169
diff changeset
337 (if (setq refer-same-file (eq major-mode 'bibtex-mode))
4ef76e689d69 (refer-bib-directory): New variable, list of
Richard M. Stallman <rms@gnu.org>
parents: 14169
diff changeset
338 (list buffer-file-name)
4ef76e689d69 (refer-bib-directory): New variable, list of
Richard M. Stallman <rms@gnu.org>
parents: 14169
diff changeset
339 (if (progn
4ef76e689d69 (refer-bib-directory): New variable, list of
Richard M. Stallman <rms@gnu.org>
parents: 14169
diff changeset
340 (goto-char (point-min))
4ef76e689d69 (refer-bib-directory): New variable, list of
Richard M. Stallman <rms@gnu.org>
parents: 14169
diff changeset
341 (re-search-forward (concat refer-bib-files-regexp
4ef76e689d69 (refer-bib-directory): New variable, list of
Richard M. Stallman <rms@gnu.org>
parents: 14169
diff changeset
342 "\\s-*\{") nil t))
4ef76e689d69 (refer-bib-directory): New variable, list of
Richard M. Stallman <rms@gnu.org>
parents: 14169
diff changeset
343 (let ((files (list (buffer-substring
4ef76e689d69 (refer-bib-directory): New variable, list of
Richard M. Stallman <rms@gnu.org>
parents: 14169
diff changeset
344 (point)
4ef76e689d69 (refer-bib-directory): New variable, list of
Richard M. Stallman <rms@gnu.org>
parents: 14169
diff changeset
345 (progn
4ef76e689d69 (refer-bib-directory): New variable, list of
Richard M. Stallman <rms@gnu.org>
parents: 14169
diff changeset
346 (re-search-forward "[,\}]"
4ef76e689d69 (refer-bib-directory): New variable, list of
Richard M. Stallman <rms@gnu.org>
parents: 14169
diff changeset
347 nil t)
4ef76e689d69 (refer-bib-directory): New variable, list of
Richard M. Stallman <rms@gnu.org>
parents: 14169
diff changeset
348 (backward-char 1)
4ef76e689d69 (refer-bib-directory): New variable, list of
Richard M. Stallman <rms@gnu.org>
parents: 14169
diff changeset
349 (point))))))
4ef76e689d69 (refer-bib-directory): New variable, list of
Richard M. Stallman <rms@gnu.org>
parents: 14169
diff changeset
350 (while (not (looking-at "\}"))
4ef76e689d69 (refer-bib-directory): New variable, list of
Richard M. Stallman <rms@gnu.org>
parents: 14169
diff changeset
351 (setq files (append files
4ef76e689d69 (refer-bib-directory): New variable, list of
Richard M. Stallman <rms@gnu.org>
parents: 14169
diff changeset
352 (list (buffer-substring
4ef76e689d69 (refer-bib-directory): New variable, list of
Richard M. Stallman <rms@gnu.org>
parents: 14169
diff changeset
353 (progn (forward-char 1)
4ef76e689d69 (refer-bib-directory): New variable, list of
Richard M. Stallman <rms@gnu.org>
parents: 14169
diff changeset
354 (point))
4ef76e689d69 (refer-bib-directory): New variable, list of
Richard M. Stallman <rms@gnu.org>
parents: 14169
diff changeset
355 (progn (re-search-forward
4ef76e689d69 (refer-bib-directory): New variable, list of
Richard M. Stallman <rms@gnu.org>
parents: 14169
diff changeset
356 "[,\}]" nil t)
4ef76e689d69 (refer-bib-directory): New variable, list of
Richard M. Stallman <rms@gnu.org>
parents: 14169
diff changeset
357 (backward-char 1)
4ef76e689d69 (refer-bib-directory): New variable, list of
Richard M. Stallman <rms@gnu.org>
parents: 14169
diff changeset
358 (point)))))))
4ef76e689d69 (refer-bib-directory): New variable, list of
Richard M. Stallman <rms@gnu.org>
parents: 14169
diff changeset
359 files)
4ef76e689d69 (refer-bib-directory): New variable, list of
Richard M. Stallman <rms@gnu.org>
parents: 14169
diff changeset
360 (error (concat "No \\\\bibliography command in this "
4ef76e689d69 (refer-bib-directory): New variable, list of
Richard M. Stallman <rms@gnu.org>
parents: 14169
diff changeset
361 "buffer, can't read refer-bib-files")))))))
4ef76e689d69 (refer-bib-directory): New variable, list of
Richard M. Stallman <rms@gnu.org>
parents: 14169
diff changeset
362 (refer-expand-files files dir-list)))
4ef76e689d69 (refer-bib-directory): New variable, list of
Richard M. Stallman <rms@gnu.org>
parents: 14169
diff changeset
363 ((eq refer-bib-files 'dir)
4ef76e689d69 (refer-bib-directory): New variable, list of
Richard M. Stallman <rms@gnu.org>
parents: 14169
diff changeset
364 (let ((dirs (nreverse dir-list))
4ef76e689d69 (refer-bib-directory): New variable, list of
Richard M. Stallman <rms@gnu.org>
parents: 14169
diff changeset
365 dir files)
4ef76e689d69 (refer-bib-directory): New variable, list of
Richard M. Stallman <rms@gnu.org>
parents: 14169
diff changeset
366 (while (setq dir (car dirs))
4ef76e689d69 (refer-bib-directory): New variable, list of
Richard M. Stallman <rms@gnu.org>
parents: 14169
diff changeset
367 (setq files
4ef76e689d69 (refer-bib-directory): New variable, list of
Richard M. Stallman <rms@gnu.org>
parents: 14169
diff changeset
368 (append (directory-files dir t "\\.bib$")
4ef76e689d69 (refer-bib-directory): New variable, list of
Richard M. Stallman <rms@gnu.org>
parents: 14169
diff changeset
369 files))
4ef76e689d69 (refer-bib-directory): New variable, list of
Richard M. Stallman <rms@gnu.org>
parents: 14169
diff changeset
370 (setq dirs (cdr dirs)))
4ef76e689d69 (refer-bib-directory): New variable, list of
Richard M. Stallman <rms@gnu.org>
parents: 14169
diff changeset
371 files))
4ef76e689d69 (refer-bib-directory): New variable, list of
Richard M. Stallman <rms@gnu.org>
parents: 14169
diff changeset
372 ((and (listp refer-bib-files)
4ef76e689d69 (refer-bib-directory): New variable, list of
Richard M. Stallman <rms@gnu.org>
parents: 14169
diff changeset
373 (or (eq refer-bib-directory 'texinputs)
4ef76e689d69 (refer-bib-directory): New variable, list of
Richard M. Stallman <rms@gnu.org>
parents: 14169
diff changeset
374 (eq refer-bib-directory 'bibinputs)))
4ef76e689d69 (refer-bib-directory): New variable, list of
Richard M. Stallman <rms@gnu.org>
parents: 14169
diff changeset
375 (refer-expand-files refer-bib-files dir-list))
4ef76e689d69 (refer-bib-directory): New variable, list of
Richard M. Stallman <rms@gnu.org>
parents: 14169
diff changeset
376 ((listp refer-bib-files) refer-bib-files)
4ef76e689d69 (refer-bib-directory): New variable, list of
Richard M. Stallman <rms@gnu.org>
parents: 14169
diff changeset
377 (t (error "Illegal value for refer-bib-files: %s"
4ef76e689d69 (refer-bib-directory): New variable, list of
Richard M. Stallman <rms@gnu.org>
parents: 14169
diff changeset
378 refer-bib-files)))))
4ef76e689d69 (refer-bib-directory): New variable, list of
Richard M. Stallman <rms@gnu.org>
parents: 14169
diff changeset
379 (if (or (eq refer-bib-directory 'texinputs)
4ef76e689d69 (refer-bib-directory): New variable, list of
Richard M. Stallman <rms@gnu.org>
parents: 14169
diff changeset
380 (eq refer-bib-directory 'bibinputs))
4ef76e689d69 (refer-bib-directory): New variable, list of
Richard M. Stallman <rms@gnu.org>
parents: 14169
diff changeset
381 (setq refer-bib-directory dir-list))
4ef76e689d69 (refer-bib-directory): New variable, list of
Richard M. Stallman <rms@gnu.org>
parents: 14169
diff changeset
382 (if refer-cache-bib-files
4ef76e689d69 (refer-bib-directory): New variable, list of
Richard M. Stallman <rms@gnu.org>
parents: 14169
diff changeset
383 (setq refer-bib-files files))
4ef76e689d69 (refer-bib-directory): New variable, list of
Richard M. Stallman <rms@gnu.org>
parents: 14169
diff changeset
384 files))
7638
fb6479579c0b entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
385
fb6479579c0b entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
386 ;;; refer.el ends here
16473
4ef76e689d69 (refer-bib-directory): New variable, list of
Richard M. Stallman <rms@gnu.org>
parents: 14169
diff changeset
387