annotate lisp/textmodes/refer.el @ 70498:d62ec265c5ad

*** empty log message ***
author YAMAMOTO Mitsuharu <mituharu@math.s.chiba-u.ac.jp>
date Sun, 07 May 2006 08:07:48 +0000
parents 067115a6e738
children 30655edb57ac c5406394f567
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
38436
b174db545cfd Some fixes to follow coding conventions.
Pavel Janík <Pavel@Janik.cz>
parents: 30326
diff changeset
1 ;;; refer.el --- look up references in bibliography files
7638
fb6479579c0b entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2
64751
5b1a238fcbb4 Update years in copyright notice; nfc.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 64084
diff changeset
3 ;; Copyright (C) 1992, 1996, 2001, 2002, 2003, 2004,
68648
067115a6e738 Update years in copyright notice; nfc.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 65680
diff changeset
4 ;; 2005, 2006 Free Software Foundation, Inc.
7638
fb6479579c0b entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
5
16473
4ef76e689d69 (refer-bib-directory): New variable, list of
Richard M. Stallman <rms@gnu.org>
parents: 14169
diff changeset
6 ;; Author: Ashwin Ram <ashwin@cc.gatech.edu>
30326
9d3a17593818 Correct maintainer's email address.
Gerd Moellmann <gerd@gnu.org>
parents: 29997
diff changeset
7 ;; Maintainer: Gernot Heiser <gernot@acm.org>
7638
fb6479579c0b entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
8 ;; Adapted-By: ESR
fb6479579c0b entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
9 ;; Keywords: bib
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 ;; This file is part of GNU Emacs.
fb6479579c0b entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
12
fb6479579c0b entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
13 ;; 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
14 ;; 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
15 ;; the Free Software Foundation; either version 2, or (at your option)
fb6479579c0b entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
16 ;; any later version.
fb6479579c0b entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
17
fb6479579c0b entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
18 ;; 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
19 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
fb6479579c0b entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
20 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
fb6479579c0b entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
21 ;; GNU General Public License for more details.
fb6479579c0b entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
22
fb6479579c0b entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
23 ;; 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
24 ;; along with GNU Emacs; see the file COPYING. If not, write to the
64084
a8fa7c632ee4 Update FSF's address.
Lute Kamstra <lute@gnu.org>
parents: 60918
diff changeset
25 ;; Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
a8fa7c632ee4 Update FSF's address.
Lute Kamstra <lute@gnu.org>
parents: 60918
diff changeset
26 ;; Boston, MA 02110-1301, USA.
7638
fb6479579c0b entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
27
fb6479579c0b entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
28 ;;; Commentary:
14169
83f275dcd93a Update FSF's address.
Erik Naggum <erik@naggum.no>
parents: 12952
diff changeset
29
7638
fb6479579c0b entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
30 ;; Functions to look up references in bibliography files given lists of
fb6479579c0b entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
31 ;; 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
32 ;; 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
33 ;; of keywords anywhere in the bibliography entry.
fb6479579c0b entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
34 ;;
fb6479579c0b entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
35 ;; To use:
fb6479579c0b entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
36 ;; (autoload 'refer-find-entry "refer" nil t)
fb6479579c0b entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
37 ;; or (require 'refer)
fb6479579c0b entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
38 ;;
fb6479579c0b entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
39 ;; To look for an article by Knuth about semaphores:
fb6479579c0b entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
40 ;; Invoke refer-find-entry, then in response to the Keywords: prompt,
fb6479579c0b entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
41 ;; 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
42 ;; as search strings).
fb6479579c0b entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
43 ;;
fb6479579c0b entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
44 ;; 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
45 ;; 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
46 ;; with a prefix argument.
fb6479579c0b entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
47 ;;
16473
4ef76e689d69 (refer-bib-directory): New variable, list of
Richard M. Stallman <rms@gnu.org>
parents: 14169
diff changeset
48 ;; 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
49 ;; 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
50 ;; (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
51 ;;
4ef76e689d69 (refer-bib-directory): New variable, list of
Richard M. Stallman <rms@gnu.org>
parents: 14169
diff changeset
52 ;; 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
53 ;; 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
54 ;;
7638
fb6479579c0b entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
55 ;; If the list of bibliography files changes, reinitialize the variable
fb6479579c0b entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
56 ;; refer-bib-files.
fb6479579c0b entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
57 ;;
fb6479579c0b entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
58 ;; To customize:
fb6479579c0b entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
59 ;; See variables refer-bib-files, refer-cache-bib-files and
fb6479579c0b entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
60 ;; 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
61 ;; 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
62 ;; directory.
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 ;; 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
65 ;; 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
66 ;; paragraph, looking for a paragraph containing all the keywords
fb6479579c0b entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
67 ;; 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
68 ;; 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
69 ;; entries, try setting the paragraph-start/separate variables, or changing
fb6479579c0b entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
70 ;; the (forward-paragraph 1) call in refer-find-entry-in-file.
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 ;;; Code:
fb6479579c0b entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
73
fb6479579c0b entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
74 (provide 'refer)
fb6479579c0b entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
75
20959
9b831f34ff7d Customized.
Stephen Eglen <stephen@gnu.org>
parents: 16473
diff changeset
76 (defgroup refer nil
9b831f34ff7d Customized.
Stephen Eglen <stephen@gnu.org>
parents: 16473
diff changeset
77 "Look up references in bibliography files."
9b831f34ff7d Customized.
Stephen Eglen <stephen@gnu.org>
parents: 16473
diff changeset
78 :prefix "refer-"
9b831f34ff7d Customized.
Stephen Eglen <stephen@gnu.org>
parents: 16473
diff changeset
79 :group 'wp)
9b831f34ff7d Customized.
Stephen Eglen <stephen@gnu.org>
parents: 16473
diff changeset
80
9b831f34ff7d Customized.
Stephen Eglen <stephen@gnu.org>
parents: 16473
diff changeset
81 (defcustom refer-bib-directory nil
16473
4ef76e689d69 (refer-bib-directory): New variable, list of
Richard M. Stallman <rms@gnu.org>
parents: 14169
diff changeset
82 "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
83 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
84 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
85 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
86 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
87 current working directory.
4ef76e689d69 (refer-bib-directory): New variable, list of
Richard M. Stallman <rms@gnu.org>
parents: 14169
diff changeset
88
4ef76e689d69 (refer-bib-directory): New variable, list of
Richard M. Stallman <rms@gnu.org>
parents: 14169
diff changeset
89 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
90 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
91
4ef76e689d69 (refer-bib-directory): New variable, list of
Richard M. Stallman <rms@gnu.org>
parents: 14169
diff changeset
92 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
93 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
94 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
95 environment if you really want it searched (which is not likely to
20959
9b831f34ff7d Customized.
Stephen Eglen <stephen@gnu.org>
parents: 16473
diff changeset
96 happen anyway)."
9b831f34ff7d Customized.
Stephen Eglen <stephen@gnu.org>
parents: 16473
diff changeset
97 :type '(choice (repeat directory) (const bibinputs) (const texinputs))
9b831f34ff7d Customized.
Stephen Eglen <stephen@gnu.org>
parents: 16473
diff changeset
98 :group 'refer)
16473
4ef76e689d69 (refer-bib-directory): New variable, list of
Richard M. Stallman <rms@gnu.org>
parents: 14169
diff changeset
99
20959
9b831f34ff7d Customized.
Stephen Eglen <stephen@gnu.org>
parents: 16473
diff changeset
100 (defcustom refer-bib-files 'dir
9b831f34ff7d Customized.
Stephen Eglen <stephen@gnu.org>
parents: 16473
diff changeset
101 "*List of \\.bib files to search for references,
7638
fb6479579c0b entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
102 or one of the following special values:
fb6479579c0b entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
103 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
104 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
105 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
106 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
107 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
108
fb6479579c0b entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
109 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
110 is automatically tried.
fb6479579c0b entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
111
fb6479579c0b entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
112 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
113 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
114 refer-cache-bib-files is nil, the list of \\.bib files to use is re-read
20959
9b831f34ff7d Customized.
Stephen Eglen <stephen@gnu.org>
parents: 16473
diff changeset
115 each time it is needed."
9b831f34ff7d Customized.
Stephen Eglen <stephen@gnu.org>
parents: 16473
diff changeset
116 :type '(choice (repeat file) (const nil) (const auto) (const dir))
9b831f34ff7d Customized.
Stephen Eglen <stephen@gnu.org>
parents: 16473
diff changeset
117 :group 'refer)
7638
fb6479579c0b entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
118
20959
9b831f34ff7d Customized.
Stephen Eglen <stephen@gnu.org>
parents: 16473
diff changeset
119 (defcustom refer-cache-bib-files t
9b831f34ff7d Customized.
Stephen Eglen <stephen@gnu.org>
parents: 16473
diff changeset
120 "*Variable determining whether the value of refer-bib-files should be cached.
7638
fb6479579c0b entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
121 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
122 nil, re-read the list of \\.bib files depending on the value of refer-bib-files
20959
9b831f34ff7d Customized.
Stephen Eglen <stephen@gnu.org>
parents: 16473
diff changeset
123 each time it is needed."
9b831f34ff7d Customized.
Stephen Eglen <stephen@gnu.org>
parents: 16473
diff changeset
124 :type 'boolean
9b831f34ff7d Customized.
Stephen Eglen <stephen@gnu.org>
parents: 16473
diff changeset
125 :group 'refer)
7638
fb6479579c0b entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
126
20959
9b831f34ff7d Customized.
Stephen Eglen <stephen@gnu.org>
parents: 16473
diff changeset
127 (defcustom refer-bib-files-regexp "\\\\bibliography"
9b831f34ff7d Customized.
Stephen Eglen <stephen@gnu.org>
parents: 16473
diff changeset
128 "*Regexp matching a bibliography file declaration.
7638
fb6479579c0b entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
129 The current buffer is expected to contain a line such as
fb6479579c0b entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
130 \\bibliography{file1,file2,file3}
fb6479579c0b entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
131 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
132 (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
133 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
134 names, within curly braces.
fb6479579c0b entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
135 If a specified file doesn't exist and has no extension, a \\.bib extension
20959
9b831f34ff7d Customized.
Stephen Eglen <stephen@gnu.org>
parents: 16473
diff changeset
136 is automatically tried."
9b831f34ff7d Customized.
Stephen Eglen <stephen@gnu.org>
parents: 16473
diff changeset
137 :type 'regexp
9b831f34ff7d Customized.
Stephen Eglen <stephen@gnu.org>
parents: 16473
diff changeset
138 :group 'refer)
7638
fb6479579c0b entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
139
fb6479579c0b entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
140 (make-variable-buffer-local 'refer-bib-files)
fb6479579c0b entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
141 (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
142 (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
143
4ef76e689d69 (refer-bib-directory): New variable, list of
Richard M. Stallman <rms@gnu.org>
parents: 14169
diff changeset
144 ;;; Internal variables
4ef76e689d69 (refer-bib-directory): New variable, list of
Richard M. Stallman <rms@gnu.org>
parents: 14169
diff changeset
145 (defvar refer-saved-state nil)
4ef76e689d69 (refer-bib-directory): New variable, list of
Richard M. Stallman <rms@gnu.org>
parents: 14169
diff changeset
146 (defvar refer-previous-keywords nil)
4ef76e689d69 (refer-bib-directory): New variable, list of
Richard M. Stallman <rms@gnu.org>
parents: 14169
diff changeset
147 (defvar refer-saved-pos nil)
4ef76e689d69 (refer-bib-directory): New variable, list of
Richard M. Stallman <rms@gnu.org>
parents: 14169
diff changeset
148 (defvar refer-same-file nil)
7638
fb6479579c0b entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
149
fb6479579c0b entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
150 (defun refer-find-entry (keywords &optional continue)
fb6479579c0b entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
151 "Find entry in refer-bib-files containing KEYWORDS.
fb6479579c0b entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
152 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
153 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
154 entry by continuing search from previous point."
fb6479579c0b entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
155 (interactive (list nil current-prefix-arg))
fb6479579c0b entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
156 (or keywords (setq keywords (if continue
fb6479579c0b entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
157 refer-previous-keywords
16473
4ef76e689d69 (refer-bib-directory): New variable, list of
Richard M. Stallman <rms@gnu.org>
parents: 14169
diff changeset
158 (read-string "Keywords: "))))
7638
fb6479579c0b entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
159 (setq refer-previous-keywords keywords)
fb6479579c0b entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
160 (refer-find-entry-internal keywords continue))
fb6479579c0b entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
161
fb6479579c0b entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
162 (defun refer-find-next-entry ()
fb6479579c0b entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
163 "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
164 (interactive)
fb6479579c0b entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
165 (refer-find-entry-internal refer-previous-keywords t))
fb6479579c0b entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
166
16473
4ef76e689d69 (refer-bib-directory): New variable, list of
Richard M. Stallman <rms@gnu.org>
parents: 14169
diff changeset
167 (defun refer-yank-key ()
4ef76e689d69 (refer-bib-directory): New variable, list of
Richard M. Stallman <rms@gnu.org>
parents: 14169
diff changeset
168 "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
169 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
170 (interactive)
4ef76e689d69 (refer-bib-directory): New variable, list of
Richard M. Stallman <rms@gnu.org>
parents: 14169
diff changeset
171 (let ((old-point (point)))
4ef76e689d69 (refer-bib-directory): New variable, list of
Richard M. Stallman <rms@gnu.org>
parents: 14169
diff changeset
172 (insert
4ef76e689d69 (refer-bib-directory): New variable, list of
Richard M. Stallman <rms@gnu.org>
parents: 14169
diff changeset
173 (save-window-excursion
4ef76e689d69 (refer-bib-directory): New variable, list of
Richard M. Stallman <rms@gnu.org>
parents: 14169
diff changeset
174 (save-excursion
4ef76e689d69 (refer-bib-directory): New variable, list of
Richard M. Stallman <rms@gnu.org>
parents: 14169
diff changeset
175 (find-file (car refer-saved-state))
4ef76e689d69 (refer-bib-directory): New variable, list of
Richard M. Stallman <rms@gnu.org>
parents: 14169
diff changeset
176 (if (looking-at
4ef76e689d69 (refer-bib-directory): New variable, list of
Richard M. Stallman <rms@gnu.org>
parents: 14169
diff changeset
177 "[ \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
178 (buffer-substring (match-beginning 1) (match-end 1))
38436
b174db545cfd Some fixes to follow coding conventions.
Pavel Janík <Pavel@Janik.cz>
parents: 30326
diff changeset
179 (error "Cannot find key for entry in file %s"
16473
4ef76e689d69 (refer-bib-directory): New variable, list of
Richard M. Stallman <rms@gnu.org>
parents: 14169
diff changeset
180 (car refer-saved-state))))))
4ef76e689d69 (refer-bib-directory): New variable, list of
Richard M. Stallman <rms@gnu.org>
parents: 14169
diff changeset
181 (if (not (= (point) old-point))
4ef76e689d69 (refer-bib-directory): New variable, list of
Richard M. Stallman <rms@gnu.org>
parents: 14169
diff changeset
182 (set-mark old-point))))
4ef76e689d69 (refer-bib-directory): New variable, list of
Richard M. Stallman <rms@gnu.org>
parents: 14169
diff changeset
183
7638
fb6479579c0b entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
184 (defun refer-find-entry-internal (keywords continue)
12952
0ad88e6d8ef1 (refer-every): Renamed from every.
Richard M. Stallman <rms@gnu.org>
parents: 7638
diff changeset
185 (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
186 (old-buffer (current-buffer))
4ef76e689d69 (refer-bib-directory): New variable, list of
Richard M. Stallman <rms@gnu.org>
parents: 14169
diff changeset
187 (old-window (selected-window))
4ef76e689d69 (refer-bib-directory): New variable, list of
Richard M. Stallman <rms@gnu.org>
parents: 14169
diff changeset
188 (new-window (selected-window))
7638
fb6479579c0b entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
189 (files (if continue
fb6479579c0b entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
190 refer-saved-state
16473
4ef76e689d69 (refer-bib-directory): New variable, list of
Richard M. Stallman <rms@gnu.org>
parents: 14169
diff changeset
191 (setq refer-saved-pos nil)
4ef76e689d69 (refer-bib-directory): New variable, list of
Richard M. Stallman <rms@gnu.org>
parents: 14169
diff changeset
192 (refer-get-bib-files)))
4ef76e689d69 (refer-bib-directory): New variable, list of
Richard M. Stallman <rms@gnu.org>
parents: 14169
diff changeset
193 (n 0)
4ef76e689d69 (refer-bib-directory): New variable, list of
Richard M. Stallman <rms@gnu.org>
parents: 14169
diff changeset
194 (found nil)
4ef76e689d69 (refer-bib-directory): New variable, list of
Richard M. Stallman <rms@gnu.org>
parents: 14169
diff changeset
195 (file nil))
4ef76e689d69 (refer-bib-directory): New variable, list of
Richard M. Stallman <rms@gnu.org>
parents: 14169
diff changeset
196 ;; 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
197 ;; 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
198 ;; that one, otherwise use any window other than the current one
29997
d6a745cf3bfc (refer-find-entry-internal): Use some-window
Gerd Moellmann <gerd@gnu.org>
parents: 20959
diff changeset
199 (setq new-window
39176
286d91f8ebe3 (refer-find-entry-internal): Use
Gerd Moellmann <gerd@gnu.org>
parents: 38436
diff changeset
200 (get-window-with-predicate
286d91f8ebe3 (refer-find-entry-internal): Use
Gerd Moellmann <gerd@gnu.org>
parents: 38436
diff changeset
201 (lambda (w)
286d91f8ebe3 (refer-find-entry-internal): Use
Gerd Moellmann <gerd@gnu.org>
parents: 38436
diff changeset
202 (while (and (not (null (setq file (nth n files))))
286d91f8ebe3 (refer-find-entry-internal): Use
Gerd Moellmann <gerd@gnu.org>
parents: 38436
diff changeset
203 (setq n (1+ n))
286d91f8ebe3 (refer-find-entry-internal): Use
Gerd Moellmann <gerd@gnu.org>
parents: 38436
diff changeset
204 (not (string-equal file
286d91f8ebe3 (refer-find-entry-internal): Use
Gerd Moellmann <gerd@gnu.org>
parents: 38436
diff changeset
205 (buffer-file-name
286d91f8ebe3 (refer-find-entry-internal): Use
Gerd Moellmann <gerd@gnu.org>
parents: 38436
diff changeset
206 (window-buffer w))))))
286d91f8ebe3 (refer-find-entry-internal): Use
Gerd Moellmann <gerd@gnu.org>
parents: 38436
diff changeset
207 file)))
29997
d6a745cf3bfc (refer-find-entry-internal): Use some-window
Gerd Moellmann <gerd@gnu.org>
parents: 20959
diff changeset
208 (unless new-window
d6a745cf3bfc (refer-find-entry-internal): Use some-window
Gerd Moellmann <gerd@gnu.org>
parents: 20959
diff changeset
209 ;; didn't find bib file in any window:
d6a745cf3bfc (refer-find-entry-internal): Use some-window
Gerd Moellmann <gerd@gnu.org>
parents: 20959
diff changeset
210 (when (one-window-p 'nomini)
d6a745cf3bfc (refer-find-entry-internal): Use some-window
Gerd Moellmann <gerd@gnu.org>
parents: 20959
diff changeset
211 (setq old-window (split-window)))
d6a745cf3bfc (refer-find-entry-internal): Use some-window
Gerd Moellmann <gerd@gnu.org>
parents: 20959
diff changeset
212 (setq new-window (next-window old-window 'nomini)))
16473
4ef76e689d69 (refer-bib-directory): New variable, list of
Richard M. Stallman <rms@gnu.org>
parents: 14169
diff changeset
213 (select-window (if refer-same-file
4ef76e689d69 (refer-bib-directory): New variable, list of
Richard M. Stallman <rms@gnu.org>
parents: 14169
diff changeset
214 old-window
4ef76e689d69 (refer-bib-directory): New variable, list of
Richard M. Stallman <rms@gnu.org>
parents: 14169
diff changeset
215 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
216 (catch 'found
4ef76e689d69 (refer-bib-directory): New variable, list of
Richard M. Stallman <rms@gnu.org>
parents: 14169
diff changeset
217 (while files
4ef76e689d69 (refer-bib-directory): New variable, list of
Richard M. Stallman <rms@gnu.org>
parents: 14169
diff changeset
218 (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
219 ((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
220 (concat (car files) ".bib")))))
4ef76e689d69 (refer-bib-directory): New variable, list of
Richard M. Stallman <rms@gnu.org>
parents: 14169
diff changeset
221 (setq refer-saved-state files)
4ef76e689d69 (refer-bib-directory): New variable, list of
Richard M. Stallman <rms@gnu.org>
parents: 14169
diff changeset
222 (if file
4ef76e689d69 (refer-bib-directory): New variable, list of
Richard M. Stallman <rms@gnu.org>
parents: 14169
diff changeset
223 (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
224 (progn
4ef76e689d69 (refer-bib-directory): New variable, list of
Richard M. Stallman <rms@gnu.org>
parents: 14169
diff changeset
225 (setq refer-saved-pos (point))
4ef76e689d69 (refer-bib-directory): New variable, list of
Richard M. Stallman <rms@gnu.org>
parents: 14169
diff changeset
226 (recenter 0)
4ef76e689d69 (refer-bib-directory): New variable, list of
Richard M. Stallman <rms@gnu.org>
parents: 14169
diff changeset
227 (throw 'found (find-file file)))
4ef76e689d69 (refer-bib-directory): New variable, list of
Richard M. Stallman <rms@gnu.org>
parents: 14169
diff changeset
228 (setq refer-saved-pos nil
4ef76e689d69 (refer-bib-directory): New variable, list of
Richard M. Stallman <rms@gnu.org>
parents: 14169
diff changeset
229 files (cdr files)))
53853
9f8bd1b673a8 (refer-find-entry-internal): Remove extra
Andreas Schwab <schwab@suse.de>
parents: 52401
diff changeset
230 (progn (ding)
9f8bd1b673a8 (refer-find-entry-internal): Remove extra
Andreas Schwab <schwab@suse.de>
parents: 52401
diff changeset
231 (message "Scanning %s... No such file" (car files))
16473
4ef76e689d69 (refer-bib-directory): New variable, list of
Richard M. Stallman <rms@gnu.org>
parents: 14169
diff changeset
232 (sit-for 1)
4ef76e689d69 (refer-bib-directory): New variable, list of
Richard M. Stallman <rms@gnu.org>
parents: 14169
diff changeset
233 (setq files (cdr files))))))
53853
9f8bd1b673a8 (refer-find-entry-internal): Remove extra
Andreas Schwab <schwab@suse.de>
parents: 52401
diff changeset
234 (ding)
9f8bd1b673a8 (refer-find-entry-internal): Remove extra
Andreas Schwab <schwab@suse.de>
parents: 52401
diff changeset
235 (message "Keywords \"%s\" not found in any \.bib file" keywords))
16473
4ef76e689d69 (refer-bib-directory): New variable, list of
Richard M. Stallman <rms@gnu.org>
parents: 14169
diff changeset
236 (select-window old-window)))
7638
fb6479579c0b entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
237
16473
4ef76e689d69 (refer-bib-directory): New variable, list of
Richard M. Stallman <rms@gnu.org>
parents: 14169
diff changeset
238 (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
239 (message "Scanning %s..." file)
4ef76e689d69 (refer-bib-directory): New variable, list of
Richard M. Stallman <rms@gnu.org>
parents: 14169
diff changeset
240 (expand-file-name file)
7638
fb6479579c0b entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
241 (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
242 (find-file file)
4ef76e689d69 (refer-bib-directory): New variable, list of
Richard M. Stallman <rms@gnu.org>
parents: 14169
diff changeset
243 (if (not old-pos)
4ef76e689d69 (refer-bib-directory): New variable, list of
Richard M. Stallman <rms@gnu.org>
parents: 14169
diff changeset
244 (goto-char (point-min))
4ef76e689d69 (refer-bib-directory): New variable, list of
Richard M. Stallman <rms@gnu.org>
parents: 14169
diff changeset
245 (goto-char old-pos)
4ef76e689d69 (refer-bib-directory): New variable, list of
Richard M. Stallman <rms@gnu.org>
parents: 14169
diff changeset
246 (forward-paragraph 1))
7638
fb6479579c0b entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
247 (let ((begin (point))
fb6479579c0b entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
248 (end 0)
fb6479579c0b entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
249 (found nil))
16473
4ef76e689d69 (refer-bib-directory): New variable, list of
Richard M. Stallman <rms@gnu.org>
parents: 14169
diff changeset
250 (while (and (not found)
4ef76e689d69 (refer-bib-directory): New variable, list of
Richard M. Stallman <rms@gnu.org>
parents: 14169
diff changeset
251 (not (eobp)))
4ef76e689d69 (refer-bib-directory): New variable, list of
Richard M. Stallman <rms@gnu.org>
parents: 14169
diff changeset
252 (forward-paragraph 1)
4ef76e689d69 (refer-bib-directory): New variable, list of
Richard M. Stallman <rms@gnu.org>
parents: 14169
diff changeset
253 (setq end (point))
4ef76e689d69 (refer-bib-directory): New variable, list of
Richard M. Stallman <rms@gnu.org>
parents: 14169
diff changeset
254 (setq found
4ef76e689d69 (refer-bib-directory): New variable, list of
Richard M. Stallman <rms@gnu.org>
parents: 14169
diff changeset
255 (refer-every (function (lambda (keyword)
4ef76e689d69 (refer-bib-directory): New variable, list of
Richard M. Stallman <rms@gnu.org>
parents: 14169
diff changeset
256 (goto-char begin)
4ef76e689d69 (refer-bib-directory): New variable, list of
Richard M. Stallman <rms@gnu.org>
parents: 14169
diff changeset
257 (re-search-forward keyword end t)))
4ef76e689d69 (refer-bib-directory): New variable, list of
Richard M. Stallman <rms@gnu.org>
parents: 14169
diff changeset
258 keywords-list))
4ef76e689d69 (refer-bib-directory): New variable, list of
Richard M. Stallman <rms@gnu.org>
parents: 14169
diff changeset
259 (if (not found)
4ef76e689d69 (refer-bib-directory): New variable, list of
Richard M. Stallman <rms@gnu.org>
parents: 14169
diff changeset
260 (progn
4ef76e689d69 (refer-bib-directory): New variable, list of
Richard M. Stallman <rms@gnu.org>
parents: 14169
diff changeset
261 (setq begin end)
4ef76e689d69 (refer-bib-directory): New variable, list of
Richard M. Stallman <rms@gnu.org>
parents: 14169
diff changeset
262 (goto-char begin))))
4ef76e689d69 (refer-bib-directory): New variable, list of
Richard M. Stallman <rms@gnu.org>
parents: 14169
diff changeset
263 (if found
4ef76e689d69 (refer-bib-directory): New variable, list of
Richard M. Stallman <rms@gnu.org>
parents: 14169
diff changeset
264 (progn (goto-char begin)
4ef76e689d69 (refer-bib-directory): New variable, list of
Richard M. Stallman <rms@gnu.org>
parents: 14169
diff changeset
265 (re-search-forward "\\W" nil t)
4ef76e689d69 (refer-bib-directory): New variable, list of
Richard M. Stallman <rms@gnu.org>
parents: 14169
diff changeset
266 (message "Scanning %s... found" file))
4ef76e689d69 (refer-bib-directory): New variable, list of
Richard M. Stallman <rms@gnu.org>
parents: 14169
diff changeset
267 (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
268 nil))))
7638
fb6479579c0b entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
269
12952
0ad88e6d8ef1 (refer-every): Renamed from every.
Richard M. Stallman <rms@gnu.org>
parents: 7638
diff changeset
270 (defun refer-every (pred l)
16473
4ef76e689d69 (refer-bib-directory): New variable, list of
Richard M. Stallman <rms@gnu.org>
parents: 14169
diff changeset
271 (cond ((null l) nil)
4ef76e689d69 (refer-bib-directory): New variable, list of
Richard M. Stallman <rms@gnu.org>
parents: 14169
diff changeset
272 ((funcall pred (car l))
4ef76e689d69 (refer-bib-directory): New variable, list of
Richard M. Stallman <rms@gnu.org>
parents: 14169
diff changeset
273 (or (null (cdr l))
4ef76e689d69 (refer-bib-directory): New variable, list of
Richard M. Stallman <rms@gnu.org>
parents: 14169
diff changeset
274 (refer-every pred (cdr l))))))
7638
fb6479579c0b entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
275
12952
0ad88e6d8ef1 (refer-every): Renamed from every.
Richard M. Stallman <rms@gnu.org>
parents: 7638
diff changeset
276 (defun refer-convert-string-to-list-of-strings (s)
7638
fb6479579c0b entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
277 (let ((current (current-buffer))
fb6479579c0b entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
278 (temp-buffer (get-buffer-create "*refer-temp*")))
fb6479579c0b entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
279 (set-buffer temp-buffer)
fb6479579c0b entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
280 (erase-buffer)
fb6479579c0b entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
281 (insert (regexp-quote s))
fb6479579c0b entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
282 (goto-char (point-min))
fb6479579c0b entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
283 (insert "(\"")
fb6479579c0b entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
284 (while (re-search-forward "[ \t]+" nil t)
fb6479579c0b entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
285 (replace-match "\" \"" t t))
fb6479579c0b entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
286 (goto-char (point-max))
fb6479579c0b entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
287 (insert "\")")
fb6479579c0b entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
288 (goto-char (point-min))
fb6479579c0b entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
289 (prog1 (read temp-buffer)
fb6479579c0b entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
290 (set-buffer current))))
fb6479579c0b entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
291
16473
4ef76e689d69 (refer-bib-directory): New variable, list of
Richard M. Stallman <rms@gnu.org>
parents: 14169
diff changeset
292 (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
293 (let (file files dir dirs)
4ef76e689d69 (refer-bib-directory): New variable, list of
Richard M. Stallman <rms@gnu.org>
parents: 14169
diff changeset
294 (while (setq file (car file-list))
4ef76e689d69 (refer-bib-directory): New variable, list of
Richard M. Stallman <rms@gnu.org>
parents: 14169
diff changeset
295 (setq dirs (copy-alist dir-list))
4ef76e689d69 (refer-bib-directory): New variable, list of
Richard M. Stallman <rms@gnu.org>
parents: 14169
diff changeset
296 (while (setq dir (car dirs))
4ef76e689d69 (refer-bib-directory): New variable, list of
Richard M. Stallman <rms@gnu.org>
parents: 14169
diff changeset
297 (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
298 (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
299 dirs nil)
4ef76e689d69 (refer-bib-directory): New variable, list of
Richard M. Stallman <rms@gnu.org>
parents: 14169
diff changeset
300 (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
301 (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
302 dir)))
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 (setq dirs (cdr dirs)))))
4ef76e689d69 (refer-bib-directory): New variable, list of
Richard M. Stallman <rms@gnu.org>
parents: 14169
diff changeset
305 (setq file-list (cdr file-list)))
4ef76e689d69 (refer-bib-directory): New variable, list of
Richard M. Stallman <rms@gnu.org>
parents: 14169
diff changeset
306 files))
4ef76e689d69 (refer-bib-directory): New variable, list of
Richard M. Stallman <rms@gnu.org>
parents: 14169
diff changeset
307
7638
fb6479579c0b entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
308 (defun refer-get-bib-files ()
16473
4ef76e689d69 (refer-bib-directory): New variable, list of
Richard M. Stallman <rms@gnu.org>
parents: 14169
diff changeset
309 (let* ((dir-list
4ef76e689d69 (refer-bib-directory): New variable, list of
Richard M. Stallman <rms@gnu.org>
parents: 14169
diff changeset
310 (cond
4ef76e689d69 (refer-bib-directory): New variable, list of
Richard M. Stallman <rms@gnu.org>
parents: 14169
diff changeset
311 ((null refer-bib-directory)
4ef76e689d69 (refer-bib-directory): New variable, list of
Richard M. Stallman <rms@gnu.org>
parents: 14169
diff changeset
312 '("."))
4ef76e689d69 (refer-bib-directory): New variable, list of
Richard M. Stallman <rms@gnu.org>
parents: 14169
diff changeset
313 ((or (eq refer-bib-directory 'texinputs)
4ef76e689d69 (refer-bib-directory): New variable, list of
Richard M. Stallman <rms@gnu.org>
parents: 14169
diff changeset
314 (eq refer-bib-directory 'bibinputs))
4ef76e689d69 (refer-bib-directory): New variable, list of
Richard M. Stallman <rms@gnu.org>
parents: 14169
diff changeset
315 (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
316 "TEXINPUTS"
4ef76e689d69 (refer-bib-directory): New variable, list of
Richard M. Stallman <rms@gnu.org>
parents: 14169
diff changeset
317 "BIBINPUTS")))
4ef76e689d69 (refer-bib-directory): New variable, list of
Richard M. Stallman <rms@gnu.org>
parents: 14169
diff changeset
318 (dirs nil))
4ef76e689d69 (refer-bib-directory): New variable, list of
Richard M. Stallman <rms@gnu.org>
parents: 14169
diff changeset
319 (if (null envvar)
4ef76e689d69 (refer-bib-directory): New variable, list of
Richard M. Stallman <rms@gnu.org>
parents: 14169
diff changeset
320 (setq envvar "."))
4ef76e689d69 (refer-bib-directory): New variable, list of
Richard M. Stallman <rms@gnu.org>
parents: 14169
diff changeset
321 (while (string-match ":" envvar)
4ef76e689d69 (refer-bib-directory): New variable, list of
Richard M. Stallman <rms@gnu.org>
parents: 14169
diff changeset
322 (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
323 (if (and (not (string-equal "" dir))
4ef76e689d69 (refer-bib-directory): New variable, list of
Richard M. Stallman <rms@gnu.org>
parents: 14169
diff changeset
324 (file-directory-p dir))
4ef76e689d69 (refer-bib-directory): New variable, list of
Richard M. Stallman <rms@gnu.org>
parents: 14169
diff changeset
325 (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
326 dirs))))
4ef76e689d69 (refer-bib-directory): New variable, list of
Richard M. Stallman <rms@gnu.org>
parents: 14169
diff changeset
327 (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
328 (if (and (not (string-equal "" envvar))
4ef76e689d69 (refer-bib-directory): New variable, list of
Richard M. Stallman <rms@gnu.org>
parents: 14169
diff changeset
329 (file-directory-p envvar))
4ef76e689d69 (refer-bib-directory): New variable, list of
Richard M. Stallman <rms@gnu.org>
parents: 14169
diff changeset
330 (setq dirs (append (list envvar) dirs)))
4ef76e689d69 (refer-bib-directory): New variable, list of
Richard M. Stallman <rms@gnu.org>
parents: 14169
diff changeset
331 (setq dirs (nreverse dirs))))
4ef76e689d69 (refer-bib-directory): New variable, list of
Richard M. Stallman <rms@gnu.org>
parents: 14169
diff changeset
332 ((listp refer-bib-directory)
4ef76e689d69 (refer-bib-directory): New variable, list of
Richard M. Stallman <rms@gnu.org>
parents: 14169
diff changeset
333 refer-bib-directory)
4ef76e689d69 (refer-bib-directory): New variable, list of
Richard M. Stallman <rms@gnu.org>
parents: 14169
diff changeset
334 (t
4ef76e689d69 (refer-bib-directory): New variable, list of
Richard M. Stallman <rms@gnu.org>
parents: 14169
diff changeset
335 (list refer-bib-directory))))
4ef76e689d69 (refer-bib-directory): New variable, list of
Richard M. Stallman <rms@gnu.org>
parents: 14169
diff changeset
336 (files
4ef76e689d69 (refer-bib-directory): New variable, list of
Richard M. Stallman <rms@gnu.org>
parents: 14169
diff changeset
337 (cond
49599
5ade352e8d1c Trailing whitespace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents: 39176
diff changeset
338 ((null refer-bib-files)
16473
4ef76e689d69 (refer-bib-directory): New variable, list of
Richard M. Stallman <rms@gnu.org>
parents: 14169
diff changeset
339 (list (expand-file-name
4ef76e689d69 (refer-bib-directory): New variable, list of
Richard M. Stallman <rms@gnu.org>
parents: 14169
diff changeset
340 (if (eq major-mode 'bibtex-mode)
4ef76e689d69 (refer-bib-directory): New variable, list of
Richard M. Stallman <rms@gnu.org>
parents: 14169
diff changeset
341 (read-file-name
65680
ed770a0a7846 2005-09-24 Emilio C. Lopes <eclig@gmx.net>
Romain Francoise <romain@orebokech.com>
parents: 64751
diff changeset
342 (format ".bib file (default %s): "
16473
4ef76e689d69 (refer-bib-directory): New variable, list of
Richard M. Stallman <rms@gnu.org>
parents: 14169
diff changeset
343 (file-name-nondirectory
4ef76e689d69 (refer-bib-directory): New variable, list of
Richard M. Stallman <rms@gnu.org>
parents: 14169
diff changeset
344 (buffer-file-name)))
4ef76e689d69 (refer-bib-directory): New variable, list of
Richard M. Stallman <rms@gnu.org>
parents: 14169
diff changeset
345 (file-name-directory (buffer-file-name))
4ef76e689d69 (refer-bib-directory): New variable, list of
Richard M. Stallman <rms@gnu.org>
parents: 14169
diff changeset
346 (file-name-nondirectory (buffer-file-name))
4ef76e689d69 (refer-bib-directory): New variable, list of
Richard M. Stallman <rms@gnu.org>
parents: 14169
diff changeset
347 t)
4ef76e689d69 (refer-bib-directory): New variable, list of
Richard M. Stallman <rms@gnu.org>
parents: 14169
diff changeset
348 (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
349 ((eq refer-bib-files 'auto)
4ef76e689d69 (refer-bib-directory): New variable, list of
Richard M. Stallman <rms@gnu.org>
parents: 14169
diff changeset
350 (let ((files
4ef76e689d69 (refer-bib-directory): New variable, list of
Richard M. Stallman <rms@gnu.org>
parents: 14169
diff changeset
351 (save-excursion
4ef76e689d69 (refer-bib-directory): New variable, list of
Richard M. Stallman <rms@gnu.org>
parents: 14169
diff changeset
352 (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
353 (list buffer-file-name)
4ef76e689d69 (refer-bib-directory): New variable, list of
Richard M. Stallman <rms@gnu.org>
parents: 14169
diff changeset
354 (if (progn
4ef76e689d69 (refer-bib-directory): New variable, list of
Richard M. Stallman <rms@gnu.org>
parents: 14169
diff changeset
355 (goto-char (point-min))
4ef76e689d69 (refer-bib-directory): New variable, list of
Richard M. Stallman <rms@gnu.org>
parents: 14169
diff changeset
356 (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
357 "\\s-*\{") nil t))
4ef76e689d69 (refer-bib-directory): New variable, list of
Richard M. Stallman <rms@gnu.org>
parents: 14169
diff changeset
358 (let ((files (list (buffer-substring
4ef76e689d69 (refer-bib-directory): New variable, list of
Richard M. Stallman <rms@gnu.org>
parents: 14169
diff changeset
359 (point)
4ef76e689d69 (refer-bib-directory): New variable, list of
Richard M. Stallman <rms@gnu.org>
parents: 14169
diff changeset
360 (progn
4ef76e689d69 (refer-bib-directory): New variable, list of
Richard M. Stallman <rms@gnu.org>
parents: 14169
diff changeset
361 (re-search-forward "[,\}]"
4ef76e689d69 (refer-bib-directory): New variable, list of
Richard M. Stallman <rms@gnu.org>
parents: 14169
diff changeset
362 nil t)
4ef76e689d69 (refer-bib-directory): New variable, list of
Richard M. Stallman <rms@gnu.org>
parents: 14169
diff changeset
363 (backward-char 1)
4ef76e689d69 (refer-bib-directory): New variable, list of
Richard M. Stallman <rms@gnu.org>
parents: 14169
diff changeset
364 (point))))))
4ef76e689d69 (refer-bib-directory): New variable, list of
Richard M. Stallman <rms@gnu.org>
parents: 14169
diff changeset
365 (while (not (looking-at "\}"))
4ef76e689d69 (refer-bib-directory): New variable, list of
Richard M. Stallman <rms@gnu.org>
parents: 14169
diff changeset
366 (setq files (append files
4ef76e689d69 (refer-bib-directory): New variable, list of
Richard M. Stallman <rms@gnu.org>
parents: 14169
diff changeset
367 (list (buffer-substring
4ef76e689d69 (refer-bib-directory): New variable, list of
Richard M. Stallman <rms@gnu.org>
parents: 14169
diff changeset
368 (progn (forward-char 1)
4ef76e689d69 (refer-bib-directory): New variable, list of
Richard M. Stallman <rms@gnu.org>
parents: 14169
diff changeset
369 (point))
4ef76e689d69 (refer-bib-directory): New variable, list of
Richard M. Stallman <rms@gnu.org>
parents: 14169
diff changeset
370 (progn (re-search-forward
4ef76e689d69 (refer-bib-directory): New variable, list of
Richard M. Stallman <rms@gnu.org>
parents: 14169
diff changeset
371 "[,\}]" nil t)
4ef76e689d69 (refer-bib-directory): New variable, list of
Richard M. Stallman <rms@gnu.org>
parents: 14169
diff changeset
372 (backward-char 1)
4ef76e689d69 (refer-bib-directory): New variable, list of
Richard M. Stallman <rms@gnu.org>
parents: 14169
diff changeset
373 (point)))))))
4ef76e689d69 (refer-bib-directory): New variable, list of
Richard M. Stallman <rms@gnu.org>
parents: 14169
diff changeset
374 files)
4ef76e689d69 (refer-bib-directory): New variable, list of
Richard M. Stallman <rms@gnu.org>
parents: 14169
diff changeset
375 (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
376 "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
377 (refer-expand-files files dir-list)))
4ef76e689d69 (refer-bib-directory): New variable, list of
Richard M. Stallman <rms@gnu.org>
parents: 14169
diff changeset
378 ((eq refer-bib-files 'dir)
4ef76e689d69 (refer-bib-directory): New variable, list of
Richard M. Stallman <rms@gnu.org>
parents: 14169
diff changeset
379 (let ((dirs (nreverse dir-list))
4ef76e689d69 (refer-bib-directory): New variable, list of
Richard M. Stallman <rms@gnu.org>
parents: 14169
diff changeset
380 dir files)
4ef76e689d69 (refer-bib-directory): New variable, list of
Richard M. Stallman <rms@gnu.org>
parents: 14169
diff changeset
381 (while (setq dir (car dirs))
4ef76e689d69 (refer-bib-directory): New variable, list of
Richard M. Stallman <rms@gnu.org>
parents: 14169
diff changeset
382 (setq files
4ef76e689d69 (refer-bib-directory): New variable, list of
Richard M. Stallman <rms@gnu.org>
parents: 14169
diff changeset
383 (append (directory-files dir t "\\.bib$")
4ef76e689d69 (refer-bib-directory): New variable, list of
Richard M. Stallman <rms@gnu.org>
parents: 14169
diff changeset
384 files))
4ef76e689d69 (refer-bib-directory): New variable, list of
Richard M. Stallman <rms@gnu.org>
parents: 14169
diff changeset
385 (setq dirs (cdr dirs)))
4ef76e689d69 (refer-bib-directory): New variable, list of
Richard M. Stallman <rms@gnu.org>
parents: 14169
diff changeset
386 files))
4ef76e689d69 (refer-bib-directory): New variable, list of
Richard M. Stallman <rms@gnu.org>
parents: 14169
diff changeset
387 ((and (listp refer-bib-files)
4ef76e689d69 (refer-bib-directory): New variable, list of
Richard M. Stallman <rms@gnu.org>
parents: 14169
diff changeset
388 (or (eq refer-bib-directory 'texinputs)
4ef76e689d69 (refer-bib-directory): New variable, list of
Richard M. Stallman <rms@gnu.org>
parents: 14169
diff changeset
389 (eq refer-bib-directory 'bibinputs)))
4ef76e689d69 (refer-bib-directory): New variable, list of
Richard M. Stallman <rms@gnu.org>
parents: 14169
diff changeset
390 (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
391 ((listp refer-bib-files) refer-bib-files)
60918
58a53f588384 * textmodes/refbib.el, textmodes/refer.el, textmodes/reftex-cite.el,
Werner LEMBERG <wl@gnu.org>
parents: 53853
diff changeset
392 (t (error "Invalid value for refer-bib-files: %s"
16473
4ef76e689d69 (refer-bib-directory): New variable, list of
Richard M. Stallman <rms@gnu.org>
parents: 14169
diff changeset
393 refer-bib-files)))))
4ef76e689d69 (refer-bib-directory): New variable, list of
Richard M. Stallman <rms@gnu.org>
parents: 14169
diff changeset
394 (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
395 (eq refer-bib-directory 'bibinputs))
4ef76e689d69 (refer-bib-directory): New variable, list of
Richard M. Stallman <rms@gnu.org>
parents: 14169
diff changeset
396 (setq refer-bib-directory dir-list))
4ef76e689d69 (refer-bib-directory): New variable, list of
Richard M. Stallman <rms@gnu.org>
parents: 14169
diff changeset
397 (if refer-cache-bib-files
4ef76e689d69 (refer-bib-directory): New variable, list of
Richard M. Stallman <rms@gnu.org>
parents: 14169
diff changeset
398 (setq refer-bib-files files))
4ef76e689d69 (refer-bib-directory): New variable, list of
Richard M. Stallman <rms@gnu.org>
parents: 14169
diff changeset
399 files))
7638
fb6479579c0b entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
400
52401
695cf19ef79e Add arch taglines
Miles Bader <miles@gnu.org>
parents: 49599
diff changeset
401 ;;; arch-tag: 151f641b-e79b-462b-9a29-a95c3793f300
7638
fb6479579c0b entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
402 ;;; refer.el ends here