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