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