;;; filesets.el --- handle group of files
-;; Copyright (C) 2002, 2003, 2004, 2005, 2006, 2007 Free Software Foundation, Inc.
+;; Copyright (C) 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010
+;; Free Software Foundation, Inc.
-;; Author: Thomas Link <t.link@gmx.at>
+;; Author: Thomas Link <sanobast-emacs@yahoo.de>
;; Maintainer: FSF
;; Keywords: filesets convenience
;; This file is part of GNU Emacs.
-;; This program is free software; you can redistribute it and/or modify
+;; GNU Emacs is free software: you can redistribute it and/or modify
;; it under the terms of the GNU General Public License as published by
-;; the Free Software Foundation; either version 3, or (at your option)
-;; any later version.
+;; the Free Software Foundation, either version 3 of the License, or
+;; (at your option) any later version.
-;; This program is distributed in the hope that it will be useful,
+;; GNU Emacs is distributed in the hope that it will be useful,
;; but WITHOUT ANY WARRANTY; without even the implied warranty of
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
;; GNU General Public License for more details.
-;; A copy of the GNU General Public License can be obtained from this
-;; program's author or from the Free Software Foundation, Inc.,
-;; 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+;; You should have received a copy of the GNU General Public License
+;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
+
+;;; Code:
(defvar filesets-version "1.8.4")
(defvar filesets-homepage
;; programs. See `filesets-external-viewers'.
;; BTW, if you close a fileset, files, which have been changed, will
-;; be silently saved. Change this behaviour by setting
+;; be silently saved. Change this behavior by setting
;; `filesets-save-buffer-fn'.
;;; Supported modes for inclusion groups (`filesets-ingroup-patterns'):
So, when should you think about setting this value to t? If filesets.el
is loaded before user customizations. Thus, if (require 'filesets)
-precedes the custom-set-variables command or, for XEmacs, if init.el is
-loaded before custom.el, set this variable to t.")
+precedes the `custom-set-variables' command or, for XEmacs, if init.el
+is loaded before custom.el, set this variable to t.")
;;; utils
(setq rv (append rv (list elt)))))))
(defun filesets-ormap (fsom-pred lst)
- "Return the tail of FSOM-LST for the head of which FSOM-PRED is non-nil."
+ "Return the tail of LST for the head of which FSOM-PRED is non-nil."
(let ((fsom-lst lst)
(fsom-rv nil))
(while (and (not (null fsom-lst))
(defcustom filesets-menu-name "Filesets"
"Filesets' menu name."
:set (function filesets-set-default)
- :type 'sexp
+ :type 'string
:group 'filesets)
-(defcustom filesets-menu-path nil
+(defcustom filesets-menu-path '("File") ; cf recentf-menu-path
"The menu under which the filesets menu should be inserted.
See `add-submenu' for documentation."
:set (function filesets-set-default)
- :type 'sexp
+ :type '(choice (const :tag "Top Level" nil)
+ (sexp :tag "Menu Path"))
+ :version "23.1" ; was nil
:group 'filesets)
-(defcustom filesets-menu-before "File"
+(defcustom filesets-menu-before "Open File..." ; cf recentf-menu-before
"The name of a menu before which this menu should be added.
See `add-submenu' for documentation."
:set (function filesets-set-default)
- :type 'sexp
+ :type '(choice (string :tag "Name")
+ (const :tag "Last" nil))
+ :version "23.1" ; was "File"
:group 'filesets)
(defcustom filesets-menu-in-menu nil
;; :group 'filesets)
(defcustom filesets-menu-cache-file
- (if (featurep 'xemacs)
- "~/.xemacs/filesets-cache.el"
- (concat user-emacs-directory "filesets-cache.el"))
+ (locate-user-emacs-file "filesets-cache.el")
"File to be used for saving the filesets menu between sessions.
Set this to \"\", to disable caching of menus.
Don't forget to check out `filesets-menu-ensure-use-cached'."
:group 'filesets)
(defcustom filesets-sort-case-sensitive-flag t
- "Non-nil means sorting of the filesete menu is case sensitive."
+ "Non-nil means sorting of the filesets menu is case sensitive."
:set (function filesets-set-default)
:type 'boolean
:group 'filesets)
:group 'filesets)
(defcustom filesets-commands
- `(("Query Replace"
- query-replace
+ `(("Isearch"
+ multi-isearch-files
+ (filesets-cmd-isearch-getargs))
+ ("Isearch (regexp)"
+ multi-isearch-files-regexp
+ (filesets-cmd-isearch-getargs))
+ ("Query Replace"
+ perform-replace
(filesets-cmd-query-replace-getargs))
("Query Replace (regexp)"
- query-replace-regexp
- (filesets-cmd-query-replace-getargs))
+ perform-replace
+ (filesets-cmd-query-replace-regexp-getargs))
("Grep <<selection>>"
"grep"
("-n " filesets-get-quoted-selection " " "<<file-name>>"))
in the pattern holding the subfile's name. 0 refers the whole
match, 1 to the first group.
-:stubp FUNCTION ... if (FUNCTION MASTER INCLUDED-FILE) returns non-nil,
+:stubp FUNCTION ... If (FUNCTION MASTER INCLUDED-FILE) returns non-nil,
INCLUDED-FILE is a stub -- see below.
-:stub-flag ... files of this type are stubs -- see below.
+:stub-flag ... Files of this type are stubs -- see below.
:scan-depth INTEGER (default: 0) ... Whether included files should be
rescanned. Set this to 0 to disable re-scanning of included file.
:tree ROOT-DIR PATTERN ... a base directory and a file pattern
-:pattern DIR PATTERN ... PATTERN is a regular expression comprising path
-and file pattern -- e.g. 'PATH/^REGEXP$'. Note the `^' at the beginning
-of the file name pattern.
+:pattern DIR PATTERN ... a base directory and a regexp matching
+ files in that directory. Usually,
+ PATTERN has the form '^REGEXP$'. Unlike
+ :tree, this form does not descend
+ recursively into subdirectories.
:filter-dirs-flag BOOLEAN ... is only used in conjunction with :tree.
"Return a sorted copy of LST, LST being a list of strings.
If `filesets-sort-menu-flag' is nil, return LST itself.
-ACCESS-FN ... function to get the string value of LST's elements.
-
-If SIMPLY-DO-IT is non-nil, the list is sorted regardless of
-`filesets-sort-menu-flag'."
+ACCESS-FN ... function to get the string value of LST's elements."
(if filesets-sort-menu-flag
(let* ((fni (or access-fn
(function identity)))
on-capture-output (:capture-output) ... Capture output of an external viewer
-on-ls ... not used
+on-ls ... Not used
-on-cmd ... not used
+on-cmd ... Not used
-on-close-all ... not used"
+on-close-all ... Not used"
(let ((def (filesets-eviewer-get-props
(or entry
(filesets-get-external-viewer filename)))))
(find-file file)))
(defun filesets-find-or-display-file (&optional file viewer)
- "Visit FILE using an external viewer or open it in an Emacs buffer."
+ "Visit FILE using an external VIEWER or open it in an Emacs buffer."
(interactive)
(let* ((file (or file
(read-file-name "Find file: " nil nil viewer)))
something)))
(defun filesets-data-get-name (entry)
- "Access to `filesets-data'. Get the entry's name."
+ "Access to `filesets-data'. Get the ENTRY's name."
(car entry))
(defun filesets-data-get-data (entry)
- "Access to `filesets-data'. Get the entry's data section."
+ "Access to `filesets-data'. Get the ENTRY's data section."
(cdr entry))
(defun filesets-alist-get (alist key &optional default carp)
"Get KEY's value in the association list ALIST.
Return DEFAULT if not found. Return (car VALUE) if CARP is non-nil."
- (let* ((elt (assoc key alist)))
+ (let ((elt (assoc key alist)))
(cond
- (elt
- (if carp
- (cadr elt)
- (cdr elt)))
- (default default)
- (t nil))))
+ (elt
+ (if carp
+ (cadr elt)
+ (cdr elt)))
+ (default default)
+ (t nil))))
(defun filesets-data-get (entry key &optional default carp)
"Extract the value for KEY in the data part of fileset ENTRY.
(filesets-alist-get (filesets-data-get-data entry) key default carp))
(defun filesets-data-set (entry key value)
- "Set the value for KEY in the data part of fileset ENTRY."
+ "Set the VALUE for KEY in the data part of fileset ENTRY."
(let* ((alist (filesets-data-get-data entry))
(elt (assoc key alist)))
(if elt
if `buffer-modified-p' returns nil.
SAVE-FUNCTION takes no argument, but works on the current buffer."
- (save-excursion
- (set-buffer buffer)
+ (with-current-buffer buffer
(if (buffer-modified-p)
(funcall save-function))
(if (not (buffer-modified-p))
(when files
(let ((fn (filesets-cmd-get-fn cmd-name))
(args (filesets-cmd-get-args cmd-name)))
- (dolist (this files nil)
- (save-excursion
- (save-restriction
- (let ((buffer (filesets-find-file this)))
- (when buffer
- (goto-char (point-min))
- (let ()
- (cond
- ((stringp fn)
- (let* ((args
- (let ((txt ""))
- (dolist (this args txt)
- (setq txt
- (concat txt
- (filesets-run-cmd--repl-fn
- this
- (lambda (this)
- (if (equal txt "") "" " ")
- (format "%s" this))))))))
- (cmd (concat fn " " args)))
- (filesets-cmd-show-result
- cmd (shell-command-to-string cmd))))
- ((symbolp fn)
- (let ((args
- (let ((argl nil))
- (dolist (this args argl)
- (setq argl
- (append argl
- (filesets-run-cmd--repl-fn
- this
- 'list)))))))
- (apply fn args))))))))))))))))
+ (if (memq fn '(multi-isearch-files multi-isearch-files-regexp))
+ (apply fn args)
+ (dolist (this files nil)
+ (save-excursion
+ (save-restriction
+ (let ((buffer (filesets-find-file this)))
+ (when buffer
+ (goto-char (point-min))
+ (progn
+ (cond
+ ((stringp fn)
+ (let* ((args
+ (let ((txt ""))
+ (dolist (this args txt)
+ (setq txt
+ (concat txt
+ (filesets-run-cmd--repl-fn
+ this
+ (lambda (this)
+ (if (equal txt "") "" " ")
+ (format "%s" this))))))))
+ (cmd (concat fn " " args)))
+ (filesets-cmd-show-result
+ cmd (shell-command-to-string cmd))))
+ ((symbolp fn)
+ (let ((args
+ (let ((argl nil))
+ (dolist (this args argl)
+ (setq argl
+ (append argl
+ (filesets-run-cmd--repl-fn
+ this
+ 'list)))))))
+ (apply fn args)))))))))))))))))
(defun filesets-get-cmd-menu ()
"Create filesets command menu."
filesets-commands)))
-;;; sampe commands
+;;; sample commands
(defun filesets-cmd-query-replace-getargs ()
- "Get arguments for `filesets-cmd-query-replace'."
- (let* ((from-string (read-string "Filesets query replace: "
- ""
- 'query-replace-history))
- (to-string (read-string
- (format "Filesets query replace %s with: " from-string)
- ""
- 'query-replace-history))
- (delimited (y-or-n-p
- "Filesets query replace: respect word boundaries? ")))
- (list from-string to-string delimited)))
+ "Get arguments for `query-replace' and `query-replace-regexp'."
+ (let ((common (query-replace-read-args "Filesets query replace" nil t)))
+ (list (nth 0 common) (nth 1 common) t nil (nth 2 common) nil
+ multi-query-replace-map)))
+
+(defun filesets-cmd-query-replace-regexp-getargs ()
+ "Get arguments for `query-replace' and `query-replace-regexp'."
+ (let ((common (query-replace-read-args "Filesets query replace" t t)))
+ (list (nth 0 common) (nth 1 common) t t (nth 2 common) nil
+ multi-query-replace-map)))
+
+(defun filesets-cmd-isearch-getargs ()
+ "Get arguments for `multi-isearch-files' and `multi-isearch-files-regexp'."
+ (and (boundp 'files) (list files)))
(defun filesets-cmd-shell-command-getargs ()
"Get arguments for `filesets-cmd-shell-command'."
(browse-url filesets-homepage))
(defun filesets-remake-shortcut (count submenu)
- "Remake a submenus shortcut when wrapping long menus."
+ "Remake a submenu's shortcut when wrapping long menus."
(let* ((name (concat (filesets-get-shortcut count)
(substring (elt submenu 0) 2))))
(if (listp submenu)
(lax-plist-put filesets-ingroup-cache emaster this))))
(defun filesets-ingroup-collect-files (fs &optional remdupl-flag master depth)
- "Helper function for `filesets-ingroup-collect'. Collect file names."
+ "Helper function for `filesets-ingroup-collect'. Collect file names."
(let* ((master (or master
(filesets-entry-get-master fs)))
(remdupl-flag (or remdupl-flag
`([,nm (filesets-file-open nil ',master ',fsn)])))))))))
(defun filesets-ingroup-collect (fs remdupl-flag master)
- "Collect names of included files & build submenu."
+ "Collect names of included files and build submenu."
(filesets-ingroup-cache-put master nil)
(filesets-message 2 "Filesets: parsing %S" master)
(filesets-ingroup-collect-build-menu