annotate lisp/hyperbole/hbmap.el @ 80:1ce6082ce73f r20-0b90

Import from CVS: tag r20-0b90
author cvs
date Mon, 13 Aug 2007 09:06:37 +0200
parents 131b0175ea99
children 4be1180a9e89
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1 ;;!emacs
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2 ;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3 ;; FILE: hbmap.el
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4 ;; SUMMARY: Hyperbole button map maintenance for queries and lookups.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5 ;; USAGE: GNU Emacs Lisp Library
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
6 ;; KEYWORDS: hypermedia, matching
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
7 ;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
8 ;; AUTHOR: Bob Weiner
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
9 ;; ORG: Brown U.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
10 ;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
11 ;; ORIG-DATE: 6-Oct-91 at 06:34:05
70
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 24
diff changeset
12 ;; LAST-MOD: 24-Oct-95 at 18:32:30 by Bob Weiner
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
13 ;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
14 ;; This file is part of Hyperbole.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
15 ;; Available for use and distribution under the same terms as GNU Emacs.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
16 ;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
17 ;; Copyright (C) 1991-1995, Free Software Foundation, Inc.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
18 ;; Developed with support from Motorola Inc.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
19 ;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
20 ;; DESCRIPTION:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
21 ;; DESCRIP-END.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
22
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
23 ;;; ************************************************************************
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
24 ;;; Public variables
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
25 ;;; ************************************************************************
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
26
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
27 (defvar hbmap:filename "HYPB"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
28 "*Filename used for quick access button files.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
29
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
30 ;;; ************************************************************************
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
31 ;;; Public functions
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
32 ;;; ************************************************************************
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
33
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
34 (defun hbmap:dir-add (dir-name &optional no-save)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
35 "Adds DIR-NAME to map of all directories in which user has written buttons.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
36 Returns t iff DIR-NAME is not already in map, nil if it is, and some
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
37 other value when cannot read or write map.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
38 Optional NO-SAVE disables saving of the map after an add."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
39 (hbmap:dir-operate (function (lambda (dir) (not (hbmap:dir-member dir))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
40 dir-name
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
41 '(progn (prin1 (list dir-name) buf) (terpri buf))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
42 no-save))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
43
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
44 (defun hbmap:dir-list ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
45 "Returns list of all directories in which user has written buttons."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
46 (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
47 (let ((buf (if (and (file-exists-p hbmap:dir-filename)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
48 (not (file-readable-p hbmap:dir-filename)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
49 nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
50 (find-file-noselect hbmap:dir-filename)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
51 (dirs))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
52 (if buf
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
53 (progn (set-buffer buf)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
54 (goto-char (point-min))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
55 (condition-case ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
56 (while (setq dirs (cons (car (read (current-buffer)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
57 dirs)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
58 (error t))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
59 dirs)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
60
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
61 (defun hbmap:dir-remove (dir-name &optional no-save)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
62 "Removes DIR-NAME from map of all dirs in which user has written buttons.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
63 Returns t iff DIR-NAME is in the map and is successfully removed, nil if it
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
64 is not, and some other value when the map is not readable or writable.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
65 Optional NO-SAVE disables saving of the map after a removal."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
66 (hbmap:dir-operate 'hbmap:dir-member dir-name
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
67 '(delete-region (point) (progn (forward-line 1) (point)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
68 no-save))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
69
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
70 (defun hbmap:dir-member (dir-name)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
71 "Returns t iff DIR-NAME is a member of user's Hyperbole map, else nil.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
72 If t, point is left at the start of the matching map entry. If nil,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
73 point is left in a position appropriate for insertion of a new entry."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
74 (let ((obuf (current-buffer))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
75 (buf (and (file-exists-p hbmap:dir-filename)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
76 (find-file-noselect hbmap:dir-filename)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
77 (rtn))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
78 (if buf
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
79 (progn (set-buffer buf) (widen) (goto-char 1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
80 (if (search-forward (concat "\n(\"" dir-name "\"") nil t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
81 (progn (beginning-of-line) (setq rtn t))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
82 (goto-char 1) (or (= (forward-line 1) 0) (insert "\n")))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
83 (set-buffer obuf)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
84 rtn))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
85
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
86 ;;; ************************************************************************
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
87 ;;; Private functions
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
88 ;;; ************************************************************************
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
89
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
90 (defun hbmap:dir-operate (pred dir-name form &optional no-save)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
91 "If PRED called on DIR-NAME is non-nil, evaluates FORM.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
92 Returns t if PRED evaluation is successful and nil when not, except when
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
93 hbmap is not readable or writable, in which case returns a symbol indicating
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
94 the error. Optional NO-SAVE disables saving of the map after operation."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
95 (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
96 (let ((buf (if (and (file-exists-p hbmap:dir-filename)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
97 (not (file-readable-p hbmap:dir-filename)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
98 nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
99 (find-file-noselect hbmap:dir-filename))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
100 (if buf
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
101 (progn (set-buffer buf)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
102 (if (funcall pred dir-name)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
103 (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
104 (setq buffer-read-only nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
105 (eval form)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
106 (if no-save t
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
107 (if (file-writable-p buffer-file-name)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
108 (progn (save-buffer) t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
109 'hbmap-not-writable)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
110 'hbmap-not-readable))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
111
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
112 ;;; ************************************************************************
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
113 ;;; Private variables
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
114 ;;; ************************************************************************
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
115
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
116 (defvar hbmap:dir-user
70
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 24
diff changeset
117 (if (memq system-type '(ms-windows windows-nt ms-dos))
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
118 "c:/_hyperb/" "~/.hyperb/")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
119 "Per user directory in which to store top level Hyperbole map data.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
120 Must end with a directory separator.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
121 Hyperbole will try to create it whenever 'hyperb:init' is called.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
122
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
123 (defvar hbmap:dir-filename
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
124 (expand-file-name "HBMAP" hbmap:dir-user)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
125 "Name of a file that lists all dirs to which a user has written buttons.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
126 See also 'hbmap:dir-user'.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
127 If you change its value, you will be unable to search for buttons created by
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
128 others who use a different value!")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
129
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
130 (provide 'hbmap)