comparison lisp/find-paths.el @ 286:57709be46d1b r21-0b41

Import from CVS: tag r21-0b41
author cvs
date Mon, 13 Aug 2007 10:35:03 +0200
parents 558f606b08ae
children 70ad99077275
comparison
equal deleted inserted replaced
285:9a3756523c1b 286:57709be46d1b
34 ;; This file contains the library functionality to find paths into the 34 ;; This file contains the library functionality to find paths into the
35 ;; XEmacs hierarchy. 35 ;; XEmacs hierarchy.
36 36
37 ;;; Code: 37 ;;; Code:
38 38
39 (defvar paths-version-control-bases '("RCS" "CVS" "SCCS") 39 (defvar paths-version-control-filename-regexp
40 "^\\(RCS\\|CVS\\|SCCS\\)$"
40 "File bases associated with version control.") 41 "File bases associated with version control.")
41 42
42 (defun paths-find-recursive-path (directories &optional max-depth exclude) 43 (defvar paths-lisp-filename-regexp
44 "^\\(.*\\.elc?\\)$"
45 "File bases that contain Lisp file.")
46
47 (defvar paths-no-lisp-directory-regexp
48 (concat "\\(" paths-version-control-filename-regexp "\\)"
49 "\\|"
50 "\\(" paths-lisp-filename-regexp "\\)")
51 "File bases that may not be directories containing Lisp code.")
52
53 (defun paths-find-recursive-path (directories &optional max-depth exclude-regexp)
43 "Return a list of the directory hierarchy underneath DIRECTORIES. 54 "Return a list of the directory hierarchy underneath DIRECTORIES.
44 The returned list is sorted by pre-order and lexicographically. 55 The returned list is sorted by pre-order and lexicographically.
45 MAX-DEPTH limits the depth of the search to MAX-DEPTH level, 56 MAX-DEPTH limits the depth of the search to MAX-DEPTH level,
46 if it is a number. If MAX-DEPTH is NIL, the search depth is unlimited. 57 if it is a number. If MAX-DEPTH is NIL, the search depth is unlimited.
47 EXCLUDE is a list of directory names to exclude from the search." 58 EXCLUDE-REGEXP is a regexp that matches directory names to exclude
59 from the search."
48 (let ((path '())) 60 (let ((path '()))
49 (while directories 61 (while directories
50 (let ((directory (file-name-as-directory 62 (let ((directory (file-name-as-directory
51 (expand-file-name 63 (expand-file-name
52 (car directories))))) 64 (car directories)))))
53 (if (file-directory-p directory) 65 (if (file-directory-p directory)
54 (let ((raw-dirs 66 (let ((raw-entries
55 (if (equal 0 max-depth) 67 (if (equal 0 max-depth)
56 '() 68 '()
57 (directory-files directory nil "^[^-.]" nil 'dirs-only))) 69 (directory-files directory nil "^[^.-]")))
58 (reverse-dirs '())) 70 (reverse-dirs '()))
59 71
60 (while raw-dirs 72 (while raw-entries
61 (if (null (member (car raw-dirs) exclude)) 73 (if (null (string-match exclude-regexp (car raw-entries)))
62 (setq reverse-dirs 74 (setq reverse-dirs
63 (cons (expand-file-name (car raw-dirs) directory) 75 (cons (expand-file-name (car raw-entries) directory)
64 reverse-dirs))) 76 reverse-dirs)))
65 (setq raw-dirs (cdr raw-dirs))) 77 (setq raw-entries (cdr raw-entries)))
66 78
67 (let ((sub-path 79 (let ((sub-path
68 (paths-find-recursive-path (reverse reverse-dirs) 80 (paths-find-recursive-path (reverse reverse-dirs)
69 (if (numberp max-depth) 81 (if (numberp max-depth)
70 (- max-depth 1) 82 (- max-depth 1)
71 max-depth) 83 max-depth)
72 exclude))) 84 exclude-regexp)))
73 (setq path (nconc path 85 (setq path (nconc path
74 (list directory) 86 (list directory)
75 sub-path)))))) 87 sub-path))))))
76 (setq directories (cdr directories))) 88 (setq directories (cdr directories)))
77 path)) 89 path))
78 90
79 (defun paths-find-recursive-load-path (directories &optional max-depth) 91 (defun paths-find-recursive-load-path (directories &optional max-depth)
80 "Construct a recursive load path underneath DIRECTORIES." 92 "Construct a recursive load path underneath DIRECTORIES."
81 (paths-find-recursive-path directories 93 (paths-find-recursive-path directories
82 max-depth paths-version-control-bases)) 94 max-depth paths-no-lisp-directory-regexp))
83 95
84 (defun paths-emacs-root-p (directory) 96 (defun paths-emacs-root-p (directory)
85 "Check if DIRECTORY is a plausible installation root for XEmacs." 97 "Check if DIRECTORY is a plausible installation root for XEmacs."
86 (or 98 (or
87 ;; installed 99 ;; installed