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