annotate lisp/tl/file-detect.el @ 8:4b173ad71786 r19-15b5

Import from CVS: tag r19-15b5
author cvs
date Mon, 13 Aug 2007 08:47:35 +0200
parents b82b59fe008d
children 49a24b4fd526
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
4
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
1 ;;; file-detect.el --- Emacs Lisp file detection utility
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
2
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
3 ;; Copyright (C) 1996 Free Software Foundation, Inc.
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
4
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
5 ;; Author: MORIOKA Tomohiko <morioka@jaist.ac.jp>
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
6 ;; Version:
8
4b173ad71786 Import from CVS: tag r19-15b5
cvs
parents: 4
diff changeset
7 ;; $Id: file-detect.el,v 1.2 1996/12/22 00:29:31 steve Exp $
4
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
8 ;; Keywords: install, module
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
9
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
10 ;; This file is part of tl (Tiny Library).
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
11
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
12 ;; This program is free software; you can redistribute it and/or
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
13 ;; modify it under the terms of the GNU General Public License as
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
14 ;; published by the Free Software Foundation; either version 2, or (at
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
15 ;; your option) any later version.
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
16
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
17 ;; This program is distributed in the hope that it will be useful, but
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
18 ;; WITHOUT ANY WARRANTY; without even the implied warranty of
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
19 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
20 ;; General Public License for more details.
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
21
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
22 ;; You should have received a copy of the GNU General Public License
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
23 ;; along with This program; see the file COPYING. If not, write to
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
24 ;; the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
25 ;; Boston, MA 02111-1307, USA.
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
26
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
27 ;;; Code:
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
28
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
29 (defvar default-load-path load-path)
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
30
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
31 (defun add-path (path &rest options)
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
32 "Add PATH to `load-path' if it exists under `default-load-path'
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
33 directories and it does not exist in `load-path'.
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
34
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
35 You can use following PATH styles:
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
36 load-path relative: \"PATH/\"
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
37 (it is searched from `defaul-load-path')
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
38 home directory relative: \"~/PATH/\" \"~USER/PATH/\"
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
39 absolute path: \"/HOO/BAR/BAZ/\"
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
40
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
41 You can specify following OPTIONS:
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
42 'all-paths search from `load-path'
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
43 instead of `default-load-path'
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
44 'append add PATH to the last of `load-path'
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
45
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
46 \[file-detect.el]"
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
47 (let ((rest (if (memq 'all-paths options)
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
48 load-path
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
49 default-load-path))
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
50 p)
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
51 (if (and (catch 'tag
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
52 (while rest
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
53 (setq p (expand-file-name path (car rest)))
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
54 (if (file-directory-p p)
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
55 (throw 'tag p)
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
56 )
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
57 (setq rest (cdr rest))
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
58 ))
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
59 (not (member p load-path))
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
60 )
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
61 (setq load-path
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
62 (if (memq 'append options)
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
63 (append load-path (list p))
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
64 (cons p load-path)
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
65 ))
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
66 )))
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
67
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
68 (defun get-latest-path (pat &optional all-paths)
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
69 "Return latest directory in default-load-path
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
70 which is matched to regexp PAT.
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
71 If optional argument ALL-PATHS is specified,
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
72 it is searched from all of load-path instead of default-load-path.
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
73 \[file-detect.el]"
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
74 (catch 'tag
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
75 (let ((paths (if all-paths
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
76 load-path
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
77 default-load-path))
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
78 dir)
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
79 (while (setq dir (car paths))
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
80 (let ((files (sort (directory-files dir t pat t)
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
81 (function file-newer-than-file-p)))
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
82 file)
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
83 (while (setq file (car files))
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
84 (if (file-directory-p file)
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
85 (throw 'tag file)
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
86 )
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
87 (setq files (cdr files))
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
88 ))
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
89 (setq paths (cdr paths))
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
90 ))))
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
91
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
92 (defun file-installed-p (file &optional paths)
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
93 "Return t if FILE exists in PATHS.
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
94 If PATHS is omitted, `load-path' is used. [file-detect.el]"
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
95 (if (null paths)
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
96 (setq paths load-path)
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
97 )
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
98 (catch 'tag
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
99 (let (path)
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
100 (while paths
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
101 (setq path (expand-file-name file (car paths)))
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
102 (if (file-exists-p path)
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
103 (throw 'tag path)
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
104 )
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
105 (setq paths (cdr paths))
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
106 ))))
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
107
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
108 (defun module-installed-p (module &optional paths)
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
109 "Return t if module is provided or exists in PATHS.
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
110 If PATHS is omitted, `load-path' is used. [file-detect.el]"
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
111 (or (featurep module)
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
112 (let ((name (symbol-name module)))
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
113 (if (null paths)
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
114 (setq paths load-path)
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
115 )
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
116 (catch 'tag
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
117 (while paths
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
118 (let ((file (expand-file-name name (car paths))))
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
119 (let ((elc-file (concat file ".elc")))
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
120 (if (file-exists-p elc-file)
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
121 (throw 'tag elc-file)
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
122 ))
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
123 (let ((el-file (concat file ".el")))
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
124 (if (file-exists-p el-file)
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
125 (throw 'tag el-file)
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
126 ))
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
127 (if (file-exists-p file)
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
128 (throw 'tag file)
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
129 )
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
130 )
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
131 (setq paths (cdr paths))
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
132 )))))
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
133
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
134
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
135 ;;; @ end
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
136 ;;;
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
137
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
138 (provide 'file-detect)
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
139
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
140 ;;; file-detect.el ends here