Commit | Line | Data |
---|---|---|
c0e48b0b RS |
1 | ;;; filesets.el --- handle group of files |
2 | ||
3 | ;; Copyright (C) 2002 Free Software Foundation, Inc. | |
4 | ||
757a6abf | 5 | ;; Author: Thomas Link <t.link@gmx.at> |
9f243b0d | 6 | ;; Maintainer: FSF |
c0e48b0b RS |
7 | ;; Keywords: filesets convenience |
8 | ||
757a6abf PJ |
9 | ;; This file is part of GNU Emacs. |
10 | ||
c0e48b0b RS |
11 | ;; This program is free software; you can redistribute it and/or modify |
12 | ;; it under the terms of the GNU General Public License as published by | |
13 | ;; the Free Software Foundation; either version 2, or (at your option) | |
14 | ;; any later version. | |
15 | ||
16 | ;; This program is distributed in the hope that it will be useful, | |
17 | ;; but WITHOUT ANY WARRANTY; without even the implied warranty of | |
18 | ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
19 | ;; GNU General Public License for more details. | |
20 | ||
21 | ;; A copy of the GNU General Public License can be obtained from this | |
22 | ;; program's author or from the Free Software Foundation, Inc., 675 Mass | |
23 | ;; Ave, Cambridge, MA 02139, USA. | |
24 | ||
f194e54a | 25 | (defvar filesets-version "1.8.4") |
c0e48b0b RS |
26 | (defvar filesets-homepage |
27 | "http://members.a1.net/t.link/CompEmacsFilesets.html") | |
28 | ||
29 | ;;; Commentary: | |
30 | ||
b3ea44f8 | 31 | ;; Define filesets, which can be opened or saved with the power of one or |
757a6abf PJ |
32 | ;; two mouse clicks only. A fileset is either a list of files, a file |
33 | ;; pattern, a base directory and a search pattern (for files), or an | |
34 | ;; inclusion group (i.e. a base file including other files). | |
c0e48b0b | 35 | |
cfce85d8 RS |
36 | ;; Usage: |
37 | ;; 1. Put (require 'filesets) and (filesets-init) in your .emacs file. | |
38 | ;; 2. Type ;; M-x filesets-edit or choose "Edit Filesets" from the menu. | |
39 | ;; 3. Save your customizations. | |
c0e48b0b | 40 | |
757a6abf | 41 | ;; Caveat: Fileset names have to be unique. |
c0e48b0b | 42 | |
757a6abf PJ |
43 | ;; Filesets.el adds a nifty filesets menu to your menubar. If you change |
44 | ;; your filesets on the fly, don't forget to select "Save Filesets" from | |
45 | ;; the menu. | |
c0e48b0b | 46 | |
757a6abf PJ |
47 | ;; Pressing on the first item in the submenu will open all files at once. |
48 | ;; Define your own function, e.g. browse-url, for opening a fileset's | |
49 | ;; files. Or define external viewers for opening files with other | |
50 | ;; programs. See `filesets-external-viewers'. | |
c0e48b0b | 51 | |
757a6abf PJ |
52 | ;; BTW, if you close a fileset, files, which have been changed, will |
53 | ;; be silently saved. Change this behaviour by setting | |
54 | ;; `filesets-save-buffer-fn'. | |
c0e48b0b RS |
55 | |
56 | ;;; Supported modes for inclusion groups (`filesets-ingroup-patterns'): | |
57 | ;; - Elisp | |
58 | ;; - Emacs-Wiki (simple names only) | |
59 | ;; - LaTeX | |
60 | ||
61 | ||
62 | ||
63 | ;;; Known bugs: | |
64 | ||
65 | ||
66 | ;;; To do: | |
67 | ||
68 | ;;- better handling of different customization scenarios | |
69 | ||
9f243b0d RS |
70 | ;; Data gathering should be better separated from building the menu |
71 | ;; so that one could (1) use filesets without installing the menu | |
72 | ;; and (2) create new "frontends" to speedbar and others. | |
73 | ||
74 | ;; The functionality to call external viewers should be isolated in | |
75 | ;; an extra package and possibly integrated with the MIME | |
76 | ;; handling. | |
c0e48b0b RS |
77 | |
78 | ;;; Credits: | |
79 | ||
80 | ;; Helpful suggestions (but no significant code) were contributed by | |
81 | ||
82 | ;;- Christoph Conrad (at gmx de) | |
83 | ;;- Christian Ohler (at Informatik Uni-Oldenburg DE) | |
84 | ;;- Richard Stallman aka RMS (at gnu org) | |
85 | ;;- Per Abrahamsen aka abraham (at dina kvl dk) | |
86 | ||
87 | ||
88 | ;;; Code: | |
89 | ||
90 | (eval-when-compile | |
91 | (require 'cl)) | |
92 | ||
93 | ||
94 | ;;; Some variables | |
757a6abf | 95 | (eval-and-compile |
78b3d0f7 RS |
96 | (defvar filesets-running-xemacs (string-match "XEmacs\\|Lucid" emacs-version) |
97 | "Non-nil means we are running XEmacs.")) | |
c0e48b0b RS |
98 | |
99 | (defvar filesets-menu-cache nil | |
100 | "The whole filesets menu.") | |
101 | (defvar filesets-cache-version nil | |
102 | "Filesets' cached version number.") | |
103 | (defvar filesets-cache-hostname nil | |
104 | "Filesets' cached system name.") | |
105 | ||
106 | (defvar filesets-ingroup-cache nil | |
107 | "A plist containing files and their ingroup data.") | |
78b3d0f7 RS |
108 | (defvar filesets-ingroup-files nil |
109 | "List of files already processed when searching for included files.") | |
c0e48b0b RS |
110 | |
111 | (defvar filesets-has-changed-flag t | |
112 | "Non-nil means some fileset definition has changed.") | |
113 | (defvar filesets-submenus nil | |
114 | "An association list with filesets menu data.") | |
115 | (defvar filesets-updated-buffers nil | |
116 | "A list of buffers with updated menu bars.") | |
117 | (defvar filesets-menu-use-cached-flag nil | |
118 | "Use cached data. See `filesets-menu-ensure-use-cached' for details.") | |
119 | (defvar filesets-update-cache-file-flag nil | |
120 | "Non-nil means the cache needs updating.") | |
121 | (defvar filesets-ignore-next-set-default nil | |
122 | "A list of custom variables for which the next `set-default' will be | |
123 | ignored.") | |
124 | ||
125 | (defvar filesets-output-buffer-flag nil | |
126 | "Non-nil means the current buffer is an output buffer created by filesets. | |
127 | Is buffer local variable.") | |
128 | ||
129 | (defvar filesets-verbosity 1 | |
9f243b0d RS |
130 | "An integer defining the level of verbosity. |
131 | 0 means no messages at all.") | |
c0e48b0b RS |
132 | |
133 | (defvar filesets-menu-ensure-use-cached | |
134 | (and filesets-running-xemacs | |
135 | (not (emacs-version>= 21 5))) | |
136 | "Make sure (X)Emacs uses filesets' cache. | |
137 | ||
138 | Well, if you use XEmacs (prior to 21.5?) custom.el is loaded after | |
139 | init.el. This means that settings saved in the cache file (see | |
140 | `filesets-menu-cache-file') will be overwritten by custom.el. In order | |
141 | to ensure the use of the cache file, set this variable to t -- which is | |
142 | the default for XEmacs prior to 21.5. If you want to change this value | |
143 | put \"(setq filesets-menu-ensure-use-cached VALUE)\" into your startup | |
144 | file -- before loading filesets.el. | |
145 | ||
146 | So, when should you think about setting this value to t? If filesets.el | |
147 | is loaded before user customizations. Thus, if (require 'filesets) | |
148 | precedes the custom-set-variables command or, for XEmacs, if init.el is | |
149 | loaded before custom.el, set this variable to t.") | |
150 | ||
151 | ||
152 | ;;; utils | |
153 | (defun filesets-filter-list (lst cond-fn) | |
154 | "Remove all elements not conforming to COND-FN from list LST. | |
155 | COND-FN takes one argument: the current element." | |
156 | ; (remove* 'dummy lst :test (lambda (dummy elt) | |
157 | ; (not (funcall cond-fn elt))))) | |
158 | (let ((rv nil)) | |
159 | (dolist (elt lst rv) | |
160 | (when (funcall cond-fn elt) | |
161 | (setq rv (append rv (list elt))))))) | |
162 | ||
f194e54a | 163 | (defun filesets-ormap (fsom-pred lst) |
f4146f4c | 164 | "Return the tail of FSOM-LST for the head of which FSOM-PRED is non-nil." |
f194e54a RS |
165 | (let ((fsom-lst lst) |
166 | (fsom-rv nil)) | |
167 | (while (and (not (null fsom-lst)) | |
168 | (null fsom-rv)) | |
169 | (if (funcall fsom-pred (car fsom-lst)) | |
170 | (setq fsom-rv fsom-lst) | |
171 | (setq fsom-lst (cdr fsom-lst)))) | |
172 | fsom-rv)) | |
173 | ||
174 | (defun filesets-some (fss-pred fss-lst) | |
e9bbdfc3 | 175 | "Return non-nil if FSS-PRED is non-nil for any element of FSS-LST. |
f194e54a RS |
176 | Like `some', return the first value of FSS-PRED that is non-nil." |
177 | (catch 'exit | |
178 | (dolist (fss-this fss-lst nil) | |
179 | (let ((fss-rv (funcall fss-pred fss-this))) | |
180 | (when fss-rv | |
181 | (throw 'exit fss-rv)))))) | |
182 | ;(fset 'filesets-some 'some) ;; or use the cl function | |
183 | ||
184 | (defun filesets-member (fsm-item fsm-lst &rest fsm-keys) | |
185 | "Find the first occurrence of FSM-ITEM in FSM-LST. | |
186 | It is supposed to work like cl's `member*'. At the moment only the :test | |
187 | key is supported." | |
188 | (let ((fsm-test (or (plist-get fsm-keys ':test) | |
189 | (function equal)))) | |
190 | (filesets-ormap (lambda (fsm-this) | |
e9bbdfc3 | 191 | (funcall fsm-test fsm-item fsm-this)) |
f194e54a RS |
192 | fsm-lst))) |
193 | ;(fset 'filesets-member 'member*) ;; or use the cl function | |
194 | ||
c0e48b0b RS |
195 | (defun filesets-sublist (lst beg &optional end) |
196 | "Get the sublist of LST from BEG to END - 1." | |
197 | (let ((rv nil) | |
198 | (i beg) | |
199 | (top (or end | |
200 | (length lst)))) | |
201 | (while (< i top) | |
202 | (setq rv (append rv (list (nth i lst)))) | |
203 | (setq i (+ i 1))) | |
204 | rv)) | |
205 | ||
206 | (defun filesets-select-command (cmd-list) | |
207 | "Select one command from CMD-LIST -- a string with space separated names." | |
208 | (let ((this (shell-command-to-string | |
209 | (format "which --skip-alias %s 2> /dev/null | head -n 1" | |
210 | cmd-list)))) | |
e9bbdfc3 | 211 | (if (equal this "") |
c0e48b0b RS |
212 | nil |
213 | (file-name-nondirectory (substring this 0 (- (length this) 1)))))) | |
214 | ||
215 | (defun filesets-which-command (cmd) | |
216 | "Calls \"which CMD\"." | |
217 | (shell-command-to-string (format "which %s" cmd))) | |
218 | ||
219 | (defun filesets-which-command-p (cmd) | |
220 | "Calls \"which CMD\" and returns non-nil if the command was found." | |
221 | (when (string-match (format "\\(/[^/]+\\)?/%s" cmd) | |
222 | (filesets-which-command cmd)) | |
223 | cmd)) | |
224 | ||
225 | (defun filesets-message (level &rest args) | |
226 | "Show a message only if LEVEL is greater or equal then `filesets-verbosity'." | |
227 | (when (<= level (abs filesets-verbosity)) | |
228 | (apply 'message args))) | |
229 | ||
230 | ||
231 | ;;; config file | |
232 | (defun filesets-save-config () | |
233 | "Save filesets' customizations." | |
234 | (interactive) | |
235 | (customize-save-customized)) | |
236 | ||
237 | (defun filesets-reset-fileset (&optional fileset no-cache) | |
238 | "Reset the cached values for one or all filesets." | |
239 | (if fileset | |
240 | (setq filesets-submenus (lax-plist-put filesets-submenus fileset nil)) | |
241 | (setq filesets-submenus nil)) | |
242 | (setq filesets-has-changed-flag t) | |
243 | (setq filesets-update-cache-file-flag (or filesets-update-cache-file-flag | |
244 | (not no-cache)))) | |
245 | ||
246 | (defun filesets-set-config (fileset var val) | |
247 | "Set-default wrapper function." | |
248 | (filesets-reset-fileset fileset) | |
249 | (set-default var val)) | |
250 | ; (customize-set-variable var val)) | |
251 | ; (filesets-build-menu)) | |
252 | ||
253 | (defun filesets-set-default (sym val &optional init-flag) | |
254 | "Set-default wrapper function used in conjunction with `defcustom'." | |
255 | (let ((ignore-flag (member sym filesets-ignore-next-set-default))) | |
256 | (if ignore-flag | |
257 | (setq filesets-ignore-next-set-default | |
258 | (delete sym filesets-ignore-next-set-default)) | |
259 | (if init-flag | |
260 | (custom-initialize-set sym val) | |
261 | (set-default sym val))) | |
262 | (not ignore-flag))) | |
263 | ||
264 | (defun filesets-set-default! (sym val) | |
265 | "Call `filestes-set-default' and reset cached data (i.e. rebuild menu)." | |
266 | (when (filesets-set-default sym val) | |
267 | (filesets-reset-fileset))) | |
268 | ||
269 | (defun filesets-set-default+ (sym val) | |
270 | "Call `filestes-set-default' and reset filesets' standard menu." | |
271 | (when (filesets-set-default sym val) | |
272 | (setq filesets-has-changed-flag t))) | |
273 | ; (filesets-reset-fileset nil t))) | |
274 | ||
9f243b0d RS |
275 | (defvar filesets-data) |
276 | ||
c0e48b0b RS |
277 | (defun filesets-data-set-default (sym val) |
278 | "Set the default for `filesets-data'." | |
279 | (if filesets-menu-use-cached-flag | |
280 | (setq filesets-menu-use-cached-flag nil) | |
281 | (when (default-boundp 'filesets-data) | |
282 | (let ((modified-filesets | |
283 | (filesets-filter-list val | |
284 | (lambda (x) | |
285 | (let ((name (car x)) | |
286 | (data (cdr x))) | |
287 | (let ((elt (assoc name filesets-data))) | |
288 | (or (not elt) | |
289 | (not (equal data (cdr elt)))))))))) | |
290 | (dolist (x modified-filesets) | |
291 | (filesets-reset-fileset (car x)))))) | |
292 | (filesets-set-default sym val)) | |
9f243b0d | 293 | \f |
c0e48b0b RS |
294 | ;;; configuration |
295 | (defgroup filesets nil | |
296 | "The fileset swapper." | |
297 | :prefix "filesets-" | |
485ecb5c | 298 | :group 'convenience |
bf247b6e | 299 | :version "22.1") |
c0e48b0b RS |
300 | |
301 | (defcustom filesets-menu-name "Filesets" | |
302 | "*Filesets' menu name." | |
303 | :set (function filesets-set-default) | |
304 | :type 'sexp | |
305 | :group 'filesets) | |
306 | ||
26f42fe4 | 307 | (if filesets-running-xemacs |
89fba92a MR |
308 | (progn |
309 | (defcustom filesets-menu-path nil | |
310 | "*The menu under which the filesets menu should be inserted. | |
c0e48b0b | 311 | XEmacs specific; see `add-submenu' for documentation." |
89fba92a MR |
312 | :set (function filesets-set-default) |
313 | :type 'sexp | |
314 | :group 'filesets) | |
c0e48b0b | 315 | |
89fba92a MR |
316 | (defcustom filesets-menu-before "File" |
317 | "*The name of a menu before which this menu should be added. | |
c0e48b0b | 318 | XEmacs specific; see `add-submenu' for documentation." |
89fba92a MR |
319 | :set (function filesets-set-default) |
320 | :type 'sexp | |
321 | :group 'filesets) | |
c0e48b0b | 322 | |
89fba92a MR |
323 | (defcustom filesets-menu-in-menu nil |
324 | "*Use that instead of `current-menubar' as the menu to change. | |
c0e48b0b | 325 | XEmacs specific; see `add-submenu' for documentation." |
89fba92a MR |
326 | :set (function filesets-set-default) |
327 | :type 'sexp | |
328 | :group 'filesets)) | |
329 | (defvar filesets-menu-path nil) | |
330 | (defvar filesets-menu-before nil) | |
331 | (defvar filesets-menu-in-menu nil)) | |
c0e48b0b RS |
332 | |
333 | (defcustom filesets-menu-shortcuts-flag t | |
334 | "*Non-nil means to prepend menus with hopefully unique shortcuts." | |
335 | :set (function filesets-set-default!) | |
336 | :type 'boolean | |
337 | :group 'filesets) | |
338 | ||
339 | (defcustom filesets-menu-shortcuts-marker "%_" | |
340 | "*String for marking menu shortcuts." | |
341 | :set (function filesets-set-default!) | |
342 | :type 'string | |
343 | :group 'filesets) | |
344 | ||
345 | ;(defcustom filesets-menu-cnvfp-flag nil | |
346 | ; "*Non-nil means show \"Convert :pattern to :files\" entry for :pattern menus." | |
347 | ; :set (function filesets-set-default!) | |
348 | ; :type 'boolean | |
349 | ; :group 'filesets) | |
350 | ||
351 | (defcustom filesets-menu-cache-file | |
352 | (if filesets-running-xemacs | |
353 | "~/.xemacs/filesets-cache.el" | |
354 | "~/.filesets-cache.el") | |
cd56bfef RS |
355 | "*File to be used for saving the filesets menu between sessions. |
356 | Set this to \"\", to disable caching of menus. | |
c0e48b0b RS |
357 | Don't forget to check out `filesets-menu-ensure-use-cached'." |
358 | :set (function filesets-set-default) | |
359 | :type 'file | |
360 | :group 'filesets) | |
cd56bfef | 361 | (put 'filesets-menu-cache-file 'risky-local-variable t) |
c0e48b0b RS |
362 | |
363 | (defcustom filesets-menu-cache-contents | |
364 | '(filesets-be-docile-flag | |
365 | filesets-submenus | |
e9bbdfc3 | 366 | filesets-menu-cache |
c0e48b0b RS |
367 | filesets-ingroup-cache) |
368 | "*Stuff we want to save in `filesets-menu-cache-file'. | |
369 | ||
370 | Possible uses: don't save configuration data in the main startup files | |
371 | but in filesets's own cache. In this case add `filesets-data' to this | |
372 | list. | |
373 | ||
374 | There is a second reason for putting `filesets-data' on this list. If | |
375 | you frequently add and remove buffers on the fly to :files filesets, you | |
376 | don't need to save your customizations if `filesets-data' is being | |
377 | mirrored in the cache file. In this case the version in the cache file | |
378 | is the current one, and the version in your startup file will be | |
379 | silently updated later on. | |
380 | ||
381 | If you want caching to work properly, at least `filesets-submenus', | |
382 | `filesets-menu-cache', and `filesets-ingroup-cache' should be in this | |
383 | list. | |
384 | ||
385 | Don't forget to check out `filesets-menu-ensure-use-cached'." | |
386 | :set (function filesets-set-default) | |
387 | :type '(repeat | |
388 | (choice :tag "Variable" | |
389 | (const :tag "filesets-submenus" | |
390 | :value filesets-submenus) | |
391 | (const :tag "filesets-menu-cache" | |
392 | :value filesets-menu-cache) | |
393 | (const :tag "filesets-ingroup-cache" | |
394 | :value filesets-ingroup-cache) | |
395 | (const :tag "filesets-data" | |
396 | :value filesets-data) | |
397 | (const :tag "filesets-external-viewers" | |
398 | :value filesets-external-viewers) | |
399 | (const :tag "filesets-ingroup-patterns" | |
400 | :value filesets-ingroup-patterns) | |
401 | (const :tag "filesets-be-docile-flag" | |
402 | :value filesets-be-docile-flag) | |
403 | (sexp :tag "Other" :value nil))) | |
404 | :group 'filesets) | |
405 | ||
406 | (defcustom filesets-cache-fill-content-hooks nil | |
407 | "*Hooks to run when writing the contents of filesets' cache file. | |
408 | ||
409 | The hook is called with the cache file as current buffer and the cursor | |
410 | at the last position. I.e. each hook has to make sure that the cursor is | |
411 | at the last position. | |
412 | ||
413 | Possible uses: If you don't want to save `filesets-data' in your normal | |
414 | configuration file, you can add a something like this | |
415 | ||
416 | \(lambda () | |
417 | \(insert (format \"(setq-default filesets-data '%S)\" | |
418 | filesets-data)) | |
419 | \(newline 2)) | |
420 | ||
421 | to this hook. | |
422 | ||
423 | Don't forget to check out `filesets-menu-ensure-use-cached'." | |
424 | :set (function filesets-set-default) | |
425 | :type 'hook | |
426 | :group 'filesets) | |
427 | ||
428 | (defcustom filesets-cache-hostname-flag nil | |
cd56bfef RS |
429 | "*Non-nil means cache the hostname. |
430 | If the current name differs from the cached one, | |
431 | rebuild the menu and create a new cache file." | |
c0e48b0b RS |
432 | :set (function filesets-set-default) |
433 | :type 'boolean | |
434 | :group 'filesets) | |
435 | ||
436 | (defcustom filesets-cache-save-often-flag nil | |
437 | "*Non-nil means save buffer on every change of the filesets menu. | |
438 | If this variable is set to nil and if Emacs crashes, the cache and | |
439 | filesets-data could get out of sync. Set this to t if this happens from | |
440 | time to time or if the fileset cache causes troubles." | |
441 | :set (function filesets-set-default) | |
442 | :type 'boolean | |
443 | :group 'filesets) | |
444 | ||
445 | (defcustom filesets-max-submenu-length 25 | |
446 | "*Maximum length of submenus. | |
447 | Set this value to 0 to turn menu splitting off. BTW, parts of submenus | |
448 | will not be rewrapped if their length exceeds this value." | |
449 | :set (function filesets-set-default) | |
450 | :type 'integer | |
451 | :group 'filesets) | |
452 | ||
453 | (defcustom filesets-max-entry-length 50 | |
454 | "*Truncate names of splitted submenus to this length." | |
455 | :set (function filesets-set-default) | |
456 | :type 'integer | |
457 | :group 'filesets) | |
458 | ||
cd56bfef | 459 | (defcustom filesets-browse-dir-function 'dired |
c0e48b0b RS |
460 | "*A function or command used for browsing directories. |
461 | When using an external command, \"%s\" will be replaced with the | |
462 | directory's name. | |
463 | ||
464 | Note: You have to manually rebuild the menu if you change this value." | |
465 | :set (function filesets-set-default) | |
466 | :type '(choice :tag "Function:" | |
467 | (const :tag "dired" | |
468 | :value dired) | |
469 | (list :tag "Command" | |
470 | :value ("" "%s") | |
471 | (string :tag "Name") | |
472 | (string :tag "Arguments")) | |
473 | (function :tag "Function" | |
474 | :value nil)) | |
475 | :group 'filesets) | |
476 | ||
cd56bfef | 477 | (defcustom filesets-open-file-function 'filesets-find-or-display-file |
c0e48b0b RS |
478 | "*The function used for opening files. |
479 | ||
480 | `filesets-find-or-display-file' ... Filesets' default function for | |
481 | visiting files. This function checks if an external viewer is defined | |
482 | for a specific file type. Either this viewer, if defined, or | |
483 | `find-file' will be used to visit a file. | |
484 | ||
485 | `filesets-find-file' ... An alternative function that always uses | |
486 | `find-file'. If `filesets-be-docile-flag' is true, a file, which isn't | |
487 | readable, will not be opened. | |
488 | ||
489 | Caveat: Changes will take effect only after rebuilding the menu." | |
490 | :set (function filesets-set-default) | |
491 | :type '(choice :tag "Function:" | |
492 | (const :tag "filesets-find-or-display-file" | |
493 | :value filesets-find-or-display-file) | |
494 | (const :tag "filesets-find-file" | |
495 | :value filesets-find-file) | |
496 | (function :tag "Function" | |
497 | :value nil)) | |
498 | :group 'filesets) | |
499 | ||
cd56bfef | 500 | (defcustom filesets-save-buffer-function 'save-buffer |
c0e48b0b RS |
501 | "*The function used to save a buffer. |
502 | Caveat: Changes will take effect after rebuilding the menu." | |
503 | :set (function filesets-set-default) | |
504 | :type '(choice :tag "Function:" | |
505 | (const :tag "save-buffer" | |
506 | :value save-buffer) | |
507 | (function :tag "Function" | |
508 | :value nil)) | |
509 | :group 'filesets) | |
510 | ||
511 | (defcustom filesets-find-file-delay | |
512 | (if (and filesets-running-xemacs gutter-buffers-tab-visible-p) | |
513 | 0.5 | |
514 | 0) | |
515 | "*Delay before calling find-file. | |
516 | This is for calls via `filesets-find-or-display-file' | |
517 | or `filesets-find-file'. | |
518 | ||
519 | Set this to 0, if you don't use XEmacs' buffer tabs." | |
520 | :set (function filesets-set-default) | |
521 | :type 'number | |
522 | :group 'filesets) | |
523 | ||
524 | (defcustom filesets-be-docile-flag nil | |
525 | "*Non-nil means don't complain if a file or a directory doesn't exist. | |
526 | This is useful if you want to use the same startup files in different | |
527 | computer environments." | |
528 | :set (function filesets-set-default) | |
529 | :type 'boolean | |
530 | :group 'filesets) | |
531 | ||
532 | (defcustom filesets-sort-menu-flag t | |
533 | "*Non-nil means sort the filesets menu alphabetically." | |
534 | :set (function filesets-set-default) | |
535 | :type 'boolean | |
536 | :group 'filesets) | |
537 | ||
538 | (defcustom filesets-sort-case-sensitive-flag t | |
539 | "*Non-nil means sorting of the filesete menu is case sensitive." | |
540 | :set (function filesets-set-default) | |
541 | :type 'boolean | |
542 | :group 'filesets) | |
543 | ||
544 | (defcustom filesets-tree-max-level 3 | |
545 | "*Maximum scan depth for directory trees. | |
546 | A :tree fileset is defined by a base directory the contents of which | |
cd56bfef | 547 | will be recursively added to the menu. `filesets-tree-max-level' tells up |
c0e48b0b RS |
548 | to which level the directory structure should be scanned/listed, |
549 | i.e. how deep the menu should be. Try something like | |
550 | ||
551 | \(\"HOME -- only one level\" | |
552 | \(:tree \"~\" \"^[^.].*[^~]$\") | |
553 | \(:tree-max-level 1) | |
554 | \(:filter-dirs-flag t)) | |
555 | \(\"HOME -- up to 3 levels\" | |
556 | \(:tree \"~\" \"^[^.].*[^~]$\") | |
557 | \(:tree-max-level 3) | |
558 | \(:filter-dirs-flag t)) | |
559 | ||
560 | and it should become clear what this option is about. In any case, | |
561 | including directory trees to the menu can take a lot of memory." | |
562 | :set (function filesets-set-default) | |
563 | :type 'integer | |
564 | :group 'filesets) | |
565 | ||
566 | (defcustom filesets-commands | |
567 | `(("Query Replace" | |
568 | query-replace | |
569 | (filesets-cmd-query-replace-getargs)) | |
570 | ("Query Replace (regexp)" | |
571 | query-replace-regexp | |
572 | (filesets-cmd-query-replace-getargs)) | |
573 | ("Grep <<selection>>" | |
574 | "grep" | |
575 | ("-n " filesets-get-quoted-selection " " "<<file-name>>")) | |
576 | ("Run Shell Command" | |
577 | filesets-cmd-shell-command | |
578 | (filesets-cmd-shell-command-getargs))) | |
579 | "*Commands to run on filesets. | |
580 | An association list of names, functions, and an argument list (or a | |
581 | function that returns one) to be run on a filesets' files. | |
582 | ||
583 | The argument <file-name> or <<file-name>> (quoted) will be replaced with | |
584 | the filename." | |
585 | :set (function filesets-set-default+) | |
586 | :type '(repeat :tag "Commands" | |
587 | (list :tag "Definition" :value ("") | |
588 | (string "Name") | |
589 | (choice :tag "Command" | |
590 | (string :tag "String") | |
591 | (function :tag "Function")) | |
592 | (repeat :tag "Argument List" | |
593 | (choice :tag "Arguments" | |
594 | (sexp :tag "Sexp" | |
595 | :value nil) | |
596 | (string :tag "File Name" | |
597 | :value "<file-name>") | |
598 | (string :tag "Quoted File Name" | |
599 | :value "<<file-name>>") | |
600 | (function :tag "Function" | |
601 | :value nil))))) | |
602 | :group 'filesets) | |
cd56bfef | 603 | (put 'filesets-commands 'risky-local-variable t) |
c0e48b0b RS |
604 | |
605 | (defcustom filesets-external-viewers | |
606 | (let | |
607 | ; ((ps-cmd (or (and (boundp 'my-ps-viewer) my-ps-viewer) | |
608 | ; (filesets-select-command "ggv gv"))) | |
609 | ; (pdf-cmd (or (and (boundp 'my-ps-viewer) my-pdf-viewer) | |
610 | ; (filesets-select-command "xpdf acroread"))) | |
611 | ; (dvi-cmd (or (and (boundp 'my-ps-viewer) my-dvi-viewer) | |
612 | ; (filesets-select-command "xdvi tkdvi"))) | |
613 | ; (doc-cmd (or (and (boundp 'my-ps-viewer) my-doc-viewer) | |
614 | ; (filesets-select-command "antiword"))) | |
615 | ; (pic-cmd (or (and (boundp 'my-ps-viewer) my-pic-viewer) | |
616 | ; (filesets-select-command "gqview ee display")))) | |
617 | ((ps-cmd "ggv") | |
618 | (pdf-cmd "xpdf") | |
619 | (dvi-cmd "xdvi") | |
620 | (doc-cmd "antiword") | |
621 | (pic-cmd "gqview")) | |
622 | `(("^.+\\..?html?$" browse-url | |
623 | ((:ignore-on-open-all t))) | |
624 | ("^.+\\.pdf$" ,pdf-cmd | |
625 | ((:ignore-on-open-all t) | |
626 | (:ignore-on-read-text t) | |
627 | (:constraint-flag ,pdf-cmd))) | |
628 | ("^.+\\.e?ps\\(.gz\\)?$" ,ps-cmd | |
629 | ((:ignore-on-open-all t) | |
630 | (:ignore-on-read-text t) | |
631 | (:constraint-flag ,ps-cmd))) | |
632 | ("^.+\\.dvi$" ,dvi-cmd | |
633 | ((:ignore-on-open-all t) | |
634 | (:ignore-on-read-text t) | |
635 | (:constraint-flag ,dvi-cmd))) | |
636 | ("^.+\\.doc$" ,doc-cmd | |
637 | ((:capture-output t) | |
638 | (:ignore-on-read-text t) | |
639 | (:constraint-flag ,doc-cmd))) | |
640 | ("^.+\\.\\(tiff\\|xpm\\|gif\\|pgn\\)$" ,pic-cmd | |
641 | ((:ignore-on-open-all t) | |
642 | (:ignore-on-read-text t) | |
643 | (:constraint-flag ,pic-cmd))))) | |
644 | "*Association list of file patterns and external viewers for use with | |
645 | `filesets-find-or-display-file'. | |
646 | ||
647 | Has the form ((FILE-PATTERN VIEWER PROPERTIES) ...), VIEWER being either a | |
648 | function or a command name as string. | |
649 | ||
650 | Properties is an association list determining filesets' behaviour in | |
651 | several conditions. Choose one from this list: | |
652 | ||
653 | :ignore-on-open-all ... Don't open files of this type automatically -- | |
654 | i.e. on open-all-files-events or when running commands | |
655 | ||
656 | :capture-output ... capture an external viewer output | |
657 | ||
658 | :constraintp FUNCTION ... use this viewer only if FUNCTION returns non-nil | |
659 | ||
f194e54a | 660 | :constraint-flag SEXP ... use this viewer only if SEXP evaluates to non-nil |
c0e48b0b RS |
661 | |
662 | :open-hook HOOK ... run hooks after spawning the viewer -- mainly useful | |
663 | in conjunction with :capture-output | |
664 | ||
665 | :args (FORMAT-STRING or SYMBOL or FUNCTION) ... a list of arguments | |
666 | \(defaults to (list \"%S\")) when using shell commands | |
667 | ||
668 | Avoid modifying this variable and achieve minor speed-ups by setting the | |
669 | variables my-ps-viewer, my-pdf-viewer, my-dvi-viewer, my-pic-viewer. | |
670 | ||
671 | In order to view pdf or rtf files in an Emacs buffer, you could use these: | |
672 | ||
673 | ||
674 | \(\"^.+\\.pdf$\" \"pdftotext\" | |
675 | \((:capture-output t) | |
676 | \(:args (\"%S - | fmt -w \" window-width)) | |
677 | \(:ignore-on-read-text t) | |
678 | \(:constraintp (lambda () | |
679 | \(and \(filesets-which-command-p \"pdftotext\") | |
680 | \(filesets-which-command-p \"fmt\")))))) | |
681 | \(\"^.+\\.rtf$\" \"rtf2htm\" | |
682 | \((:capture-output t) | |
683 | \(:args (\"%S 2> /dev/null | w3m -dump -T text/html\")) | |
684 | \(:ignore-on-read-text t) | |
685 | \(:constraintp (lambda () | |
686 | \(and (filesets-which-command-p \"rtf2htm\") | |
687 | \(filesets-which-command-p \"w3m\")))))) | |
688 | " | |
689 | :set (function filesets-set-default) | |
690 | :type '(repeat :tag "Viewer" | |
691 | (list :tag "Definition" | |
692 | :value ("^.+\\.suffix$" "") | |
693 | (regexp :tag "Pattern") | |
694 | (choice :tag "Viewer" | |
695 | (symbol :tag "Function" :value nil) | |
696 | (string :tag "Program" :value "")) | |
697 | (repeat :tag "Properties" | |
698 | (choice | |
699 | (list :tag ":constraintp" | |
700 | :value (:constraintp) | |
701 | (const :format "" | |
702 | :value :constraintp) | |
703 | (function :tag "Function")) | |
704 | (list :tag ":constraint-flag" | |
705 | :value (:constraint-flag) | |
706 | (const :format "" | |
707 | :value :constraint-flag) | |
f194e54a | 708 | (sexp :tag "Symbol")) |
c0e48b0b RS |
709 | (list :tag ":ignore-on-open-all" |
710 | :value (:ignore-on-open-all t) | |
711 | (const :format "" | |
712 | :value :ignore-on-open-all) | |
713 | (boolean :tag "Boolean")) | |
714 | (list :tag ":ignore-on-read-text" | |
715 | :value (:ignore-on-read-text t) | |
716 | (const :format "" | |
717 | :value :ignore-on-read-text) | |
718 | (boolean :tag "Boolean")) | |
719 | (list :tag ":args" | |
720 | :value (:args) | |
721 | (const :format "" | |
722 | :value :args) | |
723 | (repeat :tag "List" | |
724 | (choice :tag "Arguments" | |
725 | (string :tag "String" | |
726 | :value "") | |
727 | (symbol :tag "Symbol" | |
728 | :value nil) | |
729 | (function :tag "Function" | |
730 | :value nil)))) | |
731 | (list :tag ":open-hook" | |
732 | :value (:open-hook) | |
733 | (const :format "" | |
734 | :value :open-hook) | |
735 | (hook :tag "Hook")) | |
736 | ; (list :tag ":close-hook" | |
737 | ; :value (:close-hook) | |
738 | ; (const :format "" | |
739 | ; :value :close-hook) | |
740 | ; (hook :tag "Hook")) | |
741 | (list :tag ":capture-output" | |
742 | :value (:capture-output t) | |
743 | (const :format "" | |
744 | :value :capture-output) | |
745 | (boolean :tag "Boolean")))))) | |
746 | :group 'filesets) | |
cd56bfef | 747 | (put 'filesets-external-viewers 'risky-local-variable t) |
c0e48b0b RS |
748 | |
749 | (defcustom filesets-ingroup-patterns | |
750 | '(("^.+\\.tex$" t | |
751 | (((:name "Package") | |
752 | (:pattern "\\\\usepackage\\W*\\(\\[[^\]]*\\]\\W*\\)?{\\W*\\(.+\\)\\W*}") | |
753 | (:match-number 2) | |
754 | (:stub-flag t) | |
755 | (:get-file-name (lambda (master file) | |
756 | (filesets-which-file master | |
757 | (concat file ".sty") | |
e9bbdfc3 | 758 | (filesets-convert-path-list |
c0e48b0b RS |
759 | (or (getenv "MY_TEXINPUTS") |
760 | (getenv "TEXINPUTS"))))))) | |
761 | ((:name "Include") | |
762 | (:pattern "\\\\include\\W*{\\W*\\(.+\\)\\W*}") | |
763 | (:get-file-name (lambda (master file) | |
764 | (filesets-which-file master | |
765 | (concat file ".tex") | |
e9bbdfc3 | 766 | (filesets-convert-path-list |
c0e48b0b RS |
767 | (or (getenv "MY_TEXINPUTS") |
768 | (getenv "TEXINPUTS")))))) | |
769 | (:scan-depth 5)) | |
770 | ((:name "Input") | |
771 | (:pattern "\\\\input\\W*{\\W*\\(.+\\)\\W*}") | |
772 | (:stubp (lambda (a b) (not (filesets-files-in-same-directory-p a b)))) | |
773 | (:get-file-name (lambda (master file) | |
774 | (filesets-which-file master | |
775 | (concat file ".tex") | |
e9bbdfc3 | 776 | (filesets-convert-path-list |
c0e48b0b RS |
777 | (or (getenv "MY_TEXINPUTS") |
778 | (getenv "TEXINPUTS")))))) | |
779 | (:scan-depth 5)) | |
780 | ((:name "Bibliography") | |
781 | (:pattern "\\\\bibliography\\W*{\\W*\\(.+\\)\\W*}") | |
782 | (:get-file-name (lambda (master file) | |
783 | (filesets-which-file master | |
784 | (concat file ".bib") | |
e9bbdfc3 | 785 | (filesets-convert-path-list |
c0e48b0b RS |
786 | (or (getenv "MY_BIBINPUTS") |
787 | (getenv "BIBINPUTS"))))))))) | |
788 | ("^.+\\.el$" t | |
789 | (((:name "Require") | |
790 | (:pattern "(require\\W+'\\(.+\\))") | |
791 | (:stubp (lambda (a b) (not (filesets-files-in-same-directory-p a b)))) | |
792 | (:get-file-name (lambda (master file) | |
793 | (filesets-which-file master | |
794 | (concat file ".el") | |
795 | load-path)))) | |
796 | ((:name "Load") | |
797 | (:pattern "(load\\(-library\\)?\\W+\"\\(.+\\)\")") | |
798 | (:match-number 2) | |
799 | (:get-file-name (lambda (master file) | |
800 | (filesets-which-file master file load-path)))))) | |
801 |