Sync to HEAD
[bpt/emacs.git] / lisp / filesets.el
CommitLineData
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
123ignored.")
124
125(defvar filesets-output-buffer-flag nil
126 "Non-nil means the current buffer is an output buffer created by filesets.
127Is buffer local variable.")
128
129(defvar filesets-verbosity 1
9f243b0d
RS
130 "An integer defining the level of verbosity.
1310 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
138Well, if you use XEmacs (prior to 21.5?) custom.el is loaded after
139init.el. This means that settings saved in the cache file (see
140`filesets-menu-cache-file') will be overwritten by custom.el. In order
141to ensure the use of the cache file, set this variable to t -- which is
142the default for XEmacs prior to 21.5. If you want to change this value
143put \"(setq filesets-menu-ensure-use-cached VALUE)\" into your startup
144file -- before loading filesets.el.
145
146So, when should you think about setting this value to t? If filesets.el
147is loaded before user customizations. Thus, if (require 'filesets)
148precedes the custom-set-variables command or, for XEmacs, if init.el is
149loaded 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.
155COND-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
176Like `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.
186It is supposed to work like cl's `member*'. At the moment only the :test
187key 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-"
298 :group 'convenience)
299
300(defcustom filesets-menu-name "Filesets"
301 "*Filesets' menu name."
302 :set (function filesets-set-default)
303 :type 'sexp
304 :group 'filesets)
305
26f42fe4 306(if filesets-running-xemacs
89fba92a
MR
307 (progn
308 (defcustom filesets-menu-path nil
309 "*The menu under which the filesets menu should be inserted.
c0e48b0b 310XEmacs specific; see `add-submenu' for documentation."
89fba92a
MR
311 :set (function filesets-set-default)
312 :type 'sexp
313 :group 'filesets)
c0e48b0b 314
89fba92a
MR
315 (defcustom filesets-menu-before "File"
316 "*The name of a menu before which this menu should be added.
c0e48b0b 317XEmacs specific; see `add-submenu' for documentation."
89fba92a
MR
318 :set (function filesets-set-default)
319 :type 'sexp
320 :group 'filesets)
c0e48b0b 321
89fba92a
MR
322 (defcustom filesets-menu-in-menu nil
323 "*Use that instead of `current-menubar' as the menu to change.
c0e48b0b 324XEmacs specific; see `add-submenu' for documentation."
89fba92a
MR
325 :set (function filesets-set-default)
326 :type 'sexp
327 :group 'filesets))
328 (defvar filesets-menu-path nil)
329 (defvar filesets-menu-before nil)
330 (defvar filesets-menu-in-menu nil))
c0e48b0b
RS
331
332(defcustom filesets-menu-shortcuts-flag t
333 "*Non-nil means to prepend menus with hopefully unique shortcuts."
334 :set (function filesets-set-default!)
335 :type 'boolean
336 :group 'filesets)
337
338(defcustom filesets-menu-shortcuts-marker "%_"
339 "*String for marking menu shortcuts."
340 :set (function filesets-set-default!)
341 :type 'string
342 :group 'filesets)
343
344;(defcustom filesets-menu-cnvfp-flag nil
345; "*Non-nil means show \"Convert :pattern to :files\" entry for :pattern menus."
346; :set (function filesets-set-default!)
347; :type 'boolean
348; :group 'filesets)
349
350(defcustom filesets-menu-cache-file
351 (if filesets-running-xemacs
352 "~/.xemacs/filesets-cache.el"
353 "~/.filesets-cache.el")
cd56bfef
RS
354 "*File to be used for saving the filesets menu between sessions.
355Set this to \"\", to disable caching of menus.
c0e48b0b
RS
356Don't forget to check out `filesets-menu-ensure-use-cached'."
357 :set (function filesets-set-default)
358 :type 'file
359 :group 'filesets)
cd56bfef 360(put 'filesets-menu-cache-file 'risky-local-variable t)
c0e48b0b
RS
361
362(defcustom filesets-menu-cache-contents
363 '(filesets-be-docile-flag
364 filesets-submenus
e9bbdfc3 365 filesets-menu-cache
c0e48b0b
RS
366 filesets-ingroup-cache)
367 "*Stuff we want to save in `filesets-menu-cache-file'.
368
369Possible uses: don't save configuration data in the main startup files
370but in filesets's own cache. In this case add `filesets-data' to this
371list.
372
373There is a second reason for putting `filesets-data' on this list. If
374you frequently add and remove buffers on the fly to :files filesets, you
375don't need to save your customizations if `filesets-data' is being
376mirrored in the cache file. In this case the version in the cache file
377is the current one, and the version in your startup file will be
378silently updated later on.
379
380If you want caching to work properly, at least `filesets-submenus',
381`filesets-menu-cache', and `filesets-ingroup-cache' should be in this
382list.
383
384Don't forget to check out `filesets-menu-ensure-use-cached'."
385 :set (function filesets-set-default)
386 :type '(repeat
387 (choice :tag "Variable"
388 (const :tag "filesets-submenus"
389 :value filesets-submenus)
390 (const :tag "filesets-menu-cache"
391 :value filesets-menu-cache)
392 (const :tag "filesets-ingroup-cache"
393 :value filesets-ingroup-cache)
394 (const :tag "filesets-data"
395 :value filesets-data)
396 (const :tag "filesets-external-viewers"
397 :value filesets-external-viewers)
398 (const :tag "filesets-ingroup-patterns"
399 :value filesets-ingroup-patterns)
400 (const :tag "filesets-be-docile-flag"
401 :value filesets-be-docile-flag)
402 (sexp :tag "Other" :value nil)))
403 :group 'filesets)
404
405(defcustom filesets-cache-fill-content-hooks nil
406 "*Hooks to run when writing the contents of filesets' cache file.
407
408The hook is called with the cache file as current buffer and the cursor
409at the last position. I.e. each hook has to make sure that the cursor is
410at the last position.
411
412Possible uses: If you don't want to save `filesets-data' in your normal
413configuration file, you can add a something like this
414
415 \(lambda ()
416 \(insert (format \"(setq-default filesets-data '%S)\"
417 filesets-data))
418 \(newline 2))
419
420to this hook.
421
422Don't forget to check out `filesets-menu-ensure-use-cached'."
423 :set (function filesets-set-default)
424 :type 'hook
425 :group 'filesets)
426
427(defcustom filesets-cache-hostname-flag nil
cd56bfef
RS
428 "*Non-nil means cache the hostname.
429If the current name differs from the cached one,
430rebuild the menu and create a new cache file."
c0e48b0b
RS
431 :set (function filesets-set-default)
432 :type 'boolean
433 :group 'filesets)
434
435(defcustom filesets-cache-save-often-flag nil
436 "*Non-nil means save buffer on every change of the filesets menu.
437If this variable is set to nil and if Emacs crashes, the cache and
438filesets-data could get out of sync. Set this to t if this happens from
439time to time or if the fileset cache causes troubles."
440 :set (function filesets-set-default)
441 :type 'boolean
442 :group 'filesets)
443
444(defcustom filesets-max-submenu-length 25
445 "*Maximum length of submenus.
446Set this value to 0 to turn menu splitting off. BTW, parts of submenus
447will not be rewrapped if their length exceeds this value."
448 :set (function filesets-set-default)
449 :type 'integer
450 :group 'filesets)
451
452(defcustom filesets-max-entry-length 50
453 "*Truncate names of splitted submenus to this length."
454 :set (function filesets-set-default)
455 :type 'integer
456 :group 'filesets)
457
cd56bfef 458(defcustom filesets-browse-dir-function 'dired
c0e48b0b
RS
459 "*A function or command used for browsing directories.
460When using an external command, \"%s\" will be replaced with the
461directory's name.
462
463Note: You have to manually rebuild the menu if you change this value."
464 :set (function filesets-set-default)
465 :type '(choice :tag "Function:"
466 (const :tag "dired"
467 :value dired)
468 (list :tag "Command"
469 :value ("" "%s")
470 (string :tag "Name")
471 (string :tag "Arguments"))
472 (function :tag "Function"
473 :value nil))
474 :group 'filesets)
475
cd56bfef 476(defcustom filesets-open-file-function 'filesets-find-or-display-file
c0e48b0b
RS
477 "*The function used for opening files.
478
479`filesets-find-or-display-file' ... Filesets' default function for
480visiting files. This function checks if an external viewer is defined
481for a specific file type. Either this viewer, if defined, or
482`find-file' will be used to visit a file.
483
484`filesets-find-file' ... An alternative function that always uses
485`find-file'. If `filesets-be-docile-flag' is true, a file, which isn't
486readable, will not be opened.
487
488Caveat: Changes will take effect only after rebuilding the menu."
489 :set (function filesets-set-default)
490 :type '(choice :tag "Function:"
491 (const :tag "filesets-find-or-display-file"
492 :value filesets-find-or-display-file)
493 (const :tag "filesets-find-file"
494 :value filesets-find-file)
495 (function :tag "Function"
496 :value nil))
497 :group 'filesets)
498
cd56bfef 499(defcustom filesets-save-buffer-function 'save-buffer
c0e48b0b
RS
500 "*The function used to save a buffer.
501Caveat: Changes will take effect after rebuilding the menu."
502 :set (function filesets-set-default)
503 :type '(choice :tag "Function:"
504 (const :tag "save-buffer"
505 :value save-buffer)
506 (function :tag "Function"
507 :value nil))
508 :group 'filesets)
509
510(defcustom filesets-find-file-delay
511 (if (and filesets-running-xemacs gutter-buffers-tab-visible-p)
512 0.5
513 0)
514 "*Delay before calling find-file.
515This is for calls via `filesets-find-or-display-file'
516or `filesets-find-file'.
517
518Set this to 0, if you don't use XEmacs' buffer tabs."
519 :set (function filesets-set-default)
520 :type 'number
521 :group 'filesets)
522
523(defcustom filesets-be-docile-flag nil
524 "*Non-nil means don't complain if a file or a directory doesn't exist.
525This is useful if you want to use the same startup files in different
526computer environments."
527 :set (function filesets-set-default)
528 :type 'boolean
529 :group 'filesets)
530
531(defcustom filesets-sort-menu-flag t
532 "*Non-nil means sort the filesets menu alphabetically."
533 :set (function filesets-set-default)
534 :type 'boolean
535 :group 'filesets)
536
537(defcustom filesets-sort-case-sensitive-flag t
538 "*Non-nil means sorting of the filesete menu is case sensitive."
539 :set (function filesets-set-default)
540 :type 'boolean
541 :group 'filesets)
542
543(defcustom filesets-tree-max-level 3
544 "*Maximum scan depth for directory trees.
545A :tree fileset is defined by a base directory the contents of which
cd56bfef 546will be recursively added to the menu. `filesets-tree-max-level' tells up
c0e48b0b
RS
547to which level the directory structure should be scanned/listed,
548i.e. how deep the menu should be. Try something like
549
550 \(\"HOME -- only one level\"
551 \(:tree \"~\" \"^[^.].*[^~]$\")
552 \(:tree-max-level 1)
553 \(:filter-dirs-flag t))
554 \(\"HOME -- up to 3 levels\"
555 \(:tree \"~\" \"^[^.].*[^~]$\")
556 \(:tree-max-level 3)
557 \(:filter-dirs-flag t))
558
559and it should become clear what this option is about. In any case,
560including directory trees to the menu can take a lot of memory."
561 :set (function filesets-set-default)
562 :type 'integer
563 :group 'filesets)
564
565(defcustom filesets-commands
566 `(("Query Replace"
567 query-replace
568 (filesets-cmd-query-replace-getargs))
569 ("Query Replace (regexp)"
570 query-replace-regexp
571 (filesets-cmd-query-replace-getargs))
572 ("Grep <<selection>>"
573 "grep"
574 ("-n " filesets-get-quoted-selection " " "<<file-name>>"))
575 ("Run Shell Command"
576 filesets-cmd-shell-command
577 (filesets-cmd-shell-command-getargs)))
578 "*Commands to run on filesets.
579An association list of names, functions, and an argument list (or a
580function that returns one) to be run on a filesets' files.
581
582The argument <file-name> or <<file-name>> (quoted) will be replaced with
583the filename."
584 :set (function filesets-set-default+)
585 :type '(repeat :tag "Commands"
586 (list :tag "Definition" :value ("")
587 (string "Name")
588 (choice :tag "Command"
589 (string :tag "String")
590 (function :tag "Function"))
591 (repeat :tag "Argument List"
592 (choice :tag "Arguments"
593 (sexp :tag "Sexp"
594 :value nil)
595 (string :tag "File Name"
596 :value "<file-name>")
597 (string :tag "Quoted File Name"
598 :value "<<file-name>>")
599 (function :tag "Function"
600 :value nil)))))
601 :group 'filesets)
cd56bfef 602(put 'filesets-commands 'risky-local-variable t)
c0e48b0b
RS
603
604(defcustom filesets-external-viewers
605 (let
606; ((ps-cmd (or (and (boundp 'my-ps-viewer) my-ps-viewer)
607; (filesets-select-command "ggv gv")))
608; (pdf-cmd (or (and (boundp 'my-ps-viewer) my-pdf-viewer)
609; (filesets-select-command "xpdf acroread")))
610; (dvi-cmd (or (and (boundp 'my-ps-viewer) my-dvi-viewer)
611; (filesets-select-command "xdvi tkdvi")))
612; (doc-cmd (or (and (boundp 'my-ps-viewer) my-doc-viewer)
613; (filesets-select-command "antiword")))
614; (pic-cmd (or (and (boundp 'my-ps-viewer) my-pic-viewer)
615; (filesets-select-command "gqview ee display"))))
616 ((ps-cmd "ggv")
617 (pdf-cmd "xpdf")
618 (dvi-cmd "xdvi")
619 (doc-cmd "antiword")
620 (pic-cmd "gqview"))
621 `(("^.+\\..?html?$" browse-url
622 ((:ignore-on-open-all t)))
623 ("^.+\\.pdf$" ,pdf-cmd
624 ((:ignore-on-open-all t)
625 (:ignore-on-read-text t)
626 (:constraint-flag ,pdf-cmd)))
627 ("^.+\\.e?ps\\(.gz\\)?$" ,ps-cmd
628 ((:ignore-on-open-all t)
629 (:ignore-on-read-text t)
630 (:constraint-flag ,ps-cmd)))
631 ("^.+\\.dvi$" ,dvi-cmd
632 ((:ignore-on-open-all t)
633 (:ignore-on-read-text t)
634 (:constraint-flag ,dvi-cmd)))
635 ("^.+\\.doc$" ,doc-cmd
636 ((:capture-output t)
637 (:ignore-on-read-text t)
638 (:constraint-flag ,doc-cmd)))
639 ("^.+\\.\\(tiff\\|xpm\\|gif\\|pgn\\)$" ,pic-cmd
640 ((:ignore-on-open-all t)
641 (:ignore-on-read-text t)
642 (:constraint-flag ,pic-cmd)))))
643 "*Association list of file patterns and external viewers for use with
644`filesets-find-or-display-file'.
645
646Has the form ((FILE-PATTERN VIEWER PROPERTIES) ...), VIEWER being either a
647function or a command name as string.
648
649Properties is an association list determining filesets' behaviour in
650several conditions. Choose one from this list:
651
652:ignore-on-open-all ... Don't open files of this type automatically --
653i.e. on open-all-files-events or when running commands
654
655:capture-output ... capture an external viewer output
656
657:constraintp FUNCTION ... use this viewer only if FUNCTION returns non-nil
658
f194e54a 659:constraint-flag SEXP ... use this viewer only if SEXP evaluates to non-nil
c0e48b0b
RS
660
661:open-hook HOOK ... run hooks after spawning the viewer -- mainly useful
662in conjunction with :capture-output
663
664:args (FORMAT-STRING or SYMBOL or FUNCTION) ... a list of arguments
665\(defaults to (list \"%S\")) when using shell commands
666
667Avoid modifying this variable and achieve minor speed-ups by setting the
668variables my-ps-viewer, my-pdf-viewer, my-dvi-viewer, my-pic-viewer.
669
670In order to view pdf or rtf files in an Emacs buffer, you could use these:
671
672
673 \(\"^.+\\.pdf$\" \"pdftotext\"
674 \((:capture-output t)
675 \(:args (\"%S - | fmt -w \" window-width))
676 \(:ignore-on-read-text t)
677 \(:constraintp (lambda ()
678 \(and \(filesets-which-command-p \"pdftotext\")
679 \(filesets-which-command-p \"fmt\"))))))
680 \(\"^.+\\.rtf$\" \"rtf2htm\"
681 \((:capture-output t)
682 \(:args (\"%S 2> /dev/null | w3m -dump -T text/html\"))
683 \(:ignore-on-read-text t)
684 \(:constraintp (lambda ()
685 \(and (filesets-which-command-p \"rtf2htm\")
686 \(filesets-which-command-p \"w3m\"))))))
687"
688 :set (function filesets-set-default)
689 :type '(repeat :tag "Viewer"
690 (list :tag "Definition"
691 :value ("^.+\\.suffix$" "")
692 (regexp :tag "Pattern")
693 (choice :tag "Viewer"
694 (symbol :tag "Function" :value nil)
695 (string :tag "Program" :value ""))
696 (repeat :tag "Properties"
697 (choice
698 (list :tag ":constraintp"
699 :value (:constraintp)
700 (const :format ""
701 :value :constraintp)
702 (function :tag "Function"))
703 (list :tag ":constraint-flag"
704 :value (:constraint-flag)
705 (const :format ""
706 :value :constraint-flag)
f194e54a 707 (sexp :tag "Symbol"))
c0e48b0b
RS
708 (list :tag ":ignore-on-open-all"
709 :value (:ignore-on-open-all t)
710 (const :format ""
711 :value :ignore-on-open-all)
712 (boolean :tag "Boolean"))
713 (list :tag ":ignore-on-read-text"
714 :value (:ignore-on-read-text t)
715 (const :format ""
716 :value :ignore-on-read-text)
717 (boolean :tag "Boolean"))
718 (list :tag ":args"
719 :value (:args)
720 (const :format ""
721 :value :args)
722 (repeat :tag "List"
723 (choice :tag "Arguments"
724 (string :tag "String"
725 :value "")
726 (symbol :tag "Symbol"
727 :value nil)
728 (function :tag "Function"
729 :value nil))))
730 (list :tag ":open-hook"
731 :value (:open-hook)
732 (const :format ""
733 :value :open-hook)
734 (hook :tag "Hook"))
735; (list :tag ":close-hook"
736; :value (:close-hook)
737; (const :format ""
738; :value :close-hook)
739; (hook :tag "Hook"))
740 (list :tag ":capture-output"
741 :value (:capture-output t)
742 (const :format ""
743 :value :capture-output)
744 (boolean :tag "Boolean"))))))
745 :group 'filesets)
cd56bfef 746(put 'filesets-external-viewers 'risky-local-variable t)
c0e48b0b
RS
747
748(defcustom filesets-ingroup-patterns
749 '(("^.+\\.tex$" t
750 (((:name "Package")
751 (:pattern "\\\\usepackage\\W*\\(\\[[^\]]*\\]\\W*\\)?{\\W*\\(.+\\)\\W*}")
752 (:match-number 2)
753 (:stub-flag t)
754 (:get-file-name (lambda (master file)
755 (filesets-which-file master
756 (concat file ".sty")
e9bbdfc3 757 (filesets-convert-path-list
c0e48b0b
RS
758 (or (getenv "MY_TEXINPUTS")
759 (getenv "TEXINPUTS")))))))
760 ((:name "Include")
761 (:pattern "\\\\include\\W*{\\W*\\(.+\\)\\W*}")
762 (:get-file-name (lambda (master file)
763 (filesets-which-file master
764 (concat file ".tex")
e9bbdfc3 765 (filesets-convert-path-list
c0e48b0b
RS
766 (or (getenv "MY_TEXINPUTS")
767 (getenv "TEXINPUTS"))))))
768 (:scan-depth 5))
769 ((:name "Input")
770 (:pattern "\\\\input\\W*{\\W*\\(.+\\)\\W*}")
771 (:stubp (lambda (a b) (not (filesets-files-in-same-directory-p a b))))
772 (:get-file-name (lambda (master file)
773 (filesets-which-file master
774 (concat file ".tex")
e9bbdfc3 775 (filesets-convert-path-list
c0e48b0b
RS
776 (or (getenv "MY_TEXINPUTS")
777 (getenv "TEXINPUTS"))))))
778 (:scan-depth 5))
779 ((:name "Bibliography")
780 (:pattern "\\\\bibliography\\W*{\\W*\\(.+\\)\\W*}")
781 (:get-file-name (lambda (master file)
782 (filesets-which-file master
783 (concat file ".bib")
e9bbdfc3 784 (filesets-convert-path-list
c0e48b0b
RS
785 (or (getenv "MY_BIBINPUTS")
786 (getenv "BIBINPUTS")))))))))
787 ("^.+\\.el$" t
788 (((:name "Require")
789 (:pattern "(require\\W+'\\(.+\\))")
790 (:stubp (lambda (a b) (not (filesets-files-in-same-directory-p a b))))
791 (:get-file-name (lambda (master file)
792 (filesets-which-file master
793 (concat file ".el")
794 load-path))))
795 ((:name "Load")
796 (:pattern "(load\\(-library\\)?\\W+\"\\(.+\\)\")")
797 (:match-number 2)
798 (:get-file-name (lambda (master file)
799 (filesets-which-file master file load-path))))))
800