annotate lisp/hyperbole/hbut.el @ 24:4103f0995bd7 r19-15b95

Import from CVS: tag r19-15b95
author cvs
date Mon, 13 Aug 2007 08:51:03 +0200
parents 376386a54a3c
children 131b0175ea99
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: hbut.el
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4 ;; SUMMARY: Hyperbole button constructs.
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: extensions, hypermedia
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
24
4103f0995bd7 Import from CVS: tag r19-15b95
cvs
parents: 0
diff changeset
9 ;; ORG: InfoDock Associates
0
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: 18-Sep-91 at 02:57:09
24
4103f0995bd7 Import from CVS: tag r19-15b95
cvs
parents: 0
diff changeset
12 ;; LAST-MOD: 17-Feb-97 at 15:31:03 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 ;;
24
4103f0995bd7 Import from CVS: tag r19-15b95
cvs
parents: 0
diff changeset
17 ;; Copyright (C) 1991-1996, Free Software Foundation, Inc.
0
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 ;;; Other required Elisp libraries
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 (require 'hmoccur)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
28 (require 'hbmap)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
29 (require 'htz)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
30 (require 'hbdata)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
31 (require 'hact)
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 ;;; Public definitions
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
35 ;;; ************************************************************************
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
36
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
37 ;;; ========================================================================
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
38 ;;; ebut class - Explicit Hyperbole buttons
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
39 ;;; ========================================================================
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
40
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
41 (defvar ebut:hattr-save t
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
42 "*Non-nil value saves button data when button source is saved.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
43 Nil disables saving.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
44
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
45 (defconst ebut:max-len 100
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
46 "Maximum length of a hyper-button label.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
47
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
48
24
4103f0995bd7 Import from CVS: tag r19-15b95
cvs
parents: 0
diff changeset
49 (defun ebut:act (label)
4103f0995bd7 Import from CVS: tag r19-15b95
cvs
parents: 0
diff changeset
50 "Activates Hyperbole explicit button with LABEL from the current buffer."
4103f0995bd7 Import from CVS: tag r19-15b95
cvs
parents: 0
diff changeset
51 (interactive (list (hargs:read-match "Activate explicit button labeled: "
4103f0995bd7 Import from CVS: tag r19-15b95
cvs
parents: 0
diff changeset
52 (ebut:alist)
4103f0995bd7 Import from CVS: tag r19-15b95
cvs
parents: 0
diff changeset
53 nil t nil 'ebut)))
4103f0995bd7 Import from CVS: tag r19-15b95
cvs
parents: 0
diff changeset
54 (let* ((lbl-key (hbut:label-to-key label))
4103f0995bd7 Import from CVS: tag r19-15b95
cvs
parents: 0
diff changeset
55 (but (ebut:get lbl-key)))
4103f0995bd7 Import from CVS: tag r19-15b95
cvs
parents: 0
diff changeset
56 (if but
4103f0995bd7 Import from CVS: tag r19-15b95
cvs
parents: 0
diff changeset
57 (hbut:act but)
4103f0995bd7 Import from CVS: tag r19-15b95
cvs
parents: 0
diff changeset
58 (error "(ebut:act): No explicit button labeled: %s" label))))
4103f0995bd7 Import from CVS: tag r19-15b95
cvs
parents: 0
diff changeset
59
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
60 (defun ebut:alist (&optional file)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
61 "Returns alist with each element a list containing a button label.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
62 For use as a completion table. Gets labels from optional FILE or current
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
63 buffer."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
64 (mapcar 'list (ebut:list file)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
65
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
66 (defun ebut:at-p (&optional start-delim end-delim)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
67 "Returns explicit Hyperbole button at point or nil.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
68 Assumes point is within first line of button label, if at all.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
69 Optional START-DELIM and END-DELIM are strings that override default
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
70 button delimiters."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
71 (let ((key (ebut:label-p nil start-delim end-delim)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
72 (and key (ebut:get key))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
73
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
74 (defun ebut:create (&optional but-sym)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
75 "Creates Hyperbole explicit button based on optional BUT-SYM.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
76 Default is 'hbut:current'.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
77 Button should hold the following attributes (see 'hattr:set'):
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
78 lbl-key (normalized button label string),
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
79 loc (filename or buffer where button is located),
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
80 dir (directory name where button is located),
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
81 actype (action type that provides a default action for the button),
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
82 action (optional action that overrides the default),
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
83 args (list of arguments for action, if action takes a single
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
84 argument of the button lbl-key, args may be nil).
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
85
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
86 If successful returns any instance number to append to button label
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
87 except when instance number would be 1, then returns t. On failure,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
88 returns nil.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
89
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
90 If successful, leaves point in button data buffer, so caller should use
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
91 'save-excursion'. Does not save button data buffer."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
92 (let ((lbl-instance (hbdata:write nil but-sym)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
93 (run-hooks 'ebut:create-hook)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
94 lbl-instance))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
95
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
96 (defun ebut:delete (&optional but-sym)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
97 "Deletes Hyperbole explicit button based on optional BUT-SYM.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
98 Default is 'hbut:current'.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
99 Returns entry deleted (a list of attribute values) or nil."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
100 (if (null but-sym) (setq but-sym 'hbut:current))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
101 (if (ebut:is-p but-sym)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
102 (let* ((but-key (hattr:get but-sym 'lbl-key))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
103 (loc (hattr:get but-sym 'loc))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
104 (entry (hbdata:delete-entry but-key loc)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
105 (run-hooks 'ebut:delete-hook)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
106 entry)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
107
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
108 (defun ebut:get (&optional lbl-key buffer key-src)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
109 "Returns explicit Hyperbole button symbol given by LBL-KEY and BUFFER.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
110 KEY-SRC is given when retrieving global buttons and is full source pathname.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
111 Retrieves button data, converts into a button object and returns a symbol
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
112 which references the button.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
113
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
114 All arguments are optional. When none are given, returns symbol for
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
115 button that point is within or nil. BUFFER defaults to the current
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
116 buffer."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
117 (hattr:clear 'hbut:current)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
118 (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
119 (let ((key-file) (key-dir) (but-data) (actype))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
120 (or lbl-key (setq lbl-key (ebut:label-p)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
121 (if buffer
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
122 (if (bufferp buffer) (set-buffer buffer)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
123 (error "(ebut:get): Invalid buffer argument: %s" buffer)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
124 (if key-src
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
125 nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
126 (if (equal lbl-key (ebut:label-p))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
127 nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
128 (goto-char (point-min))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
129 (ebut:next-occurrence lbl-key))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
130 (if (setq key-src (ebut:key-src 'full))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
131 ;; 'ebut:key-src' sets current buffer to key-src buffer.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
132 (setq buffer (current-buffer)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
133 )
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
134 (if (and (stringp lbl-key) key-src)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
135 (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
136 (if (stringp key-src)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
137 (setq key-dir (file-name-directory key-src)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
138 key-file (file-name-nondirectory key-src)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
139 (setq but-data (and key-src
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
140 (hbdata:get-entry lbl-key (or key-file key-src)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
141 key-dir)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
142 (if (null but-data)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
143 nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
144 (hattr:set 'hbut:current 'lbl-key lbl-key)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
145 (hattr:set 'hbut:current 'loc key-src)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
146 (hattr:set 'hbut:current 'categ 'explicit)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
147 (hattr:set 'hbut:current 'action nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
148 (hattr:set 'hbut:current 'actype
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
149 (intern (setq actype (hbdata:actype but-data))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
150 ;; Hyperbole V1 referent compatibility
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
151 (if (= (length actype) 2)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
152 (hattr:set 'hbut:current 'referent
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
153 (hbdata:referent but-data)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
154 (hattr:set 'hbut:current 'args (hbdata:args but-data))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
155 (hattr:set 'hbut:current 'creator (hbdata:creator but-data))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
156 (hattr:set 'hbut:current
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
157 'create-time (hbdata:create-time but-data))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
158 (hattr:set 'hbut:current
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
159 'modifier (hbdata:modifier but-data))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
160 (hattr:set 'hbut:current
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
161 'mod-time (hbdata:mod-time but-data))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
162 'hbut:current)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
163 )))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
164
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
165 (defun ebut:is-p (object)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
166 "Returns non-nil if OBJECT denotes an explicit Hyperbole button."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
167 (and (symbolp object)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
168 (eq (hattr:get object 'categ) 'explicit)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
169
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
170 (defun ebut:key-of-label-p (key label)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
171 "Returns t iff KEY matches to LABEL in a case insensitive manner."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
172 (and (stringp key) (stringp label)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
173 (equal key (downcase (ebut:label-to-key label)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
174
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
175 (defun ebut:key-src (&optional full)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
176 "Return key source (usually unqualified) for current Hyperbole button.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
177 Also sets current buffer to key source.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
178 With optional FULL when source is a pathname, the full pathname is returned."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
179 (let ((src (cond ((hmail:mode-is-p) (current-buffer))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
180 ((ebut:key-src-fmt))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
181 ((save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
182 (save-restriction
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
183 (widen)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
184 (if (and (search-backward hbut:source-prefix nil t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
185 (or (memq (preceding-char) '(?\n ?\^M))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
186 (= (point) (point-min))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
187 (hbut:source full)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
188 (buffer-file-name
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
189 (if full buffer-file-name
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
190 (file-name-nondirectory buffer-file-name)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
191 (t (current-buffer))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
192 )))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
193 (cond ((null src) nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
194 ((bufferp src)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
195 (set-buffer src)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
196 src)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
197 ((file-readable-p src)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
198 (set-buffer (find-file-noselect src))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
199 src)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
200 ((file-readable-p (setq src (hpath:symlink-referent src)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
201 (set-buffer (find-file-noselect src))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
202 src))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
203
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
204 (defun ebut:key-src-fmt ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
205 "Returns unformatted filename associated with formatted current buffer.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
206 This is used to obtain the source of explicit buttons for buffers that
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
207 represent the output of particular document formatters."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
208 (cond ((or (eq major-mode 'Info-mode)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
209 (string-match "\\.info\\(-[0-9]+\\)?$" (buffer-name)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
210 (let ((src (and buffer-file-name
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
211 (substring
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
212 buffer-file-name
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
213 0 (string-match "\\.[^.]+$" buffer-file-name)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
214 (cond ((file-exists-p (concat src ".texi"))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
215 (concat src ".texi"))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
216 ((file-exists-p (concat src ".texinfo"))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
217 (concat src ".texinfo"))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
218 ((current-buffer)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
219 ))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
220
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
221 (defun ebut:key-to-label (lbl-key)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
222 "Unnormalizes LBL-KEY and returns a label string approximating actual label."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
223 (if lbl-key
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
224 (let* ((pos 0) (len (length lbl-key)) (lbl) c)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
225 (while (< pos len)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
226 (setq c (aref lbl-key pos)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
227 lbl (concat lbl
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
228 (if (= c ?_)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
229 (if (or (= (1+ pos) len)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
230 (/= (aref lbl-key (1+ pos)) ?_))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
231 " "
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
232 (setq pos (1+ pos))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
233 "_")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
234 (char-to-string c)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
235 pos (1+ pos)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
236 lbl)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
237
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
238 (defun ebut:label-p (&optional as-label start-delim end-delim pos-flag)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
239 "Returns key for Hyperbole button label that point is within.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
240 Returns nil if not within a label.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
241 Assumes point is within first line of button label, if at all.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
242 If optional AS-LABEL is non-nil, label is returned rather than the key
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
243 derived from the label. Optional START-DELIM and END-DELIM are strings
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
244 that override default button delimiters. With optional POS-FLAG non-nil,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
245 returns list of label-or-key, but-start-position, but-end-position.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
246 Positions include delimiters."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
247 (let ((opoint (point))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
248 (npoint (1+ (point)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
249 (quoted "\\(^\\|[^\\{]\\)")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
250 (start)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
251 lbl-key end but-start but-end)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
252 (or start-delim (setq start-delim ebut:start))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
253 (or end-delim (setq end-delim ebut:end))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
254 (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
255 (beginning-of-line)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
256 (while (and (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
257 (while (re-search-forward
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
258 (concat quoted (regexp-quote start-delim))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
259 npoint t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
260 (setq start t))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
261 start)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
262 (re-search-forward (concat "[^\\{]" (regexp-quote end-delim))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
263 npoint t))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
264 (setq start nil))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
265 (if start
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
266 (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
267 (setq start (point)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
268 but-start (match-end 1))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
269 (if (= ?\( (char-syntax (preceding-char)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
270 (condition-case ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
271 (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
272 (forward-char -1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
273 (forward-list)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
274 (forward-char -2))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
275 (error (goto-char (1- opoint))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
276 (goto-char (1- opoint)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
277 (and (< (point) (+ start ebut:max-len))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
278 (re-search-forward (concat quoted (regexp-quote end-delim))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
279 (+ start ebut:max-len) t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
280 (setq but-end (point)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
281 end (- (point) (length end-delim))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
282 lbl-key (ebut:label-to-key (buffer-substring start end)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
283 (cond (pos-flag
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
284 (if as-label
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
285 (list (ebut:key-to-label lbl-key) but-start but-end)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
286 (list lbl-key but-start but-end)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
287 (t (if as-label (ebut:key-to-label lbl-key) lbl-key)))))))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
288
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
289 (defun ebut:label-regexp (lbl-key &optional no-delim)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
290 "Unnormalizes LBL-KEY. Returns regular expr matching delimited but label.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
291 Optional NO-DELIM leaves off delimiters and leading and trailing space."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
292 (if lbl-key
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
293 (let* ((pos 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
294 (len (length lbl-key))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
295 (c)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
296 (sep0 "[ \t\n\^M]*")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
297 (sep "[ \t\n\^M]+")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
298 (regexp (if no-delim "" (concat (regexp-quote ebut:start) sep0)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
299 (case-fold-search))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
300 (while (< pos len)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
301 (setq c (aref lbl-key pos)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
302 regexp (concat regexp
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
303 (if (= c ?_)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
304 (if (or (= (1+ pos) len)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
305 (/= (aref lbl-key (1+ pos)) ?_))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
306 sep
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
307 (setq pos (1+ pos))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
308 "_")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
309 (regexp-quote (char-to-string c))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
310 pos (1+ pos)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
311 (if no-delim regexp
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
312 (setq regexp (concat regexp sep0 (regexp-quote ebut:end)))))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
313
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
314 (defun ebut:label-to-key (label)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
315 "Normalizes LABEL for use as a Hyperbole button key and returns key.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
316 Eliminates any fill prefix in the middle of the label, replaces '_' with
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
317 '__', removes leading and trailing whitespace and replaces each other
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
318 whitespace sequence with '_'."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
319 (if (null label)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
320 nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
321 (setq label (hbut:fill-prefix-remove label)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
322 ;; Remove leading and trailing space.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
323 label (hypb:replace-match-string "\\`[ \t\n\^M]+\\|[ \t\n\^M]+\\'"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
324 label "" t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
325 label (hypb:replace-match-string "_" label "__" t))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
326 (hypb:replace-match-string "[ \t\n\^M]+" label "_" t)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
327
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
328 (defun ebut:list (&optional file loc-p)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
329 "Returns list of button labels from given FILE or current buffer.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
330 Removes duplicate labels if optional LOC-P is omitted. With LOC-P, returns
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
331 list of elements (label start end) where start and end are the buffer
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
332 positions at which the starting button delimiter begins and ends."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
333 (interactive)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
334 (setq file (if file (and (file-exists-p file) (find-file-noselect file))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
335 (current-buffer)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
336 (if file
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
337 (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
338 (set-buffer file)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
339 (let ((buts (ebut:map (if loc-p
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
340 (function
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
341 (lambda (lbl start end)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
342 ;; Normalize label spacing
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
343 (list (ebut:key-to-label
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
344 (ebut:label-to-key lbl))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
345 start end)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
346 (function
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
347 (lambda (lbl start end)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
348 ;; Normalize label spacing
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
349 (ebut:key-to-label
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
350 (ebut:label-to-key lbl))))))))
24
4103f0995bd7 Import from CVS: tag r19-15b95
cvs
parents: 0
diff changeset
351 (if loc-p buts (if buts (nreverse (set:create buts))))))))
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
352
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
353 (fset 'map-ebut 'ebut:map)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
354 (defun ebut:map (but-func &optional start-delim end-delim
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
355 regexp-match include-delims)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
356 "Applies BUT-FUNC to buttons delimited by optional START-DELIM and END-DELIM.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
357 If REGEXP-MATCH is non-nil, only buttons which match this argument are
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
358 considered.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
359 Maps over portion of buffer visible under any current restriction.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
360 BUT-FUNC must take precisely three arguments: the button label, the
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
361 start position of the delimited button label and its end position (positions
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
362 include delimiters when INCLUDE-DELIMS is non-nil).
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
363 If END-DELIM is a symbol, e.g. t, then START-DELIM is taken as a regular
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
364 expression which matches an entire button string."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
365 (or start-delim (setq start-delim ebut:start))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
366 (or end-delim (setq end-delim ebut:end))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
367 (let* ((regexp (symbolp end-delim))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
368 (end-sym (or regexp (substring end-delim -1)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
369 (rtn)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
370 (quoted)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
371 start end but lbl)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
372 (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
373 (goto-char (point-min))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
374 (setq include-delims (if include-delims 0 1))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
375 (while (re-search-forward
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
376 (if regexp start-delim
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
377 (concat (regexp-quote start-delim)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
378 "\\([^" end-sym "\"][^" end-sym "]*\\)"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
379 (regexp-quote end-delim)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
380 nil t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
381 (setq start (match-beginning include-delims)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
382 end (match-end include-delims)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
383 but (buffer-substring (match-beginning 0) (match-end 0))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
384 lbl (buffer-substring (match-beginning 1) (match-end 1)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
385 (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
386 (goto-char start)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
387 (if (or (= (preceding-char) ?\\) (= (preceding-char) ?\{))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
388 ;; Ignore matches with quoted delimiters.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
389 (setq quoted t)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
390 (cond (quoted (setq quoted nil))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
391 ((or (not regexp-match)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
392 (string-match regexp-match but))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
393 (setq rtn (cons (funcall but-func lbl start end) rtn))))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
394 (nreverse rtn)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
395
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
396 (defun ebut:modify (&optional lbl-key but-sym)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
397 "Modifies existing Hyperbole button from optional LBL-KEY and BUT-SYM.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
398 Defaults are the key for any button label at point and 'hbut:current'.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
399 If successful, returns button's instance number except when instance
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
400 number is 1, then returns t. On failure, as when button does not exist,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
401 returns nil.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
402
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
403 If successful, leaves point in button data buffer, so caller should use
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
404 'save-excursion'. Does not save button data buffer."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
405 (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
406 (let ((lbl-instance (hbdata:write lbl-key but-sym)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
407 (run-hooks 'ebut:modify-hook)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
408 lbl-instance)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
409
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
410 (defun ebut:next-occurrence (lbl-key &optional buffer)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
411 "Moves point to next occurrence of button with LBL-KEY in optional BUFFER.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
412 BUFFER defaults to current buffer. It may be a buffer name.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
413 Returns non-nil iff occurrence is found.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
414
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
415 Remember to use (goto-char (point-min)) before calling this in order to
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
416 move to the first occurrence of the button."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
417 (if buffer
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
418 (if (not (or (bufferp buffer)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
419 (and (stringp buffer) (get-buffer buffer))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
420 (error "(ebut:next-occurrence): Invalid buffer arg: %s" buffer)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
421 (switch-to-buffer buffer)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
422 (if (re-search-forward (ebut:label-regexp lbl-key) nil t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
423 (goto-char (+ (match-beginning 0) (length ebut:start)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
424
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
425 (defun ebut:operate (curr-label new-label)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
426 "Operates on a new or existing Hyperbole button given by CURR-LABEL.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
427 When NEW-LABEL is non-nil, this is substituted for CURR-LABEL and the
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
428 associated button is modified. Otherwise, a new button is created.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
429 Returns instance string appended to label to form unique label, nil if
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
430 label is already unique. Signals an error when no such button is found
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
431 in the current buffer."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
432 (let* ((lbl-key (ebut:label-to-key curr-label))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
433 (lbl-regexp (ebut:label-regexp lbl-key))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
434 (modify new-label)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
435 (instance-flag))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
436 (or new-label (setq new-label curr-label))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
437 (hattr:set 'hbut:current 'lbl-key (ebut:label-to-key new-label))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
438 (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
439 (if (setq instance-flag
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
440 (if modify (ebut:modify lbl-key) (ebut:create)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
441 (if (hmail:editor-p) (hmail:msg-narrow))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
442 (if instance-flag
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
443 (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
444 ;; Rename all occurrences of button - those with same label.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
445 (if modify
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
446 (let* ((but-key-and-pos (ebut:label-p nil nil nil 'pos))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
447 (at-but (equal (car but-key-and-pos)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
448 (ebut:label-to-key new-label))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
449 (if at-but
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
450 (ebut:delimit (nth 1 but-key-and-pos)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
451 (nth 2 but-key-and-pos)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
452 instance-flag))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
453 (cond ((ebut:map
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
454 (function
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
455 (lambda (lbl start end)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
456 (delete-region start end)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
457 (ebut:delimit
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
458 (point)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
459 (progn (insert new-label) (point))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
460 instance-flag)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
461 nil nil lbl-regexp 'include-delims))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
462 (at-but)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
463 ((hypb:error "(ebut:operate): No button matching: %s" curr-label))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
464 ;; Add a new button.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
465 (let (start end buf-lbl)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
466 (cond ((and (marker-position (hypb:mark-marker t))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
467 (setq start (region-beginning)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
468 end (region-end)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
469 buf-lbl (buffer-substring start end))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
470 (equal buf-lbl curr-label))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
471 nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
472 ((looking-at (regexp-quote curr-label))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
473 (setq start (point)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
474 end (match-end 0)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
475 (t (setq start (point))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
476 (insert curr-label)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
477 (setq end (point))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
478 (ebut:delimit start end instance-flag))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
479 )
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
480 ;; Position point
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
481 (let ((new-key (ebut:label-to-key new-label)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
482 (cond ((equal (ebut:label-p) new-key)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
483 (forward-char 1) (search-backward ebut:start nil t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
484 (goto-char (match-end 0)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
485 ((let ((regexp (ebut:label-regexp new-key)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
486 (or (re-search-forward regexp nil t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
487 (re-search-backward regexp nil t)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
488 (goto-char (+ (match-beginning 0) (length ebut:start))))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
489 ;; instance-flag might be 't which we don't want to return.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
490 (if (stringp instance-flag) instance-flag))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
491 (hypb:error
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
492 "(ebut:operate): Operation failed. Check button attribute permissions: %s"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
493 hattr:filename))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
494
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
495 (defun ebut:search (string out-buf &optional match-part)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
496 "Writes explicit button lines matching STRING to OUT-BUF.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
497 Uses Hyperbole space into which user has written buttons for the search.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
498 By default, only matches for whole button labels are found, optional MATCH-PART
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
499 enables partial matches."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
500 (let* ((buffers (mapcar (function
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
501 (lambda (dir)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
502 (expand-file-name hattr:filename dir)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
503 (hbmap:dir-list)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
504 (total 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
505 (firstmatch))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
506 (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
507 (set-buffer out-buf)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
508 (setq buffer-read-only nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
509 (widen)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
510 (erase-buffer)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
511 (let (currbuf currfile kill-buf src-matches dir)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
512 (while buffers
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
513 (setq currbuf (car buffers)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
514 currfile (if (stringp currbuf) currbuf)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
515 kill-buf (and currfile (not (get-file-buffer currfile)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
516 buffers (cdr buffers))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
517 (if currfile
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
518 (setq currbuf (and (file-readable-p currfile)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
519 (find-file-noselect currfile))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
520 dir (file-name-directory currfile))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
521 (setq currfile (buffer-file-name currbuf)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
522 (and currfile currbuf
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
523 (unwind-protect
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
524 (setq src-matches
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
525 (hbdata:search currbuf string match-part))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
526 (if kill-buf (kill-buffer currbuf))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
527 (if src-matches
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
528 (let (elt matches)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
529 (while src-matches
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
530 (setq elt (car src-matches))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
531 (if (null elt) nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
532 (setq src-matches (cdr src-matches)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
533 currfile (expand-file-name (car elt) dir)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
534 matches (cdr elt)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
535 currbuf (get-file-buffer currfile)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
536 kill-buf (not currbuf)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
537 currbuf (or currbuf
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
538 (and (file-readable-p currfile)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
539 (find-file-noselect currfile))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
540 (if (null currbuf)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
541 (progn (set-buffer out-buf)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
542 (insert "ERROR: (ebut:search): \"" currfile
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
543 "\" is not readable.\n\n"))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
544 (set-buffer currbuf)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
545 (unwind-protect
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
546 (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
547 (widen) (goto-char 1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
548 (let ((case-fold-search t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
549 (regexp
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
550 (ebut:match-regexp matches match-part)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
551 (setq firstmatch t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
552 (while (re-search-forward regexp nil t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
553 (setq total (1+ total))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
554 (let* ((linenum (count-lines (point-min)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
555 (point)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
556 (tag (format "\n%4d:" linenum))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
557 lns start end)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
558 (setq end (progn (end-of-line) (point))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
559 start (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
560 (goto-char (match-beginning 0))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
561 (beginning-of-line) (point))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
562 lns (buffer-substring start end))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
563 (goto-char end)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
564 (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
565 (set-buffer out-buf)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
566 (if firstmatch
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
567 (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
568 (insert hbut:source-prefix "\""
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
569 currfile "\"\n")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
570 (setq firstmatch nil)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
571 (insert tag lns))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
572 (set-buffer out-buf)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
573 (if (not firstmatch) (insert "\n\n"))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
574 (if kill-buf (kill-buffer currbuf)))))))))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
575 total))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
576
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
577 ;;; ------------------------------------------------------------------------
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
578 (defun ebut:delimit (start end instance-str)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
579 "Delimits button label spanning region START to END in current buffer.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
580 If button is already delimited or delimit fails, returns nil, else t.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
581 Inserts INSTANCE-STR after END, before ending delimiter."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
582 (goto-char start)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
583 (if (looking-at (regexp-quote ebut:start))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
584 (forward-char (length ebut:start)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
585 (if (ebut:label-p)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
586 nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
587 (if (not (stringp instance-str)) (setq instance-str ""))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
588 (insert ebut:start)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
589 (goto-char (setq end (+ end (length ebut:start))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
590 (insert instance-str ebut:end)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
591 (setq end (+ end (length instance-str) (length ebut:end)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
592 (and (fboundp 'hproperty:but-add) (hproperty:but-add start end hproperty:but))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
593 (hbut:comment start end)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
594 (goto-char end)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
595 t))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
596
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
597 (defun ebut:match-regexp (match-keys match-part)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
598 "Returns regexp to match to all explicit button keys from MATCH-KEYS."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
599 (setq match-part (if match-part
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
600 (concat "[^" (substring ebut:end -1) "]*")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
601 "[ \t\n]*"))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
602 (concat
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
603 (regexp-quote ebut:start) match-part
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
604 "\\(" (mapconcat (function
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
605 (lambda (key) (ebut:label-regexp key 'no-delim)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
606 match-keys "\\|")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
607 "\\)" match-part (regexp-quote ebut:end)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
608
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
609 (defconst ebut:start "<("
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
610 "String matching the start of a hyper-button.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
611 (defconst ebut:end ")>"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
612 "String matching the end of a hyper-button.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
613 (defconst ebut:instance-sep ":"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
614 "String of one character, separates an ebut label from its instance num.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
615
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
616 ;;; ========================================================================
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
617 ;;; gbut class - Global Hyperbole buttons - activated by typing label name
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
618 ;;; ========================================================================
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
619
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
620 (defvar gbut:file (expand-file-name hbmap:filename hbmap:dir-user)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
621 "File that stores Hyperbole buttons accessible by name, global buttons.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
622
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
623 (defun gbut:act (label)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
624 "Activates Hyperbole global button with LABEL."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
625 (interactive (list (hargs:read-match "Activate global button labeled: "
24
4103f0995bd7 Import from CVS: tag r19-15b95
cvs
parents: 0
diff changeset
626 (mapcar 'list (gbut:label-list))
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
627 nil t nil 'ebut)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
628 (let* ((lbl-key (hbut:label-to-key label))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
629 (but (ebut:get lbl-key nil gbut:file)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
630 (if but
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
631 (hbut:act but)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
632 (error "(gbut:act): No global button labeled: %s" label))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
633
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
634 (defun gbut:help (label)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
635 "Displays help for Hyperbole global button with LABEL."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
636 (interactive (list (hargs:read-match "Report on global button labeled: "
24
4103f0995bd7 Import from CVS: tag r19-15b95
cvs
parents: 0
diff changeset
637 (mapcar 'list (gbut:label-list))
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
638 nil t nil 'ebut)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
639 (let* ((lbl-key (hbut:label-to-key label))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
640 (but (ebut:get lbl-key nil gbut:file)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
641 (if but
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
642 (hbut:report but)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
643 (error "(gbut:help): No global button labeled: %s" label))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
644
24
4103f0995bd7 Import from CVS: tag r19-15b95
cvs
parents: 0
diff changeset
645 (defun gbut:label-list ()
4103f0995bd7 Import from CVS: tag r19-15b95
cvs
parents: 0
diff changeset
646 "Returns list of global button labels."
4103f0995bd7 Import from CVS: tag r19-15b95
cvs
parents: 0
diff changeset
647 (mapcar 'hbut:key-to-label (gbut:key-list)))
4103f0995bd7 Import from CVS: tag r19-15b95
cvs
parents: 0
diff changeset
648
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
649 ;;; ------------------------------------------------------------------------
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
650 (defun gbut:key-list ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
651 "Returns list of global button label keys."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
652 (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
653 (if (hbdata:to-entry-buf gbut:file)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
654 (let ((gbuts))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
655 (save-restriction
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
656 (narrow-to-region (point) (if (search-forward "\^L" nil t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
657 (point) (point-max)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
658 (goto-char (point-min))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
659 (condition-case ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
660 (while (setq gbuts (cons (car (read (current-buffer))) gbuts)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
661 (error nil))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
662 gbuts)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
663
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
664 ;;; ========================================================================
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
665 ;;; hattr class
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
666 ;;; ========================================================================
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
667
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
668 (defun hattr:attributes (obj-symbol)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
669 "Returns a list of OBJ-SYMBOL's attributes as symbols."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
670 (if (symbolp obj-symbol)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
671 (let* ((attr-val-list (symbol-plist obj-symbol))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
672 (i -1))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
673 (delq nil (mapcar (function
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
674 (lambda (elt)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
675 (setq i (1+ i))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
676 (and (= (% i 2) 0) elt)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
677 attr-val-list)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
678
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
679 (defun hattr:clear (hbut)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
680 "Removes all of HBUT's attributes except `variable-documentation'."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
681 (let (sublist)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
682 (or (symbolp hbut)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
683 (error "(hattr:clear): Argument not a Hyperbole button: %s" hbut))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
684 (if (setq sublist (memq 'variable-documentation (symbol-plist hbut)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
685 (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
686 (setcdr (cdr sublist) nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
687 (setplist hbut sublist))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
688 (setplist hbut nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
689 )))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
690
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
691 (defun hattr:copy (from-hbut to-hbut)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
692 "Copies attributes FROM-HBUT TO-HBUT, eliminating attributes TO-HBUT had.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
693 Returns TO-HBUT."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
694 (mapcar
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
695 (function
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
696 (lambda (hbut)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
697 (or (and hbut (symbolp hbut))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
698 (error "(hattr:clear): Argument not a Hyperbole button: %s" hbut))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
699 (list from-hbut to-hbut))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
700 (unwind-protect
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
701 nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
702 (hattr:clear to-hbut)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
703 (setplist to-hbut (copy-sequence (symbol-plist from-hbut))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
704 to-hbut)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
705
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
706 (defun hattr:get (obj-symbol attr-symbol)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
707 "Returns value of OBJ-SYMBOL's attribute ATTR-SYMBOL."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
708 (get obj-symbol attr-symbol))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
709
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
710 (defun hattr:list (obj-symbol)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
711 "Returns a property list of OBJ-SYMBOL's attributes.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
712 Each pair of elements is: <attrib-name> <attrib-value>."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
713 (if (symbolp obj-symbol)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
714 (symbol-plist obj-symbol)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
715 (error "(hattr:list): Argument not a symbol: %s" obj-symbol)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
716
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
717 (defun hattr:memq (attr-symbol obj-symbol)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
718 "Returns t if ATTR-SYMBOL is in OBJ-SYMBOL's attribute list, else nil."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
719 (and (symbolp obj-symbol) (symbolp attr-symbol)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
720 (let* ((attr-val-list (symbol-plist obj-symbol))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
721 (attr-list (let ((i -1))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
722 (delq nil (mapcar
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
723 (function
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
724 (lambda (elt)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
725 (setq i (1+ i))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
726 (and (= (% i 2) 0) elt)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
727 attr-val-list)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
728 (if (memq attr-symbol attr-list) t))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
729
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
730 (defun hattr:report (attrib-list)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
731 "Pretty prints to standard-output attribute-value pairs from ATTRIB-LIST.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
732 Ignores nil valued attributes. Returns t unless no attributes are printed."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
733 (let ((has-attr) attr val len)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
734 (if (or (null attrib-list) (not (listp attrib-list))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
735 ;; odd number of elements?
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
736 (= (% (length attrib-list) 2) 1))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
737 nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
738 (while (setq attr (car attrib-list))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
739 (setq val (car (setq attrib-list (cdr attrib-list)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
740 attrib-list (cdr attrib-list))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
741 (if val
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
742 (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
743 (setq has-attr t
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
744 attr (symbol-name attr)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
745 len (max (- 16 (length attr)) 1))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
746 (princ " ") (princ attr) (princ ":")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
747 (princ (make-string len ? ))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
748 (let (str)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
749 (prin1 (cond ((string-match "time" attr)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
750 (htz:date-unix val
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
751 (and (>= (aref val 0) ?0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
752 (<= (aref val 0) ?9)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
753 "GMT") htz:local))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
754 ((and (setq str (if (stringp val) val
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
755 (prin1-to-string val)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
756 (string-match "\\`actypes::" str))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
757 (intern (substring str (match-end 0))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
758 (t val))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
759 (terpri))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
760 has-attr)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
761
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
762 (defun hattr:save ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
763 "Saves button attribute file for current directory, if modified.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
764 Suitable for use as part of 'write-file-hooks'."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
765 (let* ((bd-file (expand-file-name hattr:filename default-directory))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
766 (buf (and (stringp default-directory)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
767 (get-file-buffer bd-file))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
768 (if (and ebut:hattr-save buf (not (eq buf (current-buffer))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
769 (let ((ebut:hattr-save));; Prevents 'write-file-hooks' looping.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
770 (and (buffer-modified-p buf)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
771 (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
772 (set-buffer buf) (save-buffer)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
773 ;; Unlock button attribute file; kill buffer so user is
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
774 ;; never holding a buffer which is out of sync with file,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
775 ;; due to some other user's edits.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
776 ;; Maybe this should be user or site configurable.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
777 (or (buffer-modified-p buf) (kill-buffer buf))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
778 )))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
779 ;; Must return nil, so can be used as part of write-file-hooks.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
780 nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
781
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
782 (defun hattr:set (obj-symbol attr-symbol attr-value)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
783 "Sets OBJ-SYMBOL's attribute ATTR-SYMBOL to ATTR-VALUE."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
784 (put obj-symbol attr-symbol attr-value))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
785
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
786 (fset 'hattr:summarize 'hattr:report)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
787
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
788 (defvar hattr:filename
24
4103f0995bd7 Import from CVS: tag r19-15b95
cvs
parents: 0
diff changeset
789 (if hyperb:microcruft-os-p "_hypb" ".hypb")
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
790 "Per directory file name in which explicit button attributes are stored.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
791 If you change its value, you will be unable to use buttons created by
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
792 others who use a different value!")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
793
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
794 ;;; ========================================================================
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
795 ;;; hbut class - abstract
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
796 ;;; ========================================================================
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
797
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
798 (defun hbut:act (hbut)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
799 "Performs action for explicit or implicit Hyperbole button symbol HBUT."
24
4103f0995bd7 Import from CVS: tag r19-15b95
cvs
parents: 0
diff changeset
800 (if hbut (apply 'actype:act (hattr:get hbut 'actype)
4103f0995bd7 Import from CVS: tag r19-15b95
cvs
parents: 0
diff changeset
801 (hattr:get hbut 'args))))
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
802
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
803 (defun hbut:action (hbut)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
804 "Returns appropriate action for Hyperbole button symbol HBUT."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
805 (let ((categ (hattr:get hbut 'categ)) (atype) (action))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
806 (if (eq categ 'explicit)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
807 (progn (setq action (hattr:get hbut 'action)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
808 atype (hattr:get hbut 'actype))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
809 (if (= (length (symbol-name atype)) 2)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
810 atype
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
811 (or action (actype:action atype))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
812 ;; Must be an implicit button.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
813 (if (fboundp atype) atype))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
814
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
815 (defun hbut:at-p ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
816 "Returns symbol for explicit or implicit Hyperbole button at point or nil."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
817 (or (ebut:at-p) (ibut:at-p)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
818
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
819
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
820 (defun hbut:comment (start end)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
821 "Comment button label spanning region START to END in current buffer.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
822 Use buffer commenting grammar, if any, otherwise don't comment."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
823 (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
824 (if comment-start
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
825 (if (or (equal comment-end "")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
826 (null comment-end))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
827 (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
828 (beginning-of-line)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
829 (if (search-forward comment-start start t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
830 nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
831 (goto-char start)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
832 (insert comment-start)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
833 (if (/= (preceding-char) ? )
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
834 (insert ? ))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
835 ;; Comments have both start and end delimiters
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
836 (if (and (re-search-backward
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
837 (concat (regexp-quote comment-start) "\\|"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
838 (regexp-quote comment-end))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
839 nil t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
840 (looking-at (regexp-quote comment-start)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
841 nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
842 (goto-char start)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
843 (insert comment-start)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
844 (if (/= (preceding-char) ? )
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
845 (insert ? ))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
846 (goto-char (+ (point) (- end start)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
847 (if (/= (following-char) ? )
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
848 (insert ? ))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
849 (insert comment-end)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
850 )))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
851
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
852 ;;; Regexps derived in part from "filladapt.el" under the GPL, Copyright
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
853 ;;; 1989 Kyle E. Jones.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
854 (defvar hbut:fill-prefix-regexps
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
855 '(
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
856 ;; Included text in news or mail messages
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
857 "\n[ \t]*\\([:|<>]+ *\\)+"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
858 ;; Included text generated by SUPERCITE. We can't hope to match all
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
859 ;; the possible variations.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
860 "\n[ \t]*[^'`\"< \t]*> *"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
861 ;; Lisp comments
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
862 "\n[ \t]*\\(;+[ \t]*\\)+"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
863 ;; UNIX shell comments
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
864 "\n[ \t]*\\(#+[ \t]*\\)+"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
865 ;; C++ comments
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
866 "\n[ \t]*//[/ \t]+"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
867 ;; C or Pascal comments, one open and close per line, so match close
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
868 ;; then open.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
869 "\\*+[/\)][ \t]*\n+[ \t]*[/\(]\\*+"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
870 "}[ \t]*\n+[ \t]*{"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
871 ;; Eiffel or Sather comments
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
872 "\n[ \t]*--[ \t]+"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
873 ;; Fortran comments
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
874 "\n[Cc][ \t]+"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
875 ;; Postscript comments
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
876 "\n[ \t]*\\(%+[ \t]*\\)+"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
877 )
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
878 "List of regexps of fill prefixes to remove from the middle of buttons.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
879
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
880 (defun hbut:fill-prefix-remove (label)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
881 "Removes any recognized fill prefix from within LABEL.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
882 'hbut:fill-prefix-regexps' is a list of fill prefixes to recognize."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
883 (if (string-match "\n" label)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
884 (mapcar
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
885 (function
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
886 (lambda (fill-prefix)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
887 (and (string-match "\n" label)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
888 (setq label
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
889 (hypb:replace-match-string fill-prefix label " " t)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
890 hbut:fill-prefix-regexps))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
891 label)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
892
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
893 (defun hbut:is-p (object)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
894 "Returns non-nil if object denotes a Hyperbole button."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
895 (and (symbolp object) (hattr:get object 'categ)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
896
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
897 (fset 'hbut:key-src 'ebut:key-src)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
898 (fset 'hbut:key-to-label 'ebut:key-to-label)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
899
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
900 (defun hbut:label (hbut)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
901 "Returns the label for Hyperbole button symbol HBUT."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
902 (if (hbut:is-p hbut)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
903 (hbut:key-to-label (hattr:get hbut 'lbl-key))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
904 (error "(hbut:label): Argument is not a Hyperbole button symbol, '%s'"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
905 hbut)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
906
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
907 (fset 'hbut:label-p 'ebut:label-p)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
908 (fset 'hbut:label-to-key 'ebut:label-to-key)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
909
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
910 (defun hbut:report (&optional arg)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
911 "Pretty prints the attributes of a button or buttons.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
912
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
913 Takes an optional ARG interpreted as follows:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
914 a button symbol - report on that button;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
915 nil - report on button at point, if any;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
916 integer > 0 - report on all explicit buttons in buffer, alphabetize;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
917 integer < 1 - report on all explicit buttons in occurrence order;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
918
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
919 Returns number of buttons reported on or nil if none."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
920 (setq arg (cond ((or (integerp arg) (symbolp arg)) arg)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
921 ((listp arg)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
922 (if (integerp (setq arg (car arg))) arg 1))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
923 (t 1)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
924 (let* ((but (if (and arg (symbolp arg)) arg (hbut:at-p)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
925 (curr-key (and but (hattr:get but 'lbl-key)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
926 (key-src (or (and but (hattr:get but 'loc)) (hbut:key-src)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
927 (lbl-lst (cond ((not arg)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
928 (if curr-key (list (ebut:key-to-label curr-key))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
929 ((symbolp arg) (if curr-key
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
930 (list (hbut:key-to-label
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
931 (hattr:get arg 'lbl-key)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
932 ((< arg 1) (ebut:list))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
933 (t (sort (ebut:list)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
934 (function
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
935 (lambda (s1 s2)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
936 (string< (downcase s1) (downcase s2))))))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
937 (key-buf (current-buffer))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
938 (buf-name (hypb:help-buf-name))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
939 (attribs))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
940 (if lbl-lst
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
941 (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
942 (with-output-to-temp-buffer buf-name
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
943 (princ hbut:source-prefix)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
944 (prin1 key-src)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
945 (terpri)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
946 (terpri)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
947 (mapcar
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
948 (function
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
949 (lambda (lbl)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
950 (if (setq but
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
951 (cond ((or (null arg) (symbolp arg)) but)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
952 (t (ebut:get (ebut:label-to-key lbl) key-buf)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
953 attribs (hattr:list but))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
954 (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
955 (princ (if (ibut:is-p but)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
956 lbl
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
957 (concat ebut:start lbl ebut:end)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
958 (terpri)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
959 (let ((doc (actype:doc but (= 1 (length lbl-lst)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
960 (if doc
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
961 (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
962 (princ " ")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
963 (princ doc)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
964 (terpri))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
965 (hattr:report
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
966 ;; (if (eq (car (cdr (memq 'categ attribs))) 'explicit)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
967 ;; (memq 'action attribs)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
968 ;; (memq 'categ attribs))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
969 attribs)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
970 (terpri))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
971 )))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
972 lbl-lst))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
973 (length lbl-lst)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
974
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
975 (defun hbut:source (&optional full)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
976 "Returns Hyperbole source buffer or file given at point.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
977 If a file, always returns a full path if optional FULL is non-nil."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
978 (goto-char (match-end 0))
24
4103f0995bd7 Import from CVS: tag r19-15b95
cvs
parents: 0
diff changeset
979 (cond ((looking-at "#<buffer \"?\\([^ \n\"]+\\)\"?>")
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
980 (get-buffer (buffer-substring (match-beginning 1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
981 (match-end 1))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
982 ((looking-at "\".+\"")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
983 (let* ((file (buffer-substring (1+ (match-beginning 0))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
984 (1- (match-end 0))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
985 (absolute (file-name-absolute-p file)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
986 (if (and full (not absolute))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
987 (expand-file-name file default-directory)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
988 file)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
989
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
990 (fset 'hbut:summarize 'hbut:report)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
991
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
992 (defvar hbut:current nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
993 "Currently selected Hyperbole button.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
994 Available to action routines.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
995
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
996 (defconst hbut:source-prefix moccur-source-prefix
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
997 "String found at start of a buffer containing only a hyper-button menu.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
998 This expression should be followed immediately by a file-name indicating the
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
999 source file for the buttons in the menu, if any.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1000
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1001 ;;; ========================================================================
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1002 ;;; htype class - Hyperbole Types, e.g. action and implicit button types
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1003 ;;; ========================================================================
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1004
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1005 (require 'set)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1006
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1007 (defun htype:body (htype-sym)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1008 "Return body for HTYPE-SYM. If HTYPE-SYM is nil, return nil."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1009 (and htype-sym (hypb:indirect-function htype-sym)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1010
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1011 (defun htype:category (type-category)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1012 "Return list of symbols in Hyperbole TYPE-CATEGORY in priority order.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1013 Symbols contain category component.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1014 TYPE-CATEGORY should be 'actypes, 'ibtypes or nil for all."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1015 (let ((types (symset:get type-category 'symbols))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1016 (categ-name (symbol-name type-category)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1017 (mapcar (function
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1018 (lambda (type)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1019 (intern (concat categ-name "::" (symbol-name type)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1020 types)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1021
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1022 ;; Thanks to JWZ for help on this.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1023 (defmacro htype:create (type type-category doc params body property-list)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1024 "Create a new Hyperbole TYPE within TYPE-CATEGORY (both unquoted symbols).
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1025 Third arg DOC is a string describing the type.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1026 Fourth arg PARAMS is a list of parameters to send to the fifth arg BODY,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1027 which is a list of forms executed when the type is evaluated.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1028 Sixth arg PROPERTY-LIST is attached to the new type's symbol.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1029
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1030 This symbol is returned."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1031 (let* ((sym (htype:symbol type type-category))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1032 (action (nconc (list 'defun sym params doc) body)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1033 (` (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1034 (, action)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1035 (setplist '(, sym) (, property-list))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1036 (symset:add '(, type) '(, type-category) 'symbols)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1037 (run-hooks 'htype:create-hook)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1038 '(, sym)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1039
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1040 (defun htype:delete (type type-category)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1041 "Delete a Hyperbole TYPE derived from TYPE-CATEGORY (both symbols).
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1042 Return the Hyperbole symbol for the TYPE if it existed, else nil."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1043 (let* ((sym (htype:symbol type type-category))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1044 (exists (fboundp 'sym)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1045 (setplist sym nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1046 (symset:delete type type-category 'symbols)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1047 (fmakunbound sym)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1048 (run-hooks 'htype:delete-hook)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1049 (and exists sym)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1050
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1051 (defun htype:doc (type)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1052 "Return documentation for Hyperbole TYPE, a symbol."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1053 (documentation type))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1054
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1055 (defun htype:names (type-category &optional sym)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1056 "Return list of current names for Hyperbole TYPE-CATEGORY in priority order.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1057 Names do not contain category component.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1058 TYPE-CATEGORY should be 'actypes, 'ibtypes or nil for all.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1059 When optional SYM is given, return the name for that symbol only, if any."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1060 (let ((types (symset:get type-category 'symbols))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1061 (sym-name (and sym (symbol-name sym))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1062 (if sym-name
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1063 ;; Strip category from sym-name before looking for a match.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1064 (progn (if (string-match "::" sym-name)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1065 (setq sym (intern (substring sym-name (match-end 0)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1066 (if (memq sym types) (symbol-name sym)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1067 (mapcar 'symbol-name types))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1068
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1069 ;;; ------------------------------------------------------------------------
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1070
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1071 (defun htype:symbol (type type-category)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1072 "Return Hyperbole type symbol composed from TYPE and TYPE-CATEGORY (both symbols)."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1073 (intern (concat (symbol-name type-category) "::"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1074 (symbol-name type))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1075
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1076 ;;; ========================================================================
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1077 ;;; ibut class - Implicit Hyperbole Buttons
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1078 ;;; ========================================================================
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1079
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1080 (defun ibut:at-p (&optional key-only)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1081 "Returns symbol for implicit button at point, else nil.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1082 With optional KEY-ONLY, returns only the label key for button."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1083 (let ((types (htype:category 'ibtypes))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1084 ;; Global var used in (hact) function, don't delete.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1085 (hrule:action 'actype:identity)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1086 (itype)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1087 (args)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1088 (is-type))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1089 (or key-only (hattr:clear 'hbut:current))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1090 (while (and (not is-type) types)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1091 (setq itype (car types))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1092 (if (setq args (funcall itype))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1093 (setq is-type itype)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1094 (setq types (cdr types))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1095 (if is-type
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1096 (if key-only
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1097 (hattr:get 'hbut:current 'lbl-key)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1098 (hattr:set 'hbut:current 'loc (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1099 (hbut:key-src 'full)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1100 (hattr:set 'hbut:current 'categ is-type)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1101 (or (hattr:get 'hbut:current 'args)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1102 (not (listp args))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1103 (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1104 (hattr:set 'hbut:current 'actype
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1105 (or
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1106 ;; Hyperbole action type
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1107 (intern-soft (concat "actypes::"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1108 (symbol-name (car args))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1109 ;; Regular Emacs Lisp function symbol
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1110 (car args)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1111 ))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1112 (hattr:set 'hbut:current 'args (cdr args))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1113 'hbut:current))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1114
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1115 (defun ibut:is-p (object)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1116 "Returns non-nil if object denotes an implicit Hyperbole button."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1117 (if (symbolp object)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1118 (let ((categ (hattr:get object 'categ)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1119 (and categ (string-match "^ibtypes::" (symbol-name categ))))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1120
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1121 (defun ibut:label-p ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1122 "Returns key for Hyperbole implicit button label that point is on or nil."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1123 (ibut:at-p 'key-only))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1124
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1125 (defun ibut:label-set (label &optional start end)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1126 "Sets current implicit button attributes from LABEL and START, END position.
24
4103f0995bd7 Import from CVS: tag r19-15b95
cvs
parents: 0
diff changeset
1127 Returns label. START and END are optional. When given, they specify the
4103f0995bd7 Import from CVS: tag r19-15b95
cvs
parents: 0
diff changeset
1128 region in the buffer to flash when this implicit button is activated or
4103f0995bd7 Import from CVS: tag r19-15b95
cvs
parents: 0
diff changeset
1129 queried for its attributes. If LABEL is a list, it is assumed to contain all
4103f0995bd7 Import from CVS: tag r19-15b95
cvs
parents: 0
diff changeset
1130 arguments."
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1131 (cond ((stringp label)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1132 (hattr:set 'hbut:current 'lbl-key (hbut:label-to-key label))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1133 (and start (hattr:set 'hbut:current 'lbl-start start))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1134 (and end (hattr:set 'hbut:current 'lbl-end end)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1135 ((and label (listp label))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1136 (hattr:set 'hbut:current 'lbl-key (hbut:label-to-key (car label)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1137 (hattr:set 'hbut:current 'lbl-start (nth 1 label))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1138 (hattr:set 'hbut:current 'lbl-end (nth 2 label)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1139 (t (error "(ibut:label-set): Invalid label arg: '%s'" label)))
24
4103f0995bd7 Import from CVS: tag r19-15b95
cvs
parents: 0
diff changeset
1140 label)
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1141
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1142 ;;; ========================================================================
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1143 ;;; ibtype class - Implicit button types
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1144 ;;; ========================================================================
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1145
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1146 (fset 'defib 'ibtype:create)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1147 (put 'ibtype:create 'lisp-indent-function 'defun)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1148 (defmacro ibtype:create (type params doc at-p &optional to-p style)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1149 "Creates implicit button TYPE (unquoted sym) with PARAMS, described by DOC.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1150 PARAMS are presently ignored.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1151
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1152 AT-P is a boolean form of no arguments which determines whether or not point
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1153 is within a button of this type.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1154 Optional TO-P is a boolean form which moves point immediately after the next
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1155 button of this type within the current buffer and returns a list of (button-
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1156 label start-pos end-pos), or nil when none is found.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1157 Optional STYLE is a display style specification to use when highlighting
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1158 buttons of this type; most useful when TO-P is also given.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1159
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1160 Returns symbol created when successful, else nil. Nil indicates that action
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1161 type for ibtype is presently undefined."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1162 (if type
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1163 (let ((to-func (if to-p (action:create nil (list to-p))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1164 (at-func (list at-p)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1165 (` (htype:create (, type) ibtypes (, doc) nil (, at-func)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1166 (list 'to-p (, to-func) 'style (, style)))))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1167
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1168 (defun ibtype:delete (type)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1169 "Deletes an implicit button TYPE (a symbol).
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1170 Returns TYPE's symbol if it existed, else nil."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1171 (htype:delete type 'ibtypes))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1172
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1173 ;;; ========================================================================
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1174 ;;; symset class - Hyperbole internal symbol set maintenance
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1175 ;;; ========================================================================
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1176
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1177 (require 'set)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1178
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1179 (defun symset:add (elt symbol prop)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1180 "Adds ELT to SYMBOL's PROP set.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1181 Returns nil iff ELT is already in SET. Uses 'eq' for comparison."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1182 (let* ((set (get symbol prop))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1183 (set:equal-op 'eq)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1184 (new-set (set:add elt set)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1185 (and new-set (put symbol prop new-set))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1186
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1187 (fset 'symset:delete 'symset:remove)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1188
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1189 (defun symset:get (symbol prop)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1190 "Returns SYMBOL's PROP set."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1191 (get symbol prop))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1192
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1193 (defun symset:remove (elt symbol prop)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1194 "Removes ELT from SYMBOL's PROP set and returns the new set.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1195 Assumes PROP is a valid set. Uses 'eq' for comparison."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1196 (let ((set (get symbol prop))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1197 (set:equal-op 'eq))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1198 (put symbol prop (set:remove elt set))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1199
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1200
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1201 (provide 'hbut)