~ubuntu-branches/ubuntu/trusty/librep/trusty

« back to all changes in this revision

Viewing changes to lisp/rep/io/files.jl

  • Committer: Bazaar Package Importer
  • Author(s): Christian Marillat
  • Date: 2001-11-13 15:06:22 UTC
  • Revision ID: james.westby@ubuntu.com-20011113150622-vgmgmk6srj3kldr3
Tags: upstream-0.15.2
ImportĀ upstreamĀ versionĀ 0.15.2

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#| rep.io.files bootstrap
 
2
 
 
3
   $Id: files.jl,v 1.4 2000/09/19 10:32:56 john Exp $
 
4
 
 
5
   Copyright (C) 2000 John Harper <john@dcs.warwick.ac.uk>
 
6
 
 
7
   This file is part of librep.
 
8
 
 
9
   librep is free software; you can redistribute it and/or modify it
 
10
   under the terms of the GNU General Public License as published by
 
11
   the Free Software Foundation; either version 2, or (at your option)
 
12
   any later version.
 
13
 
 
14
   librep is distributed in the hope that it will be useful, but
 
15
   WITHOUT ANY WARRANTY; without even the implied warranty of
 
16
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
17
   GNU General Public License for more details.
 
18
 
 
19
   You should have received a copy of the GNU General Public License
 
20
   along with librep; see the file COPYING.  If not, write to
 
21
   the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
 
22
|#
 
23
 
 
24
(declare (in-module rep.io.files))
 
25
 
 
26
(open-structures '(rep.lang.symbols
 
27
                   rep.data
 
28
                   rep.system))
 
29
 
 
30
(defun file-name= (name1 name2)
 
31
  "Returns t when NAME1 and NAME2 both name the same file."
 
32
  (string= (canonical-file-name name1) (canonical-file-name name2)))
 
33
 
 
34
(defun file-newer-than-file-p (file1 file2)
 
35
  "Returns t when FILE1 was modified more recently than FILE2."
 
36
  (time-later-p (file-modtime file1) (file-modtime file2)))
 
37
 
 
38
(defun load-all (file #!optional callback)
 
39
  "Try to load files called FILE (or FILE.jl, etc) from all directories in the
 
40
LISP load path (except the current directory)."
 
41
  (let loop ((dirs load-path))
 
42
    ;; Normally the last entry in load-path is `.' We don't
 
43
    ;; want to use that. But can't just check if each item
 
44
    ;; is the current directory since sometimes rep is run
 
45
    ;; with REPLISPDIR=.
 
46
    (when dirs
 
47
      (when (or (cdr dirs) (not (member (car dirs) '("." ""))))
 
48
        (let
 
49
            ((full-name (expand-file-name file (car dirs))))
 
50
          (when (or (file-exists-p full-name)
 
51
                    (file-exists-p (concat full-name ".jl"))
 
52
                    (file-exists-p (concat full-name ".jlc")))
 
53
            (if callback
 
54
                (callback full-name)
 
55
              (load full-name nil t)))))
 
56
      (loop (cdr dirs)))))
 
57
 
 
58
(defun call-after-load (library thunk)
 
59
  "Arrange for THUNK to be called immediately after the library of Lisp code
 
60
LIBRARY has been read by the `load' function. Note that LIBRARY must exactly
 
61
match the FILE argument to `load'."
 
62
  (let ((tem (assoc library after-load-alist)))
 
63
    (if tem
 
64
        (rplacd tem (cons thunk (cdr tem)))
 
65
      (setq after-load-alist (cons (cons library (list thunk))
 
66
                                   after-load-alist)))))
 
67
 
 
68
(defun eval-after-load (library form)
 
69
  "Arrange for FORM to be evaluated immediately after the library of Lisp code
 
70
LIBRARY has been read by the `load' function. Note that LIBRARY must exactly
 
71
match the FILE argument to `load'."
 
72
  (call-after-load library (lambda ()
 
73
                             (eval form (get-structure *user-structure*)))))
 
74
 
 
75
(export-bindings '(file-name= file-newer-than-file-p
 
76
                   load-all call-after-load eval-after-load))