annotate lisp/hyperbole/hbut.el @ 0:376386a54a3c r19-14

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