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