File: lisp-file-db.el

package info (click to toggle)
xemacs20 20.4-13
  • links: PTS
  • area: main
  • in suites: slink
  • size: 67,324 kB
  • ctags: 57,643
  • sloc: lisp: 586,197; ansic: 184,662; sh: 4,296; asm: 3,179; makefile: 2,021; perl: 1,059; csh: 96; sed: 22
file content (39 lines) | stat: -rw-r--r-- 1,610 bytes parent folder | download | duplicates (13)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
(defvar *default-db-name* (expand-file-name "~/.xemacs/lisp-file-database")
  "Default location of the database")

(defun build-lisp-file-db (&optional db-name path rebuild)
  "Create a database of all lisp files in the directories given by PATH.
DB-NAME is the database name, defaulting to *default-db-name*
PATH is a list of directories to search, defaulting to load-path.
REBUILD "
  (let ((path (or path load-path))
	(db (open-database (or db-name *default-db-name*) nil nil "rw+")))
    ;; For each entry in path, find all files in it and put them in
    ;; the database.
    (dolist (dir path)
      (dolist (file (directory-files dir t nil t t))
	;; Separate the file name and the directory.  The key is the
	;; filename, and the value is the whole pathname.  However, if
	;; the key already exists, DON'T put that entry in.  We want
	;; things that occur first in load-path to override entries
	;; later in load-path
	(let ((fname (file-name-nondirectory file)))
	  (put-database fname file db nil))))))

(defun show-lisp-db (&optional db-name)
  (let ((db (open-database (or db-name *default-db-name*) nil nil "r"))
	(entries '()))
    (map-database #'(lambda (key val)
		      (push (cons key val) entries))
		  db)
    (nreverse entries)))

(defun lookup-lisp-file-db (file &optional db-name)
  (let ((name (file-name-nondirectory file))
	(db (open-database (or db-name *default-db-name*) nil nil "r")))
    (do* ((ext '("" ".elc" ".el") (rest ext))
	 (entry (get-database (concat name (first ext)) db)
		(get-database (concat name (first ext)) db)))
	((or entry (null ext)) entry)
      ())))