diff options
| author | Roland Winkler | 2025-01-12 15:17:28 -0600 |
|---|---|---|
| committer | Roland Winkler | 2025-01-12 15:17:28 -0600 |
| commit | 14b5ba7c61fd8fb1e2c8fe956ee925b4a59c10c8 (patch) | |
| tree | 750ad2676f87f01be58d470747a6eb071b03fec6 | |
| parent | 99b85e116f09e68e0d5750c9772d0a2489680078 (diff) | |
| download | emacs-14b5ba7c61fd8fb1e2c8fe956ee925b4a59c10c8.tar.gz emacs-14b5ba7c61fd8fb1e2c8fe956ee925b4a59c10c8.zip | |
bibtex-string-file-path and bibtex-file-path are lists of directories
* lisp/textmodes/bibtex.el (bibtex-string-file-path, bibtex-file-path):
These user options are now lists of directories. For backward compatibility,
the old, obsolete format is still supported.
(bibtex-string-files-init, bibtex-initialize): Change accordingly.
Use file-name-extension and file-name-with-extension.
* etc/NEWS: Entry for new format of bibtex-string-file-path and
bibtex-file-path.
| -rw-r--r-- | etc/NEWS | 5 | ||||
| -rw-r--r-- | lisp/textmodes/bibtex.el | 110 |
2 files changed, 69 insertions, 46 deletions
| @@ -826,6 +826,11 @@ Use 'bibtex-aux-opt-alist' instead. | |||
| 826 | *** New user option 'bibtex-entry-ask-for-key'. | 826 | *** New user option 'bibtex-entry-ask-for-key'. |
| 827 | When enabled, 'bibtex-entry' asks for a key. | 827 | When enabled, 'bibtex-entry' asks for a key. |
| 828 | 828 | ||
| 829 | --- | ||
| 830 | *** 'bibtex-string-file-path' and 'bibtex-file-path' are lists of directories. | ||
| 831 | For backward compatibility, considered obsolete, these user options | ||
| 832 | may still be strings with colon separated lists of directories. | ||
| 833 | |||
| 829 | ** Midnight mode | 834 | ** Midnight mode |
| 830 | 835 | ||
| 831 | --- | 836 | --- |
diff --git a/lisp/textmodes/bibtex.el b/lisp/textmodes/bibtex.el index 601331cbce2..83d8f2e6e70 100644 --- a/lisp/textmodes/bibtex.el +++ b/lisp/textmodes/bibtex.el | |||
| @@ -1095,13 +1095,16 @@ to the directories specified in `bibtex-string-file-path'." | |||
| 1095 | :group 'bibtex | 1095 | :group 'bibtex |
| 1096 | :type '(repeat file)) | 1096 | :type '(repeat file)) |
| 1097 | 1097 | ||
| 1098 | (defcustom bibtex-string-file-path (getenv "BIBINPUTS") | 1098 | (defcustom bibtex-string-file-path (split-string (getenv "BIBINPUTS") ":+" t) |
| 1099 | "Colon-separated list of paths to search for `bibtex-string-files'. | 1099 | "List of directories to search for `bibtex-string-files'. |
| 1100 | Initialized from the BIBINPUTS environment variable." | 1100 | By default, initialized from the BIBINPUTS environment variable. |
| 1101 | For backward compatibility, considered obsolete, it may also be | ||
| 1102 | a single string with a colon separated list of directories." | ||
| 1101 | :group 'bibtex | 1103 | :group 'bibtex |
| 1102 | :version "27.1" | 1104 | :version "31.1" |
| 1103 | :type '(choice string | 1105 | :type '(choice (repeat directory) |
| 1104 | (const :tag "Not Set" nil))) | 1106 | (string :tag "String (obsolete)") |
| 1107 | (const :tag "Not set" nil))) | ||
| 1105 | 1108 | ||
| 1106 | (defcustom bibtex-files nil | 1109 | (defcustom bibtex-files nil |
| 1107 | "List of BibTeX files that are searched for entry keys. | 1110 | "List of BibTeX files that are searched for entry keys. |
| @@ -1114,13 +1117,16 @@ See also `bibtex-search-entry-globally'." | |||
| 1114 | :type '(repeat (choice (const :tag "bibtex-file-path" bibtex-file-path) | 1117 | :type '(repeat (choice (const :tag "bibtex-file-path" bibtex-file-path) |
| 1115 | directory file))) | 1118 | directory file))) |
| 1116 | 1119 | ||
| 1117 | (defcustom bibtex-file-path (getenv "BIBINPUTS") | 1120 | (defcustom bibtex-file-path (split-string (getenv "BIBINPUTS") ":+" t) |
| 1118 | "Colon separated list of paths to search for `bibtex-files'. | 1121 | "List of directories to search for `bibtex-files'. |
| 1119 | Initialized from the BIBINPUTS environment variable." | 1122 | By default, initialized from the BIBINPUTS environment variable. |
| 1123 | For backward compatibility, considered obsolete, it may also be | ||
| 1124 | a single string with a colon separated list of directories." | ||
| 1120 | :group 'bibtex | 1125 | :group 'bibtex |
| 1121 | :version "27.1" | 1126 | :version "31.1" |
| 1122 | :type '(choice string | 1127 | :type '(choice (repeat directory) |
| 1123 | (const :tag "Not Set" nil))) | 1128 | (string :tag "String (obsolete)") |
| 1129 | (const :tag "Not set" nil))) | ||
| 1124 | 1130 | ||
| 1125 | (defcustom bibtex-search-entry-globally nil | 1131 | (defcustom bibtex-search-entry-globally nil |
| 1126 | "If non-nil, interactive calls of `bibtex-search-entry' search globally. | 1132 | "If non-nil, interactive calls of `bibtex-search-entry' search globally. |
| @@ -3195,30 +3201,35 @@ Return alist of strings if parsing was completed, `aborted' otherwise." | |||
| 3195 | 3201 | ||
| 3196 | (defun bibtex-string-files-init () | 3202 | (defun bibtex-string-files-init () |
| 3197 | "Return initialization for `bibtex-strings'. | 3203 | "Return initialization for `bibtex-strings'. |
| 3198 | Use `bibtex-predefined-strings' and BibTeX files `bibtex-string-files'." | 3204 | Use `bibtex-predefined-strings' and BibTeX files `bibtex-string-files' |
| 3199 | (save-match-data | 3205 | with `bibtex-string-file-path'." |
| 3200 | (let ((dirlist (split-string (or bibtex-string-file-path default-directory) | 3206 | (let ((dirlist |
| 3201 | ":+")) | 3207 | (or (if (stringp bibtex-string-file-path) ; obsolete format |
| 3202 | (case-fold-search) | 3208 | (save-match-data |
| 3203 | string-files fullfilename compl bounds found) | 3209 | (split-string bibtex-string-file-path ":+" t)) |
| 3204 | ;; collect absolute file names of valid string files | 3210 | bibtex-string-file-path) |
| 3205 | (dolist (filename bibtex-string-files) | 3211 | (list default-directory))) |
| 3206 | (unless (string-match "\\.bib\\'" filename) | 3212 | string-files) |
| 3207 | (setq filename (concat filename ".bib"))) | 3213 | ;; collect absolute file names of valid string files |
| 3208 | ;; test filenames | 3214 | (dolist (filename bibtex-string-files) |
| 3209 | (if (file-name-absolute-p filename) | 3215 | (unless (string= "bib" (file-name-extension filename)) |
| 3210 | (if (file-readable-p filename) | 3216 | (setq filename (file-name-with-extension filename "bib"))) |
| 3211 | (push filename string-files) | 3217 | ;; test filenames |
| 3212 | (user-error "BibTeX strings file %s not found" filename)) | 3218 | (if (file-name-absolute-p filename) |
| 3219 | (if (file-readable-p filename) | ||
| 3220 | (push filename string-files) | ||
| 3221 | (user-error "BibTeX strings file %s not found" filename)) | ||
| 3222 | (let (found) | ||
| 3213 | (dolist (dir dirlist) | 3223 | (dolist (dir dirlist) |
| 3214 | (when (file-readable-p | 3224 | ;; filename may exist in multiple directories |
| 3215 | (setq fullfilename (expand-file-name filename dir))) | 3225 | (let ((fullfilename (expand-file-name filename dir))) |
| 3216 | (push fullfilename string-files) | 3226 | (when (file-readable-p fullfilename) |
| 3217 | (setq found t))) | 3227 | (push fullfilename string-files) |
| 3228 | (setq found t)))) | ||
| 3218 | (unless found | 3229 | (unless found |
| 3219 | (user-error "File %s not in paths defined via bibtex-string-file-path" | 3230 | (user-error "File %s not in bibtex-string-file-path" filename))))) |
| 3220 | filename)))) | 3231 | ;; parse string files |
| 3221 | ;; parse string files | 3232 | (let (compl bounds) |
| 3222 | (dolist (filename string-files) | 3233 | (dolist (filename string-files) |
| 3223 | (with-temp-buffer | 3234 | (with-temp-buffer |
| 3224 | (insert-file-contents filename) | 3235 | (insert-file-contents filename) |
| @@ -3270,9 +3281,20 @@ already set. If SELECT is non-nil interactively select a BibTeX buffer. | |||
| 3270 | When called interactively, FORCE is t, CURRENT is t if current buffer | 3281 | When called interactively, FORCE is t, CURRENT is t if current buffer |
| 3271 | visits a file using `bibtex-mode', and SELECT is t if current buffer | 3282 | visits a file using `bibtex-mode', and SELECT is t if current buffer |
| 3272 | does not use `bibtex-mode'." | 3283 | does not use `bibtex-mode'." |
| 3273 | (interactive (list (eq major-mode 'bibtex-mode) t | 3284 | ;; Interactively, exclude current buffer if it does not visit a file |
| 3285 | ;; using `bibtex-mode'. This way, we exclude BibTeX buffers such as | ||
| 3286 | ;; `bibtex-search-buffer' that are not visiting a BibTeX file. | ||
| 3287 | ;; Also, calling `bibtex-initialize' gives meaningful results for any | ||
| 3288 | ;; current buffer. | ||
| 3289 | (interactive (list (eq major-mode 'bibtex-mode) | ||
| 3290 | (and buffer-file-name (eq major-mode 'bibtex-mode)) | ||
| 3274 | (not (eq major-mode 'bibtex-mode)))) | 3291 | (not (eq major-mode 'bibtex-mode)))) |
| 3275 | (let ((file-path (split-string (or bibtex-file-path default-directory) ":+")) | 3292 | (let ((file-path |
| 3293 | (or (if (stringp bibtex-file-path) ; obsolete format | ||
| 3294 | (save-match-data | ||
| 3295 | (split-string bibtex-file-path ":+" t)) | ||
| 3296 | bibtex-file-path) | ||
| 3297 | (list default-directory))) | ||
| 3276 | file-list dir-list buffer-list) | 3298 | file-list dir-list buffer-list) |
| 3277 | ;; generate list of BibTeX files | 3299 | ;; generate list of BibTeX files |
| 3278 | (dolist (file bibtex-files) | 3300 | (dolist (file bibtex-files) |
| @@ -3280,20 +3302,20 @@ does not use `bibtex-mode'." | |||
| 3280 | (setq dir-list (append dir-list file-path))) | 3302 | (setq dir-list (append dir-list file-path))) |
| 3281 | ((file-accessible-directory-p file) | 3303 | ((file-accessible-directory-p file) |
| 3282 | (push file dir-list)) | 3304 | (push file dir-list)) |
| 3283 | ((progn (unless (string-match "\\.bib\\'" file) | 3305 | ((progn (unless (string= "bib" (file-name-extension file)) |
| 3284 | (setq file (concat file ".bib"))) | 3306 | (setq file (file-name-with-extension file "bib"))) |
| 3285 | (file-name-absolute-p file)) | 3307 | (file-name-absolute-p file)) |
| 3286 | (push file file-list)) | 3308 | (push file file-list)) |
| 3287 | (t | 3309 | (t |
| 3288 | (let (expanded-file-name found) | 3310 | (let (expanded-file-name found) |
| 3289 | (dolist (dir file-path) | 3311 | (dolist (dir file-path) |
| 3312 | ;; filename may exist in multiple directories | ||
| 3290 | (when (file-readable-p | 3313 | (when (file-readable-p |
| 3291 | (setq expanded-file-name (expand-file-name file dir))) | 3314 | (setq expanded-file-name (expand-file-name file dir))) |
| 3292 | (push expanded-file-name file-list) | 3315 | (push expanded-file-name file-list) |
| 3293 | (setq found t))) | 3316 | (setq found t))) |
| 3294 | (unless found | 3317 | (unless found |
| 3295 | (user-error "File `%s' not in paths defined via bibtex-file-path" | 3318 | (user-error "File `%s' not in bibtex-file-path" file)))))) |
| 3296 | file)))))) | ||
| 3297 | (dolist (file file-list) | 3319 | (dolist (file file-list) |
| 3298 | (unless (file-readable-p file) | 3320 | (unless (file-readable-p file) |
| 3299 | (user-error "BibTeX file `%s' not found" file))) | 3321 | (user-error "BibTeX file `%s' not found" file))) |
| @@ -3307,12 +3329,6 @@ does not use `bibtex-mode'." | |||
| 3307 | (if (file-readable-p file) | 3329 | (if (file-readable-p file) |
| 3308 | (push (find-file-noselect file) buffer-list))) | 3330 | (push (find-file-noselect file) buffer-list))) |
| 3309 | ;; Include current buffer iff we want it. | 3331 | ;; Include current buffer iff we want it. |
| 3310 | ;; Exclude current buffer if it does not visit a file using `bibtex-mode'. | ||
| 3311 | ;; This way we exclude BibTeX buffers such as `bibtex-search-buffer' | ||
| 3312 | ;; that are not visiting a BibTeX file. Also, calling `bibtex-initialize' | ||
| 3313 | ;; gives meaningful results for any current buffer. | ||
| 3314 | (unless (and current (eq major-mode 'bibtex-mode) buffer-file-name) | ||
| 3315 | (setq current nil)) | ||
| 3316 | (cond ((and current (not (memq (current-buffer) buffer-list))) | 3332 | (cond ((and current (not (memq (current-buffer) buffer-list))) |
| 3317 | (push (current-buffer) buffer-list)) | 3333 | (push (current-buffer) buffer-list)) |
| 3318 | ((and (not current) (memq (current-buffer) buffer-list)) | 3334 | ((and (not current) (memq (current-buffer) buffer-list)) |
| @@ -3321,6 +3337,8 @@ does not use `bibtex-mode'." | |||
| 3321 | (let (string-init) | 3337 | (let (string-init) |
| 3322 | (dolist (buffer buffer-list) | 3338 | (dolist (buffer buffer-list) |
| 3323 | (with-current-buffer buffer | 3339 | (with-current-buffer buffer |
| 3340 | ;; `bibtex-reference-keys' and `bibtex-strings' are buffer-local | ||
| 3341 | ;; lazy completion tables. So we only initiate them as needed. | ||
| 3324 | (if (or force (functionp bibtex-reference-keys)) | 3342 | (if (or force (functionp bibtex-reference-keys)) |
| 3325 | (bibtex-parse-keys)) | 3343 | (bibtex-parse-keys)) |
| 3326 | (when (or force (functionp bibtex-strings)) | 3344 | (when (or force (functionp bibtex-strings)) |