;; Created: Sun Nov 10 1996
;; Keywords: convenience
;;
-;; Copyright (C) 1996, 2000 Free Software Foundation, Inc.
+;; Copyright (C) 1996, 2000, 2001, 2002, 2003, 2004,
+;; 2005, 2006, 2007, 2008 Free Software Foundation, Inc.
;; This file is part of GNU Emacs.
-;; GNU Emacs 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 2, or (at your option)
-;; any later version.
+;; the Free Software Foundation, either version 3 of the License, or
+;; (at your option) any later version.
;; GNU Emacs is distributed in the hope that it will be useful,
;; but WITHOUT ANY WARRANTY; without even the implied warranty of
;; GNU General Public License for more details.
;; You should have received a copy of the GNU General Public License
-;; along with GNU Emacs; see the file COPYING. If not, write to the
-;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
-;; Boston, MA 02111-1307, USA.
+;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
;;; Commentary:
;;
:type 'string
:group 'file-cache)
+(defcustom file-cache-find-command-posix-flag 'not-defined
+ "*Set to t, if `file-cache-find-command' handles wildcards POSIX style.
+This variable is automatically set to nil or non-nil
+if it has the initial value `not-defined' whenever you first
+call the `file-cache-add-directory-using-find'.
+
+Under Windows operating system where Cygwin is available, this value
+should be t."
+ :type '(choice (const :tag "Yes" t)
+ (const :tag "No" nil)
+ (const :tag "Unknown" not-defined))
+ :group 'file-cache)
+
(defcustom file-cache-locate-command "locate"
"*External program used by `file-cache-add-directory-using-locate'."
:type 'string
:group 'file-cache
)
-(defcustom file-cache-assoc-function
- (if (memq system-type (list 'ms-dos 'windows-nt 'cygwin))
- 'assoc-ignore-case
- 'assoc)
- "Function to use to check completions in the file cache.
-Defaults to `assoc-ignore-case' on DOS and Windows, and `assoc' on
-other systems."
+(defcustom file-cache-ignore-case
+ (memq system-type (list 'ms-dos 'windows-nt 'cygwin))
+ "Non-nil means ignore case when checking completions in the file cache.
+Defaults to nil on DOS and Windows, and t on other systems."
:type 'sexp
:group 'file-cache
)
(defvar file-cache-alist nil
"Internal data structure to hold cache of file names.")
-(defvar file-cache-completions-keymap nil
+(defvar file-cache-completions-keymap
+ (let ((map (make-sparse-keymap)))
+ (set-keymap-parent map completion-list-mode-map)
+ (define-key map [mouse-2] 'file-cache-mouse-choose-completion)
+ (define-key map "\C-m" 'file-cache-choose-completion)
+ map)
"Keymap for file cache completions buffer.")
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; Functions to add files to the cache
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
+;;;###autoload
(defun file-cache-add-directory (directory &optional regexp)
"Add DIRECTORY to the file cache.
If the optional REGEXP argument is non-nil, only files which match it will
(dir-files (directory-files dir t regexp))
)
;; Filter out files we don't want to see
- (mapcar
+ (mapc
'(lambda (file)
- (mapcar
- '(lambda (regexp)
- (if (string-match regexp file)
- (setq dir-files (delq file dir-files))))
- file-cache-filter-regexps))
+ (if (file-directory-p file)
+ (setq dir-files (delq file dir-files))
+ (mapc
+ '(lambda (regexp)
+ (if (string-match regexp file)
+ (setq dir-files (delq file dir-files))))
+ file-cache-filter-regexps)))
dir-files)
(file-cache-add-file-list dir-files))))
+;;;###autoload
(defun file-cache-add-directory-list (directory-list &optional regexp)
"Add DIRECTORY-LIST (a list of directory names) to the file cache.
If the optional REGEXP argument is non-nil, only files which match it
(mapcar 'file-cache-add-file file-list))
;; Workhorse function
+
+;;;###autoload
(defun file-cache-add-file (file)
"Add FILE to the file cache."
(interactive "fAdd File: ")
(if (not (file-exists-p file))
- (message "File %s does not exist" file)
+ (message "Filecache: file %s does not exist" file)
(let* ((file-name (file-name-nondirectory file))
(dir-name (file-name-directory file))
- (the-entry (funcall file-cache-assoc-function
- file-name file-cache-alist))
+ (the-entry (assoc-string
+ file-name file-cache-alist
+ file-cache-ignore-case))
)
;; Does the entry exist already?
(if the-entry
file-cache-alist)))
)))
+;;;###autoload
(defun file-cache-add-directory-using-find (directory)
"Use the `find' command to add files to the file cache.
Find is run in DIRECTORY."
(interactive "DAdd files under directory: ")
(let ((dir (expand-file-name directory)))
+ (when (memq system-type '(windows-nt cygwin))
+ (if (eq file-cache-find-command-posix-flag 'not-defined)
+ (setq file-cache-find-command-posix-flag
+ (executable-command-find-posix-p file-cache-find-command))))
(set-buffer (get-buffer-create file-cache-buffer))
(erase-buffer)
(call-process file-cache-find-command nil
(get-buffer file-cache-buffer) nil
dir "-name"
- (if (eq system-type 'windows-nt) "'*'" "*")
+ (if (memq system-type '(windows-nt cygwin))
+ (if file-cache-find-command-posix-flag
+ "\\*"
+ "'*'")
+ "*")
"-print")
(file-cache-add-from-file-cache-buffer)))
+;;;###autoload
(defun file-cache-add-directory-using-locate (string)
"Use the `locate' command to add files to the file cache.
STRING is passed as an argument to the locate command."
string)
(file-cache-add-from-file-cache-buffer))
+;;;###autoload
(defun file-cache-add-directory-recursively (dir &optional regexp)
"Adds DIR and any subdirectories to the file-cache.
This function does not use any external programs
(lambda(file)
(or (file-directory-p file)
(let (filtered)
- (mapcar
+ (mapc
(function
(lambda(regexp)
(and (string-match regexp file)
Each entry matches the regular expression `file-cache-buffer-default-regexp'
or the optional REGEXP argument."
(set-buffer file-cache-buffer)
- (mapcar
+ (mapc
(function (lambda (elt)
(goto-char (point-min))
(delete-matching-lines elt)))
(interactive
(list (completing-read "Delete file from cache: " file-cache-alist)))
(setq file-cache-alist
- (delq (funcall file-cache-assoc-function file file-cache-alist)
+ (delq (assoc-string file file-cache-alist file-cache-ignore-case)
file-cache-alist)))
(defun file-cache-delete-file-list (file-list)
"Delete files matching REGEXP from the file cache."
(interactive "sRegexp: ")
(let ((delete-list))
- (mapcar '(lambda (elt)
- (and (string-match regexp (car elt))
- (setq delete-list (cons (car elt) delete-list))))
- file-cache-alist)
+ (mapc '(lambda (elt)
+ (and (string-match regexp (car elt))
+ (setq delete-list (cons (car elt) delete-list))))
+ file-cache-alist)
(file-cache-delete-file-list delete-list)
- (message "Deleted %d files from file cache" (length delete-list))))
+ (message "Filecache: deleted %d files from file cache"
+ (length delete-list))))
(defun file-cache-delete-directory (directory)
"Delete DIRECTORY from the file cache."
(interactive "DDelete directory from file cache: ")
(let ((dir (expand-file-name directory))
(result 0))
- (mapcar
+ (mapc
'(lambda (entry)
(if (file-cache-do-delete-directory dir entry)
(setq result (1+ result))))
file-cache-alist)
(if (zerop result)
- (error "No entries containing %s found in cache" directory)
- (message "Deleted %d entries" result))))
+ (error "Filecache: no entries containing %s found in cache" directory)
+ (message "Filecache: deleted %d entries" result))))
(defun file-cache-do-delete-directory (dir entry)
(let ((directory-list (cdr entry))
;; Returns the name of a directory for a file in the cache
(defun file-cache-directory-name (file)
- (let* ((directory-list (cdr (funcall file-cache-assoc-function
- file file-cache-alist)))
+ (let* ((directory-list (cdr (assoc-string
+ file file-cache-alist
+ file-cache-ignore-case)))
(len (length directory-list))
(directory)
(num)
)
(if (not (listp directory-list))
- (error "Unknown type in file-cache-alist for key %s" file))
+ (error "Filecache: unknown type in file-cache-alist for key %s" file))
(cond
;; Single element
((eq 1 len)
(setq directory (elt directory-list 0)))
;; No elements
((eq 0 len)
- (error "No directory found for key %s" file))
+ (error "Filecache: no directory found for key %s" file))
;; Multiple elements
(t
(let* ((minibuffer-dir (file-name-directory (minibuffer-contents)))
;; If we've already inserted a unique string, see if the user
;; wants to use that one
(if (and (string= string completion-string)
- (funcall file-cache-assoc-function string file-cache-alist))
+ (assoc-string string file-cache-alist
+ file-cache-ignore-case))
(if (and (eq last-command this-command)
(string= file-cache-last-completion completion-string))
(progn
(substring completion-string (length string)))
;; Add our own setup function to the Completions Buffer
(let ((completion-setup-hook
- (reverse
- (append (list 'file-cache-completion-setup-function)
- completion-setup-hook)))
- )
+ (append completion-setup-hook
+ (list 'file-cache-completion-setup-function))))
(with-output-to-temp-buffer file-cache-completions-buffer
- (display-completion-list completion-list))
- )
- )
+ (display-completion-list completion-list string))))
(setq file-cache-string (file-cache-file-name completion-string))
(if (string= file-cache-string (minibuffer-contents))
(file-cache-temp-minibuffer-message
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(defun file-cache-completion-setup-function ()
- (set-buffer file-cache-completions-buffer)
-
- (if file-cache-completions-keymap
- nil
- (setq file-cache-completions-keymap
- (copy-keymap completion-list-mode-map))
- (define-key file-cache-completions-keymap [mouse-2]
- 'file-cache-mouse-choose-completion)
- (define-key file-cache-completions-keymap "\C-m"
- 'file-cache-choose-completion))
-
- (use-local-map file-cache-completions-keymap)
- )
+ (with-current-buffer standard-output ;; i.e. file-cache-completions-buffer
+ (use-local-map file-cache-completions-keymap)))
(defun file-cache-choose-completion ()
"Choose a completion in the `*Completions*' buffer."
)
(t
(with-output-to-temp-buffer "*Completions*"
- (display-completion-list all))
+ (display-completion-list all pattern))
))
))
"Output a list of files whose names (not including directories)
match REGEXP."
(let ((results))
- (mapcar
+ (mapc
(function
(lambda(cache-element)
(and (string-match regexp
"Debugging function."
(interactive
(list (completing-read "File Cache: " file-cache-alist)))
- (message "%s" (funcall file-cache-assoc-function file file-cache-alist))
+ (message "%s" (assoc-string file file-cache-alist
+ file-cache-ignore-case))
)
(defun file-cache-display ()
(with-current-buffer
(get-buffer-create buf)
(erase-buffer)
- (mapcar
+ (mapc
(function
- (lambda(item)
- (insert (nth 1 item) (nth 0 item) "\n")))
- file-cache-alist)
+ (lambda(item)
+ (insert (nth 1 item) (nth 0 item) "\n")))
+ file-cache-alist)
(pop-to-buffer buf)
)))
;; Keybindings
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
-;;;###autoload (define-key minibuffer-local-completion-map [C-tab] 'file-cache-minibuffer-complete)
-;;;###autoload (define-key minibuffer-local-map [C-tab] 'file-cache-minibuffer-complete)
-;;;###autoload (define-key minibuffer-local-must-match-map [C-tab] 'file-cache-minibuffer-complete)
-
(provide 'filecache)
+;; arch-tag: 433d3ca4-4af2-47ce-b2cf-1f727460f538
;;; filecache.el ends here