comparison lisp/filesets.el @ 44934:ae16f63fe28f

*** empty log message ***
author Richard M. Stallman <rms@gnu.org>
date Sun, 28 Apr 2002 21:16:32 +0000
parents
children f23f11648559
comparison
equal deleted inserted replaced
44933:89bfde1b51f5 44934:ae16f63fe28f
1 ;;; filesets.el --- handle group of files
2
3 ;; Copyright (C) 2002 Free Software Foundation, Inc.
4
5 ;; Author: Thomas Link aka t.link (at gmx at)
6 ;; Time-stamp: <2002-03-22>
7 ;; Keywords: filesets convenience
8
9 ;; This program is free software; you can redistribute it and/or modify
10 ;; it under the terms of the GNU General Public License as published by
11 ;; the Free Software Foundation; either version 2, or (at your option)
12 ;; any later version.
13
14 ;; This program is distributed in the hope that it will be useful,
15 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
16 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 ;; GNU General Public License for more details.
18
19 ;; A copy of the GNU General Public License can be obtained from this
20 ;; program's author or from the Free Software Foundation, Inc., 675 Mass
21 ;; Ave, Cambridge, MA 02139, USA.
22
23 (defvar filesets-version "1.8.1")
24 (defvar filesets-homepage
25 "http://members.a1.net/t.link/CompEmacsFilesets.html")
26
27 ;;; Commentary:
28
29 ;;Define filesets, which can be opened or saved with the power one or
30 ;;two mouse clicks only. A fileset is either a list of files, a file
31 ;;pattern, a base directory and a search pattern (for files), or an
32 ;;inclusion group (i.e. a base file including other files).
33
34 ;;Usage: 1. Put (require 'filesets) into your start-up file. 2. Type
35 ;;M-x filesets-edit or choose "Edit Filesets" from the menu. 3. Save
36 ;;your customizations.
37
38 ;;Caveat: Fileset names have to be unique.
39
40 ;;Filesets.el adds a nifty filesets menu to your menubar. If you change
41 ;;your filesets on the fly, don't forget to select "Save Filesets" from
42 ;;the menu.
43
44 ;;Pressing on the first item in the submenu will open all files at once.
45 ;;Define your own function, e.g. browse-url, for opening a fileset's
46 ;;files. Or define external viewers for opening files with other
47 ;;programs. See `filesets-external-viewers'.
48
49 ;;BTW, if you close a fileset, files, which have been changed, will
50 ;;be silently saved. Change this behaviour by setting
51 ;;`filesets-save-buffer-fn'.
52
53 ;;; Supported modes for inclusion groups (`filesets-ingroup-patterns'):
54 ;; - Elisp
55 ;; - Emacs-Wiki (simple names only)
56 ;; - LaTeX
57
58
59
60 ;;; Known bugs:
61
62
63 ;;; To do:
64
65 ;;- better handling of different customization scenarios
66
67
68 ;;; Credits:
69
70 ;; Helpful suggestions (but no significant code) were contributed by
71
72 ;;- Christoph Conrad (at gmx de)
73 ;;- Christian Ohler (at Informatik Uni-Oldenburg DE)
74 ;;- Richard Stallman aka RMS (at gnu org)
75 ;;- Per Abrahamsen aka abraham (at dina kvl dk)
76
77
78 ;;; Code:
79
80 (eval-when-compile
81 (require 'cl))
82
83
84 ;;; Some variables
85 (unless (boundp 'filesets-running-xemacs)
86 (defvar filesets-running-xemacs (string-match "XEmacs\\|Lucid" emacs-version)
87 "Non-nil means we are runninn XEmacs."))
88
89 (defvar filesets-menu-cache nil
90 "The whole filesets menu.")
91 (defvar filesets-cache-version nil
92 "Filesets' cached version number.")
93 (defvar filesets-cache-hostname nil
94 "Filesets' cached system name.")
95
96 (defvar filesets-ingroup-cache nil
97 "A plist containing files and their ingroup data.")
98 (defvar filesets-ingroup-paths nil
99 "A temporary list of path already processed when searching for
100 included files.")
101
102 (defvar filesets-has-changed-flag t
103 "Non-nil means some fileset definition has changed.")
104 (defvar filesets-submenus nil
105 "An association list with filesets menu data.")
106 (defvar filesets-updated-buffers nil
107 "A list of buffers with updated menu bars.")
108 (defvar filesets-menu-use-cached-flag nil
109 "Use cached data. See `filesets-menu-ensure-use-cached' for details.")
110 (defvar filesets-update-cache-file-flag nil
111 "Non-nil means the cache needs updating.")
112 (defvar filesets-ignore-next-set-default nil
113 "A list of custom variables for which the next `set-default' will be
114 ignored.")
115
116 (defvar filesets-output-buffer-flag nil
117 "Non-nil means the current buffer is an output buffer created by filesets.
118 Is buffer local variable.")
119
120 (defvar filesets-verbosity 1
121 "An integer defining the level of verbosity. 0 means no messages
122 at all.")
123
124 (defvar filesets-menu-ensure-use-cached
125 (and filesets-running-xemacs
126 (not (emacs-version>= 21 5)))
127 "Make sure (X)Emacs uses filesets' cache.
128
129 Well, if you use XEmacs (prior to 21.5?) custom.el is loaded after
130 init.el. This means that settings saved in the cache file (see
131 `filesets-menu-cache-file') will be overwritten by custom.el. In order
132 to ensure the use of the cache file, set this variable to t -- which is
133 the default for XEmacs prior to 21.5. If you want to change this value
134 put \"(setq filesets-menu-ensure-use-cached VALUE)\" into your startup
135 file -- before loading filesets.el.
136
137 So, when should you think about setting this value to t? If filesets.el
138 is loaded before user customizations. Thus, if (require 'filesets)
139 precedes the custom-set-variables command or, for XEmacs, if init.el is
140 loaded before custom.el, set this variable to t.")
141
142
143 ;;; utils
144 (defun filesets-filter-list (lst cond-fn)
145 "Remove all elements not conforming to COND-FN from list LST.
146 COND-FN takes one argument: the current element."
147 ; (remove* 'dummy lst :test (lambda (dummy elt)
148 ; (not (funcall cond-fn elt)))))
149 (let ((rv nil))
150 (dolist (elt lst rv)
151 (when (funcall cond-fn elt)
152 (setq rv (append rv (list elt)))))))
153
154 (defun filesets-sublist (lst beg &optional end)
155 "Get the sublist of LST from BEG to END - 1."
156 (let ((rv nil)
157 (i beg)
158 (top (or end
159 (length lst))))
160 (while (< i top)
161 (setq rv (append rv (list (nth i lst))))
162 (setq i (+ i 1)))
163 rv))
164
165 (defun filesets-select-command (cmd-list)
166 "Select one command from CMD-LIST -- a string with space separated names."
167 (let ((this (shell-command-to-string
168 (format "which --skip-alias %s 2> /dev/null | head -n 1"
169 cmd-list))))
170 (if (equal this "")
171 nil
172 (file-name-nondirectory (substring this 0 (- (length this) 1))))))
173
174 (defun filesets-which-command (cmd)
175 "Calls \"which CMD\"."
176 (shell-command-to-string (format "which %s" cmd)))
177
178 (defun filesets-which-command-p (cmd)
179 "Calls \"which CMD\" and returns non-nil if the command was found."
180 (when (string-match (format "\\(/[^/]+\\)?/%s" cmd)
181 (filesets-which-command cmd))
182 cmd))
183
184 (defun filesets-message (level &rest args)
185 "Show a message only if LEVEL is greater or equal then `filesets-verbosity'."
186 (when (<= level (abs filesets-verbosity))
187 (apply 'message args)))
188
189
190 ;;; config file
191 (defun filesets-save-config ()
192 "Save filesets' customizations."
193 (interactive)
194 (customize-save-customized))
195
196 (defun filesets-reset-fileset (&optional fileset no-cache)
197 "Reset the cached values for one or all filesets."
198 (if fileset
199 (setq filesets-submenus (lax-plist-put filesets-submenus fileset nil))
200 (setq filesets-submenus nil))
201 (setq filesets-has-changed-flag t)
202 (setq filesets-update-cache-file-flag (or filesets-update-cache-file-flag
203 (not no-cache))))
204
205 (defun filesets-set-config (fileset var val)
206 "Set-default wrapper function."
207 (filesets-reset-fileset fileset)
208 (set-default var val))
209 ; (customize-set-variable var val))
210 ; (filesets-build-menu))
211
212 (defun filesets-set-default (sym val &optional init-flag)
213 "Set-default wrapper function used in conjunction with `defcustom'."
214 (let ((ignore-flag (member sym filesets-ignore-next-set-default)))
215 (if ignore-flag
216 (setq filesets-ignore-next-set-default
217 (delete sym filesets-ignore-next-set-default))
218 (if init-flag
219 (custom-initialize-set sym val)
220 (set-default sym val)))
221 (not ignore-flag)))
222
223 (defun filesets-set-default! (sym val)
224 "Call `filestes-set-default' and reset cached data (i.e. rebuild menu)."
225 (when (filesets-set-default sym val)
226 (filesets-reset-fileset)))
227
228 (defun filesets-set-default+ (sym val)
229 "Call `filestes-set-default' and reset filesets' standard menu."
230 (when (filesets-set-default sym val)
231 (setq filesets-has-changed-flag t)))
232 ; (filesets-reset-fileset nil t)))
233
234 (defun filesets-data-set-default (sym val)
235 "Set the default for `filesets-data'."
236 (if filesets-menu-use-cached-flag
237 (setq filesets-menu-use-cached-flag nil)
238 (when (default-boundp 'filesets-data)
239 (let ((modified-filesets
240 (filesets-filter-list val
241 (lambda (x)
242 (let ((name (car x))
243 (data (cdr x)))
244 (let ((elt (assoc name filesets-data)))
245 (or (not elt)
246 (not (equal data (cdr elt))))))))))
247 (dolist (x modified-filesets)
248 (filesets-reset-fileset (car x))))))
249 (filesets-set-default sym val))
250
251
252
253 ;;; configuration
254 (defgroup filesets nil
255 "The fileset swapper."
256 :prefix "filesets-"
257 :group 'convenience)
258
259 (defcustom filesets-menu-name "Filesets"
260 "*Filesets' menu name."
261 :set (function filesets-set-default)
262 :type 'sexp
263 :group 'filesets)
264
265 (defcustom filesets-menu-path nil
266 "*The menu under which the filesets menu should be inserted.
267 XEmacs specific; see `add-submenu' for documentation."
268 :set (function filesets-set-default)
269 :type 'sexp
270 :group 'filesets)
271
272 (defcustom filesets-menu-before "File"
273 "*The name of a menu before which this menu should be added.
274 XEmacs specific; see `add-submenu' for documentation."
275 :set (function filesets-set-default)
276 :type 'sexp
277 :group 'filesets)
278
279 (defcustom filesets-menu-in-menu nil
280 "*Use that instead of `current-menubar' as the menu to change.
281 XEmacs specific; see `add-submenu' for documentation."
282 :set (function filesets-set-default)
283 :type 'sexp
284 :group 'filesets)
285
286 (defcustom filesets-menu-shortcuts-flag t
287 "*Non-nil means to prepend menus with hopefully unique shortcuts."
288 :set (function filesets-set-default!)
289 :type 'boolean
290 :group 'filesets)
291
292 (defcustom filesets-menu-shortcuts-marker "%_"
293 "*String for marking menu shortcuts."
294 :set (function filesets-set-default!)
295 :type 'string
296 :group 'filesets)
297
298 ;(defcustom filesets-menu-cnvfp-flag nil
299 ; "*Non-nil means show \"Convert :pattern to :files\" entry for :pattern menus."
300 ; :set (function filesets-set-default!)
301 ; :type 'boolean
302 ; :group 'filesets)
303
304 (defcustom filesets-menu-cache-file
305 (if filesets-running-xemacs
306 "~/.xemacs/filesets-cache.el"
307 "~/.filesets-cache.el")
308 "*File to be used for saving the filesets menu between (X)Emacs
309 sessions. Set this to \"\", to disable caching of menus.
310 Don't forget to check out `filesets-menu-ensure-use-cached'."
311 :set (function filesets-set-default)
312 :type 'file
313 :group 'filesets)
314
315 (defcustom filesets-menu-cache-contents
316 '(filesets-be-docile-flag
317 filesets-submenus
318 filesets-menu-cache
319 filesets-ingroup-cache)
320 "*Stuff we want to save in `filesets-menu-cache-file'.
321
322 Possible uses: don't save configuration data in the main startup files
323 but in filesets's own cache. In this case add `filesets-data' to this
324 list.
325
326 There is a second reason for putting `filesets-data' on this list. If
327 you frequently add and remove buffers on the fly to :files filesets, you
328 don't need to save your customizations if `filesets-data' is being
329 mirrored in the cache file. In this case the version in the cache file
330 is the current one, and the version in your startup file will be
331 silently updated later on.
332
333 If you want caching to work properly, at least `filesets-submenus',
334 `filesets-menu-cache', and `filesets-ingroup-cache' should be in this
335 list.
336
337 Don't forget to check out `filesets-menu-ensure-use-cached'."
338 :set (function filesets-set-default)
339 :type '(repeat
340 (choice :tag "Variable"
341 (const :tag "filesets-submenus"
342 :value filesets-submenus)
343 (const :tag "filesets-menu-cache"
344 :value filesets-menu-cache)
345 (const :tag "filesets-ingroup-cache"
346 :value filesets-ingroup-cache)
347 (const :tag "filesets-data"
348 :value filesets-data)
349 (const :tag "filesets-external-viewers"
350 :value filesets-external-viewers)
351 (const :tag "filesets-ingroup-patterns"
352 :value filesets-ingroup-patterns)
353 (const :tag "filesets-be-docile-flag"
354 :value filesets-be-docile-flag)
355 (sexp :tag "Other" :value nil)))
356 :group 'filesets)
357
358 (defcustom filesets-cache-fill-content-hooks nil
359 "*Hooks to run when writing the contents of filesets' cache file.
360
361 The hook is called with the cache file as current buffer and the cursor
362 at the last position. I.e. each hook has to make sure that the cursor is
363 at the last position.
364
365 Possible uses: If you don't want to save `filesets-data' in your normal
366 configuration file, you can add a something like this
367
368 \(lambda ()
369 \(insert (format \"(setq-default filesets-data '%S)\"
370 filesets-data))
371 \(newline 2))
372
373 to this hook.
374
375 Don't forget to check out `filesets-menu-ensure-use-cached'."
376 :set (function filesets-set-default)
377 :type 'hook
378 :group 'filesets)
379
380 (defcustom filesets-cache-hostname-flag nil
381 "*Non-nil means cache the hostname. If the current name differs from
382 the cached one, rebuild the menu and create a new cache file."
383 :set (function filesets-set-default)
384 :type 'boolean
385 :group 'filesets)
386
387 (defcustom filesets-cache-save-often-flag nil
388 "*Non-nil means save buffer on every change of the filesets menu.
389 If this variable is set to nil and if Emacs crashes, the cache and
390 filesets-data could get out of sync. Set this to t if this happens from
391 time to time or if the fileset cache causes troubles."
392 :set (function filesets-set-default)
393 :type 'boolean
394 :group 'filesets)
395
396 (defcustom filesets-max-submenu-length 25
397 "*Maximum length of submenus.
398 Set this value to 0 to turn menu splitting off. BTW, parts of submenus
399 will not be rewrapped if their length exceeds this value."
400 :set (function filesets-set-default)
401 :type 'integer
402 :group 'filesets)
403
404 (defcustom filesets-max-entry-length 50
405 "*Truncate names of splitted submenus to this length."
406 :set (function filesets-set-default)
407 :type 'integer
408 :group 'filesets)
409
410 (defcustom filesets-browse-dir-fn 'dired
411 "*A function or command used for browsing directories.
412 When using an external command, \"%s\" will be replaced with the
413 directory's name.
414
415 Note: You have to manually rebuild the menu if you change this value."
416 :set (function filesets-set-default)
417 :type '(choice :tag "Function:"
418 (const :tag "dired"
419 :value dired)
420 (list :tag "Command"
421 :value ("" "%s")
422 (string :tag "Name")
423 (string :tag "Arguments"))
424 (function :tag "Function"
425 :value nil))
426 :group 'filesets)
427
428 (defcustom filesets-open-file-fn 'filesets-find-or-display-file
429 "*The function used for opening files.
430
431 `filesets-find-or-display-file' ... Filesets' default function for
432 visiting files. This function checks if an external viewer is defined
433 for a specific file type. Either this viewer, if defined, or
434 `find-file' will be used to visit a file.
435
436 `filesets-find-file' ... An alternative function that always uses
437 `find-file'. If `filesets-be-docile-flag' is true, a file, which isn't
438 readable, will not be opened.
439
440 Caveat: Changes will take effect only after rebuilding the menu."
441 :set (function filesets-set-default)
442 :type '(choice :tag "Function:"
443 (const :tag "filesets-find-or-display-file"
444 :value filesets-find-or-display-file)
445 (const :tag "filesets-find-file"
446 :value filesets-find-file)
447 (function :tag "Function"
448 :value nil))
449 :group 'filesets)
450
451 (defcustom filesets-save-buffer-fn 'save-buffer
452 "*The function used to save a buffer.
453 Caveat: Changes will take effect after rebuilding the menu."
454 :set (function filesets-set-default)
455 :type '(choice :tag "Function:"
456 (const :tag "save-buffer"
457 :value save-buffer)
458 (function :tag "Function"
459 :value nil))
460 :group 'filesets)
461
462 (defcustom filesets-find-file-delay
463 (if (and filesets-running-xemacs gutter-buffers-tab-visible-p)
464 0.5
465 0)
466 "*Delay before calling find-file.
467 This is for calls via `filesets-find-or-display-file'
468 or `filesets-find-file'.
469
470 Set this to 0, if you don't use XEmacs' buffer tabs."
471 :set (function filesets-set-default)
472 :type 'number
473 :group 'filesets)
474
475 (defcustom filesets-be-docile-flag nil
476 "*Non-nil means don't complain if a file or a directory doesn't exist.
477 This is useful if you want to use the same startup files in different
478 computer environments."
479 :set (function filesets-set-default)
480 :type 'boolean
481 :group 'filesets)
482
483 (defcustom filesets-sort-menu-flag t
484 "*Non-nil means sort the filesets menu alphabetically."
485 :set (function filesets-set-default)
486 :type 'boolean
487 :group 'filesets)
488
489 (defcustom filesets-sort-case-sensitive-flag t
490 "*Non-nil means sorting of the filesete menu is case sensitive."
491 :set (function filesets-set-default)
492 :type 'boolean
493 :group 'filesets)
494
495 (defcustom filesets-tree-max-level 3
496 "*Maximum scan depth for directory trees.
497 A :tree fileset is defined by a base directory the contents of which
498 will be recursively added to the menu. filesets-tree-max-level tells up
499 to which level the directory structure should be scanned/listed,
500 i.e. how deep the menu should be. Try something like
501
502 \(\"HOME -- only one level\"
503 \(:tree \"~\" \"^[^.].*[^~]$\")
504 \(:tree-max-level 1)
505 \(:filter-dirs-flag t))
506 \(\"HOME -- up to 3 levels\"
507 \(:tree \"~\" \"^[^.].*[^~]$\")
508 \(:tree-max-level 3)
509 \(:filter-dirs-flag t))
510
511 and it should become clear what this option is about. In any case,
512 including directory trees to the menu can take a lot of memory."
513 :set (function filesets-set-default)
514 :type 'integer
515 :group 'filesets)
516
517 (defcustom filesets-commands
518 `(("Query Replace"
519 query-replace
520 (filesets-cmd-query-replace-getargs))
521 ("Query Replace (regexp)"
522 query-replace-regexp
523 (filesets-cmd-query-replace-getargs))
524 ("Grep <<selection>>"
525 "grep"
526 ("-n " filesets-get-quoted-selection " " "<<file-name>>"))
527 ("Run Shell Command"
528 filesets-cmd-shell-command
529 (filesets-cmd-shell-command-getargs)))
530 "*Commands to run on filesets.
531 An association list of names, functions, and an argument list (or a
532 function that returns one) to be run on a filesets' files.
533
534 The argument <file-name> or <<file-name>> (quoted) will be replaced with
535 the filename."
536 :set (function filesets-set-default+)
537 :type '(repeat :tag "Commands"
538 (list :tag "Definition" :value ("")
539 (string "Name")
540 (choice :tag "Command"
541 (string :tag "String")
542 (function :tag "Function"))
543 (repeat :tag "Argument List"
544 (choice :tag "Arguments"
545 (sexp :tag "Sexp"
546 :value nil)
547 (string :tag "File Name"
548 :value "<file-name>")
549 (string :tag "Quoted File Name"
550 :value "<<file-name>>")
551 (function :tag "Function"
552 :value nil)))))
553 :group 'filesets)
554
555 (defcustom filesets-external-viewers
556 (let
557 ; ((ps-cmd (or (and (boundp 'my-ps-viewer) my-ps-viewer)
558 ; (filesets-select-command "ggv gv")))
559 ; (pdf-cmd (or (and (boundp 'my-ps-viewer) my-pdf-viewer)
560 ; (filesets-select-command "xpdf acroread")))
561 ; (dvi-cmd (or (and (boundp 'my-ps-viewer) my-dvi-viewer)
562 ; (filesets-select-command "xdvi tkdvi")))
563 ; (doc-cmd (or (and (boundp 'my-ps-viewer) my-doc-viewer)
564 ; (filesets-select-command "antiword")))
565 ; (pic-cmd (or (and (boundp 'my-ps-viewer) my-pic-viewer)
566 ; (filesets-select-command "gqview ee display"))))
567 ((ps-cmd "ggv")
568 (pdf-cmd "xpdf")
569 (dvi-cmd "xdvi")
570 (doc-cmd "antiword")
571 (pic-cmd "gqview"))
572 `(("^.+\\..?html?$" browse-url
573 ((:ignore-on-open-all t)))
574 ("^.+\\.pdf$" ,pdf-cmd
575 ((:ignore-on-open-all t)
576 (:ignore-on-read-text t)
577 (:constraint-flag ,pdf-cmd)))
578 ("^.+\\.e?ps\\(.gz\\)?$" ,ps-cmd
579 ((:ignore-on-open-all t)
580 (:ignore-on-read-text t)
581 (:constraint-flag ,ps-cmd)))
582 ("^.+\\.dvi$" ,dvi-cmd
583 ((:ignore-on-open-all t)
584 (:ignore-on-read-text t)
585 (:constraint-flag ,dvi-cmd)))
586 ("^.+\\.doc$" ,doc-cmd
587 ((:capture-output t)
588 (:ignore-on-read-text t)
589 (:constraint-flag ,doc-cmd)))
590 ("^.+\\.\\(tiff\\|xpm\\|gif\\|pgn\\)$" ,pic-cmd
591 ((:ignore-on-open-all t)
592 (:ignore-on-read-text t)
593 (:constraint-flag ,pic-cmd)))))
594 "*Association list of file patterns and external viewers for use with
595 `filesets-find-or-display-file'.
596
597 Has the form ((FILE-PATTERN VIEWER PROPERTIES) ...), VIEWER being either a
598 function or a command name as string.
599
600 Properties is an association list determining filesets' behaviour in
601 several conditions. Choose one from this list:
602
603 :ignore-on-open-all ... Don't open files of this type automatically --
604 i.e. on open-all-files-events or when running commands
605
606 :capture-output ... capture an external viewer output
607
608 :constraintp FUNCTION ... use this viewer only if FUNCTION returns non-nil
609
610 :constraint-flag SYMBOL ... use this viewer only if SYMBOL is non-nil
611
612 :open-hook HOOK ... run hooks after spawning the viewer -- mainly useful
613 in conjunction with :capture-output
614
615 :args (FORMAT-STRING or SYMBOL or FUNCTION) ... a list of arguments
616 \(defaults to (list \"%S\")) when using shell commands
617
618 Avoid modifying this variable and achieve minor speed-ups by setting the
619 variables my-ps-viewer, my-pdf-viewer, my-dvi-viewer, my-pic-viewer.
620
621 In order to view pdf or rtf files in an Emacs buffer, you could use these:
622
623
624 \(\"^.+\\.pdf$\" \"pdftotext\"
625 \((:capture-output t)
626 \(:args (\"%S - | fmt -w \" window-width))
627 \(:ignore-on-read-text t)
628 \(:constraintp (lambda ()
629 \(and \(filesets-which-command-p \"pdftotext\")
630 \(filesets-which-command-p \"fmt\"))))))
631 \(\"^.+\\.rtf$\" \"rtf2htm\"
632 \((:capture-output t)
633 \(:args (\"%S 2> /dev/null | w3m -dump -T text/html\"))
634 \(:ignore-on-read-text t)
635 \(:constraintp (lambda ()
636 \(and (filesets-which-command-p \"rtf2htm\")
637 \(filesets-which-command-p \"w3m\"))))))
638 "
639 :set (function filesets-set-default)
640 :type '(repeat :tag "Viewer"
641 (list :tag "Definition"
642 :value ("^.+\\.suffix$" "")
643 (regexp :tag "Pattern")
644 (choice :tag "Viewer"
645 (symbol :tag "Function" :value nil)
646 (string :tag "Program" :value ""))
647 (repeat :tag "Properties"
648 (choice
649 (list :tag ":constraintp"
650 :value (:constraintp)
651 (const :format ""
652 :value :constraintp)
653 (function :tag "Function"))
654 (list :tag ":constraint-flag"
655 :value (:constraint-flag)
656 (const :format ""
657 :value :constraint-flag)
658 (symbol :tag "Symbol"))
659 (list :tag ":ignore-on-open-all"
660 :value (:ignore-on-open-all t)
661 (const :format ""
662 :value :ignore-on-open-all)
663 (boolean :tag "Boolean"))
664 (list :tag ":ignore-on-read-text"
665 :value (:ignore-on-read-text t)
666 (const :format ""
667 :value :ignore-on-read-text)
668 (boolean :tag "Boolean"))
669 (list :tag ":args"
670 :value (:args)
671 (const :format ""
672 :value :args)
673 (repeat :tag "List"
674 (choice :tag "Arguments"
675 (string :tag "String"
676 :value "")
677 (symbol :tag "Symbol"
678 :value nil)
679 (function :tag "Function"
680 :value nil))))
681 (list :tag ":open-hook"
682 :value (:open-hook)
683 (const :format ""
684 :value :open-hook)
685 (hook :tag "Hook"))
686 ; (list :tag ":close-hook"
687 ; :value (:close-hook)
688 ; (const :format ""
689 ; :value :close-hook)
690 ; (hook :tag "Hook"))
691 (list :tag ":capture-output"
692 :value (:capture-output t)
693 (const :format ""
694 :value :capture-output)
695 (boolean :tag "Boolean"))))))
696 :group 'filesets)
697
698
699 (defcustom filesets-ingroup-patterns
700 '(("^.+\\.tex$" t
701 (((:name "Package")
702 (:pattern "\\\\usepackage\\W*\\(\\[[^\]]*\\]\\W*\\)?{\\W*\\(.+\\)\\W*}")
703 (:match-number 2)
704 (:stub-flag t)
705 (:get-file-name (lambda (master file)
706 (filesets-which-file master
707 (concat file ".sty")
708 (filesets-convert-path-list
709 (or (getenv "MY_TEXINPUTS")
710 (getenv "TEXINPUTS")))))))
711 ((:name "Include")
712 (:pattern "\\\\include\\W*{\\W*\\(.+\\)\\W*}")
713 (:get-file-name (lambda (master file)
714 (filesets-which-file master
715 (concat file ".tex")
716 (filesets-convert-path-list
717 (or (getenv "MY_TEXINPUTS")
718 (getenv "TEXINPUTS"))))))
719 (:scan-depth 5))
720 ((:name "Input")
721 (:pattern "\\\\input\\W*{\\W*\\(.+\\)\\W*}")
722 (:stubp (lambda (a b) (not (filesets-files-in-same-directory-p a b))))
723 (:get-file-name (lambda (master file)
724 (filesets-which-file master
725 (concat file ".tex")
726 (filesets-convert-path-list
727 (or (getenv "MY_TEXINPUTS")
728 (getenv "TEXINPUTS"))))))
729 (:scan-depth 5))
730 ((:name "Bibliography")
731 (:pattern "\\\\bibliography\\W*{\\W*\\(.+\\)\\W*}")
732 (:get-file-name (lambda (master file)
733 (filesets-which-file master
734 (concat file ".bib")
735 (filesets-convert-path-list
736 (or (getenv "MY_BIBINPUTS")
737 (getenv "BIBINPUTS")))))))))
738 ("^.+\\.el$" t
739 (((:name "Require")
740 (:pattern "(require\\W+'\\(.+\\))")
741 (:stubp (lambda (a b) (not (filesets-files-in-same-directory-p a b))))
742 (:get-file-name (lambda (master file)
743 (filesets-which-file master
744 (concat file ".el")
745 load-path))))
746 ((:name "Load")
747 (:pattern "(load\\(-library\\)?\\W+\"\\(.+\\)\")")
748 (:match-number 2)
749 (:get-file-name (lambda (master file)
750 (filesets-which-file master file load-path))))))
751 ("^\\([A-ZÄÖÜ][a-zäöüß]+\\([A-ZÄÖÜ][a-zäöüß]+\\)+\\)$" t
752 (((:pattern "\\<\\([A-ZÄÖÜ][a-zäöüß]+\\([A-ZÄÖÜ][a-zäöüß]+\\)+\\)\\>")
753 (:scan-depth 5)
754 (:stubp (lambda (a b) (not (filesets-files-in-same-directory-p a b))))
755 (:case-sensitive t)
756 (:get-file-name (lambda (master file)
757 (filesets-which-file
758 master
759 file
760 (if (boundp 'emacs-wiki-directories)
761 emacs-wiki-directories
762 nil))))))))
763
764 "*Inclusion group definitions.
765
766 Define how to find included file according to a file's mode (being
767 defined by a file pattern).
768
769 A valid entry has the form (FILE-PATTERN REMOVE-DUPLICATES-FLAG
770 CMD-DEF1 ...), CMD-DEF1 being a plist containing the fields :pattern
771 \(mandatory), :name, :get-file-name, :match-number, :scan-depth,
772 :preprocess, :case-sensitive.
773
774 File Pattern ... A regexp matching the file's name for which the
775 following rules should be applied.
776
777 Remove Duplicates ... If t, only the first occurrence of an included
778 file is retained. (See below for a full explanation.)
779
780 :name STRING ... This pattern's name.
781
782 :pattern REGEXP ... A regexp matching the command. This regexp has to
783 include a group that holds the name of the included file.
784
785 :get-file-name FUNCTION (default: `filesets-which-file') ... A function
786 that takes two arguments (the path of the master file and the name
787 of the included file) and returns a valid path or nil -- if the
788 subfile can't be found.
789
790 :match-number INTEGER (default: 1) ... The number of the match/group
791 in the pattern holding the subfile's name. 0 refers the whole
792 match, 1 to the first group.
793
794 :stubp FUNCTION ... if (FUNCTION MASTER INCLUDED-FILE) returns non-nil,
795 INCLUDED-FILE is a stub -- see below.
796
797 :stub-flag ... files of this type are stubs -- see below.
798
799 :scan-depth INTEGER (default: 0) ... Whether included files should be
800 rescanned. Set this to 0 to disable re-scanning of included file.
801
802 :preprocess FUNCTION ... A function modifying a buffer holding the
803 master file so that pattern matching becomes easier. This is usually
804 used to narrow a buffer to the relevant region. This function could also
805 be destructive and simply delete non-relevant text.
806
807 :case-sensitive BOOLEAN (default: nil) ... Whether a pattern is
808 case-sensitive or not.
809
810
811 Stubs:
812
813 First, a stub is a file that shows up in the menu but will not be
814 included in an ingroup's file listing -- i.e. filesets will never
815 operate on this file automatically. Secondly, in opposition to normal
816 files stubs are not scanned for new inclusion groups. This is useful if
817 you want to have quick access to library headers.
818
819 In the menu, an asterisk is appended to the stub's name.
820
821
822 Remove Duplicates:
823
824 E.g. File A and file B refer to file X; X refers to A. If
825 you choose not to remove duplicates the tree would look like:
826
827 M + A - X - A ...
828 B - X - A ...
829
830 As you can see, there is some chance that you run in circles.
831 Nevertheless, up to some degree this could still be what you want.
832
833 With duplicates removed, it would be:
834
835 M + A - X
836 B"
837 :set (function filesets-set-default)
838 :type '(repeat
839 :tag "Include"
840 (list
841 :tag "Definition" :value ("^.+\\.suffix$" t)
842 (regexp :tag "File Pattern" :value "^.+\\.suffix$")
843 (boolean :tag "Remove Duplicates" :value t)
844 (repeat :tag "Commands"
845 (repeat :tag "Command"
846 (choice
847 :tag "Definition"
848 (list :tag ":name"
849 :value (:name "")
850 (const :format "" :value :name)
851 (string :tag "String"))
852 (list :tag ":pattern"
853 :value (:pattern "\\<CMD\\W*\\(.+\\)\\>")
854 (const :format "" :value :pattern)
855 (regexp :tag "RegExp"))
856 (list :tag ":get-file-name"
857 :value (:get-file-name)
858 (const :format "" :value :get-file-name)
859 (function :tag "Function"))
860 (list :tag ":match-number"
861 :value (:match-number 1)
862 (const :format "" :value :match-number)
863 (integer :tag "Integer"))
864 (list :tag ":stub-flag"
865 :value (:stub-flag t)
866 (const :format "" :value :stub-flag)
867 (boolean :tag "Boolean"))
868 (list :tag ":stubp"
869 :value (:stubp)
870 (const :format "" :value :stubp)
871 (function :tag "Function"))
872 (list :tag ":scan-depth"
873 :value (:scan-depth 0)
874 (const :format "" :value :scan-depth)
875 (integer :tag "Integer"))
876 (list :tag ":case-sensitive"
877 :value (:case-sensitive)
878 (const :format "" :value :case-sensitive)
879 (boolean :tag "Boolean"))
880 (list :tag ":preprocess"
881 :value (:preprocess)
882 (const :format "" :value :preprocess)
883 (function :tag "Function")))))))
884 :group 'filesets)
885
886 (defcustom filesets-data
887 nil
888 "*Fileset definitions.
889
890 A fileset is either a list of files, a file pattern, a base directory
891 and a search pattern (for files), or a base file. Changes to this
892 variable will take effect after rebuilding the menu.
893
894 Caveat: Fileset names have to be unique.
895
896 Example definition:
897 '\(\(\"My Wiki\"
898 \(:ingroup \"~/Etc/My-Wiki/WikiContents\"))
899 \(\"My Homepage\"
900 \(:pattern \"~/public_html/\" \"^.+\\\\.html$\")
901 \(:open filesets-find-file))
902 \(\"User Configuration\"
903 \(:files \"~/.xinitrc\"
904 \"~/.bashrc\"
905 \"~/.bash_profile\"))
906 \(\"HOME\"
907 \(:tree \"~\" \"^[^.].*[^~]$\")
908 \(:filter-dirs-flag t)))
909
910 `filesets-data' is a list of (NAME-AS-STRING . DEFINITION), DEFINITION
911 being an association list with the fields:
912
913 :files FILE-1 .. FILE-N ... a list of files belonging to a fileset
914
915 :ingroup FILE-NAME ... an inclusion group's base file.
916
917 :tree ROOT-DIR PATTERN ... a base directory and a file pattern
918
919 :pattern DIR PATTERN ... PATTERN is a regular expression comprising path
920 and file pattern -- e.g. 'PATH/^REGEXP$'. Note the `^' at the beginning
921 of the file name pattern.
922
923 :filter-dirs-flag BOOLEAN ... is only used in conjunction with :tree.
924
925 :tree-max-level INTEGER ... recurse into directories this many levels
926 (see `filesets-tree-max-level' for a full explanation)
927
928 :dormant-flag BOOLEAN ... non-nil means don't show this item in the
929 menu; dormant filesets can still be manipulated via commands available
930 from the minibuffer -- e.g. `filesets-open', `filesets-close', or
931 `filesets-run-cmd'
932
933 :dormant-p FUNCTION ... a function returning :dormant-flag
934
935 :open FUNCTION ... the function used to open file belonging to this
936 fileset. The function takes a file name as argument
937
938 :save FUNCTION ... the function used to save file belonging to this
939 fileset; it takes no arguments, but works on the current buffer.
940
941 Either :files, :pattern, :tree, or :ingroup must be supplied. :files
942 overrules :tree, :tree overrules :pattern, :pattern overrules :ingroup,
943 i.e. these tags are mutually exclusive. The fields :open and :save are
944 optional.
945
946 In conjunction with the :tree tag, :save is void. :open refers to the
947 function used for opening files in a directory, not for opening the
948 directory. For browsing directories, `filesets-browse-dir-fn' is used.
949
950 Before using :ingroup, make sure that the file type is already
951 defined in `filesets-ingroup-patterns'."
952 :group 'filesets
953 :set (function filesets-data-set-default)
954 :type '(repeat
955 (cons :tag "Fileset"
956 (string :tag "Name" :value "")
957 (repeat :tag "Data"
958 (choice
959 :tag "Type" :value nil
960 (list :tag "Pattern"
961 :value (:pattern "~/" "^.+\\.suffix$")
962 (const :format "" :value :pattern)
963 (directory :tag "Dir")
964 (regexp :tag "Pattern"))
965 (cons :tag "Files"
966 :value (:files)
967 (const :format "" :value :files)
968 (repeat :tag "Files" file))
969 (list :tag "Single File"
970 :value (:file "~/")
971 (const :format "" :value :file)
972 (file :tag "File"))
973 (list :tag "Inclusion group"
974 :value (:ingroup "~/")
975 (const :format "" :value :ingroup)
976 (file :tag "File" :value "~/"))
977 (list :tag "Directory Tree"
978 :value (:tree "~/" "^.+\\.suffix$")
979 (const :format "" :value :tree)
980 (directory :tag "Dir")
981 (regexp :tag "Pattern"))
982 (list :tag "Filter directories"
983 :value (:filter-dirs-flag)
984 (const :format "" :value :filter-dirs-flag)
985 (boolean :tag "Boolean" :value nil))
986 (list :tag "Scanning depth"
987 :value (:tree-max-level 3)
988 (const :format "" :value :tree-max-level)
989 (integer :tag "Integer"))
990 (list :tag "Verbosity"
991 :value (:verbosity 1)
992 (const :format "" :value :verbosity)
993 (integer :tag "Integer"))
994 (list :tag "Conceal fileset (Flag)"
995 :value (:dormant-flag)
996 (const :format "" :value :dormant-flag)
997 (boolean :tag "Boolean"))
998 (list :tag "Conceal fileset (Function)"
999 :value (:dormant-p)
1000 (const :format "" :value :dormant-p)
1001 (function :tag "Function"))
1002 (list :tag "Save function"
1003 :value (:save)
1004 (const :format "" :value :save)
1005 (function :tag "Function"))
1006 (list :tag "Open function"
1007 :value (:open)
1008 (const :format "" :value :open)
1009 (function :tag "Function")))))))
1010
1011
1012 (defcustom filesets-query-user-limit 15
1013 "*Query the user before opening a fileset with that many files."
1014 :set (function filesets-set-default)
1015 :type 'integer
1016 :group 'filesets)
1017
1018
1019 (defun filesets-error (class &rest args)
1020 "`error' wrapper."
1021 (error (apply 'concat
1022 (mapcar (lambda (x) (format "%s " x))
1023 args))))
1024
1025 ;;; Emacs compatibility
1026 (eval-and-compile
1027 (if filesets-running-xemacs
1028 (progn
1029 (fset 'filesets-add-submenu 'add-submenu))
1030
1031 (progn
1032
1033 (require 'easymenu)
1034
1035 ;; This should work for 21.1 Emacs
1036 (defun filesets-add-submenu (menu-path submenu &optional
1037 before in-menu)
1038 "`easy-menu-define' wrapper."
1039 (easy-menu-define
1040 filesets-submenu global-map "Filesets menu" submenu))
1041 )))
1042
1043 ;;; helper
1044 ;(defmacro filesets-testing (feature messagep &rest body)
1045 ; (cond
1046 ; ((equal filesets-version "testing")
1047 ; `(progn ,@body))
1048 ; (messagep
1049 ; (message "Filestats: feature `%s' is disabled." feature)
1050 ; nil)
1051 ; (t
1052 ; nil)))
1053
1054 ;(defun filesets-not-yet-implemented (feature)
1055 ; (message "Filestats: `%s' is not yet implemented." feature))
1056
1057 (defun filesets-filter-dir-names (lst &optional negative)
1058 "Remove non-directory names from a list of strings. If NEGATIVE is
1059 non-nil, remove all directory names."
1060 (filesets-filter-list lst
1061 (lambda (x)
1062 (and (not (string-match "^\\.+/$" x))
1063 (if negative
1064 (not (string-match "[:/\\]$" x))
1065 (string-match "[:/\\]$" x))))))
1066
1067 (defun filesets-conditional-sort (lst &optional access-fn simply-do-it)
1068 "Return a sorted copy of LST, LST being a list of strings.
1069 If `filesets-sort-menu-flag' is nil, return LST itself.
1070
1071 ACCESS-FN ... function to get the string value of LST's elements.
1072
1073 If SIMPLY-DO-IT is non-nil, the list is sorted regardless of
1074 `filesets-sort-menu-flag'."
1075 (if filesets-sort-menu-flag
1076 (let* ((fni (or access-fn
1077 (function identity)))
1078 (fn (if filesets-sort-case-sensitive-flag
1079 (lambda (a b)
1080 (string< (funcall fni a)
1081 (funcall fni b)))
1082 (lambda (a b)
1083 (string< (upcase (funcall fni a))
1084 (upcase (funcall fni b)))))))
1085 (sort (copy-list lst) fn))
1086 lst))
1087
1088 (defun filesets-directory-files (dir &optional
1089 pattern what full-flag match-dirs-flag)
1090 "Get WHAT (:files or :dirs) in DIR. If PATTERN is provided return only
1091 those entries matching this regular expression. If MATCH-DIRS-FLAG is
1092 non-nil, also match directory entries. Return full path if FULL-FLAG is
1093 non-nil."
1094 (filesets-message 2 "Filesets: scanning %S" dir)
1095 (cond
1096 ((file-exists-p dir)
1097 (let ((files nil)
1098 (dirs nil))
1099 (dolist (this (file-name-all-completions "" dir))
1100 (cond
1101 ((string-match "^\\.+/$" this)
1102 nil)
1103 ((string-match "[:/\\]$" this)
1104 (when (or (not match-dirs-flag)
1105 (not pattern)
1106 (string-match pattern this))
1107 (filesets-message 5 "Filesets: matched dir %S with pattern %S"
1108 this pattern)
1109 (setq dirs (cons this dirs))))
1110 (t
1111 (when (or (not pattern)
1112 (string-match pattern this))
1113 (filesets-message 5 "Filesets: matched file %S with pattern %S"
1114 this pattern)
1115 (setq files (cons (if full-flag
1116 (concat (file-name-as-directory dir) this)
1117 this)
1118 files))))))
1119 (cond
1120 ((equal what ':dirs)
1121 (filesets-conditional-sort dirs))
1122 ((equal what ':files)
1123 (filesets-conditional-sort files))
1124 (t
1125 (append (filesets-conditional-sort files)
1126 (filesets-conditional-sort dirs))))))
1127 (filesets-be-docile-flag
1128 (filesets-message 1 "Filesets: %S doesn't exist" dir)
1129 nil)
1130 (t
1131 (filesets-error 'error "Filesets: " dir " does not exist"))))
1132
1133 (defun filesets-quote (txt)
1134 "Return TXT in quotes."
1135 (concat "\"" txt "\""))
1136
1137 (defun filesets-get-selection ()
1138 "Get the text between mark and point -- i.e. the selection or region."
1139 (let ((m (mark))
1140 (p (point)))
1141 (if m
1142 (buffer-substring (min m p) (max m p))
1143 (filesets-error 'error "No selection."))))
1144
1145 (defun filesets-get-quoted-selection ()
1146 "Return the currently selected text in quotes."
1147 (filesets-quote (filesets-get-selection)))
1148
1149 (defun filesets-get-shortcut (n)
1150 "Create menu shortcuts based on number N."
1151 (let ((n (mod (- n 1) 51)))
1152 (cond
1153 ((not filesets-menu-shortcuts-flag)
1154 "")
1155 ((<= n 9)
1156 (concat (number-to-string n) " "))
1157 ((<= n 35)
1158 (format "%c " (+ 87 n)))
1159 ((<= n 51)
1160 (format "%c " (+ -3 n))))))
1161
1162 (defun filesets-files-equalp (a b)
1163 "Compare two filenames A and B after expansion."
1164 (equal (expand-file-name a) (expand-file-name b)))
1165
1166 (defun filesets-files-in-same-directory-p (a b)
1167 "Compare two filenames A and B after expansion."
1168 (let ((ad (file-name-directory (expand-file-name a)))
1169 (bd (file-name-directory (expand-file-name b))))
1170 (equal ad bd)))
1171
1172 (defun filesets-convert-path-list (string)
1173 "Return a path-list given as STRING as list."
1174 (if string
1175 (mapcar (lambda (x) (file-name-as-directory x))
1176 (split-string string path-separator))
1177 nil))
1178
1179 (defun filesets-which-file (master filename &optional path-list)
1180 "Search for a FILENAME relative to a MASTER file in PATH-LIST."
1181 (let ((f (concat (file-name-directory master)
1182 filename)))
1183 (if (file-exists-p f)
1184 f
1185 (some (lambda (dir)
1186 (let ((dir (file-name-as-directory dir))
1187 (files (if (file-exists-p dir)
1188 (filesets-directory-files dir nil ':files)
1189 nil)))
1190 (some (lambda (file)
1191 (if (equal filename (file-name-nondirectory file))
1192 (concat dir file)
1193 nil))
1194 files)))
1195 path-list))))
1196
1197
1198 (defun filesets-eviewer-get-props (entry)
1199 "Get ENTRY's (representing an external viewer) properties."
1200 (nth 2 entry))
1201
1202 (defun filesets-eviewer-constraint-p (entry)
1203 (let* ((props (filesets-eviewer-get-props entry))
1204 (constraint (assoc ':constraintp props))
1205 (constraint-flag (assoc ':constraint-flag props)))
1206 (cond
1207 (constraint
1208 (funcall (cadr constraint)))
1209 (constraint-flag
1210 (eval (cadr constraint-flag)))
1211 (t
1212 t))))
1213
1214 (defun filesets-get-external-viewer (file)
1215 "Find an external viewer for FILE."
1216 (let ((filename (file-name-nondirectory file)))
1217 (some
1218 (lambda (entry)
1219 (when (and (string-match (nth 0 entry) filename)
1220 (filesets-eviewer-constraint-p entry))
1221 entry))
1222 filesets-external-viewers)))
1223
1224 (defun filesets-get-external-viewer-by-name (name)
1225 "Get the external viewer definition called NAME."
1226 (when name
1227 (some
1228 (lambda (entry)
1229 (when (and (string-equal (nth 1 entry) name)
1230 (filesets-eviewer-constraint-p entry))
1231 entry))
1232 filesets-external-viewers)))
1233
1234 (defun filesets-filetype-property (filename event &optional entry)
1235 "Returns non-nil if a file of a specific type has special flags/tags.
1236
1237 Events (corresponding tag):
1238
1239 on-open-all (:ignore-on-open-all) ... Exclude files of this when opening
1240 a fileset
1241
1242 on-grep (:ignore-on-read-text) ... Exclude files of this when running
1243 the \"Grep <<selection>>\" command
1244
1245 on-capture-output (:capture-output) ... Capture output of an external viewer
1246
1247 on-ls ... not used
1248
1249 on-cmd ... not used
1250
1251 on-close-all ... not used"
1252 (let ((def (filesets-eviewer-get-props
1253 (or entry
1254 (filesets-get-external-viewer filename)))))
1255 (filesets-alist-get def
1256 (case event
1257 ((on-open-all) ':ignore-on-open-all)
1258 ((on-grep) ':ignore-on-read-text)
1259 ((on-cmd) nil)
1260 ((on-close-all) nil))
1261 nil t)))
1262
1263 (defun filesets-filetype-get-prop (property filename &optional entry)
1264 "Returns PROPERTY for filename -- use ENTRY if provided."
1265 (let ((def (filesets-eviewer-get-props
1266 (or entry
1267 (filesets-get-external-viewer filename)))))
1268 (when def
1269 (filesets-alist-get def property nil t))))
1270
1271 (defun filesets-reset-filename-on-change ()
1272 "Reset a buffer's filename if the buffer is being modified."
1273 (when filesets-output-buffer-flag
1274 (set-visited-file-name nil t)))
1275
1276 (defun filesets-spawn-external-viewer (file &optional ev-entry)
1277 "Start an external viewer for FILE.
1278 Use the viewer defined in EV-ENTRY (a valid element of
1279 `filesets-external-viewers') if provided."
1280 (let* ((file (expand-file-name file))
1281 (entry (or ev-entry
1282 (filesets-get-external-viewer file))))
1283 (if entry
1284 (let* ((vwr (cadr entry))
1285 (co-flag (filesets-filetype-get-prop ':capture-output file entry))
1286 (oh (filesets-filetype-get-prop ':open-hook file entry))
1287 (args (let ((fmt (filesets-filetype-get-prop ':args file entry)))
1288 (if fmt
1289 (let ((rv ""))
1290 (dolist (this fmt rv)
1291 (setq rv (concat rv
1292 (cond
1293 ((stringp this)
1294 (format this file))
1295 ((and (symbolp this)
1296 (fboundp this))
1297 (format "%S" (funcall this)))
1298 (t
1299 (format "%S" this)))))))
1300 (format "%S" file))))
1301 (output
1302 (cond
1303 ((and (functionp vwr) co-flag)
1304 (funcall vwr file))
1305 ((functionp vwr)
1306 (funcall vwr file)
1307 nil)
1308 (co-flag
1309 (shell-command-to-string (format "%s %s" vwr args)))
1310 (t
1311 (shell-command (format "%s %s&" vwr args))
1312 nil))))
1313 (if co-flag
1314 (progn
1315 (switch-to-buffer (format "Filesets: %s %s" vwr file))
1316 (insert output)
1317 (make-local-variable 'filesets-output-buffer-flag)
1318 (setq filesets-output-buffer-flag t)
1319 (set-visited-file-name file t)
1320 (when oh
1321 (run-hooks 'oh))
1322 (set-buffer-modified-p nil)
1323 (setq buffer-read-only t)
1324 (beginning-of-buffer))
1325 (when oh
1326 (run-hooks 'oh))))
1327 (filesets-error 'error
1328 "Filesets: general error when spawning external viewer"))))
1329
1330 (defun filesets-find-file (file)
1331 "Call `find-file' after a possible delay (see `filesets-find-file-delay').
1332 If `filesets-be-docile-flag' is true, a file, which isn't readable, will
1333 not be opened."
1334 ; (sleep-for filesets-find-file-delay)
1335 (when (or (file-readable-p file)
1336 (not filesets-be-docile-flag))
1337 (sit-for filesets-find-file-delay)
1338 (find-file file)))
1339
1340 (defun filesets-find-or-display-file (&optional file viewer)
1341 "Visit FILE using an external viewer or open it in an Emacs buffer."
1342 (interactive)
1343 (let* ((file (or file
1344 (read-file-name "Find file: " nil nil viewer)))
1345 (external-viewer-def (or
1346 (filesets-get-external-viewer-by-name viewer)
1347 (filesets-get-external-viewer file))))
1348 (filesets-message 3 "Filesets: view %S using %s" file external-viewer-def)
1349 (if external-viewer-def
1350 (filesets-spawn-external-viewer file external-viewer-def)
1351 (filesets-find-file file))))
1352
1353 (defun fsfind-file-using ()
1354 "Select a viewer and call `filesets-find-or-display-file'."
1355 (interactive)
1356 (let* ((lst (mapcar (lambda (this)
1357 (let ((a (cadr this)))
1358 (list (format "%s" a) a)))
1359 filesets-external-viewers))
1360 (viewer (completing-read "Using viewer: " lst nil t)))
1361 (when viewer
1362 (filesets-find-or-display-file nil (cadr (assoc viewer lst))))))
1363
1364 (defun filesets-browser-name ()
1365 "Get the directory browser's name as defined in `filesets-browse-dir-fn'."
1366 (cond
1367 ((listp filesets-browse-dir-fn)
1368 (car filesets-browse-dir-fn))
1369 (t
1370 filesets-browse-dir-fn)))
1371
1372 (defun filesets-browse-dir (dir)
1373 "Browse DIR using `filesets-browse-dir-fn'."
1374 (if (functionp filesets-browse-dir-fn)
1375 (funcall filesets-browse-dir-fn dir)
1376 (let ((name (car filesets-browse-dir-fn))
1377 (args (format (cadr filesets-browse-dir-fn) (expand-file-name dir))))
1378 (with-temp-buffer
1379 (start-process (concat "Filesets:" name)
1380 "*Filesets external directory browser*"
1381 name args)))))
1382
1383 (defun filesets-get-fileset-name (something)
1384 "Get SOMETHING's name. (Don't ask.)"
1385 (cond
1386 ((listp something)
1387 (car something))
1388 (t
1389 something)))
1390
1391 (defun filesets-data-get-name (entry)
1392 "Access to `filesets-data'. Get the entry's name"
1393 (car entry))
1394
1395 (defun filesets-data-get-data (entry)
1396 "Access to `filesets-data'. Get the entry's data section"
1397 (cdr entry))
1398
1399 (defun filesets-alist-get (alist key &optional default carp)
1400 "Get KEY's value in the association list ALIST.
1401 Return DEFAULT if not found. Return (car VALUE) if CARP is non-nil."
1402 (let* ((elt (assoc key alist)))
1403 (cond
1404 (elt
1405 (if carp
1406 (cadr elt)
1407 (cdr elt)))
1408 (default default)
1409 (t nil))))
1410
1411 (defun filesets-data-get (entry key &optional default carp)
1412 "Extract the value for KEY in the data part of fileset ENTRY.
1413 Return DEFAULT if not found. Return (car VALUE) if CARP is non-nil."
1414 (filesets-alist-get (filesets-data-get-data entry) key default carp))
1415
1416 (defun filesets-data-set (entry key value)
1417 "Set the value for KEY in the data part of fileset ENTRY."
1418 (let* ((alist (filesets-data-get-data entry))
1419 (elt (assoc key alist)))
1420 (if elt
1421 (setcdr elt value)
1422 (setcdr entry (cons (cons key value) alist)))))
1423
1424 (defun filesets-entry-mode (entry)
1425 "Return fileset ENTRY's mode: :files, :file, :tree, :pattern, or :ingroup.
1426 See `filesets-data'."
1427 (let ((data (filesets-data-get-data entry)))
1428 (some (lambda (x)
1429 (if (assoc x data)
1430 x))
1431 '(:files :tree :pattern :ingroup :file))))
1432
1433 (defun filesets-entry-get-open-fn (fileset-name &optional fileset-entry)
1434 "Get the open-function for FILESET-NAME.
1435 Use FILESET-ENTRY for finding the open function, if provided."
1436 (filesets-data-get (or fileset-entry
1437 (filesets-get-fileset-from-name fileset-name))
1438 ':open filesets-open-file-fn t))
1439
1440 (defun filesets-entry-get-save-fn (fileset-name &optional fileset-entry)
1441 "Get the save-function for FILESET-NAME.
1442 Use FILESET-ENTRY for finding the save function, if provided."
1443 (filesets-data-get (or fileset-entry
1444 (filesets-get-fileset-from-name fileset-name))
1445 ':save filesets-save-buffer-fn t))
1446
1447 (defun filesets-entry-get-files (entry)
1448 "Get the file list for fileset ENTRY."
1449 (filesets-data-get entry ':files))
1450
1451 (defun filesets-entry-set-files (entry data &optional anyways)
1452 "Set the file list for fileset ENTRY."
1453 (let ((files (filesets-entry-get-files entry)))
1454 (if (or anyways files)
1455 (filesets-data-set entry ':files data))))
1456
1457 (defun filesets-entry-get-verbosity (entry)
1458 "Get verbosity level for fileset ENTRY."
1459 (filesets-data-get entry ':verbosity 1 t))
1460
1461 (defun filesets-entry-get-file (entry)
1462 "Get the single file for fileset ENTRY."
1463 (filesets-data-get entry ':file nil t))
1464
1465 (defun filesets-entry-get-pattern (entry)
1466 "Get the base directory + file pattern for fileset ENTRY."
1467 ; (filesets-data-get entry ':pattern nil t))
1468 (filesets-data-get entry ':pattern))
1469
1470 (defun filesets-entry-get-pattern--pattern (list)
1471 "Get the file pattern for LIST."
1472 (if (= (length list) 1) ;; for compatibility with filesets < v1.5.5
1473 (file-name-nondirectory (car list))
1474 (cadr list)))
1475
1476 (defun filesets-entry-get-pattern--dir (list)
1477 "Get a file pattern's base directory for LIST."
1478 (if (= (length list) 1) ;; for compatibility with filesets < v1.5.5
1479 (file-name-directory (car list))
1480 (car list)))
1481
1482 (defun filesets-entry-get-tree (entry)
1483 "Get the tree pattern for fileset ENTRY."
1484 (filesets-data-get entry ':tree))
1485
1486 (defun filesets-entry-get-dormant-flag (entry)
1487 "Get dormant flag for fileset ENTRY."
1488 (let ((fn (filesets-data-get entry ':dormant-p nil t)))
1489 (if fn
1490 (funcall fn)
1491 (filesets-data-get entry ':dormant-flag nil t))))
1492
1493 (defun filesets-entry-get-filter-dirs-flag (entry)
1494 "Get filter-dirs-flag for fileset ENTRY."
1495 (filesets-data-get entry ':filter-dirs-flag nil t))
1496
1497 (defun filesets-entry-get-tree-max-level (entry)
1498 "Get maximal tree scanning depth for fileset ENTRY."
1499 (filesets-data-get entry ':tree-max-level nil t))
1500
1501 (defun filesets-entry-get-master (entry)
1502 "Get the base file for fileset ENTRY."
1503 (filesets-data-get entry ':ingroup nil t))
1504
1505 (defun filesets-file-open (open-function file-name &optional fileset-name)
1506 "Open FILE-NAME using OPEN-FUNCTION. If OPEN-FUNCTION is nil, it's
1507 value will be deduced from FILESET-NAME"
1508 (let ((open-function (or open-function
1509 (filesets-entry-get-open-fn fileset-name))))
1510 (if (file-readable-p file-name)
1511 (funcall open-function file-name)
1512 (message "Filesets: Couldn't open `%s'" file-name))))
1513
1514 (defun filesets-file-close (save-function buffer)
1515 "Close BUFFER.
1516 First, save the buffer's contents using SAVE-FUNCTION. Then, kill buffer
1517 if `buffer-modified-p' returns nil.
1518
1519 SAVE-FUNCTION takes no argument, but works on the current buffer."
1520 (save-excursion
1521 (set-buffer buffer)
1522 (if (buffer-modified-p)
1523 (funcall save-function))
1524 (if (not (buffer-modified-p))
1525 (kill-buffer buffer))))
1526
1527 (defun filesets-get-fileset-from-name (name &optional mode)
1528 "Get fileset definition for NAME."
1529 (case mode
1530 ((:ingroup :tree)
1531 name)
1532 (t
1533 (assoc name filesets-data))))
1534
1535
1536 ;;; commands
1537 (defun filesets-cmd-get-def (cmd-name)
1538 "Get `filesets-commands' entry for CMD-NAME."
1539 (assoc cmd-name filesets-commands))
1540
1541 (defun filesets-cmd-get-args (cmd-name)
1542 (let ((args (let ((def (filesets-cmd-get-def cmd-name)))
1543 (nth 2 def)))
1544 (rv nil))
1545 (dolist (this args rv)
1546 (cond
1547 ((and (symbolp this) (fboundp this))
1548 (let ((x (funcall this)))
1549 (setq rv (append rv (if (listp x) x (list x))))))
1550 (t
1551 (setq rv (append rv (list this))))))))
1552
1553 (defun filesets-cmd-get-fn (cmd-name)
1554 (let ((def (filesets-cmd-get-def cmd-name)))
1555 (nth 1 def)))
1556
1557 (defun filesets-cmd-show-result (cmd output)
1558 "Show OUTPUT of CMD (a shell command)."
1559 (pop-to-buffer "*Filesets: Shell Command Output*")
1560 (end-of-buffer)
1561 (insert "*** ")
1562 (insert cmd)
1563 (newline)
1564 (insert output)
1565 (newline))
1566
1567 (defun filesets-run-cmd--repl-fn (arg &optional format-fn)
1568 "Helper function for `filesets-run-cmd'. Apply FORMAT-FN to arg.
1569 Replace <file-name> or <<file-name>> with filename."
1570 (funcall format-fn (cond
1571 ((equal arg "<file-name>")
1572 (buffer-file-name))
1573 ((equal arg "<<file-name>>")
1574 (filesets-quote (buffer-file-name)))
1575 (t
1576 arg))))
1577
1578 (defun filesets-run-cmd (&optional cmd-name fileset mode)
1579 "Run CMD-NAME (see `filesets-commands') on FILESET."
1580 (interactive)
1581 (let* ((cmd-name (or cmd-name
1582 (completing-read "Select command: " filesets-commands
1583 nil t)))
1584 (name (or fileset
1585 (completing-read "Select fileset: " filesets-data nil t))))
1586 (when (and cmd-name name)
1587 (let* ((event (if (equal cmd-name "Grep <<selection>>")
1588 'on-grep
1589 'on-cmd))
1590 (files (if (and fileset
1591 (or (equal mode ':ingroup)
1592 (equal mode ':tree)))
1593 (filesets-get-filelist fileset mode event)
1594 (filesets-get-filelist
1595 (filesets-get-fileset-from-name name)
1596 mode event))))
1597 (when files
1598 (let ((fn (filesets-cmd-get-fn cmd-name))
1599 (args (filesets-cmd-get-args cmd-name)))
1600 (dolist (this files nil)
1601 (save-excursion
1602 (save-restriction
1603 (let ((buffer (filesets-find-file this)))
1604 (when buffer
1605 (beginning-of-buffer)
1606 (let ()
1607 (cond
1608 ((stringp fn)
1609 (let* ((args
1610 (let ((txt ""))
1611 (dolist (this args txt)
1612 (setq txt
1613 (concat txt
1614 (filesets-run-cmd--repl-fn
1615 this
1616 (lambda (this)
1617 (if (equal txt "") "" " ")
1618 (format "%s" this))))))))
1619 (cmd (concat fn " " args)))
1620 (filesets-cmd-show-result
1621 cmd (shell-command-to-string cmd))))
1622 ((symbolp fn)
1623 (let ((args
1624 (let ((argl nil))
1625 (dolist (this args argl)
1626 (setq argl
1627 (append argl
1628 (filesets-run-cmd--repl-fn
1629 this
1630 'list)))))))
1631 (apply fn args))))))))))))))))
1632
1633 (defun filesets-get-cmd-menu ()
1634 "Create filesets command menu."
1635 `("+ Commands"
1636 . ,(mapcar (lambda (this)
1637 (let ((name (car this)))
1638 `[,name (filesets-run-cmd ,name)]))
1639 filesets-commands)))
1640
1641
1642 ;;; sampe commands
1643 (defun filesets-cmd-query-replace-getargs ()
1644 "Get arguments for `filesets-cmd-query-replace'."
1645 (let* ((from-string (read-string "Filesets query replace: "
1646 ""
1647 'query-replace-history))
1648 (to-string (read-string
1649 (format "Filesets query replace %s with: " from-string)
1650 ""
1651 'query-replace-history))
1652 (delimited (y-or-n-p
1653 "Filesets query replace: respect word boundaries? ")))
1654 (list from-string to-string delimited)))
1655
1656 (defun filesets-cmd-shell-command-getargs ()
1657 "Get arguments for `filesets-cmd-shell-command'."
1658 (let* ((arg (read-string "Shell command (%s = file): "
1659 "%s"
1660 'shell-command-history)))
1661 arg))
1662
1663 (defun filesets-cmd-shell-command (txt)
1664 "Wrapper function for `shell-command'."
1665 (let ((ok (if (buffer-modified-p)
1666 (let ((ok (y-or-n-p "Save buffer? ")))
1667 (when ok
1668 (save-buffer))
1669 ok)
1670 t)))
1671 (when ok
1672 (let ((cmd (format txt (buffer-file-name))))
1673 (message "Filesets: %s" cmd)
1674 (filesets-cmd-show-result cmd
1675 (shell-command-to-string cmd))))))
1676
1677
1678 ;;; body
1679 (defun filesets-get-filelist (entry &optional mode event)
1680 "Get all files for fileset ENTRY.
1681 Assume MODE (see `filesets-entry-mode'), if provided."
1682 (let* ((mode (or mode
1683 (filesets-entry-mode entry)))
1684 (fl (case mode
1685 ((:files)
1686 (filesets-entry-get-files entry))
1687 ((:file)
1688 (list (filesets-entry-get-file entry)))
1689 ((:ingroup)
1690 (let ((entry (expand-file-name
1691 (if (stringp entry)
1692 entry
1693 (filesets-entry-get-master entry)))))
1694 (cons entry (filesets-ingroup-cache-get entry))))
1695 ((:tree)
1696 (let ((dir (nth 0 entry))
1697 (patt (nth 1 entry)))
1698 (filesets-directory-files dir patt ':files t)))
1699 ((:pattern)
1700 (let ((dirpatt (filesets-entry-get-pattern entry)))
1701 (if dirpatt
1702 (let ((dir (filesets-entry-get-pattern--dir dirpatt))
1703 (patt (filesets-entry-get-pattern--pattern dirpatt)))
1704 ;;(filesets-message 3 "Filesets: scanning %s" dirpatt)
1705 (filesets-directory-files dir patt ':files t))
1706 ;; (message "Filesets: malformed entry: %s" entry)))))))
1707 (filesets-error 'error "Filesets: malformed entry: "
1708 entry)))))))
1709 (filesets-filter-list fl
1710 (lambda (file)
1711 (not (filesets-filetype-property file event))))))
1712
1713 (defun filesets-open (&optional mode name lookup-name)
1714 "Open the fileset called NAME.
1715 Use LOOKUP-NAME for searching additional data if provided."
1716 (interactive)
1717 (let* ((name (or name
1718 (completing-read "Open fileset: " filesets-data nil t)))
1719 (fileset (filesets-get-fileset-from-name name mode))
1720 (lookup-fs (if lookup-name
1721 (filesets-get-fileset-from-name lookup-name)
1722 fileset))
1723 (mode (or mode (filesets-entry-mode lookup-fs))))
1724 (if fileset
1725 (let* ((files (filesets-get-filelist fileset mode 'on-open-all))
1726 (n (length files))
1727 (open-function (filesets-entry-get-open-fn nil lookup-fs)))
1728 (if (or (<= n filesets-query-user-limit)
1729 (y-or-n-p (format "Filesets: Open all %d files in %s? "
1730 n name)))
1731 (dolist (this files nil)
1732 (filesets-file-open open-function this))
1733 (message "Filesets: cancelled")))
1734 (filesets-error 'error "Filesets: Unknown fileset: " name))))
1735
1736 (defun filesets-close (&optional mode name lookup-name)
1737 "Close all buffers belonging to the fileset called NAME.
1738 Use LOOKUP-NAME for deducing the save-function, if provided."
1739 (interactive)
1740 (let* ((name (or name
1741 (completing-read "Close fileset: " filesets-data nil t)))
1742 (fileset (filesets-get-fileset-from-name name mode))
1743 (lookup-fs (if lookup-name
1744 (filesets-get-fileset-from-name lookup-name)
1745 fileset))
1746 (mode (or mode (filesets-entry-mode lookup-fs))))
1747 (if fileset
1748 (let ((files (filesets-get-filelist fileset mode 'on-close-all))
1749 (save-function (filesets-entry-get-save-fn nil lookup-fs)))
1750 (dolist (file-name files nil)
1751 (let* ((buffer (get-file-buffer file-name)))
1752 (if buffer
1753 (filesets-file-close save-function buffer)))))
1754 ; (message "Filesets: Unknown fileset: `%s'" name))))
1755 (filesets-error 'error "Filesets: Unknown fileset: " name))))
1756
1757 (defun filesets-add-buffer (&optional name buffer)
1758 "Add BUFFER (or current-buffer) to the fileset called NAME.
1759 User will be queried, if no fileset name is provided."
1760 (interactive)
1761 (let* ((buffer (or buffer
1762 (current-buffer)))
1763 (name (or name
1764 (completing-read
1765 (format "Add '%s' to fileset: " buffer)
1766 filesets-data nil t)))
1767 (entry (assoc name filesets-data)))
1768 (if entry
1769 (let* ((files (filesets-entry-get-files entry))
1770 (this (buffer-file-name buffer))
1771 (inlist (member* this files :test 'filesets-files-equalp)))
1772 (cond
1773 (inlist
1774 (message "Filesets: '%s' is already in '%s'" this name))
1775 ((and (equal (filesets-entry-mode entry) ':files)
1776 this)
1777 (filesets-entry-set-files entry (cons this files) t)
1778 (filesets-set-config name 'filesets-data filesets-data))
1779 (t
1780 (message "Filesets: Can't add '%s' to fileset '%s'" this name)))))))
1781
1782 (defun filesets-remove-buffer (&optional name buffer)
1783 "Remove BUFFER (or current-buffer) to fileset NAME.
1784 User will be queried, if no fileset name is provided."
1785 (interactive)
1786 (let* ((buffer (or buffer
1787 (current-buffer)))
1788 (name (or name
1789 (completing-read
1790 (format "Remove '%s' from fileset: " buffer)
1791 filesets-data nil t)))
1792 (entry (assoc name filesets-data)))
1793 (if entry
1794 (let* ((files (filesets-entry-get-files entry))
1795 (this (buffer-file-name buffer))
1796 (inlist (member* this files :test 'filesets-files-equalp)))
1797 ;;(message "%s %s %s" files this inlist)
1798 (if (and files this inlist)
1799 (let ((new (list (cons ':files (delete (car inlist) files)))))
1800 (setcdr entry new)
1801 (filesets-set-config name 'filesets-data filesets-data))
1802 (message "Filesets: Can't remove '%s' from fileset '%s'"
1803 this
1804 name))))))
1805
1806 (defun filesets-convert-patterns (name)
1807 "Change fileset NAME's mode from :pattern to :files."
1808 (interactive)
1809 (let ((entry (assoc name filesets-data)))
1810 (if entry
1811 (let ((pattern (filesets-entry-get-pattern entry))
1812 (patfiles (filesets-get-filelist entry ':pattern)))
1813 (if pattern
1814 (progn
1815 (filesets-entry-set-files entry patfiles t)
1816 (filesets-set-config name 'filesets-data filesets-data)))))))
1817
1818 (defun filesets-edit ()
1819 "Customize `filesets-data'."
1820 (interactive)
1821 (customize-variable 'filesets-data))
1822
1823 (defun filesets-customize ()
1824 "Customize the filesets group."
1825 (interactive)
1826 (customize-group 'filesets))
1827
1828 (defun filesets-info ()
1829 "Display filesets's version information."
1830 (interactive)
1831 (if (y-or-n-p (format "Filesets v%s: visit homepage? " filesets-version))
1832 (filesets-goto-homepage)))
1833
1834 (defun filesets-goto-homepage ()
1835 "Show filesets's homepage."
1836 (interactive)
1837 (browse-url filesets-homepage))
1838
1839 (defun filesets-remake-shortcut (count submenu)
1840 "Remake a submenus shortcut when wrapping long menus."
1841 (let* ((name (concat (filesets-get-shortcut count)
1842 (substring (elt submenu 0) 2))))
1843 (if (listp submenu)
1844 (cons name (cdr submenu))
1845 (apply 'vector (list name (cdr (append submenu nil)))))))
1846 ; (vconcat `[,name] (subseq submenu 1)))))
1847
1848 (defun filesets-wrap-submenu (submenu-body)
1849 "Split long submenus."
1850 (let ((bl (length submenu-body)))
1851 (if (or (= filesets-max-submenu-length 0)
1852 (<= bl filesets-max-submenu-length))
1853 submenu-body
1854 (let* ((result nil)
1855 (factor (ceiling (/ (float bl)
1856 filesets-max-submenu-length))))
1857 (do ((data submenu-body (cdr data))
1858 (n 1 (+ n 1))
1859 (count 0 (+ count factor)))
1860 ((or (> count bl)
1861 (null data)))
1862 ; (let ((sl (subseq submenu-body count
1863 (let ((sl (filesets-sublist submenu-body count
1864 (let ((x (+ count factor)))
1865 (if (>= bl x)
1866 x
1867 nil)))))
1868 (when sl
1869 (setq result
1870 (append
1871 result
1872 (if (= (length sl) 1)
1873 (if filesets-menu-shortcuts-flag
1874 (list (filesets-remake-shortcut n (car sl)))
1875 sl)
1876 `((,(concat
1877 (filesets-get-shortcut n)
1878 (let ((rv ""))
1879 (do ((x sl (cdr x)))
1880 ((null x))
1881 (let ((y (concat (elt (car x) 0)
1882 (if (null (cdr x))
1883 ""
1884 ", "))))
1885 (setq rv
1886 (concat
1887 rv
1888 (if filesets-menu-shortcuts-flag
1889 (substring y 2)
1890 y)))))
1891 (if (> (length rv)
1892 filesets-max-entry-length)
1893 (concat
1894 (substring rv 0 filesets-max-entry-length)
1895 " ...")
1896 rv)))
1897 ,@sl))))))))
1898 result))))
1899
1900 (defun filesets-get-menu-epilog (something &optional
1901 mode lookup-name rebuild-flag)
1902 "Get submenu epilog for SOMETHING (usually a fileset).
1903 If mode is :tree or :ingroup, SOMETHING is some weird construct and
1904 LOOKUP-NAME is used as lookup name for retrieving fileset specific settings."
1905 (case mode
1906 ((:tree)
1907 `("---"
1908 ["Close all files" (filesets-close ',mode ',something ',lookup-name)]
1909 ["Run Command" (filesets-run-cmd nil ',something ',mode)]
1910 [,(format "Browse with `%s'" (filesets-browser-name))
1911 (filesets-browse-dir ',(car something))]
1912 ,@(when rebuild-flag
1913 `(["Rebuild this submenu"
1914 (filesets-rebuild-this-submenu ',lookup-name)]))))
1915 ((:ingroup)
1916 `("---"
1917 ["Close all files" (filesets-close ',mode ',something ',lookup-name)]
1918 ["Run Command" (filesets-run-cmd nil ',something ',mode)]
1919 ,@(when rebuild-flag
1920 `(["Rebuild this submenu"
1921 (filesets-rebuild-this-submenu ',lookup-name)]))))
1922 ((:pattern)
1923 `("---"
1924 ["Close all files" (filesets-close ',mode ',something)]
1925 ["Run Command" (filesets-run-cmd nil ',something ',mode)]
1926 [,(format "Browse with `%s'" (filesets-browser-name))
1927 ,(list 'filesets-browse-dir
1928 (filesets-entry-get-pattern--dir
1929 (filesets-entry-get-pattern
1930 (filesets-get-fileset-from-name something ':pattern))))]
1931 ; [,(concat (if filesets-menu-shortcuts-flag
1932 ; (concat "Con" filesets-menu-shortcuts-marker "vert")
1933 ; "Convert")
1934 ; " :pattern to :files")
1935 ; ,(list (function filesets-convert-patterns) something)]
1936 ,@(when rebuild-flag
1937 `(["Rebuild this submenu"
1938 (filesets-rebuild-this-submenu ',lookup-name)]))))
1939 ((:files)
1940 `("---"
1941 [,(concat "Close all files") (filesets-close ',mode ',something)]
1942 ["Run Command" (filesets-run-cmd nil ',something ',mode)]
1943 ["Add current buffer"
1944 (filesets-add-buffer ',something (current-buffer))]
1945 ["Remove current buffer"
1946 (filesets-remove-buffer ',something (current-buffer))]
1947 ,@(when rebuild-flag
1948 `(["Rebuild this submenu"
1949 (filesets-rebuild-this-submenu ',lookup-name)]))))
1950 (t
1951 (filesets-error 'error "Filesets: malformed definition of " something))))
1952
1953 (defun filesets-ingroup-get-data (master pos &optional fun)
1954 "Access to `filesets-ingroup-patterns'. Extract data section."
1955 (let ((masterfile (file-name-nondirectory master))
1956 (fn (or fun (lambda (a b)
1957 (and (stringp a)
1958 (stringp b)
1959 (string-match a b))))))
1960 (some (lambda (x)
1961 (if (funcall fn (car x) masterfile)
1962 (nth pos x)
1963 nil))
1964 filesets-ingroup-patterns)))
1965
1966 (defun filesets-ingroup-get-pattern (master)
1967 "Access to `filesets-ingroup-patterns'. Extract patterns."
1968 (filesets-ingroup-get-data master 2))
1969
1970 (defun filesets-ingroup-get-remdupl-p (master)
1971 "Access to `filesets-ingroup-patterns'. Extract remove-duplicates-flag."
1972 (filesets-ingroup-get-data master 1))
1973
1974 (defun filesets-ingroup-collect-finder (patt case-sencitivep)
1975 "Helper function for `filesets-ingroup-collect'. Find pattern PATT."
1976 (let ((cfs case-fold-search)
1977 (rv (progn
1978 (setq case-fold-search (not case-sencitivep))
1979 (re-search-forward patt nil t))))
1980 (setq case-fold-search cfs)
1981 rv))
1982
1983 (defun filesets-ingroup-cache-get (master)
1984 "Access to `filesets-ingroup-cache'."
1985 (lax-plist-get filesets-ingroup-cache master))
1986
1987 (defun filesets-ingroup-cache-put (master file)
1988 "Access to `filesets-ingroup-cache'."
1989 (let* ((emaster (expand-file-name master))
1990 (this (if file
1991 (cons file (filesets-ingroup-cache-get emaster))
1992 nil)))
1993 (setq filesets-ingroup-cache
1994 (lax-plist-put filesets-ingroup-cache emaster this))))
1995
1996 (defun filesets-ingroup-collect-files (fs &optional remdupl-flag master depth)
1997 "Helper function for `filesets-ingroup-collect'. Collect file names."
1998 (let* ((master (or master
1999 (filesets-entry-get-master fs)))
2000 (remdupl-flag (or remdupl-flag
2001 (filesets-ingroup-get-remdupl-p master))))
2002 (filesets-ingroup-cache-put master nil)
2003 (filesets-message 2 "Filesets: parsing %S" master)
2004 (let ((cmdpatts (filesets-ingroup-get-pattern master))
2005 (count 0)
2006 (rv nil))
2007 (if cmdpatts
2008 (dolist (this-def cmdpatts rv)
2009 (let* ((this-patt (filesets-alist-get this-def ':pattern nil t))
2010 (this-name (filesets-alist-get this-def ':name "" t))
2011 (this-pp (filesets-alist-get this-def ':preprocess nil t))
2012 (this-mn (filesets-alist-get this-def ':match-number 1 t))
2013 (this-sd (or depth
2014 (filesets-alist-get this-def ':scan-depth 0 t)))
2015 (this-csp (filesets-alist-get this-def ':case-sensitive nil t))
2016 (this-fn (filesets-alist-get
2017 this-def ':get-file-name 'filesets-which-file t))
2018 (this-stubp (filesets-alist-get this-def ':stubp nil t))
2019 (this-stub-flag (filesets-alist-get this-def ':stub-flag nil t))
2020 (flist nil)
2021 (lst nil))
2022 (cond
2023 ((not this-patt)
2024 (filesets-error 'error "Filesets: malformed :ingroup definition "
2025 this-def))
2026 ((<= this-sd 0)
2027 (setq rv (nconc rv `(((,master ,this-name))))))
2028 (t
2029 (with-temp-buffer
2030 (insert-file-contents master)
2031 (goto-char (point-min))
2032 (when this-pp
2033 (funcall this-pp))
2034 (while (filesets-ingroup-collect-finder this-patt this-csp)
2035 (let* ((txt (match-string this-mn))
2036 (f (funcall this-fn master txt)))
2037 (when (and f
2038 (not (member f flist))
2039 (or (not remdupl-flag)
2040 (not (member*
2041 f filesets-ingroup-paths
2042 :test 'filesets-files-equalp))))
2043 (let ((no-stub-flag
2044 (and (not this-stub-flag)
2045 (if this-stubp
2046 (not (funcall this-stubp master f))
2047 t))))
2048 (setq count (+ count 1))
2049 (setq flist (cons f flist))
2050 (setq filesets-ingroup-paths
2051 (cons f filesets-ingroup-paths))
2052 (when no-stub-flag
2053 (filesets-ingroup-cache-put master f))
2054 (setq lst (append lst (list f))))))))
2055 (when lst
2056 (setq rv
2057 (nconc rv
2058 (mapcar (lambda (this)
2059 `((,this ,this-name)
2060 ,@(filesets-ingroup-collect-files
2061 fs remdupl-flag this
2062 (- this-sd 1))))
2063 lst))))))))
2064 (filesets-message 2 "Filesets: no patterns defined for %S" master)))))
2065
2066 (defun filesets-ingroup-collect-build-menu (fs flist &optional other-count)
2067 "Helper function for `filesets-ingroup-collect'. Build the menu.
2068 FS is a fileset's name. FLIST is a list returned by
2069 `filesets-ingroup-collect-files'."
2070 (if (null flist)
2071 nil
2072 (let ((count 0)
2073 (fsn fs)
2074 (rv nil))
2075 (dolist (this flist rv)
2076 (setq count (+ count 1))
2077 (let* ((def (if (listp this) (car this) (list this "")))
2078 (files (if (listp this) (cdr this) nil))
2079 (master (nth 0 def))
2080 (name (nth 1 def))
2081 (nm (concat (filesets-get-shortcut (if (or (not other-count) files)
2082 count other-count))
2083 (if (or (null name) (equal name ""))
2084 ""
2085 (format "%s: " name))
2086 (file-name-nondirectory master))))
2087 (setq rv
2088 (append rv
2089 (if files
2090 `((,nm
2091 [,(concat "Inclusion Group: "
2092 (file-name-nondirectory master))
2093 (filesets-open ':ingroup ',master ',fsn)]
2094 "---"
2095 [,master (filesets-file-open nil ',master ',fsn)]
2096 "---"
2097 ,@(let ((count 0))
2098 (mapcar
2099 (lambda (this)
2100 (setq count (+ count 1))
2101 (let ((ff (filesets-ingroup-collect-build-menu
2102 fs (list this) count)))
2103 (if (= (length ff) 1)
2104 (car ff)
2105 ff)))
2106 files))
2107 ,@(filesets-get-menu-epilog master ':ingroup fsn)))
2108 `([,nm (filesets-file-open nil ',master ',fsn)])))))))))
2109
2110 (defun filesets-ingroup-collect (fs remdupl-flag master &optional depth)
2111 "Collect names of included files & build submenu."
2112 (filesets-ingroup-cache-put master nil)
2113 (filesets-message 2 "Filesets: parsing %S" master)
2114 (filesets-ingroup-collect-build-menu
2115 fs
2116 (filesets-ingroup-collect-files fs remdupl-flag master)))
2117
2118 (defun filesets-build-ingroup-submenu (lookup-name master)
2119 "Build a :ingroup submenu for file MASTER."
2120 (if (file-readable-p master)
2121 (let ((remdupl-flag (filesets-ingroup-get-remdupl-p master)))
2122 (setq filesets-ingroup-paths (list master))
2123 (filesets-ingroup-collect lookup-name remdupl-flag master))
2124 (if filesets-be-docile-flag
2125 (progn
2126 (message "Filesets: can't parse %s" master)
2127 nil)
2128 (filesets-error 'error "Filesets: can't parse " master))))
2129
2130 (defun filesets-build-dir-submenu-now (level depth entry lookup-name dir patt fd
2131 &optional rebuild-flag)
2132 "Helper function for `filesets-build-dir-submenu'."
2133 ;;(filesets-message 3 "Filesets: scanning %s" dir)
2134 (if (or (= depth 0)
2135 (< level depth))
2136 (let* ((dir (file-name-as-directory dir))
2137 (header `([,(concat "Tree: "
2138 (if (= level 0)
2139 dir
2140 (concat ".../"
2141 (file-name-as-directory
2142 (file-name-nondirectory
2143 (directory-file-name dir))))))
2144 ,(list (function filesets-open)
2145 ':tree
2146 `(quote (,dir ,patt))
2147 lookup-name)]
2148 "---"))
2149 (dirlist (filesets-directory-files dir patt nil nil fd))
2150 (subdirs (filesets-filter-dir-names dirlist))
2151 (count 0)
2152 (dirsmenu (mapcar
2153 (lambda (x)
2154 (setq count (+ count 1))
2155 (let* ((x (file-name-as-directory x))
2156 (xx (concat dir x))
2157 (dd (filesets-build-dir-submenu-now
2158 (+ level 1) depth entry
2159 lookup-name xx patt fd))
2160 (nm (concat (filesets-get-shortcut count)
2161 x)))
2162 (if dd
2163 `(,nm ,@dd)
2164 `[,nm ,(list 'filesets-browse-dir xx)])))
2165 subdirs))
2166 (files (filesets-filter-dir-names dirlist t))
2167 (filesmenu (mapcar (lambda (x)
2168 (setq count (+ count 1))
2169 `[,(concat (filesets-get-shortcut count)
2170 x)
2171 (filesets-file-open nil
2172 (quote ,(concat dir x))
2173 (quote ,lookup-name))])
2174 files)))
2175 (append header
2176 (filesets-wrap-submenu
2177 (append
2178 dirsmenu
2179 filesmenu))
2180 (filesets-get-menu-epilog `(,dir ,patt) ':tree
2181 lookup-name rebuild-flag)))
2182 nil))
2183
2184 (defun filesets-build-dir-submenu (entry lookup-name dir patt)
2185 "Build a :tree submenu named LOOKUP-NAME with base directory DIR including
2186 all files matching PATT for filesets ENTRY."
2187 (let ((fd (filesets-entry-get-filter-dirs-flag entry))
2188 (depth (or (filesets-entry-get-tree-max-level entry)
2189 filesets-tree-max-level)))
2190 (filesets-build-dir-submenu-now 0 depth entry lookup-name dir patt fd t)))
2191
2192 (defun filesets-build-submenu (count lookup-name entry)
2193 "Build submenu for the fileset ENTRY named LOOKUP-NAME.
2194 Construct a shortcut from COUNT."
2195 (let ((lookup-name (or lookup-name
2196 (filesets-data-get-name entry))))
2197 (message "Filesets: %s" lookup-name)
2198 (let ((mode (filesets-entry-mode entry))
2199 (filesets-verbosity (filesets-entry-get-verbosity entry))
2200 (this-lookup-name (concat (filesets-get-shortcut count)
2201 lookup-name)))
2202 (case mode
2203 ((:file)
2204 (let* ((file (filesets-entry-get-file entry)))
2205 `[,this-lookup-name
2206 (filesets-file-open nil ',file ',lookup-name)]))
2207 (t
2208 `(,this-lookup-name
2209 ,@(case mode
2210 ((:pattern)
2211 (let* ((files (filesets-get-filelist entry mode 'on-ls))
2212 (dirpatt (filesets-entry-get-pattern entry))
2213 (pattname (apply 'concat (cons "Pattern: " dirpatt)))
2214 (count 0))
2215 ;;(filesets-message 3 "Filesets: scanning %S" pattname)
2216 `([,pattname
2217 ,(list (function filesets-open) mode lookup-name)]
2218 "---"
2219 ,@(filesets-wrap-submenu
2220 (mapcar
2221 (lambda (x)
2222 (setq count (+ count 1))
2223 `[,(concat (filesets-get-shortcut count)
2224 (file-name-nondirectory x))
2225 (filesets-file-open nil ',x ',lookup-name)])
2226 files))
2227 ,@(filesets-get-menu-epilog lookup-name mode
2228 lookup-name t))))
2229 ((:ingroup)
2230 (let* ((master (filesets-entry-get-master entry)))
2231 ;;(filesets-message 3 "Filesets: parsing %S" master)
2232 `([,(concat "Inclusion Group: "
2233 (file-name-nondirectory master))
2234 (filesets-open ',mode ',master ',lookup-name)]
2235 "---"
2236 [,master (filesets-file-open nil ',master ',lookup-name)]
2237 "---"
2238 ,@(filesets-wrap-submenu
2239 (filesets-build-ingroup-submenu lookup-name master))
2240 ,@(filesets-get-menu-epilog master mode lookup-name t))))
2241 ((:tree)
2242 (let* ((dirpatt (filesets-entry-get-tree entry))
2243 (dir (car dirpatt))
2244 (patt (cadr dirpatt)))
2245 (filesets-build-dir-submenu entry lookup-name dir patt)))
2246 ((:files)
2247 (let ((files (filesets-get-filelist entry mode 'on-open-all))
2248 (count 0))
2249 `([,(concat "Files: " lookup-name)
2250 (filesets-open ',mode ',lookup-name)]
2251 "---"
2252 ,@(filesets-wrap-submenu
2253 (mapcar
2254 (lambda (x)
2255 (setq count (+ count 1))
2256 `[,(concat (filesets-get-shortcut count)
2257 (file-name-nondirectory x))
2258 (filesets-file-open nil ',x ',lookup-name)])
2259 (filesets-conditional-sort
2260 files
2261 (function file-name-nondirectory))))
2262 ,@(filesets-get-menu-epilog lookup-name mode
2263 lookup-name t)))))))))))
2264
2265 (defun filesets-remove-from-ubl (&optional buffer)
2266 "BUFFER or current-buffer require update of the filesets menu."
2267 (let ((b (or buffer
2268 (current-buffer))))
2269 (if (member b filesets-updated-buffers)
2270 (setq filesets-updated-buffers
2271 (delete b filesets-updated-buffers)))))
2272
2273 (defun filesets-build-menu-now (from-scratch-flag)
2274 "Update the filesets menu.
2275 Build all new if FROM-SCRATCH-FLAG is non-nil. (To really build from the
2276 bottom up, set `filesets-submenus' to nil, first.)"
2277 (when (or from-scratch-flag
2278 filesets-has-changed-flag
2279 (not filesets-menu-cache))
2280 (setq filesets-menu-cache nil)
2281 (setq filesets-has-changed-flag nil)
2282 (setq filesets-updated-buffers nil)
2283 (setq filesets-update-cache-file-flag t)
2284 (do ((data (filesets-conditional-sort filesets-data (function car))
2285 (cdr data))
2286 (count 1 (+ count 1)))
2287 ((null data))
2288 (let* ((this (car data))
2289 (name (filesets-data-get-name this))
2290 (cached (lax-plist-get filesets-submenus name))
2291 (submenu (or cached
2292 (filesets-build-submenu count name this))))
2293 (unless cached
2294 (setq filesets-submenus
2295 (lax-plist-put filesets-submenus name submenu)))
2296 (unless (filesets-entry-get-dormant-flag this)
2297 (setq filesets-menu-cache
2298 (append filesets-menu-cache (list submenu))))))
2299 (when filesets-cache-save-often-flag
2300 (filesets-menu-cache-file-save-maybe)))
2301 (let ((cb (current-buffer)))
2302 (when (not (member cb filesets-updated-buffers))
2303 (filesets-add-submenu
2304 filesets-menu-path
2305 `(,filesets-menu-name
2306 ("# Filesets"
2307 ["Edit Filesets" filesets-edit]
2308 ["Save Filesets" filesets-save-config]
2309 ["Save Menu Cache" filesets-menu-cache-file-save]
2310 ["Rebuild Menu" filesets-build-menu]
2311 ["Customize" filesets-customize]
2312 ["About" filesets-info])
2313 ,(filesets-get-cmd-menu)
2314 "---"
2315 ,@filesets-menu-cache)
2316 filesets-menu-before
2317 filesets-menu-in-menu)
2318 (setq filesets-updated-buffers
2319 (cons cb filesets-updated-buffers))
2320 (message nil)
2321 ;;(message "Filesets updated: %s" cb)
2322 )))
2323
2324 (defun filesets-build-menu-maybe ()
2325 "Update the filesets menu."
2326 (interactive)
2327 (filesets-build-menu-now nil))
2328
2329 (defun filesets-build-menu ()
2330 "Force rebuild of the filesets menu."
2331 (interactive)
2332 ;(setq filesets-submenus nil)
2333 (filesets-reset-fileset)
2334 (filesets-build-menu-now t)
2335 (filesets-menu-cache-file-save-maybe))
2336
2337 (defun filesets-rebuild-this-submenu (fileset)
2338 "Force rebuild of FILESET submenu."
2339 (filesets-reset-fileset fileset)
2340 (filesets-build-menu-now t))
2341
2342 (defun filesets-menu-cache-file-save-maybe (&optional simply-do-it)
2343 "Write filesets' cache file.
2344 If SIMPLY-DO-IT is non-nil, the cache file will be written no matter if
2345 fileset thinks this is necessary or not."
2346 (when (and (not (equal filesets-menu-cache-file ""))
2347 (or simply-do-it
2348 filesets-update-cache-file-flag))
2349 (when (file-exists-p filesets-menu-cache-file)
2350 (delete-file filesets-menu-cache-file))
2351 ;;(message "Filesets: saving menu cache")
2352 (with-temp-buffer
2353 (dolist (this filesets-menu-cache-contents)
2354 (if (get this 'custom-type)
2355 (progn
2356 (insert (format "(setq-default %s '%S)" this (eval this)))
2357 (when filesets-menu-ensure-use-cached
2358 (newline)
2359 (insert (format "(setq %s (cons '%s %s))"
2360 'filesets-ignore-next-set-default
2361 this
2362 'filesets-ignore-next-set-default))))
2363 (insert (format "(setq %s '%S)" this (eval this))))
2364 (newline 2))
2365 (insert (format "(setq filesets-cache-version %S)" filesets-version))
2366 (newline 2)
2367 (when filesets-cache-hostname-flag
2368 (insert (format "(setq filesets-cache-hostname %S)" (system-name)))
2369 (newline 2))
2370 (run-hooks 'filesets-cache-fill-content-hooks)
2371 (write-file filesets-menu-cache-file))
2372 (setq filesets-has-changed-flag nil)
2373 (setq filesets-update-cache-file-flag nil)))
2374
2375 (defun filesets-menu-cache-file-save ()
2376 "Save filesets' menu cache file."
2377 (interactive)
2378 (filesets-menu-cache-file-save-maybe t))
2379
2380 (defun filesets-update-cleanup ()
2381 "Rebuild the menu and save the cache file after updating user data."
2382 (interactive)
2383 (message "Filesets v%s: updating menu & cache from version %s"
2384 filesets-version (or filesets-cache-version "???"))
2385 (filesets-build-menu)
2386 (filesets-menu-cache-file-save-maybe)
2387 (filesets-menu-cache-file-load))
2388
2389 (defun filesets-update-pre010505 ()
2390 (let ((msg
2391 "Filesets: manual editing of user data required!
2392
2393 Filesets has detected that you were using an older version before,
2394 which requires some manual updating. Type 'y' for editing the startup
2395 file now.
2396
2397 The layout of `filesets-data' has changed. Please delete your cache file
2398 and edit your startup file as shown below:
2399
2400 1. `filesets-data': Edit all :pattern filesets in your startup file and
2401 transform all entries as shown in this example:
2402
2403 \(\"Test\" (:pattern \"~/dir/^pattern$\"))
2404 --> \(\"Test\" (:pattern \"~/dir/\" \"^pattern$\"))
2405
2406 2. `filesets-data': Change all occurances of \":document\" to \":ingroup\":
2407
2408 \(\(\"Test\" \(:document \"~/dir/file\"))
2409 --> \(\(\"Test\" \(:ingroup \"~/dir/file\"))
2410
2411 3. `filesets-subdocument-patterns': If you already modified the variable
2412 previously called `filesets-subdocument-patterns', change its name to
2413 `filesets-ingroup-patterns'.
2414
2415 4. `filesets-menu-cache-contents': If you already modified this
2416 variable, change the entry `filesets-subdocument--cache' to
2417 `filesets-ingroup-cache'.
2418
2419 5. Type M-x filesets-update-cleanup and restart Emacs.
2420
2421 We apologize for the inconvenience."))
2422 (let* ((cf (or custom-file user-init-file)))
2423 (switch-to-buffer-other-frame "*Filesets update*")
2424 (insert msg)
2425 (when (y-or-n-p (format "Edit startup (%s) file now? " cf))
2426 (find-file-other-window cf))
2427 (filesets-error 'error msg))))
2428
2429 (defun filesets-update (version cached-version)
2430 "Do some cleanup after updating filesets.el."
2431 (cond
2432 ((or (not cached-version)
2433 (string< cached-version "1.5.5")
2434 (boundp 'filesets-subdocument-patterns))
2435 (filesets-update-pre010505)))
2436 (filesets-update-cleanup))
2437
2438 (defun filesets-menu-cache-file-load ()
2439 "Load filesets' menu cache file."
2440 (cond
2441 ((and (not (equal filesets-menu-cache-file ""))
2442 (file-readable-p filesets-menu-cache-file))
2443 (load-file filesets-menu-cache-file)
2444 (if (and (equal filesets-cache-version filesets-version)
2445 (if filesets-cache-hostname-flag
2446 (equal filesets-cache-hostname (system-name))
2447 t))
2448 (progn
2449 (setq filesets-update-cache-file-flag nil)
2450 t)
2451 (filesets-update filesets-version filesets-cache-version)))
2452 (t
2453 (setq filesets-update-cache-file-flag t)
2454 nil)))
2455
2456 (defun filesets-exit ()
2457 (filesets-menu-cache-file-save-maybe))
2458
2459 (defun filesets-init ()
2460 "Filesets initialization.
2461 Set up hooks, load the cache file -- if existing -- and build the menu."
2462 (add-hook (if filesets-running-xemacs 'activate-menubar-hook 'menu-bar-update-hook)
2463 (function filesets-build-menu-maybe))
2464 (add-hook 'kill-buffer-hook (function filesets-remove-from-ubl))
2465 (add-hook 'first-change-hook (function filesets-reset-filename-on-change))
2466 (add-hook 'kill-emacs-hook (function filesets-exit))
2467 (if (filesets-menu-cache-file-load)
2468 (progn
2469 (filesets-build-menu-maybe)
2470 ;;Well, normally when we use XEmacs <= 21.4, custom.el is loaded
2471 ;;after init.el. This more or less ignores the next
2472 ;;`filesets-data-set-default'
2473 (if filesets-menu-ensure-use-cached
2474 (setq filesets-menu-use-cached-flag t)))
2475 (filesets-build-menu)))
2476
2477
2478 ;;; run
2479 (filesets-init)
2480
2481 (provide 'filesets)
2482
2483 ;;; Local Variables:
2484 ;;; time-stamp-format:"%:y-%02m-%02d"
2485 ;;; sentence-end-double-space:t
2486 ;;; End:
2487
2488 ;;; filesets.el ends here