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

Import from CVS: tag r19-15b95
author cvs
date Mon, 13 Aug 2007 08:51:03 +0200
parents 376386a54a3c
children 131b0175ea99
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1 ;;!emacs
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2 ;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3 ;; FILE: hui.el
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4 ;; SUMMARY: GNU Emacs User Interface to Hyperbole
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5 ;; USAGE: GNU Emacs Lisp Library
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
6 ;; KEYWORDS: hypermedia
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
7 ;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
8 ;; AUTHOR: Bob Weiner
24
4103f0995bd7 Import from CVS: tag r19-15b95
cvs
parents: 0
diff changeset
9 ;; ORG: InfoDock Associates
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
10 ;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
11 ;; ORIG-DATE: 19-Sep-91 at 21:42:03
24
4103f0995bd7 Import from CVS: tag r19-15b95
cvs
parents: 0
diff changeset
12 ;; LAST-MOD: 10-Nov-96 at 01:51:13 by Bob Weiner
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
13 ;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
14 ;; This file is part of Hyperbole.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
15 ;; Available for use and distribution under the same terms as GNU Emacs.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
16 ;;
24
4103f0995bd7 Import from CVS: tag r19-15b95
cvs
parents: 0
diff changeset
17 ;; Copyright (C) 1991-1996, Free Software Foundation, Inc.
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
18 ;; Developed with support from Motorola Inc.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
19 ;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
20 ;; DESCRIPTION:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
21 ;; DESCRIP-END.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
22
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
23 ;;; ************************************************************************
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
24 ;;; Other required Elisp libraries
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
25 ;;; ************************************************************************
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
26
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
27 (require 'hargs) (require 'set) (require 'hmail)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
28
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
29 ;;; ************************************************************************
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
30 ;;; Public variables
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
31 ;;; ************************************************************************
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
32
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
33 (defvar hui:ebut-delete-confirm-p t
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
34 "*Non-nil means prompt before interactively deleting explicit buttons.")
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 ;;; Public functions
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
38 ;;; ************************************************************************
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
39
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
40 (defun hui:ebut-create (&optional start end)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
41 "Creates an explicit but starting from label between optional START and END.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
42 Indicates by delimiting and adding any necessary instance number of the button
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
43 label."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
44 (interactive (list (and (marker-position (hypb:mark-marker t))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
45 (region-beginning))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
46 (and (marker-position (hypb:mark-marker t))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
47 (region-end))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
48 (let ((default-lbl) lbl but-buf actype)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
49 (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
50 (setq default-lbl
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
51 (hui:hbut-label-default start end (not (interactive-p)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
52 lbl (hui:hbut-label default-lbl "ebut-create"))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
53 (if (not (equal lbl default-lbl)) (setq default-lbl nil))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
54
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
55 (setq but-buf (if default-lbl (current-buffer) (hui:ebut-buf)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
56 (hui:buf-writable-err but-buf "ebut-create")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
57
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
58 (hattr:set 'hbut:current 'loc (hui:key-src but-buf))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
59 (hattr:set 'hbut:current 'dir (hui:key-dir but-buf))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
60 (setq actype (hui:actype))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
61 (hattr:set 'hbut:current 'actype actype)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
62 (hattr:set 'hbut:current 'args (hargs:actype-get actype))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
63 (hattr:set 'hbut:current 'action
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
64 (and (boundp 'hui:ebut-prompt-for-action)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
65 hui:ebut-prompt-for-action (hui:action actype)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
66 )
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
67 (ebut:operate lbl nil)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
68
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
69 (defun hui:ebut-delete (but-key &optional key-src)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
70 "Deletes explicit Hyperbole button given by BUT-KEY in optional KEY-SRC.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
71 KEY-SRC may be a buffer or a pathname, when nil the current buffer is used.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
72 Returns t if button is deleted, nil if user chooses not to delete or signals
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
73 an error otherwise. If called interactively, prompts user whether to delete
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
74 and derives BUT-KEY from the button that point is within.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
75 Signals an error if point is not within a button."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
76 (interactive (list (if (ebut:at-p)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
77 (hattr:get 'hbut:current 'lbl-key)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
78 nil)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
79 (cond ((null but-key)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
80 (hypb:error
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
81 "(ebut-delete): Point is not over the label of an existing button."))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
82 ((not (stringp but-key))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
83 (hypb:error
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
84 "(ebut-delete): Invalid label key argument: '%s'." but-key)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
85 (let ((interactive (interactive-p)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
86 (if (and hui:ebut-delete-confirm-p interactive)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
87 (if (y-or-n-p (format "Delete button %s%s%s? "
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
88 ebut:start
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
89 (hbut:key-to-label but-key) ebut:end))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
90 (hui:ebut-delete-op interactive but-key key-src)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
91 (message ""))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
92 (hui:ebut-delete-op interactive but-key key-src))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
93
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
94 (defun hui:ebut-edit ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
95 "Creates or modifies an explicit Hyperbole button when conditions are met.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
96 A region must have been delimited with the action-key and point must now be
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
97 within it before this function is called or it will do nothing. The region
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
98 must be no larger than the size given by 'ebut:max-len'. It must be entirely
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
99 within or entirely outside of an existing explicit button. When region is
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
100 within the button, the button is interactively modified. Otherwise, a new
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
101 button is created interactively with the region as the default label."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
102 (interactive)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
103 (let ((m (marker-position (hypb:mark-marker t)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
104 (op action-key-depress-prev-point) (p (point)) (lbl-key))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
105 (if (and m (eq (marker-buffer m) (marker-buffer op))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
106 (< op m) (<= (- m op) ebut:max-len)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
107 (<= p m) (<= op p))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
108 (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
109 (if (setq lbl-key (ebut:label-p))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
110 (hui:ebut-modify lbl-key)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
111 (hui:ebut-create op m))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
112 t))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
113
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
114 (defun hui:ebut-modify (lbl-key)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
115 "Modifies an explicit Hyperbole button given by LBL-KEY.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
116 Signals an error when no such button is found in the current buffer."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
117 (interactive (list (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
118 (hui:buf-writable-err (current-buffer) "ebut-modify")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
119 (or (ebut:label-p)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
120 (ebut:label-to-key
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
121 (hargs:read-match "Button to modify: "
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
122 (ebut:alist) nil t
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
123 nil 'ebut))))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
124 (let ((lbl (ebut:key-to-label lbl-key))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
125 (but-buf (current-buffer))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
126 actype but new-lbl)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
127 (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
128 (or (interactive-p)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
129 (hui:buf-writable-err but-buf "ebut-modify"))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
130
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
131 (or (setq but (ebut:get lbl-key but-buf))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
132 (progn (pop-to-buffer but-buf)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
133 (hypb:error "(ebut-modify): Invalid button, no data for '%s'." lbl)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
134
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
135 (setq new-lbl
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
136 (hargs:read
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
137 "Change button label to: "
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
138 (function
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
139 (lambda (lbl)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
140 (and (not (string= lbl "")) (<= (length lbl) ebut:max-len))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
141 lbl
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
142 (format "(ebut-modify): Enter a string of at most %s chars."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
143 ebut:max-len)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
144 'string))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
145
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
146 (hattr:set 'hbut:current 'loc (hui:key-src but-buf))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
147 (hattr:set 'hbut:current 'dir (hui:key-dir but-buf))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
148 (setq actype (hui:actype (hattr:get but 'actype)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
149 (hattr:set 'hbut:current 'actype actype)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
150 (hattr:set 'hbut:current 'args (hargs:actype-get actype 'modifying))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
151 (hattr:set 'hbut:current 'action
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
152 (and (boundp 'hui:ebut-prompt-for-action)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
153 hui:ebut-prompt-for-action (hui:action actype)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
154 )
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
155 (ebut:operate lbl new-lbl)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
156
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
157 (defun hui:ebut-rename (curr-label new-label)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
158 "Renames explicit Hyperbole button given by CURR-LABEL to NEW-LABEL.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
159 If called interactively when point is not within an explicit button:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
160 prompts for old and new button label values and performs rename.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
161 If called interactively when point is within an explicit button:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
162 saves button label and tells user to edit label, then call again.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
163 second call changes the button's name from the stored value to the
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
164 edited value.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
165 Signals an error if any problem occurs."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
166 (interactive
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
167 (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
168 (let (curr-label new-label)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
169 (hui:buf-writable-err (current-buffer) "ebut-rename")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
170 (if hui:ebut-label-prev
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
171 (setq curr-label hui:ebut-label-prev
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
172 new-label (ebut:label-p 'as-label))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
173 (setq new-label nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
174 curr-label
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
175 (or (ebut:label-p 'as-label)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
176 (let ((buts (ebut:alist)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
177 (if (null buts)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
178 (hypb:error "(ebut-rename): No explicit buttons in buffer.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
179 (prog1 (hargs:read-match
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
180 "Button label to rename: "
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
181 buts nil t nil 'ebut)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
182 (setq new-label
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
183 (hargs:read
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
184 "Rename button label to: "
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
185 (function
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
186 (lambda (lbl)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
187 (and (not (string= lbl ""))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
188 (<= (length lbl) ebut:max-len))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
189 curr-label
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
190 (format
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
191 "(ebut-rename): Use a quoted string of at most %s chars."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
192 ebut:max-len)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
193 'string))))))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
194 (list curr-label new-label))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
195
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
196 (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
197 (if (interactive-p)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
198 nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
199 (hui:buf-writable-err (current-buffer) "ebut-rename")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
200 (if (or (not (stringp curr-label)) (string= curr-label ""))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
201 (hypb:error "(ebut-rename): 'curr-label' must be a non-empty string: %s"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
202 curr-label))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
203 (and (stringp new-label) (string= new-label "")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
204 (hypb:error "(ebut-rename): 'new-label' must be a non-empty string: %s"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
205 new-label)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
206 (or (ebut:get (ebut:label-to-key curr-label))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
207 (hypb:error "(ebut-rename): Can't rename %s since no button data."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
208 curr-label))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
209 )
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
210 (cond (new-label
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
211 (ebut:operate curr-label new-label)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
212 (setq hui:ebut-label-prev nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
213 (message "Renamed from '%s' to '%s'." curr-label new-label))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
214 (curr-label
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
215 (setq hui:ebut-label-prev curr-label)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
216 (message "Edit button label and use same command to finish rename."))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
217 (t (hypb:error "(ebut-rename): Move point to within a button label."))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
218
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
219 (defun hui:ebut-search (string &optional match-part)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
220 "Shows lines of files/buffers containing an explicit but match for STRING.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
221 Returns number of buttons matched and displayed.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
222 By default, only matches for whole button labels are found, optional MATCH-PART
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
223 enables partial matches. The match lines are shown in a buffer which serves as
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
224 a menu to find any of the occurrences."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
225 (interactive (list (read-string "Search for button string: ")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
226 (y-or-n-p "Enable partial matches? ")))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
227 (if (not (stringp string))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
228 (hypb:error "(ebut-search): String to search for is required."))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
229 (let* ((prefix (if (> (length string) 14)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
230 (substring string 0 13) string))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
231 (out-buf (get-buffer-create (concat "*" prefix " Hypb Search*")))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
232 (total (ebut:search string out-buf match-part)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
233 (if (> total 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
234 (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
235 (set-buffer out-buf)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
236 (moccur-mode)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
237 (if (fboundp 'outline-minor-mode)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
238 (and (progn (goto-char 1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
239 (search-forward "\C-m" nil t))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
240 (outline-minor-mode 1)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
241 (if (fboundp 'hproperty:but-create)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
242 (hproperty:but-create nil nil (regexp-quote
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
243 (if match-part string
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
244 (concat ebut:start string ebut:end)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
245 (goto-char (point-min))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
246 (pop-to-buffer out-buf)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
247 (if (interactive-p) (message "%d match%s." total
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
248 (if (> total 1) "es" ""))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
249 total))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
250 (if (interactive-p) (message "No matches.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
251 total))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
252
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
253 (defun hui:error (&rest args)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
254 (hypb:error "(hui:error): Obsolete, use hypb:error instead."))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
255
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
256 (defun hui:gbut-create (lbl)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
257 "Creates Hyperbole global button with LBL."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
258 (interactive "sCreate global button labeled: ")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
259 (let (but-buf actype)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
260 (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
261 (setq actype (hui:actype))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
262 (setq but-buf (set-buffer (find-file-noselect gbut:file)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
263 (hui:buf-writable-err but-buf "ebut-create")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
264 ;; This prevents movement of point which might be useful to user.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
265 (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
266 (goto-char (point-max))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
267 (hattr:set 'hbut:current 'loc (hui:key-src but-buf))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
268 (hattr:set 'hbut:current 'dir (hui:key-dir but-buf))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
269 (hattr:set 'hbut:current 'actype actype)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
270 (hattr:set 'hbut:current 'args (hargs:actype-get actype))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
271 (hattr:set 'hbut:current 'action
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
272 (and (boundp 'hui:ebut-prompt-for-action)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
273 hui:ebut-prompt-for-action (hui:action actype)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
274 (setq lbl (concat lbl (ebut:operate lbl nil)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
275 (goto-char (point-max))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
276 (insert "\n")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
277 (save-buffer)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
278 )
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
279 (message "%s created." lbl)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
280 )))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
281
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
282 (defun hui:gbut-modify (lbl-key)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
283 "Modifies a global Hyperbole button given by LBL-KEY.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
284 Signals an error when no such button is found."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
285 (interactive (list (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
286 (hui:buf-writable-err
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
287 (find-file-noselect gbut:file) "gbut-modify")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
288 (hbut:label-to-key
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
289 (hargs:read-match "Global button to modify: "
24
4103f0995bd7 Import from CVS: tag r19-15b95
cvs
parents: 0
diff changeset
290 (mapcar 'list (gbut:label-list))
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
291 nil t nil 'ebut)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
292 (let ((lbl (hbut:key-to-label lbl-key))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
293 (but-buf (find-file-noselect gbut:file))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
294 actype but new-lbl)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
295 (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
296 (or (interactive-p)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
297 (hui:buf-writable-err but-buf "gbut-modify"))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
298
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
299 (or (setq but (ebut:get lbl-key but-buf))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
300 (progn (pop-to-buffer but-buf)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
301 (hypb:error
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
302 "(gbut-modify): Invalid button, no data for '%s'." lbl)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
303
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
304 (setq new-lbl
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
305 (hargs:read
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
306 "Change global button label to: "
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
307 (function
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
308 (lambda (lbl)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
309 (and (not (string= lbl "")) (<= (length lbl) ebut:max-len))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
310 lbl
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
311 (format "(gbut-modify): Enter a string of at most %s chars."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
312 ebut:max-len)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
313 'string))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
314
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
315 (hattr:set 'hbut:current 'loc (hui:key-src but-buf))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
316 (hattr:set 'hbut:current 'dir (hui:key-dir but-buf))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
317 (setq actype (hui:actype (hattr:get but 'actype)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
318 (hattr:set 'hbut:current 'actype actype)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
319 (hattr:set 'hbut:current 'args (hargs:actype-get actype 'modifying))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
320 (hattr:set 'hbut:current 'action
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
321 (and (boundp 'hui:ebut-prompt-for-action)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
322 hui:ebut-prompt-for-action (hui:action actype)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
323 (set-buffer but-buf)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
324 (ebut:operate lbl new-lbl))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
325
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
326 (defun hui:hbut-act (&optional but)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
327 "Executes action for optional Hyperbole button symbol BUT in current buffer.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
328 Default is the current button."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
329 (interactive
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
330 (let ((but (hbut:at-p)) (lst))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
331 (list
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
332 (cond (but)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
333 ((setq lst (ebut:alist))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
334 (ebut:get (ebut:label-to-key
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
335 (hargs:read-match "Button to execute: " lst nil t
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
336 (ebut:label-p 'as-label) 'ebut))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
337 (t (hypb:error "(hbut-act): No explicit buttons in buffer."))))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
338 (cond ((and (interactive-p) (null but))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
339 (hypb:error "(hbut-act): No current button to activate."))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
340 ((not (hbut:is-p but))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
341 (hypb:error "(hbut-act): Button is invalid; it has no attributes."))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
342 (t (or but (setq but 'hbut:current))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
343 (hui:but-flash) (hyperb:act but))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
344
24
4103f0995bd7 Import from CVS: tag r19-15b95
cvs
parents: 0
diff changeset
345 (defun hui:hbut-current-act ()
4103f0995bd7 Import from CVS: tag r19-15b95
cvs
parents: 0
diff changeset
346 "Activate Hyperbole button at point or signal an error if there is no such button."
4103f0995bd7 Import from CVS: tag r19-15b95
cvs
parents: 0
diff changeset
347 (interactive)
4103f0995bd7 Import from CVS: tag r19-15b95
cvs
parents: 0
diff changeset
348 (let ((but (hbut:at-p)))
4103f0995bd7 Import from CVS: tag r19-15b95
cvs
parents: 0
diff changeset
349 (cond ((null but)
4103f0995bd7 Import from CVS: tag r19-15b95
cvs
parents: 0
diff changeset
350 (hypb:error "(hbut-act): No current button to activate."))
4103f0995bd7 Import from CVS: tag r19-15b95
cvs
parents: 0
diff changeset
351 ((not (hbut:is-p but))
4103f0995bd7 Import from CVS: tag r19-15b95
cvs
parents: 0
diff changeset
352 (hypb:error "(hbut-act): Button is invalid; it has no attributes."))
4103f0995bd7 Import from CVS: tag r19-15b95
cvs
parents: 0
diff changeset
353 (t (hui:but-flash) (hyperb:act but)))))
4103f0995bd7 Import from CVS: tag r19-15b95
cvs
parents: 0
diff changeset
354
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
355 (defun hui:hbut-help (&optional but)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
356 "Checks for and explains an optional button given by symbol, BUT.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
357 BUT defaults to the button whose label point is within."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
358 (interactive)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
359 (setq but (or but (hbut:at-p)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
360 (ebut:get (ebut:label-to-key
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
361 (hargs:read-match "Help for button: "
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
362 (ebut:alist) nil t nil 'ebut)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
363 (or but
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
364 (hypb:error "(hbut-help): Move point to a valid Hyperbole button."))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
365 (if (not (hbut:is-p but))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
366 (cond (but (hypb:error "(hbut-help): Invalid button."))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
367 (t (hypb:error
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
368 "(hbut-help): Not on an implicit button and no buffer explicit buttons."))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
369 (let ((type-help-func (intern-soft
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
370 (concat
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
371 (htype:names 'ibtypes (hattr:get but 'categ))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
372 ":help"))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
373 (or (equal (hypb:indirect-function 'hui:but-flash)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
374 (function (lambda nil)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
375 ;; Only flash button if point is on it.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
376 (let ((lbl-key (hattr:get but 'lbl-key)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
377 (and lbl-key
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
378 (or (equal lbl-key (ebut:label-p))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
379 (equal lbl-key (ibut:label-p)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
380 (hui:but-flash))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
381 (if type-help-func
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
382 (funcall type-help-func but)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
383 (let ((total (hbut:report but)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
384 (if total (hui:help-ebut-highlight))))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
385
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
386 (defun hui:hbut-label (default-label func-name)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
387 "Reads button label from user using DEFAULT-LABEL and caller's FUNC-NAME."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
388 (hargs:read "Button label: "
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
389 (function
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
390 (lambda (lbl)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
391 (and (not (string= lbl "")) (<= (length lbl) ebut:max-len))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
392 default-label
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
393 (format "(%s): Enter a string of at most %s chars."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
394 func-name ebut:max-len)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
395 'string))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
396
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
397 (defun hui:hbut-label-default (start end &optional skip-len-test)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
398 "Returns default label based on START and END region markers or points.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
399 Optional SKIP-LEN-TEST means don't limit label to 'ebut:max-len' length.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
400 Returns nil if START or END are invalid or if region fails length test.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
401
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
402 Also has side effect of moving point to start of default label, if any."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
403 (if (markerp start) (setq start (marker-position start)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
404 (if (markerp end) (setq end (marker-position end)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
405 ;; Test whether to use region as default button label.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
406 (if (and (integerp start) (integerp end)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
407 (or skip-len-test
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
408 (<= (max (- end start) (- start end)) ebut:max-len)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
409 (progn (goto-char start)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
410 (buffer-substring start end))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
411
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
412 (defun hui:hbut-report (&optional arg)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
413 "Pretty prints attributes of current button, using optional prefix ARG.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
414 See 'hbut:report'."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
415 (interactive "P")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
416 (if (and arg (symbolp arg))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
417 (hui:hbut-help arg)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
418 (let ((total (hbut:report arg)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
419 (if total
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
420 (progn (hui:help-ebut-highlight)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
421 (message "%d button%s." total (if (/= total 1) "s" "")))))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
422
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
423 (fset 'hui:hbut-summarize 'hui:hbut-report)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
424
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
425 (defun hui:link-directly ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
426 "Creates a Hyperbole link button at depress point, linked to release point.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
427 See also documentation for 'hui:link-possible-types'."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
428 (let* ((link-types (hui:link-possible-types))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
429 (but-window action-key-depress-window)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
430 (num-types (length link-types))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
431 (release-window (selected-window))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
432 (but-modify nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
433 type-and-args lbl-key but-loc but-dir)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
434 (select-window action-key-depress-window)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
435 (hui:buf-writable-err (current-buffer) "link-directly")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
436 (if (ebut:at-p)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
437 (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
438 (setq but-modify t
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
439 but-loc (hattr:get 'hbut:current 'loc)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
440 but-dir (hattr:get 'hbut:current 'dir)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
441 lbl-key (hattr:get 'hbut:current 'lbl-key)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
442 (setq but-loc (hui:key-src (current-buffer))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
443 but-dir (hui:key-dir (current-buffer))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
444 lbl-key (hbut:label-to-key
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
445 (hui:hbut-label
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
446 (if (marker-position (hypb:mark-marker t))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
447 (hui:hbut-label-default
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
448 (region-beginning) (region-end)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
449 "link-directly"))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
450 (select-window release-window)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
451
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
452 (cond ((= num-types 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
453 (error "(link-directly): No possible link type to create."))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
454 ((= num-types 1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
455 (hui:link-create but-modify
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
456 but-window lbl-key but-loc but-dir
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
457 (setq type-and-args (car link-types))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
458 (t;; more than 1
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
459 (let ((item)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
460 type)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
461 (hui:link-create
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
462 but-modify but-window
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
463 lbl-key but-loc but-dir
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
464 (setq type-and-args
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
465 (hui:menu-select
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
466 (cons '("Link to>")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
467 (mapcar
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
468 (function
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
469 (lambda (type-and-args)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
470 (setq type (car type-and-args))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
471 (list
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
472 (capitalize
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
473 (if (string-match
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
474 "^\\(link-to\\|eval\\)-"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
475 (setq item (symbol-name type)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
476 (setq item (substring
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
477 item (match-end 0)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
478 item))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
479 type-and-args
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
480 (documentation
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
481 (intern (concat "actypes::"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
482 (symbol-name type)))))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
483 link-types))))))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
484 (message "`%s' button %s type `%s'."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
485 (hbut:key-to-label lbl-key)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
486 (if but-modify "set to" "created with")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
487 (car type-and-args))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
488
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
489 ;;; ************************************************************************
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
490 ;;; Private functions
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
491 ;;; ************************************************************************
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
492
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
493 (defun hui:action (actype &optional prompt)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
494 "Prompts for and returns an action to override action from ACTYPE."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
495 (and actype
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
496 (let* ((act) (act-str)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
497 (params (actype:params actype))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
498 (params-str (and params (concat " " (prin1-to-string params))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
499 )
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
500 (while (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
501 (while (and (setq act-str
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
502 (hargs:read
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
503 (or prompt (concat "Action" params-str
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
504 ": ")) nil nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
505 nil 'string))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
506 (not (string= act-str ""))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
507 (condition-case ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
508 (progn (setq act (read act-str)) nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
509 (error
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
510 (beep) (message "Invalid action syntax.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
511 (sit-for 3) t))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
512 (and (not (symbolp act))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
513 params
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
514 ;; Use the weak condition that action must
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
515 ;; involve at least one of actype's parameters
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
516 ;; or else we assume the action is invalid, tell
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
517 ;; the user and provide another chance for entry.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
518 (not (memq t
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
519 (mapcar
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
520 (function
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
521 (lambda (param)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
522 (setq param (symbol-name param))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
523 (and (string-match
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
524 (concat "[\( \t\n,']"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
525 (regexp-quote param)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
526 "[\(\) \t\n\"]")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
527 act-str)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
528 t)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
529 params)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
530 ))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
531 (beep) (message "Action must use at least one parameter.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
532 (sit-for 3))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
533 (let (head)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
534 (while (cond ((listp act)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
535 (and act (setq head (car act))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
536 (not (or (eq head 'lambda)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
537 (eq head 'defun)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
538 (eq head 'defmacro)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
539 (setq act (list 'lambda params act))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
540 nil ;; terminate loop
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
541 ))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
542 ((symbolp act)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
543 (setq act (cons act params)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
544 ((stringp act)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
545 (setq act (action:kbd-macro act 1)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
546 ;; Unrecognized form
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
547 (t (setq act nil))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
548 )))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
549 act)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
550
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
551 (defun hui:actype (&optional default-actype prompt)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
552 "Using optional DEFAULT-ACTYPE, PROMPTs for a button action type.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
553 DEFAULT-ACTYPE may be a valid symbol or symbol-name."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
554 (and default-actype (symbolp default-actype)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
555 (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
556 (setq default-actype (symbol-name default-actype))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
557 (if (string-match "actypes::" default-actype)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
558 (setq default-actype (substring default-actype (match-end 0))))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
559 (if (or (null default-actype) (stringp default-actype))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
560 (intern-soft
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
561 (concat "actypes::"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
562 (hargs:read-match (or prompt "Button's action type: ")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
563 (mapcar 'list (htype:names 'actypes))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
564 nil t default-actype 'actype)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
565 (hypb:error "(actype): Invalid default action type received.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
566 ))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
567
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
568 (defun hui:buf-writable-err (but-buf func-name)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
569 "If BUT-BUF is read-only or is unwritable, signal an error from FUNC-NAME."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
570 (let ((obuf (prog1 (current-buffer) (set-buffer but-buf)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
571 ;; (unwritable (and buffer-file-name
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
572 ;; (not (file-writable-p buffer-file-name))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
573 (err))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
574 ;; (if unwritable
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
575 ;; Commented error out since some people want to be able to create
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
576 ;; buttons within files which they have purposely marked read-only.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
577 ;; (setq err
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
578 ;; (format "(ebut-modify): You are not allowed to modify '%s'."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
579 ;; (file-name-nondirectory buffer-file-name))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
580 (if buffer-read-only
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
581 (setq err
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
582 (format
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
583 "Button buffer '%s' is read-only. Use %s to change it."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
584 (buffer-name but-buf)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
585 (hypb:cmd-key-string
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
586 (if (where-is-internal 'vc-toggle-read-only)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
587 'vc-toggle-read-only 'toggle-read-only))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
588 )))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
589 (set-buffer obuf)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
590 (if err (progn (pop-to-buffer but-buf) (hypb:error err)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
591
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
592 (defun hui:ebut-buf (&optional prompt)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
593 "Prompt for and return a buffer in which to place a button."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
594 (let ((buf-name))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
595 (while
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
596 (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
597 (setq buf-name
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
598 (hargs:read-match
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
599 (or prompt "Button's buffer: ")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
600 (delq nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
601 (mapcar
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
602 (function
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
603 (lambda (buf)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
604 (let ((b (buffer-name buf)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
605 (if (and (not (string-match "mail\\*" b))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
606 (not (string-match "\\*post-news\\*" b))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
607 (string-match "\\`[* ]" b))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
608 nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
609 (cons b nil)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
610 (buffer-list)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
611 nil t (buffer-name) 'buffer))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
612 (or (null buf-name) (equal buf-name "")))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
613 (beep))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
614 (get-buffer buf-name)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
615
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
616 (defun hui:ebut-delete-op (interactive but-key key-src)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
617 "INTERACTIVEly or not deletes explicit Hyperbole button given by BUT-KEY in KEY-SRC.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
618 KEY-SRC may be a buffer or a pathname, when nil the current buffer is used.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
619 Returns t if button is deleted, signals error otherwise. If called
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
620 with INTERACTIVE non-nil, derives BUT-KEY from the button that point is
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
621 within."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
622 (let ((buf (current-buffer)) (ebut))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
623 (if (if interactive
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
624 (ebut:delete)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
625 (cond ((or (null key-src) (and (bufferp key-src) (setq buf key-src)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
626 (setq ebut (ebut:get but-key key-src)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
627 ((and (stringp key-src)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
628 (setq buf (find-file-noselect key-src)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
629 (setq ebut (ebut:get but-key buf)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
630 (t (hypb:error "(ebut-delete): Invalid key-src: '%s'." key-src)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
631 (if ebut
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
632 (ebut:delete ebut)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
633 (hypb:error "(ebut-delete): No valid %s button in %s."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
634 (ebut:key-to-label but-key) buf))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
635 )
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
636 (progn (set-buffer buf)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
637 (if interactive
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
638 (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
639 (call-interactively 'hui:ebut-unmark)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
640 (message "Button deleted."))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
641 (hui:ebut-unmark but-key key-src))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
642 (if (hmail:reader-p) (hmail:msg-narrow))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
643 )
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
644 (hypb:error "(ebut-delete): You may not delete buttons from this buffer."))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
645
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
646 (defun hui:ebut-delimit (start end instance-str)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
647 (hypb:error "(hui:ebut-delimit): Obsolete, use ebut:delimit instead."))
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 hui:ebut-operate (curr-label new-label)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
650 (hypb:error "(hui:ebut-operate): Obsolete, use ebut:operate instead."))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
651
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
652 (defun hui:ebut-unmark (&optional but-key key-src directory)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
653 "Remove delimiters from button given by BUT-KEY in KEY-SRC of DIRECTORY.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
654 All args are optional, the current button and buffer file are the defaults."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
655 (interactive)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
656 (let ((form (function
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
657 (lambda ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
658 (let ((buffer-read-only) start end)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
659 (setq start (match-beginning 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
660 end (match-end 0))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
661 (and (fboundp 'hproperty:but-delete)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
662 (hproperty:but-delete start))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
663 (skip-chars-backward " \t\n")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
664 (skip-chars-backward "0-9")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
665 (if (= (preceding-char) (string-to-char ebut:instance-sep))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
666 (setq start (1- (point))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
667 (if (search-backward ebut:start (- (point) ebut:max-len) t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
668 (if current-prefix-arg
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
669 ;; Remove button label, delimiters and preceding
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
670 ;; space, if any.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
671 (delete-region (max (point-min)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
672 (1- (match-beginning 0)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
673 end)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
674 ;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
675 ;; Remove button delimiters only.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
676 ;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
677 ;; Remove button ending delimiter
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
678 (delete-region start end)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
679 ;; Remove button starting delimiter
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
680 (delete-region (match-beginning 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
681 (match-end 0)))))))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
682 (if (interactive-p)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
683 (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
684 (if (search-forward ebut:end nil t) (funcall form)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
685 ;; Non-interactive invocation.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
686 (let ((cur-p))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
687 (if (and (or (null key-src) (eq key-src buffer-file-name))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
688 (or (null directory) (eq directory default-directory)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
689 (setq cur-p t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
690 (set-buffer (find-file-noselect
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
691 (expand-file-name key-src directory))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
692 (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
693 (goto-char (point-min))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
694 (if (re-search-forward (ebut:label-regexp but-key) nil t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
695 (progn (funcall form)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
696 ;; If modified a buffer other than the current one,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
697 ;; save it.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
698 (or cur-p (save-buffer)))))))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
699
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
700 (defun hui:file-find (file-name)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
701 "If FILE-NAME is readable, finds it, else signals an error."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
702 (if (and (stringp file-name) (file-readable-p file-name))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
703 (find-file file-name)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
704 (hypb:error "(file-find): \"%s\" does not exist or is not readable."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
705 file-name)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
706
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
707 (defun hui:hbut-term-highlight (start end)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
708 "For terminals only: Emphasize a button spanning from START to END."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
709 (save-restriction
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
710 (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
711 (goto-char start)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
712 (narrow-to-region (point-min) start)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
713 (sit-for 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
714 (setq inverse-video t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
715 (goto-char (point-min))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
716 (widen)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
717 (narrow-to-region (point) end)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
718 (sit-for 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
719 (setq inverse-video nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
720 )))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
721
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
722 (defun hui:hbut-term-unhighlight (start end)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
723 "For terminals only: Remove any emphasis from hyper-button at START to END."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
724 (save-restriction
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
725 (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
726 (goto-char start)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
727 (narrow-to-region (point-min) start)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
728 (sit-for 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
729 (setq inverse-video nil))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
730
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
731 (defun hui:help-ebut-highlight ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
732 "Highlight any explicit buttons in help buffer associated with current buffer."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
733 (if (fboundp 'hproperty:but-create)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
734 (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
735 (set-buffer
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
736 (get-buffer (hypb:help-buf-name)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
737 (hproperty:but-create))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
738
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
739 (defun hui:htype-delete (htype-sym)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
740 "Deletes HTYPE-SYM from use in current Hyperbole session.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
741 HTYPE-SYM must be redefined for use again."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
742 (and htype-sym (symbolp htype-sym)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
743 (let ((type
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
744 (intern (hargs:read-match
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
745 (concat "Delete from " (symbol-name htype-sym) ": ")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
746 (mapcar 'list (htype:names htype-sym))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
747 nil t nil htype-sym))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
748 (htype:delete type htype-sym))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
749
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
750 (defun hui:htype-help (htype-sym &optional no-sort)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
751 "Displays documentation for types from HTYPE-SYM which match to a regexp.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
752 Optional NO-SORT means display in decreasing priority order (natural order)."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
753 (and htype-sym (symbolp htype-sym)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
754 (let* ((tstr (symbol-name htype-sym))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
755 (tprefix (concat tstr "::"))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
756 (buf-name (hypb:help-buf-name (capitalize tstr)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
757 (temp-buffer-show-hook
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
758 (function
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
759 (lambda (buf)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
760 (set-buffer buf) (goto-char (point-min))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
761 (replace-regexp "^" " ") (goto-char (point-min))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
762 (replace-string (concat " " tprefix) "")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
763 (goto-char (point-min)) (set-buffer-modified-p nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
764 (display-buffer buf nil))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
765 (temp-buffer-show-function temp-buffer-show-hook)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
766 (names (htype:names htype-sym))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
767 (term (hargs:read-match
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
768 (concat (capitalize tstr)
24
4103f0995bd7 Import from CVS: tag r19-15b95
cvs
parents: 0
diff changeset
769 " to describe (RET for all): ")
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
770 (mapcar 'list (cons "" names))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
771 nil t nil htype-sym))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
772 nm-list
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
773 doc-list)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
774 (setq nm-list
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
775 (if (string= term "")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
776 (let ((type-names
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
777 (mapcar (function (lambda (nm) (concat tprefix nm)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
778 names)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
779 (if no-sort type-names
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
780 (sort type-names 'string<)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
781 (cons (concat tprefix term) nil))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
782 doc-list (delq nil (mapcar
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
783 (function
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
784 (lambda (name)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
785 (let ((doc (documentation
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
786 (intern-soft name))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
787 (if doc (cons name doc)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
788 nm-list)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
789 (with-output-to-temp-buffer buf-name
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
790 (mapcar (function (lambda (nm-doc-cons)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
791 (princ (car nm-doc-cons)) (terpri)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
792 (princ (cdr nm-doc-cons)) (terpri)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
793 doc-list)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
794
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
795 (defun hui:key-dir (but-buf)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
796 "Returns button key src directory based on BUT-BUF, a buffer."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
797 (if (bufferp but-buf)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
798 (let ((file (buffer-file-name but-buf)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
799 (if file
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
800 (file-name-directory (hpath:symlink-referent file))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
801 (cdr (assq 'default-directory (buffer-local-variables but-buf)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
802 (hypb:error "(hui:key-dir): '%s' is not a valid buffer.")))
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 hui:key-src (but-buf)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
805 "Returns button key src location based on BUT-BUF, a buffer.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
806 This is BUT-BUF when button data is stored in the buffer and the
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
807 button's source file name when the button data is stored externally."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
808 (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
809 (set-buffer but-buf)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
810 (cond ((hmail:mode-is-p) but-buf)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
811 ((hpath:symlink-referent (buffer-file-name but-buf)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
812 (t but-buf))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
813
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
814 (defun hui:link-create (modify but-window lbl-key but-loc but-dir type-and-args)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
815 "Creates or modifies a new Hyperbole button.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
816 If MODIFY is non-nil, modifies button at point in BUT-WINDOW,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
817 otherwise, prompts for button label and creates a button.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
818 LBL-KEY is internal form of button label. BUT-LOC is file or buffer
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
819 in which to create button. BUT-DIR is directory of BUT-LOC.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
820 TYPE-AND-ARGS is the action type for the button followed by any arguments it requires."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
821 (hattr:set 'hbut:current 'loc but-loc)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
822 (hattr:set 'hbut:current 'dir but-dir)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
823 (hattr:set 'hbut:current 'actype (intern-soft
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
824 (concat "actypes::"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
825 (symbol-name
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
826 (car type-and-args)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
827 (hattr:set 'hbut:current 'args (cdr type-and-args))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
828
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
829 (select-window but-window)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
830 (let ((label (ebut:key-to-label lbl-key)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
831 (ebut:operate label (if modify label)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
832 )
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
833
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
834 (defun hui:link-possible-types ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
835 "Returns list of possible link types for a Hyperbole button link to point.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
836 Each list element is a list of the link type and any arguments it requires.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
837
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
838 The link types considered are fixed. Defining new link types will not alter
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
839 the possible types. The code must be changed to do that.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
840
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
841 Referent Context Possible Link Type Returned
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
842 ----------------------------------------------------
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
843 Explicit Button link-to-ebut
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
844 or
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
845 Info Node link-to-Info-node
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
846 or
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
847 Mail Reader Msg link-to-mail
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
848
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
849 Outline Regexp Prefix link-to-string-match
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
850 or
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
851 Directory Name link-to-directory
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
852 or
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
853 File Name link-to-file
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
854 or
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
855 Koutline Cell link-to-kcell
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
856 or
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
857 Buffer attached to File link-to-file
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
858 or
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
859 Buffer without File link-to-buffer-tmp
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
860
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
861 Elisp Buffer at Start
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
862 or End of Sexpression eval-elisp
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
863 "
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
864 (let (val)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
865 (delq nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
866 (list (if (ebut:at-p)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
867 (list 'link-to-ebut buffer-file-name (ebut:label-p)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
868 (cond ((eq major-mode 'Info-mode)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
869 (let ((hargs:reading-p 'Info-node))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
870 (list 'link-to-Info-node (hargs:at-p))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
871 ((hmail:reader-p)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
872 (list 'link-to-mail
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
873 (list (rmail:msg-id-get) buffer-file-name)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
874 )
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
875 (cond
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
876 ;; If link is within an outline-regexp prefix, use
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
877 ;; a link-to-string-match.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
878 ((and (boundp 'outline-regexp)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
879 (stringp outline-regexp)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
880 (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
881 (<= (point)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
882 (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
883 (beginning-of-line)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
884 (if (looking-at outline-regexp)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
885 (match-end 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
886 0)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
887 (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
888 (end-of-line)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
889 (let ((heading (buffer-substring
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
890 (point)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
891 (progn (beginning-of-line) (point))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
892 (occur 1))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
893 (while (search-backward heading nil t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
894 (setq occur (1+ occur)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
895 (list 'link-to-string-match
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
896 heading occur buffer-file-name))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
897 ((let ((hargs:reading-p 'directory))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
898 (setq val (hargs:at-p t)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
899 (list 'link-to-directory val))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
900 ((let ((hargs:reading-p 'file))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
901 (setq val (hargs:at-p t)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
902 (list 'link-to-file val (point)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
903 ((eq major-mode 'kotl-mode)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
904 (list 'link-to-kcell buffer-file-name (kcell-view:idstamp)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
905 (buffer-file-name
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
906 (list 'link-to-file buffer-file-name (point)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
907 (t (list 'link-to-buffer-tmp (buffer-name)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
908 )
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
909 (and (fboundp 'smart-emacs-lisp-mode-p)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
910 (smart-emacs-lisp-mode-p)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
911 (or (= (char-syntax (following-char)) ?\()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
912 (= (char-syntax (preceding-char)) ?\)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
913 (setq val (hargs:sexpression-p))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
914 (list 'eval-elisp val))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
915 ))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
916
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
917
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
918 ;;; ************************************************************************
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
919 ;;; Private variables
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
920 ;;; ************************************************************************
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
921
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
922
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
923 (defvar hui:ebut-label-prev nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
924 "String value of previous button name during an explicit button rename.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
925 At other times, values must be nil.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
926
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
927 (provide 'hui)