annotate lisp/wid-edit.el @ 219:262b8bb4a523 r20-4b8

Import from CVS: tag r20-4b8
author cvs
date Mon, 13 Aug 2007 10:09:35 +0200
parents 78f53ef88e17
children 6c0ae1f9357f
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
209
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1 ;;; wid-edit.el --- Functions for creating and using widgets.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2 ;;
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3 ;; Copyright (C) 1996, 1997 Free Software Foundation, Inc.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
4 ;;
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
5 ;; Author: Per Abrahamsen <abraham@dina.kvl.dk>
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
6 ;; Maintainer: Hrvoje Niksic <hniksic@srce.hr>
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
7 ;; Keywords: extensions
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
8 ;; Version: 1.9960-x
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
9 ;; X-URL: http://www.dina.kvl.dk/~abraham/custom/
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
10
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
11 ;; This file is part of XEmacs.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
12
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
13 ;; XEmacs is free software; you can redistribute it and/or modify
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
14 ;; it under the terms of the GNU General Public License as published by
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
15 ;; the Free Software Foundation; either version 2, or (at your option)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
16 ;; any later version.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
17
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
18 ;; XEmacs is distributed in the hope that it will be useful,
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
19 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
20 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
21 ;; GNU General Public License for more details.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
22
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
23 ;; You should have received a copy of the GNU General Public License
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
24 ;; along with XEmacs; see the file COPYING. If not, write to the
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
25 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
26 ;; Boston, MA 02111-1307, USA.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
27
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
28 ;;; Commentary:
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
29 ;;
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
30 ;; See `widget.el'.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
31
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
32
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
33 ;;; Code:
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
34
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
35 (require 'widget)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
36
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
37 (autoload 'finder-commentary "finder" nil t)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
38
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
39 ;;; Customization.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
40
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
41 (defgroup widgets nil
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
42 "Customization support for the Widget Library."
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
43 :link '(custom-manual "(widget)Top")
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
44 :link '(url-link :tag "Development Page"
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
45 "http://www.dina.kvl.dk/~abraham/custom/")
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
46 :link '(emacs-library-link :tag "Lisp File" "widget.el")
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
47 :prefix "widget-"
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
48 :group 'extensions
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
49 :group 'hypermedia)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
50
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
51 (defgroup widget-documentation nil
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
52 "Options controling the display of documentation strings."
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
53 :group 'widgets)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
54
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
55 (defgroup widget-faces nil
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
56 "Faces used by the widget library."
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
57 :group 'widgets
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
58 :group 'faces)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
59
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
60 (defvar widget-documentation-face 'widget-documentation-face
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
61 "Face used for documentation strings in widges.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
62 This exists as a variable so it can be set locally in certain buffers.")
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
63
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
64 (defface widget-documentation-face '((((class color)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
65 (background dark))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
66 (:foreground "lime green"))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
67 (((class color)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
68 (background light))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
69 (:foreground "dark green"))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
70 (t nil))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
71 "Face used for documentation text."
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
72 :group 'widget-documentation
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
73 :group 'widget-faces)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
74
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
75 (defvar widget-button-face 'widget-button-face
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
76 "Face used for buttons in widges.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
77 This exists as a variable so it can be set locally in certain buffers.")
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
78
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
79 (defface widget-button-face '((t (:bold t)))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
80 "Face used for widget buttons."
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
81 :group 'widget-faces)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
82
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
83 (defcustom widget-mouse-face 'highlight
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
84 "Face used for widget buttons when the mouse is above them."
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
85 :type 'face
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
86 :group 'widget-faces)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
87
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
88 (defface widget-field-face '((((class grayscale color)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
89 (background light))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
90 (:background "gray85"))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
91 (((class grayscale color)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
92 (background dark))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
93 (:background "dim gray"))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
94 (t
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
95 (:italic t)))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
96 "Face used for editable fields."
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
97 :group 'widget-faces)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
98
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
99 ;; Currently unused
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
100 ;(defface widget-single-line-field-face '((((class grayscale color)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
101 ; (background light))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
102 ; (:background "gray85"))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
103 ; (((class grayscale color)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
104 ; (background dark))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
105 ; (:background "dim gray"))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
106 ; (t
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
107 ; (:italic t)))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
108 ; "Face used for editable fields spanning only a single line."
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
109 ; :group 'widget-faces)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
110 ;
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
111 ;(defvar widget-single-line-display-table
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
112 ; (let ((table (make-display-table)))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
113 ; (aset table 9 "^I")
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
114 ; (aset table 10 "^J")
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
115 ; table)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
116 ; "Display table used for single-line editable fields.")
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
117 ;
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
118 ;(set-face-display-table 'widget-single-line-field-face
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
119 ; widget-single-line-display-table)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
120
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
121
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
122 ;; Some functions from this file have been ported to C for speed.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
123 ;; Setting this to t (*before* loading wid-edit.el) will make them
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
124 ;; shadow the subrs. It should be used only for debugging purposes.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
125 (defvar widget-shadow-subrs nil)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
126
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
127
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
128 ;;; Utility functions.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
129 ;;
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
130 ;; These are not really widget specific.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
131
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
132 (when (or (not (fboundp 'widget-plist-member))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
133 widget-shadow-subrs)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
134 ;; Recoded in C, for efficiency. It used to be a defsubst, but old
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
135 ;; compiled code won't fail -- it will just be slower.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
136 (defun widget-plist-member (plist prop)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
137 ;; Return non-nil if PLIST has the property PROP.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
138 ;; PLIST is a property list, which is a list of the form
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
139 ;; (PROP1 VALUE1 PROP2 VALUE2 ...). PROP is a symbol.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
140 ;; Unlike `plist-get', this allows you to distinguish between a missing
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
141 ;; property and a property with the value nil.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
142 ;; The value is actually the tail of PLIST whose car is PROP.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
143 (while (and plist (not (eq (car plist) prop)))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
144 (setq plist (cddr plist)))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
145 plist))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
146
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
147 (defun widget-princ-to-string (object)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
148 ;; Return string representation of OBJECT, any Lisp object.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
149 ;; No quoting characters are used; no delimiters are printed around
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
150 ;; the contents of strings.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
151 (with-current-buffer (get-buffer-create " *widget-tmp*")
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
152 (erase-buffer)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
153 (princ object (current-buffer))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
154 (buffer-string)))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
155
219
262b8bb4a523 Import from CVS: tag r20-4b8
cvs
parents: 213
diff changeset
156 (defun widget-prettyprint-to-string (object)
262b8bb4a523 Import from CVS: tag r20-4b8
cvs
parents: 213
diff changeset
157 ;; Like pp-to-string, but uses `cl-prettyprint'
262b8bb4a523 Import from CVS: tag r20-4b8
cvs
parents: 213
diff changeset
158 ;; #### FIX ME!!!!
262b8bb4a523 Import from CVS: tag r20-4b8
cvs
parents: 213
diff changeset
159 (with-current-buffer (get-buffer-create " *widget-tmp*")
262b8bb4a523 Import from CVS: tag r20-4b8
cvs
parents: 213
diff changeset
160 (erase-buffer)
262b8bb4a523 Import from CVS: tag r20-4b8
cvs
parents: 213
diff changeset
161 (cl-prettyprint object)
262b8bb4a523 Import from CVS: tag r20-4b8
cvs
parents: 213
diff changeset
162 (buffer-string)))
262b8bb4a523 Import from CVS: tag r20-4b8
cvs
parents: 213
diff changeset
163
209
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
164 (defun widget-clear-undo ()
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
165 "Clear all undo information."
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
166 (buffer-disable-undo)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
167 (buffer-enable-undo))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
168
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
169 (defcustom widget-menu-max-size 40
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
170 "Largest number of items allowed in a popup-menu.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
171 Larger menus are read through the minibuffer."
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
172 :group 'widgets
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
173 :type 'integer)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
174
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
175 (defcustom widget-menu-minibuffer-flag nil
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
176 "*Control how to ask for a choice from the keyboard.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
177 Non-nil means use the minibuffer;
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
178 nil means read a single character."
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
179 :group 'widgets
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
180 :type 'boolean)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
181
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
182 (defun widget-choose (title items &optional event)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
183 "Choose an item from a list.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
184
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
185 First argument TITLE is the name of the list.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
186 Second argument ITEMS is an list whose members are either
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
187 (NAME . VALUE), to indicate selectable items, or just strings to
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
188 indicate unselectable items.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
189 Optional third argument EVENT is an input event.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
190
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
191 The user is asked to choose between each NAME from the items alist,
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
192 and the VALUE of the chosen element will be returned. If EVENT is a
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
193 mouse event, and the number of elements in items is less than
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
194 `widget-menu-max-size', a popup menu will be used, otherwise the
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
195 minibuffer."
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
196 (cond ((and (< (length items) widget-menu-max-size)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
197 event
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
198 (console-on-window-system-p))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
199 ;; Pressed by the mouse.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
200 (let ((val (get-popup-menu-response
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
201 (cons title
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
202 (mapcar (lambda (x)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
203 (if (stringp x)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
204 (vector x nil nil)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
205 (vector (car x) (list (car x)) t)))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
206 items)))))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
207 (setq val (and val
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
208 (listp (event-object val))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
209 (stringp (car-safe (event-object val)))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
210 (car (event-object val))))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
211 (cdr (assoc val items))))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
212 ((and (not widget-menu-minibuffer-flag)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
213 ;; Can't handle more than 10 items (as many digits)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
214 (<= (length items) 10))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
215 ;; Construct a menu of the choices
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
216 ;; and then use it for prompting for a single character.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
217 (let* ((overriding-terminal-local-map (make-sparse-keymap))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
218 (map (make-sparse-keymap title))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
219 (next-digit ?0)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
220 some-choice-enabled value)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
221 ;; Define SPC as a prefix char to get to this menu.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
222 (define-key overriding-terminal-local-map " " map)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
223 (with-current-buffer (get-buffer-create " widget-choose")
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
224 (erase-buffer)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
225 (insert "Available choices:\n\n")
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
226 (dolist (choice items)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
227 (when (consp choice)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
228 (let* ((name (car choice))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
229 (function (cdr choice)))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
230 (insert (format "%c = %s\n" next-digit name))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
231 (define-key map (vector next-digit) function)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
232 (setq some-choice-enabled t)))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
233 ;; Allocate digits to disabled alternatives
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
234 ;; so that the digit of a given alternative never varies.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
235 (incf next-digit))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
236 (insert "\nC-g = Quit"))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
237 (or some-choice-enabled
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
238 (error "None of the choices is currently meaningful"))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
239 (define-key map [?\C-g] 'keyboard-quit)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
240 (define-key map [t] 'keyboard-quit)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
241 ;(setcdr map (nreverse (cdr map)))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
242 ;; Unread a SPC to lead to our new menu.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
243 (push (character-to-event ?\ ) unread-command-events)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
244 ;; Read a char with the menu, and return the result
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
245 ;; that corresponds to it.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
246 (save-window-excursion
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
247 (display-buffer (get-buffer " widget-choose"))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
248 (let ((cursor-in-echo-area t))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
249 (setq value
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
250 (lookup-key overriding-terminal-local-map
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
251 (read-key-sequence (concat title ": ") t)))))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
252 (message "")
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
253 (when (or (eq value 'keyboard-quit)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
254 (null value))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
255 (error "Canceled"))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
256 value))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
257 (t
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
258 ;; Read the choice of name from the minibuffer.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
259 (setq items (remove-if 'stringp items))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
260 (let ((val (completing-read (concat title ": ") items nil t)))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
261 (if (stringp val)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
262 (let ((try (try-completion val items)))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
263 (when (stringp try)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
264 (setq val try))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
265 (cdr (assoc val items)))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
266 nil)))))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
267
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
268
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
269 ;;; Widget text specifications.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
270 ;;
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
271 ;; These functions are for specifying text properties.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
272
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
273 (defcustom widget-field-add-space t
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
274 ;; Setting this to nil might be available, once some problems are resolved.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
275 "Non-nil means add extra space at the end of editable text fields.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
276
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
277 This is needed on all versions of Emacs. If you don't add the space,
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
278 it will become impossible to edit a zero size field."
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
279 :type 'boolean
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
280 :group 'widgets)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
281
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
282 (defcustom widget-field-use-before-change
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
283 (and (or (> emacs-minor-version 34)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
284 (> emacs-major-version 19))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
285 (not (string-match "XEmacs" emacs-version)))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
286 "Non-nil means use `before-change-functions' to track editable fields.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
287 This enables the use of undo, but doesn't work on Emacs 19.34 and earlier.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
288 Using before hooks also means that the :notify function can't know the
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
289 new value."
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
290 :type 'boolean
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
291 :group 'widgets)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
292
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
293 (defun widget-specify-field (widget from to)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
294 "Specify editable button for WIDGET between FROM and TO."
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
295 (save-excursion
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
296 (goto-char to)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
297 (cond ((null (widget-get widget :size))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
298 (forward-char 1))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
299 ;; Terminating space is not part of the field, but necessary in
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
300 ;; order for local-map to work. Remove next sexp if local-map works
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
301 ;; at the end of the extent.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
302 (widget-field-add-space
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
303 (insert-and-inherit " ")))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
304 (setq to (point)))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
305 (let ((map (widget-get widget :keymap))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
306 (face (or (widget-get widget :value-face) 'widget-field-face))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
307 (help-echo (widget-get widget :help-echo))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
308 (extent (make-extent from to)))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
309 (unless (or (stringp help-echo) (null help-echo))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
310 (setq help-echo 'widget-mouse-help))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
311 (widget-put widget :field-extent extent)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
312 (and (or (not widget-field-add-space)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
313 (widget-get widget :size))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
314 (set-extent-property extent 'end-closed nil))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
315 (set-extent-property extent 'detachable nil)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
316 (set-extent-property extent 'field widget)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
317 (set-extent-property extent 'button-or-field t)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
318 (set-extent-property extent 'keymap map)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
319 (set-extent-property extent 'face face)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
320 (set-extent-property extent 'balloon-help help-echo)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
321 (set-extent-property extent 'help-echo help-echo)))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
322
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
323 (defun widget-specify-button (widget from to)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
324 "Specify button for WIDGET between FROM and TO."
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
325 (let ((face (widget-apply widget :button-face-get))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
326 (help-echo (widget-get widget :help-echo))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
327 (extent (make-extent from to))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
328 (map (widget-get widget :button-keymap)))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
329 (widget-put widget :button-extent extent)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
330 (unless (or (null help-echo) (stringp help-echo))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
331 (setq help-echo 'widget-mouse-help))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
332 (set-extent-property extent 'start-open t)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
333 (set-extent-property extent 'button widget)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
334 (set-extent-property extent 'button-or-field t)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
335 (set-extent-property extent 'mouse-face widget-mouse-face)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
336 (set-extent-property extent 'balloon-help help-echo)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
337 (set-extent-property extent 'help-echo help-echo)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
338 (set-extent-property extent 'face face)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
339 (set-extent-property extent 'keymap map)))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
340
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
341 (defun widget-mouse-help (extent)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
342 "Find mouse help string for button in extent."
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
343 (let* ((widget (widget-at (extent-start-position extent)))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
344 (help-echo (and widget (widget-get widget :help-echo))))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
345 (cond ((stringp help-echo)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
346 help-echo)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
347 ((and (functionp help-echo)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
348 (stringp (setq help-echo (funcall help-echo widget))))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
349 help-echo)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
350 (t
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
351 (format "(widget %S :help-echo %S)" widget help-echo)))))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
352
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
353 (defun widget-specify-sample (widget from to)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
354 ;; Specify sample for WIDGET between FROM and TO.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
355 (let ((face (widget-apply widget :sample-face-get))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
356 (extent (make-extent from to nil)))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
357 (set-extent-property extent 'start-open t)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
358 (set-extent-property extent 'face face)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
359 (widget-put widget :sample-extent extent)))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
360
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
361 (defun widget-specify-doc (widget from to)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
362 ;; Specify documentation for WIDGET between FROM and TO.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
363 (let ((extent (make-extent from to)))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
364 (set-extent-property extent 'start-open t)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
365 (set-extent-property extent 'widget-doc widget)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
366 (set-extent-property extent 'face widget-documentation-face)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
367 (widget-put widget :doc-extent extent)))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
368
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
369 (defmacro widget-specify-insert (&rest form)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
370 ;; Execute FORM without inheriting any text properties.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
371 `(save-restriction
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
372 (let ((inhibit-read-only t)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
373 before-change-functions
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
374 after-change-functions)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
375 (insert "<>")
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
376 (narrow-to-region (- (point) 2) (point))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
377 (goto-char (1+ (point-min)))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
378 ;; We use `prog1' instead of a `result' variable, as the latter
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
379 ;; confuses the byte-compiler in some cases (a warning).
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
380 (prog1 (progn ,@form)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
381 (delete-region (point-min) (1+ (point-min)))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
382 (delete-region (1- (point-max)) (point-max))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
383 (goto-char (point-max))))))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
384
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
385 (put 'widget-specify-insert 'edebug-form-spec '(&rest form))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
386
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
387
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
388 ;;; Inactive Widgets.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
389
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
390 (defface widget-inactive-face '((((class grayscale color)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
391 (background dark))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
392 (:foreground "light gray"))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
393 (((class grayscale color)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
394 (background light))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
395 (:foreground "dim gray"))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
396 (t
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
397 (:italic t)))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
398 "Face used for inactive widgets."
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
399 :group 'widget-faces)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
400
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
401 ;; For inactiveness to work on complex structures, it is not
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
402 ;; sufficient to keep track of whether a button/field/glyph is
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
403 ;; inactive or not -- we must know how many time it was deactivated
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
404 ;; (inactiveness level). Successive deactivations of the same button
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
405 ;; increment its inactive-count, and activations decrement it. When
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
406 ;; inactive-count reaches 0, the button/field/glyph is reactivated.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
407
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
408 (defun widget-activation-widget-mapper (extent action)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
409 "Activate or deactivate EXTENT's widget (button or field).
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
410 Suitable for use with `map-extents'."
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
411 (ecase action
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
412 (:activate
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
413 (decf (extent-property extent :inactive-count))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
414 (when (zerop (extent-property extent :inactive-count))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
415 (set-extent-properties
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
416 extent (extent-property extent :inactive-plist))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
417 (set-extent-property extent :inactive-plist nil)))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
418 (:deactivate
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
419 (incf (extent-property extent :inactive-count 0))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
420 ;; Store a plist of old properties, which will be fed to
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
421 ;; `set-extent-properties'.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
422 (unless (extent-property extent :inactive-plist)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
423 (set-extent-property
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
424 extent :inactive-plist
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
425 (list 'mouse-face (extent-property extent 'mouse-face)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
426 'help-echo (extent-property extent 'help-echo)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
427 'keymap (extent-property extent 'keymap)))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
428 (set-extent-properties
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
429 extent '(mouse-face nil help-echo nil keymap nil)))))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
430 nil)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
431
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
432 (defun widget-activation-glyph-mapper (extent action)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
433 (let ((activate-p (if (eq action :activate) t nil)))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
434 (if activate-p
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
435 (decf (extent-property extent :inactive-count))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
436 (incf (extent-property extent :inactive-count 0)))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
437 (when (or (and activate-p
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
438 (zerop (extent-property extent :inactive-count)))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
439 (and (not activate-p)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
440 (not (zerop (extent-property extent :inactive-count)))))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
441 (let* ((glyph-widget (extent-property extent 'glyph-widget))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
442 (up-glyph (widget-get glyph-widget :glyph-up))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
443 (inactive-glyph (widget-get glyph-widget :glyph-inactive))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
444 (new-glyph (if activate-p up-glyph inactive-glyph)))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
445 ;; Check that the new glyph exists, and differs from the
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
446 ;; default one.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
447 (and up-glyph inactive-glyph (not (eq up-glyph inactive-glyph))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
448 ;; Check if the glyph is already installed.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
449 (not (eq (extent-end-glyph extent) new-glyph))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
450 ;; Change it.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
451 (set-extent-end-glyph extent new-glyph)))))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
452 nil)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
453
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
454 (defun widget-specify-inactive (widget from to)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
455 "Make WIDGET inactive for user modifications."
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
456 (unless (widget-get widget :inactive)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
457 (let ((extent (make-extent from to)))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
458 ;; It is no longer necessary for the extent to be read-only, as
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
459 ;; the inactive editable fields now lose their keymaps.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
460 (set-extent-properties
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
461 extent '(start-open t face widget-inactive-face
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
462 detachable t priority 2001 widget-inactive t))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
463 (widget-put widget :inactive extent))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
464 ;; Deactivate the buttons and fields within the range. In some
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
465 ;; cases, the fields are not yet setup at the time this function
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
466 ;; is called. Those fields are deactivated explicitly by
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
467 ;; `widget-setup'.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
468 (map-extents 'widget-activation-widget-mapper
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
469 nil from to :deactivate nil 'button-or-field)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
470 ;; Deactivate glyphs.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
471 (map-extents 'widget-activation-glyph-mapper
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
472 nil from to :deactivate nil 'glyph-widget)))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
473
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
474 (defun widget-specify-active (widget)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
475 "Make WIDGET active for user modifications."
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
476 (let ((inactive (widget-get widget :inactive)))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
477 (when inactive
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
478 ;; Reactivate the buttons and fields covered by the extent.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
479 (map-extents 'widget-activation-widget-mapper
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
480 inactive nil nil :activate nil 'button-or-field)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
481 ;; Reactivate the glyphs.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
482 (map-extents 'widget-activation-glyph-mapper
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
483 inactive nil nil :activate nil 'end-glyph)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
484 (delete-extent inactive)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
485 (widget-put widget :inactive nil))))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
486
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
487
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
488 ;;; Widget Properties.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
489
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
490 (defsubst widget-type (widget)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
491 "Return the type of WIDGET, a symbol."
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
492 (car widget))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
493
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
494 (when (or (not (fboundp 'widget-put))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
495 widget-shadow-subrs)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
496 (defun widget-put (widget property value)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
497 "In WIDGET set PROPERTY to VALUE.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
498 The value can later be retrived with `widget-get'."
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
499 (setcdr widget (plist-put (cdr widget) property value))))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
500
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
501 ;; Recoded in C, for efficiency:
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
502 (when (or (not (fboundp 'widget-get))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
503 widget-shadow-subrs)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
504 (defun widget-get (widget property)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
505 "In WIDGET, get the value of PROPERTY.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
506 The value could either be specified when the widget was created, or
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
507 later with `widget-put'."
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
508 (let ((missing t)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
509 value tmp)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
510 (while missing
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
511 (cond ((setq tmp (widget-plist-member (cdr widget) property))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
512 (setq value (car (cdr tmp))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
513 missing nil))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
514 ((setq tmp (car widget))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
515 (setq widget (get tmp 'widget-type)))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
516 (t
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
517 (setq missing nil))))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
518 value)))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
519
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
520 (defun widget-get-indirect (widget property)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
521 "In WIDGET, get the value of PROPERTY.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
522 If the value is a symbol, return its binding.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
523 Otherwise, just return the value."
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
524 (let ((value (widget-get widget property)))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
525 (if (symbolp value)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
526 (symbol-value value)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
527 value)))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
528
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
529 (defun widget-member (widget property)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
530 "Non-nil iff there is a definition in WIDGET for PROPERTY."
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
531 (cond ((widget-plist-member (cdr widget) property)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
532 t)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
533 ((car widget)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
534 (widget-member (get (car widget) 'widget-type) property))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
535 (t nil)))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
536
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
537 (when (or (not (fboundp 'widget-apply))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
538 widget-shadow-subrs)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
539 ;;This is in C, so don't ###utoload
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
540 (defun widget-apply (widget property &rest args)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
541 "Apply the value of WIDGET's PROPERTY to the widget itself.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
542 ARGS are passed as extra arguments to the function."
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
543 (apply (widget-get widget property) widget args)))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
544
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
545 (defun widget-value (widget)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
546 "Extract the current value of WIDGET."
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
547 (widget-apply widget
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
548 :value-to-external (widget-apply widget :value-get)))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
549
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
550 (defun widget-value-set (widget value)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
551 "Set the current value of WIDGET to VALUE."
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
552 (widget-apply widget
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
553 :value-set (widget-apply widget
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
554 :value-to-internal value)))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
555
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
556 (defun widget-match-inline (widget vals)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
557 ;; In WIDGET, match the start of VALS.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
558 (cond ((widget-get widget :inline)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
559 (widget-apply widget :match-inline vals))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
560 ((and vals
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
561 (widget-apply widget :match (car vals)))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
562 (cons (list (car vals)) (cdr vals)))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
563 (t nil)))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
564
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
565 (defun widget-apply-action (widget &optional event)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
566 "Apply :action in WIDGET in response to EVENT."
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
567 (if (widget-apply widget :active)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
568 (widget-apply widget :action event)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
569 (error "Attempt to perform action on inactive widget")))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
570
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
571
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
572 ;;; Helper functions.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
573 ;;
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
574 ;; These are widget specific.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
575
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
576 ;;;###autoload
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
577 (defun widget-prompt-value (widget prompt &optional value unbound)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
578 "Prompt for a value matching WIDGET, using PROMPT.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
579 The current value is assumed to be VALUE, unless UNBOUND is non-nil."
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
580 (unless (listp widget)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
581 (setq widget (list widget)))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
582 (setq prompt (format "[%s] %s" (widget-type widget) prompt))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
583 (setq widget (widget-convert widget))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
584 (let ((answer (widget-apply widget :prompt-value prompt value unbound)))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
585 (unless (widget-apply widget :match answer)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
586 (error "Value does not match %S type." (car widget)))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
587 answer))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
588
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
589 (defun widget-get-sibling (widget)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
590 "Get the item WIDGET is assumed to toggle.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
591 This is only meaningful for radio buttons or checkboxes in a list."
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
592 (let* ((parent (widget-get widget :parent))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
593 (children (widget-get parent :children))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
594 child)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
595 (catch 'child
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
596 (while children
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
597 (setq child (car children)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
598 children (cdr children))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
599 (when (eq (widget-get child :button) widget)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
600 (throw 'child child)))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
601 nil)))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
602
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
603 (defun widget-map-buttons (function &optional buffer maparg)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
604 "Map FUNCTION over the buttons in BUFFER.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
605 FUNCTION is called with the arguments WIDGET and MAPARG.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
606
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
607 If FUNCTION returns non-nil, the walk is cancelled.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
608
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
609 The arguments MAPARG, and BUFFER default to nil and (current-buffer),
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
610 respectively."
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
611 (map-extents (lambda (extent ignore)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
612 ;; If FUNCTION returns non-nil, we bail out
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
613 (funcall function (extent-property extent 'button) maparg))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
614 nil nil nil nil nil
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
615 'button))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
616
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
617
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
618 ;;; Glyphs.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
619
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
620 (defcustom widget-glyph-directory (locate-data-directory "custom")
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
621 "Where widget glyphs are located.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
622 If this variable is nil, widget will try to locate the directory
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
623 automatically."
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
624 :group 'widgets
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
625 :type 'directory)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
626
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
627 (defcustom widget-glyph-enable t
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
628 "If non nil, use glyphs in images when available."
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
629 :group 'widgets
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
630 :type 'boolean)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
631
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
632 (defcustom widget-image-conversion
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
633 '((xpm ".xpm") (gif ".gif") (png ".png") (jpeg ".jpg" ".jpeg")
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
634 (xbm ".xbm"))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
635 "Conversion alist from image formats to file name suffixes."
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
636 :group 'widgets
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
637 :type '(repeat (cons :format "%v"
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
638 (symbol :tag "Image Format" unknown)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
639 (repeat :tag "Suffixes"
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
640 (string :format "%v")))))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
641
219
262b8bb4a523 Import from CVS: tag r20-4b8
cvs
parents: 213
diff changeset
642 ;; Don't use this, because we cannot yet distinguish between widget
262b8bb4a523 Import from CVS: tag r20-4b8
cvs
parents: 213
diff changeset
643 ;; glyphs associated with user action, and actionless ones.
262b8bb4a523 Import from CVS: tag r20-4b8
cvs
parents: 213
diff changeset
644 ;(defvar widget-glyph-pointer-glyph
262b8bb4a523 Import from CVS: tag r20-4b8
cvs
parents: 213
diff changeset
645 ; (make-pointer-glyph [cursor-font :data "hand2"])
262b8bb4a523 Import from CVS: tag r20-4b8
cvs
parents: 213
diff changeset
646 ; "Glyph to be used as the mouse pointer shape over glyphs.
262b8bb4a523 Import from CVS: tag r20-4b8
cvs
parents: 213
diff changeset
647 ;Use `set-glyph-image' to change this.")
211
78478c60bfcd Import from CVS: tag r20-4b4
cvs
parents: 209
diff changeset
648
209
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
649 (defvar widget-glyph-cache nil
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
650 "Cache of glyphs associated with strings (files).")
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
651
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
652 (defun widget-glyph-find (image tag)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
653 "Create a glyph corresponding to IMAGE with string TAG as fallback.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
654 IMAGE can already be a glyph, or a file name sans extension (xpm,
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
655 xbm, gif, jpg, or png) located in `widget-glyph-directory', or
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
656 in one of the data directories.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
657 It can also be a valid image instantiator, in which case it will be
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
658 used to make the glyph, with an additional TAG string fallback."
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
659 (cond ((not (and image widget-glyph-enable))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
660 ;; We don't want to use glyphs.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
661 nil)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
662 ((and (not (console-on-window-system-p))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
663 ;; We don't use glyphs on TTY consoles, although we
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
664 ;; could. However, glyph faces aren't yet working
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
665 ;; properly, and movement through glyphs is unintuitive.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
666 ;; As an exception, when TAG is nil, we assume that the
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
667 ;; caller knows what he is doing, and that the tag is
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
668 ;; encoded within the glyph.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
669 (not (glyphp image)))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
670 nil)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
671 ((glyphp image)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
672 ;; Already a glyph. Use it.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
673 image)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
674 ((stringp image)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
675 ;; A string. Look it up in the cache first...
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
676 (or (lax-plist-get widget-glyph-cache image)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
677 ;; ...and then in the relevant directories
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
678 (let* ((dirlist (cons (or widget-glyph-directory
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
679 (locate-data-directory "custom"))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
680 data-directory-list))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
681 (formats widget-image-conversion)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
682 file)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
683 (while (and formats (not file))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
684 ;; This dance is necessary, because XEmacs signals an
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
685 ;; error when it encounters an unrecognized image
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
686 ;; format.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
687 (when (valid-image-instantiator-format-p (caar formats))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
688 (setq file (locate-file image dirlist
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
689 (mapconcat 'identity (cdar formats)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
690 ":"))))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
691 (unless file
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
692 (pop formats)))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
693 (when file
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
694 ;; We create a glyph with the file as the default image
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
695 ;; instantiator, and the TAG fallback
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
696 (let ((glyph (make-glyph `([,(caar formats) :file ,file]
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
697 [string :data ,tag]))))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
698 ;; Cache the glyph
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
699 (laxputf widget-glyph-cache image glyph)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
700 ;; ...and return it
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
701 glyph)))))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
702 ((valid-instantiator-p image 'image)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
703 ;; A valid image instantiator (e.g. [gif :file "somefile"] etc.)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
704 (make-glyph `(,image [string :data ,tag])))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
705 (t
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
706 ;; Oh well.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
707 nil)))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
708
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
709 (defun widget-glyph-insert (widget tag image &optional down inactive)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
710 "In WIDGET, insert the text TAG or, if supported, IMAGE.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
711 IMAGE should either be a glyph, an image instantiator, an image file
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
712 name sans extension (xpm, xbm, gif, jpg, or png) located in
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
713 `widget-glyph-directory', or anything else allowed by
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
714 `widget-glyph-find'.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
715
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
716 If IMAGE is a list, it will be taken as a list of (UP DOWN INACTIVE)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
717 glyphs. The down and inactive glyphs are shown when glyph is pressed
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
718 or inactive, respectively.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
719
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
720 The optional DOWN and INACTIVE arguments are deprecated, and exist
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
721 only because of compatibility."
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
722 ;; Convert between IMAGE being a list, etc. Must use `psetq',
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
723 ;; because otherwise change to `image' screws up the rest.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
724 (psetq image (or (and (consp image)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
725 (car image))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
726 image)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
727 down (or (and (consp image)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
728 (nth 1 image))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
729 down)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
730 inactive (or (and (consp image)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
731 (nth 2 image))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
732 inactive))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
733 (let ((glyph (widget-glyph-find image tag)))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
734 (if glyph
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
735 (widget-glyph-insert-glyph widget glyph
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
736 (widget-glyph-find down tag)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
737 (widget-glyph-find inactive tag))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
738 (insert tag))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
739 glyph))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
740
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
741 (defun widget-glyph-insert-glyph (widget glyph &optional down inactive)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
742 "In WIDGET, insert GLYPH.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
743 If optional arguments DOWN and INACTIVE are given, they should be
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
744 glyphs used when the widget is pushed and inactive, respectively."
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
745 (insert "*")
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
746 (let ((extent (make-extent (point) (1- (point))))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
747 (help-echo (and widget (widget-get widget :help-echo)))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
748 (map (and widget (widget-get widget :button-keymap))))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
749 (set-extent-property extent 'glyph-widget widget)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
750 ;; It would be fun if we could make this extent atomic, so it
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
751 ;; doesn't mess with cursor motion. But atomic-extents library is
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
752 ;; currently a mess, so I'd rather not use it.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
753 (set-extent-property extent 'invisible t)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
754 (set-extent-property extent 'start-open t)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
755 (set-extent-property extent 'end-open t)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
756 (set-extent-property extent 'keymap map)
219
262b8bb4a523 Import from CVS: tag r20-4b8
cvs
parents: 213
diff changeset
757 ;;(set-extent-property extent 'pointer widget-glyph-pointer-glyph)
209
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
758 (set-extent-end-glyph extent glyph)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
759 (unless (or (stringp help-echo) (null help-echo))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
760 (setq help-echo 'widget-mouse-help))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
761 (when help-echo
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
762 (set-extent-property extent 'balloon-help help-echo)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
763 (set-extent-property extent 'help-echo help-echo)))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
764 (when widget
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
765 (widget-put widget :glyph-up glyph)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
766 (when down (widget-put widget :glyph-down down))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
767 (when inactive (widget-put widget :glyph-inactive inactive))))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
768
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
769
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
770 ;;; Buttons.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
771
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
772 (defgroup widget-button nil
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
773 "The look of various kinds of buttons."
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
774 :group 'widgets)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
775
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
776 (defcustom widget-button-prefix ""
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
777 "String used as prefix for buttons."
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
778 :type 'string
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
779 :group 'widget-button)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
780
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
781 (defcustom widget-button-suffix ""
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
782 "String used as suffix for buttons."
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
783 :type 'string
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
784 :group 'widget-button)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
785
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
786
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
787 ;;; Creating Widgets.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
788
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
789 ;;;###autoload
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
790 (defun widget-create (type &rest args)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
791 "Create widget of TYPE.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
792 The optional ARGS are additional keyword arguments."
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
793 (let ((widget (apply 'widget-convert type args)))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
794 (widget-apply widget :create)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
795 widget))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
796
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
797 (defun widget-create-child-and-convert (parent type &rest args)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
798 "As part of the widget PARENT, create a child widget TYPE.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
799 The child is converted, using the keyword arguments ARGS."
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
800 (let ((widget (apply 'widget-convert type args)))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
801 (widget-put widget :parent parent)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
802 (unless (widget-get widget :indent)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
803 (widget-put widget :indent (+ (or (widget-get parent :indent) 0)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
804 (or (widget-get widget :extra-offset) 0)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
805 (widget-get parent :offset))))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
806 (widget-apply widget :create)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
807 widget))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
808
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
809 (defun widget-create-child (parent type)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
810 "Create widget of TYPE."
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
811 (let ((widget (copy-sequence type)))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
812 (widget-put widget :parent parent)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
813 (unless (widget-get widget :indent)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
814 (widget-put widget :indent (+ (or (widget-get parent :indent) 0)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
815 (or (widget-get widget :extra-offset) 0)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
816 (widget-get parent :offset))))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
817 (widget-apply widget :create)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
818 widget))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
819
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
820 (defun widget-create-child-value (parent type value)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
821 "Create widget of TYPE with value VALUE."
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
822 (let ((widget (copy-sequence type)))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
823 (widget-put widget :value (widget-apply widget :value-to-internal value))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
824 (widget-put widget :parent parent)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
825 (unless (widget-get widget :indent)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
826 (widget-put widget :indent (+ (or (widget-get parent :indent) 0)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
827 (or (widget-get widget :extra-offset) 0)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
828 (widget-get parent :offset))))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
829 (widget-apply widget :create)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
830 widget))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
831
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
832 ;;;###autoload
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
833 (defun widget-delete (widget)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
834 "Delete WIDGET."
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
835 (widget-apply widget :delete))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
836
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
837 (defun widget-convert (type &rest args)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
838 "Convert TYPE to a widget without inserting it in the buffer.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
839 The optional ARGS are additional keyword arguments."
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
840 ;; Don't touch the type.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
841 (let* ((widget (if (symbolp type)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
842 (list type)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
843 (copy-sequence type)))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
844 (current widget)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
845 (keys args))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
846 ;; First set the :args keyword.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
847 (while (cdr current) ;Look in the type.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
848 (let ((next (car (cdr current))))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
849 (if (and (symbolp next) (eq (aref (symbol-name next) 0) ?:))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
850 (setq current (cdr (cdr current)))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
851 (setcdr current (list :args (cdr current)))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
852 (setq current nil))))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
853 (while args ;Look in the args.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
854 (let ((next (nth 0 args)))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
855 (if (and (symbolp next) (eq (aref (symbol-name next) 0) ?:))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
856 (setq args (nthcdr 2 args))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
857 (widget-put widget :args args)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
858 (setq args nil))))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
859 ;; Then Convert the widget.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
860 (setq type widget)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
861 (while type
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
862 (let ((convert-widget (plist-get (cdr type) :convert-widget)))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
863 (if convert-widget
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
864 (setq widget (funcall convert-widget widget))))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
865 (setq type (get (car type) 'widget-type)))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
866 ;; Finally set the keyword args.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
867 (while keys
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
868 (let ((next (nth 0 keys)))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
869 (if (and (symbolp next) (eq (aref (symbol-name next) 0) ?:))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
870 (progn
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
871 (widget-put widget next (nth 1 keys))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
872 (setq keys (nthcdr 2 keys)))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
873 (setq keys nil))))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
874 ;; Convert the :value to internal format.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
875 (if (widget-member widget :value)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
876 (let ((value (widget-get widget :value)))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
877 (widget-put widget
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
878 :value (widget-apply widget :value-to-internal value))))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
879 ;; Return the newly created widget.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
880 widget))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
881
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
882 (defun widget-insert (&rest args)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
883 "Call `insert' with ARGS and make the text read only."
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
884 (let ((inhibit-read-only t)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
885 before-change-functions
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
886 after-change-functions)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
887 (apply 'insert args)))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
888
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
889 (defun widget-convert-text (type from to
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
890 &optional button-from button-to
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
891 &rest args)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
892 "Return a widget of type TYPE with endpoint FROM TO.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
893 Optional ARGS are extra keyword arguments for TYPE.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
894 and TO will be used as the widgets end points. If optional arguments
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
895 BUTTON-FROM and BUTTON-TO are given, these will be used as the widgets
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
896 button end points.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
897 Optional ARGS are extra keyword arguments for TYPE."
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
898 (let ((widget (apply 'widget-convert type :delete 'widget-leave-text args))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
899 (from (copy-marker from))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
900 (to (copy-marker to)))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
901 (set-marker-insertion-type from t)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
902 (set-marker-insertion-type to nil)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
903 (widget-put widget :from from)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
904 (widget-put widget :to to)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
905 (when button-from
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
906 (widget-specify-button widget button-from button-to))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
907 widget))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
908
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
909 (defun widget-convert-button (type from to &rest args)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
910 "Return a widget of type TYPE with endpoint FROM TO.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
911 Optional ARGS are extra keyword arguments for TYPE.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
912 No text will be inserted to the buffer, instead the text between FROM
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
913 and TO will be used as the widgets end points, as well as the widgets
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
914 button end points."
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
915 (apply 'widget-convert-text type from to from to args))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
916
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
917 (defun widget-leave-text (widget)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
918 "Remove markers and extents from WIDGET and its children."
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
919 (let ((from (widget-get widget :from))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
920 (to (widget-get widget :to))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
921 (button (widget-get widget :button-extent))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
922 (sample (widget-get widget :sample-extent))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
923 (doc (widget-get widget :doc-extent))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
924 (field (widget-get widget :field-extent))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
925 (children (widget-get widget :children)))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
926 (set-marker from nil)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
927 (set-marker to nil)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
928 ;; Maybe we should delete the extents here? As this code doesn't
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
929 ;; remove them from widget structures, maybe it's safer to just
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
930 ;; detach them. That's what `delete-overlay' did.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
931 (when button
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
932 (detach-extent button))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
933 (when sample
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
934 (detach-extent sample))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
935 (when doc
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
936 (detach-extent doc))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
937 (when field
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
938 (detach-extent field))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
939 (mapc 'widget-leave-text children)))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
940
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
941
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
942 ;;; Keymap and Commands.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
943
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
944 (defvar widget-keymap nil
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
945 "Keymap containing useful binding for buffers containing widgets.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
946 Recommended as a parent keymap for modes using widgets.")
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
947
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
948 (unless widget-keymap
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
949 (setq widget-keymap (make-sparse-keymap))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
950 (define-key widget-keymap [tab] 'widget-forward)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
951 (define-key widget-keymap [(shift tab)] 'widget-backward)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
952 (define-key widget-keymap [(meta tab)] 'widget-backward)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
953 (define-key widget-keymap [backtab] 'widget-backward))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
954
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
955 (defvar widget-global-map global-map
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
956 "Keymap used for events the widget does not handle themselves.")
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
957 (make-variable-buffer-local 'widget-global-map)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
958
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
959 (defvar widget-field-keymap nil
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
960 "Keymap used inside an editable field.")
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
961
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
962 (unless widget-field-keymap
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
963 (setq widget-field-keymap (make-sparse-keymap))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
964 (set-keymap-parents widget-field-keymap global-map)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
965 (define-key widget-field-keymap "\C-k" 'widget-kill-line)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
966 (define-key widget-field-keymap [(meta tab)] 'widget-complete)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
967 (define-key widget-field-keymap [tab] 'widget-forward)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
968 (define-key widget-field-keymap [(shift tab)] 'widget-backward)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
969 (define-key widget-field-keymap "\C-m" 'widget-field-activate)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
970 (define-key widget-field-keymap "\C-a" 'widget-beginning-of-line)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
971 (define-key widget-field-keymap "\C-e" 'widget-end-of-line)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
972 (define-key widget-field-keymap "\C-t" 'widget-transpose-chars))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
973
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
974 (defvar widget-text-keymap nil
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
975 "Keymap used inside a text field.")
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
976
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
977 (unless widget-text-keymap
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
978 (setq widget-text-keymap (make-sparse-keymap))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
979 (set-keymap-parents widget-field-keymap global-map)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
980 (define-key widget-text-keymap "\C-a" 'widget-beginning-of-line)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
981 (define-key widget-text-keymap "\C-e" 'widget-end-of-line)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
982 (define-key widget-text-keymap "\C-t" 'widget-transpose-chars))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
983
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
984 (defvar widget-button-keymap nil
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
985 "Keymap used inside a button.")
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
986
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
987 (unless widget-button-keymap
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
988 (setq widget-button-keymap (make-sparse-keymap))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
989 (set-keymap-parents widget-button-keymap widget-keymap)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
990 (define-key widget-button-keymap "\C-m" 'widget-button-press)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
991 (define-key widget-button-keymap [button2] 'widget-button-click)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
992 ;; Ideally, button3 within a button should invoke a button-specific
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
993 ;; menu.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
994 (define-key widget-button-keymap [button3] 'widget-button-click)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
995 ;;Glyph support.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
996 (define-key widget-button-keymap [button1] 'widget-button1-click))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
997
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
998
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
999 (defun widget-field-activate (pos &optional event)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1000 "Invoke the ediable field at point."
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1001 (interactive "@d")
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1002 (let ((field (widget-field-find pos)))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1003 (if field
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1004 (widget-apply-action field event)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1005 (call-interactively
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1006 (lookup-key widget-global-map (this-command-keys))))))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1007
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1008 (defface widget-button-pressed-face
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1009 '((((class color))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1010 (:foreground "red"))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1011 (t
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1012 (:bold t :underline t)))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1013 "Face used for pressed buttons."
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1014 :group 'widget-faces)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1015
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1016 (defun widget-event-point (event)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1017 "Character position of the mouse event, or nil."
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1018 (and (mouse-event-p event)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1019 (event-point event)))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1020
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1021 (defun widget-button-click (event)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1022 "Invoke button below mouse pointer."
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1023 (interactive "@e")
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1024 (cond ((event-glyph event)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1025 (widget-glyph-click event))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1026 ((widget-event-point event)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1027 (let* ((pos (widget-event-point event))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1028 (button (get-char-property pos 'button)))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1029 (if button
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1030 (let* ((extent (widget-get button :button-extent))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1031 (face (extent-property extent 'face))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1032 (mouse-face (extent-property extent 'mouse-face))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1033 (help-echo (extent-property extent 'help-echo)))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1034 (unwind-protect
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1035 (progn
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1036 ;; Merge relevant faces, and make the result mouse-face.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1037 (let ((merge `(widget-button-pressed-face ,mouse-face)))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1038 (nconc merge (if (listp face)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1039 face (list face)))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1040 (setq merge (delete-if-not 'find-face merge))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1041 (set-extent-property extent 'mouse-face merge))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1042 (unless (widget-apply button :mouse-down-action event)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1043 ;; Wait for button release.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1044 (while (not (button-release-event-p
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1045 (setq event (next-event))))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1046 (dispatch-event event)))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1047 ;; Disallow mouse-face and help-echo.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1048 (set-extent-property extent 'mouse-face nil)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1049 (set-extent-property extent 'help-echo nil)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1050 (setq pos (widget-event-point event))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1051 (unless (eq (current-buffer) (extent-object extent))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1052 ;; Barf if dispatch-event tripped us by
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1053 ;; changing buffer.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1054 (error "Buffer changed during mouse motion"))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1055 ;; Do the associated action.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1056 (when (and pos (extent-in-region-p extent pos pos))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1057 (widget-apply-action button event)))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1058 ;; Unwinding: fully release the button.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1059 (set-extent-property extent 'mouse-face mouse-face)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1060 (set-extent-property extent 'help-echo help-echo)))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1061 ;; This should not happen!
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1062 (error "`widget-button-click' called outside button"))))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1063 (t
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1064 (message "You clicked somewhere weird"))))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1065
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1066 (defun widget-button1-click (event)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1067 "Invoke glyph below mouse pointer."
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1068 (interactive "@e")
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1069 (if (event-glyph event)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1070 (widget-glyph-click event)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1071 ;; Should somehow avoid this.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1072 (let ((command (lookup-key widget-global-map (this-command-keys))))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1073 (and (commandp command)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1074 (call-interactively command)))))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1075
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1076 (defun widget-glyph-click (event)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1077 "Handle click on a glyph."
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1078 (let* ((glyph (event-glyph event))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1079 (extent (event-glyph-extent event))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1080 (widget (extent-property extent 'glyph-widget))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1081 (down-glyph (or (and widget (widget-get widget :glyph-down)) glyph))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1082 (up-glyph (or (and widget (widget-get widget :glyph-up)) glyph))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1083 (last event))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1084 (unless (widget-apply widget :active)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1085 (error "This widget is inactive"))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1086 (let ((current-glyph 'down))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1087 ;; We always know what glyph is drawn currently, to avoid
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1088 ;; unnecessary extent changes. Is this any noticable gain?
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1089 (unwind-protect
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1090 (progn
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1091 ;; Press the glyph.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1092 (set-extent-end-glyph extent down-glyph)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1093 ;; Redisplay (shouldn't be needed, but...)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1094 (sit-for 0)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1095 (unless (widget-apply widget :mouse-down-action event)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1096 ;; Wait for the release.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1097 (while (not (button-release-event-p last))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1098 (unless (button-press-event-p last)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1099 (dispatch-event last))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1100 (when (motion-event-p last)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1101 ;; Update glyphs on mouse motion.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1102 (if (eq extent (event-glyph-extent last))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1103 (unless (eq current-glyph 'down)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1104 (set-extent-end-glyph extent down-glyph)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1105 (setq current-glyph 'down))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1106 (unless (eq current-glyph 'up)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1107 (set-extent-end-glyph extent up-glyph)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1108 (setq current-glyph 'up))))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1109 (setq last (next-event event))))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1110 (unless (eq (current-buffer) (extent-object extent))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1111 ;; Barf if dispatch-event tripped us by changing buffer.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1112 (error "Buffer changed during mouse motion"))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1113 ;; Apply widget action.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1114 (when (eq extent (event-glyph-extent last))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1115 (let ((widget (extent-property (event-glyph-extent event)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1116 'glyph-widget)))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1117 (cond ((null widget)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1118 (message "You clicked on a glyph"))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1119 ((not (widget-apply widget :active))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1120 (error "This glyph is inactive"))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1121 (t
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1122 (widget-apply-action widget event))))))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1123 ;; Release the glyph.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1124 (and (eq current-glyph 'down)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1125 ;; The extent might have been detached or deleted
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1126 (extent-live-p extent)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1127 (not (extent-detached-p extent))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1128 (set-extent-end-glyph extent up-glyph))))))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1129
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1130 (defun widget-button-press (pos &optional event)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1131 "Invoke button at POS."
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1132 (interactive "@d")
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1133 (let ((button (get-char-property pos 'button)))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1134 (if button
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1135 (widget-apply-action button event)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1136 (let ((command (lookup-key widget-global-map (this-command-keys))))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1137 (when (commandp command)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1138 (call-interactively command))))))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1139
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1140 (defun widget-tabable-at (&optional pos last-tab backwardp)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1141 "Return the tabable widget at POS, or nil.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1142 POS defaults to the value of (point)."
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1143 (unless pos
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1144 (setq pos (point)))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1145 (let ((widget (widget-at pos)))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1146 (if widget
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1147 (let ((order (widget-get widget :tab-order)))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1148 (if order
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1149 (if last-tab (and (= order (if backwardp
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1150 (1- last-tab)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1151 (1+ last-tab)))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1152 widget)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1153 (and (> order 0) widget))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1154 widget))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1155 nil)))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1156
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1157 ;; Return the button or field extent at point.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1158 (defun widget-button-or-field-extent (pos)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1159 (or (and (get-char-property pos 'button)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1160 (widget-get (get-char-property pos 'button)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1161 :button-extent))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1162 (and (get-char-property pos 'field)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1163 (widget-get (get-char-property pos 'field)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1164 :field-extent))))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1165
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1166 (defun widget-next-button-or-field (pos)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1167 "Find the next button, or field, and return its start position, or nil.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1168 Internal function, don't use it outside `wid-edit'."
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1169 (let* ((at-point (widget-button-or-field-extent pos))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1170 (extent (map-extents
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1171 (lambda (ext ignore)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1172 ext)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1173 nil (if at-point (extent-end-position at-point) pos)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1174 nil nil 'start-open 'button-or-field)))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1175 (and extent
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1176 (extent-start-position extent))))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1177
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1178 ;; This is too slow in buffers with many buttons (W3).
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1179 (defun widget-previous-button-or-field (pos)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1180 "Find the previous button, or field, and return its start position, or nil.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1181 Internal function, don't use it outside `wid-edit'."
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1182 (let* ((at-point (widget-button-or-field-extent pos))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1183 previous-extent)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1184 (map-extents
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1185 (lambda (ext ignore)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1186 (if (eq ext at-point)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1187 ;; We reached the extent we were on originally
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1188 (if (= pos (extent-start-position at-point))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1189 previous-extent
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1190 (setq previous-extent at-point))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1191 (setq previous-extent ext)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1192 nil))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1193 nil nil pos nil 'start-open 'button-or-field)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1194 (and previous-extent
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1195 (extent-start-position previous-extent))))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1196
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1197 (defun widget-move (arg)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1198 "Move point to the ARG next field or button.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1199 ARG may be negative to move backward."
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1200 (let ((opoint (point)) (wrapped 0)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1201 (last-tab (widget-get (widget-at (point)) :tab-order))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1202 nextpos found)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1203 ;; Movement backward
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1204 (while (< arg 0)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1205 (setq nextpos (widget-previous-button-or-field (point)))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1206 (if nextpos
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1207 (progn
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1208 (goto-char nextpos)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1209 (when (and (not (get-char-property nextpos 'widget-inactive))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1210 (widget-tabable-at nil last-tab t))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1211 (incf arg)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1212 (setq found t
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1213 last-tab (widget-get (widget-at (point))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1214 :tab-order))))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1215 (if (and (not found) (> wrapped 1))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1216 (setq arg 0
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1217 found nil)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1218 (goto-char (point-max))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1219 (incf wrapped))))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1220 ;; Movement forward
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1221 (while (> arg 0)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1222 (setq nextpos (widget-next-button-or-field (point)))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1223 (if nextpos
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1224 (progn
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1225 (goto-char nextpos)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1226 (when (and (not (get-char-property nextpos 'widget-inactive))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1227 (widget-tabable-at nil last-tab))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1228 (decf arg)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1229 (setq found t
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1230 last-tab (widget-get (widget-at (point))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1231 :tab-order))))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1232 (if (and (not found) (> wrapped 1))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1233 (setq arg 0
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1234 found nil)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1235 (goto-char (point-min))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1236 (incf wrapped))))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1237 (if (not found)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1238 (goto-char opoint)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1239 (widget-echo-help (point))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1240 (run-hooks 'widget-move-hook))))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1241
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1242 (defun widget-forward (arg)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1243 "Move point to the next field or button.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1244 With optional ARG, move across that many fields."
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1245 (interactive "p")
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1246 (run-hooks 'widget-forward-hook)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1247 (widget-move arg))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1248
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1249 (defun widget-backward (arg)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1250 "Move point to the previous field or button.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1251 With optional ARG, move across that many fields."
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1252 (interactive "p")
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1253 (run-hooks 'widget-backward-hook)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1254 (widget-move (- arg)))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1255
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1256 (defun widget-beginning-of-line ()
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1257 "Go to beginning of field or beginning of line, whichever is first."
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1258 (interactive "_")
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1259 (let* ((field (widget-field-find (point)))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1260 (start (and field (widget-field-start field))))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1261 (if (and start (not (eq start (point))))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1262 (goto-char start)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1263 (call-interactively 'beginning-of-line))))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1264
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1265 (defun widget-end-of-line ()
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1266 "Go to end of field or end of line, whichever is first."
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1267 (interactive "_")
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1268 (let* ((field (widget-field-find (point)))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1269 (end (and field (widget-field-end field))))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1270 (if (and end (not (eq end (point))))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1271 (goto-char end)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1272 (call-interactively 'end-of-line))))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1273
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1274 (defun widget-kill-line ()
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1275 "Kill to end of field or end of line, whichever is first."
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1276 (interactive)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1277 (let* ((field (widget-field-find (point)))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1278 (newline (save-excursion (forward-line 1) (point)))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1279 (end (and field (widget-field-end field))))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1280 (if (and field (> newline end))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1281 (kill-region (point) end)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1282 (call-interactively 'kill-line))))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1283
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1284 (defun widget-transpose-chars (arg)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1285 "Like `transpose-chars', but works correctly at end of widget."
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1286 (interactive "*P")
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1287 (let* ((field (widget-field-find (point)))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1288 (start (and field (widget-field-start field)))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1289 (end (and field (widget-field-end field)))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1290 (last-non-space (and start end
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1291 (save-excursion
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1292 (goto-char end)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1293 (skip-chars-backward " \t\n" start)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1294 (point)))))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1295 (cond ((and last-non-space
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1296 (or (= last-non-space start)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1297 (= last-non-space (1+ start))))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1298 ;; empty or one-character field
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1299 nil)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1300 ((= (point) start)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1301 ;; at the beginning of the field -- we would get an error here.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1302 (error "Cannot transpose at beginning of field"))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1303 (t
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1304 (when (and (null arg)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1305 (= last-non-space (point)))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1306 (forward-char -1))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1307 (transpose-chars arg)))))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1308
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1309 (defcustom widget-complete-field (lookup-key global-map "\M-\t")
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1310 "Default function to call for completion inside fields."
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1311 :options '(ispell-complete-word complete-tag lisp-complete-symbol)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1312 :type 'function
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1313 :group 'widgets)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1314
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1315 (defun widget-complete ()
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1316 "Complete content of editable field from point.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1317 When not inside a field, move to the previous button or field."
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1318 (interactive)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1319 ;; Somehow, this should make pressing M-TAB twice scroll the
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1320 ;; completions window.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1321 (let ((field (widget-field-find (point))))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1322 (if field
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1323 (widget-apply field :complete)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1324 (error "Not in an editable field"))))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1325
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1326
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1327 ;;; Setting up the buffer.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1328
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1329 (defvar widget-field-new nil)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1330 ;; List of all newly created editable fields in the buffer.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1331 (make-variable-buffer-local 'widget-field-new)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1332
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1333 (defvar widget-field-list nil)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1334 ;; List of all editable fields in the buffer.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1335 (make-variable-buffer-local 'widget-field-list)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1336
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1337 (defun widget-setup ()
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1338 "Setup current buffer so editing string widgets works."
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1339 (let ((inhibit-read-only t)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1340 (after-change-functions nil)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1341 before-change-functions
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1342 field)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1343 (while widget-field-new
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1344 (setq field (car widget-field-new)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1345 widget-field-new (cdr widget-field-new)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1346 widget-field-list (cons field widget-field-list))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1347 (let ((from (car (widget-get field :field-extent)))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1348 (to (cdr (widget-get field :field-extent))))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1349 (widget-specify-field field
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1350 (marker-position from) (marker-position to))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1351 (set-marker from nil)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1352 (set-marker to nil))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1353 ;; If the field is placed within the inactive zone, deactivate it.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1354 (let ((extent (widget-get field :field-extent)))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1355 (when (get-char-property (extent-start-position extent)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1356 'widget-inactive)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1357 (widget-activation-widget-mapper extent :deactivate)))))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1358 (widget-clear-undo)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1359 (widget-add-change))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1360
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1361 (defvar widget-field-last nil)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1362 ;; Last field containing point.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1363 (make-variable-buffer-local 'widget-field-last)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1364
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1365 (defvar widget-field-was nil)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1366 ;; The widget data before the change.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1367 (make-variable-buffer-local 'widget-field-was)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1368
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1369 (defun widget-field-buffer (widget)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1370 "Return the start of WIDGET's editing field."
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1371 (let ((extent (widget-get widget :field-extent)))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1372 (and extent (extent-object extent))))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1373
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1374 (defun widget-field-start (widget)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1375 "Return the start of WIDGET's editing field."
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1376 (let ((extent (widget-get widget :field-extent)))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1377 (and extent (extent-start-position extent))))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1378
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1379 (defun widget-field-end (widget)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1380 "Return the end of WIDGET's editing field."
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1381 (let ((extent (widget-get widget :field-extent)))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1382 ;; Don't subtract one if local-map works at the end of the extent.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1383 (and extent (if (or widget-field-add-space
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1384 (null (widget-get widget :size)))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1385 (1- (extent-end-position extent))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1386 (extent-end-position extent)))))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1387
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1388 (defun widget-field-find (pos)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1389 "Return the field at POS.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1390 Unlike (get-char-property POS 'field) this, works with empty fields too."
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1391 (let ((field-extent (map-extents (lambda (extent ignore)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1392 extent)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1393 nil pos pos nil nil 'field)))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1394 (and field-extent
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1395 (extent-property field-extent 'field))))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1396
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1397 ;; Old version, without `map-extents'.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1398 ;(defun widget-field-find (pos)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1399 ; (let ((fields widget-field-list)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1400 ; field found)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1401 ; (while fields
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1402 ; (setq field (car fields)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1403 ; fields (cdr fields))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1404 ; (let ((start (widget-field-start field))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1405 ; (end (widget-field-end field)))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1406 ; (when (and (<= start pos) (<= pos end))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1407 ; (when found
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1408 ; (debug "Overlapping fields"))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1409 ; (setq found field))))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1410 ; found))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1411
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1412 (defun widget-before-change (from to)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1413 ;; Barf if the text changed is outside the editable fields.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1414 (unless inhibit-read-only
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1415 (let ((from-field (widget-field-find from))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1416 (to-field (widget-field-find to)))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1417 (cond ((or (null from-field)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1418 (null to-field))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1419 ;; Either end of change is not within a field.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1420 (add-hook 'post-command-hook 'widget-add-change nil t)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1421 (error "Attempt to change text outside editable field"))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1422 ((not (eq from-field to-field))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1423 ;; The change begins in one fields, and ends in another one.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1424 (add-hook 'post-command-hook 'widget-add-change nil t)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1425 (error "Change should be restricted to a single field"))
213
78f53ef88e17 Import from CVS: tag r20-4b5
cvs
parents: 211
diff changeset
1426 ((or (and from-field
78f53ef88e17 Import from CVS: tag r20-4b5
cvs
parents: 211
diff changeset
1427 (get-char-property from 'widget-inactive))
78f53ef88e17 Import from CVS: tag r20-4b5
cvs
parents: 211
diff changeset
1428 (and to-field
78f53ef88e17 Import from CVS: tag r20-4b5
cvs
parents: 211
diff changeset
1429 (get-char-property to 'widget-inactive)))
78f53ef88e17 Import from CVS: tag r20-4b5
cvs
parents: 211
diff changeset
1430 ;; Trying to change an inactive editable field.
78f53ef88e17 Import from CVS: tag r20-4b5
cvs
parents: 211
diff changeset
1431 (add-hook 'post-command-hook 'widget-add-change nil t)
78f53ef88e17 Import from CVS: tag r20-4b5
cvs
parents: 211
diff changeset
1432 (error "Attempt to change an inactive field"))
209
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1433 (widget-field-use-before-change
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1434 ;; #### Bletch! This loses because XEmacs get confused
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1435 ;; if before-change-functions change the contents of
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1436 ;; buffer before from/to.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1437 (condition-case nil
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1438 (widget-apply from-field :notify from-field)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1439 (error (debug "Before Change"))))))))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1440
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1441 (defun widget-add-change ()
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1442 (make-local-hook 'post-command-hook)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1443 (remove-hook 'post-command-hook 'widget-add-change t)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1444 (make-local-hook 'before-change-functions)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1445 (add-hook 'before-change-functions 'widget-before-change nil t)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1446 (make-local-hook 'after-change-functions)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1447 (add-hook 'after-change-functions 'widget-after-change nil t))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1448
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1449 (defun widget-after-change (from to old)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1450 ;; Adjust field size and text properties.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1451
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1452 ;; Also, notify the widgets (so, for example, a variable changes its
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1453 ;; state to `modified'. when it is being edited.)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1454 (condition-case nil
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1455 (let ((field (widget-field-find from))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1456 (other (widget-field-find to)))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1457 (when field
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1458 (unless (eq field other)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1459 (debug "Change in different fields"))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1460 (let ((size (widget-get field :size))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1461 (secret (widget-get field :secret)))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1462 (when size
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1463 (let ((begin (widget-field-start field))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1464 (end (widget-field-end field)))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1465 (cond ((< (- end begin) size)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1466 ;; Field too small.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1467 (save-excursion
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1468 (goto-char end)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1469 (insert-char ?\ (- (+ begin size) end))))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1470 ((> (- end begin) size)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1471 ;; Field too large and
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1472 (if (or (< (point) (+ begin size))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1473 (> (point) end))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1474 ;; Point is outside extra space.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1475 (setq begin (+ begin size))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1476 ;; Point is within the extra space.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1477 (setq begin (point)))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1478 (save-excursion
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1479 (goto-char end)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1480 (while (and (eq (preceding-char) ?\ )
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1481 (> (point) begin))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1482 (delete-backward-char 1)))))))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1483 (when secret
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1484 (let ((begin (widget-field-start field))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1485 (end (widget-field-end field)))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1486 (when size
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1487 (while (and (> end begin)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1488 (eq (char-after (1- end)) ?\ ))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1489 (setq end (1- end))))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1490 (while (< begin end)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1491 (let ((old (char-after begin)))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1492 (unless (eq old secret)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1493 (subst-char-in-region begin (1+ begin) old secret)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1494 (put-text-property begin (1+ begin) 'secret old))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1495 (incf begin))))))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1496 (widget-apply field :notify field)))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1497 (error (debug "After Change"))))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1498
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1499
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1500 ;;; Widget Functions
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1501 ;;
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1502 ;; These functions are used in the definition of multiple widgets.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1503
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1504 (defun widget-parent-action (widget &optional event)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1505 "Tell :parent of WIDGET to handle the :action.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1506 Optional EVENT is the event that triggered the action."
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1507 (widget-apply (widget-get widget :parent) :action event))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1508
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1509 (defun widget-children-value-delete (widget)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1510 "Delete all :children and :buttons in WIDGET."
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1511 (mapc 'widget-delete (widget-get widget :children))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1512 (widget-put widget :children nil)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1513 (mapc 'widget-delete (widget-get widget :buttons))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1514 (widget-put widget :buttons nil))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1515
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1516 (defun widget-children-validate (widget)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1517 "All the :children must be valid."
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1518 (let ((children (widget-get widget :children))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1519 child found)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1520 (while (and children (not found))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1521 (setq child (car children)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1522 children (cdr children)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1523 found (widget-apply child :validate)))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1524 found))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1525
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1526 (defun widget-types-convert-widget (widget)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1527 "Convert :args as widget types in WIDGET."
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1528 (widget-put widget :args (mapcar 'widget-convert (widget-get widget :args)))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1529 widget)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1530
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1531 (defun widget-value-convert-widget (widget)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1532 "Initialize :value from :args in WIDGET."
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1533 (let ((args (widget-get widget :args)))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1534 (when args
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1535 (widget-put widget :value (car args))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1536 ;; Don't convert :value here, as this is done in `widget-convert'.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1537 ;; (widget-put widget :value (widget-apply widget
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1538 ;; :value-to-internal (car args)))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1539 (widget-put widget :args nil)))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1540 widget)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1541
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1542 (defun widget-value-value-get (widget)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1543 "Return the :value property of WIDGET."
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1544 (widget-get widget :value))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1545
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1546 ;;; The `default' Widget.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1547
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1548 (define-widget 'default nil
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1549 "Basic widget other widgets are derived from."
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1550 :value-to-internal (lambda (widget value) value)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1551 :value-to-external (lambda (widget value) value)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1552 :button-prefix 'widget-button-prefix
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1553 :button-suffix 'widget-button-suffix
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1554 :complete 'widget-default-complete
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1555 :create 'widget-default-create
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1556 :indent nil
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1557 :offset 0
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1558 :format-handler 'widget-default-format-handler
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1559 :button-face-get 'widget-default-button-face-get
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1560 :sample-face-get 'widget-default-sample-face-get
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1561 :button-keymap widget-button-keymap
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1562 :delete 'widget-default-delete
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1563 :value-set 'widget-default-value-set
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1564 :value-inline 'widget-default-value-inline
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1565 :menu-tag-get 'widget-default-menu-tag-get
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1566 :validate (lambda (widget) nil)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1567 :active 'widget-default-active
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1568 :activate 'widget-specify-active
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1569 :deactivate 'widget-default-deactivate
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1570 :mouse-down-action (lambda (widget event) nil)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1571 :action 'widget-default-action
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1572 :notify 'widget-default-notify
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1573 :prompt-value 'widget-default-prompt-value)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1574
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1575 (defun widget-default-complete (widget)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1576 "Call the value of the :complete-function property of WIDGET.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1577 If that does not exists, call the value of `widget-complete-field'."
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1578 (let ((fun (widget-get widget :complete-function)))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1579 (call-interactively (or fun widget-complete-field))))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1580
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1581 (defun widget-default-create (widget)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1582 "Create WIDGET at point in the current buffer."
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1583 (widget-specify-insert
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1584 (let ((from (point))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1585 button-begin button-end button-glyph
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1586 sample-begin sample-end
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1587 doc-begin doc-end
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1588 value-pos)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1589 (insert (widget-get widget :format))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1590 (goto-char from)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1591 ;; Parse escapes in format. Coding this in C would speed up
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1592 ;; things *a lot*.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1593 (while (re-search-forward "%\\(.\\)" nil t)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1594 (let ((escape (aref (match-string 1) 0)))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1595 (replace-match "" t t)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1596 (cond ((eq escape ?%)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1597 (insert "%"))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1598 ((eq escape ?\[)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1599 (setq button-begin (point-marker))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1600 (set-marker-insertion-type button-begin nil))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1601 ((eq escape ?\])
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1602 (setq button-end (point-marker))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1603 (set-marker-insertion-type button-end nil))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1604 ((eq escape ?\{)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1605 (setq sample-begin (point)))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1606 ((eq escape ?\})
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1607 (setq sample-end (point)))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1608 ((eq escape ?n)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1609 (when (widget-get widget :indent)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1610 (insert "\n")
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1611 (insert-char ?\ (widget-get widget :indent))))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1612 ((eq escape ?t)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1613 (let* ((tag (widget-get widget :tag))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1614 (glyph (widget-get widget :tag-glyph)))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1615 (cond (glyph
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1616 (setq button-glyph
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1617 (widget-glyph-insert
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1618 widget (or tag "Image") glyph)))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1619 (tag
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1620 (insert tag))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1621 (t
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1622 (let ((standard-output (current-buffer)))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1623 (princ (widget-get widget :value)))))))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1624 ((eq escape ?d)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1625 (let ((doc (widget-get widget :doc)))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1626 (when doc
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1627 (setq doc-begin (point))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1628 (insert doc)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1629 (while (eq (preceding-char) ?\n)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1630 (delete-backward-char 1))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1631 (insert "\n")
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1632 (setq doc-end (point)))))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1633 ((eq escape ?v)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1634 (if (and button-begin (not button-end))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1635 (widget-apply widget :value-create)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1636 (setq value-pos (point-marker))))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1637 (t
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1638 (widget-apply widget :format-handler escape)))))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1639 ;; Specify button, sample, and doc, and insert value.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1640 (when (and button-begin button-end)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1641 (unless button-glyph
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1642 (goto-char button-begin)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1643 (insert (widget-get-indirect widget :button-prefix))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1644 (goto-char button-end)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1645 (set-marker-insertion-type button-end t)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1646 (insert (widget-get-indirect widget :button-suffix)))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1647 (widget-specify-button widget button-begin button-end)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1648 ;; Is this necessary?
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1649 (set-marker button-begin nil)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1650 (set-marker button-end nil))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1651 (and sample-begin sample-end
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1652 (widget-specify-sample widget sample-begin sample-end))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1653 (and doc-begin doc-end
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1654 (widget-specify-doc widget doc-begin doc-end))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1655 (when value-pos
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1656 (goto-char value-pos)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1657 (widget-apply widget :value-create)))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1658 (let ((from (point-min-marker))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1659 (to (point-max-marker)))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1660 (set-marker-insertion-type from t)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1661 (set-marker-insertion-type to nil)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1662 (widget-put widget :from from)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1663 (widget-put widget :to to)))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1664 (widget-clear-undo))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1665
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1666 (defun widget-default-format-handler (widget escape)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1667 ;; We recognize the %h escape by default.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1668 (let* ((buttons (widget-get widget :buttons)))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1669 (cond ((eq escape ?h)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1670 (let* ((doc-property (widget-get widget :documentation-property))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1671 (doc-try (cond ((widget-get widget :doc))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1672 ((symbolp doc-property)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1673 (documentation-property
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1674 (widget-get widget :value)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1675 doc-property))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1676 (t
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1677 (funcall doc-property
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1678 (widget-get widget :value)))))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1679 (doc-text (and (stringp doc-try)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1680 (> (length doc-try) 1)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1681 doc-try))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1682 (doc-indent (widget-get widget :documentation-indent)))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1683 (when doc-text
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1684 (and (eq (preceding-char) ?\n)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1685 (widget-get widget :indent)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1686 (insert-char ?\ (widget-get widget :indent)))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1687 ;; The `*' in the beginning is redundant.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1688 (when (eq (aref doc-text 0) ?*)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1689 (setq doc-text (substring doc-text 1)))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1690 ;; Get rid of trailing newlines.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1691 (when (string-match "\n+\\'" doc-text)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1692 (setq doc-text (substring doc-text 0 (match-beginning 0))))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1693 (push (widget-create-child-and-convert
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1694 widget 'documentation-string
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1695 :indent (cond ((numberp doc-indent)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1696 doc-indent)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1697 ((null doc-indent)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1698 nil)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1699 (t 0))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1700 doc-text)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1701 buttons))))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1702 (t
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1703 (error "Unknown escape `%c'" escape)))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1704 (widget-put widget :buttons buttons)))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1705
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1706 (defun widget-default-button-face-get (widget)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1707 ;; Use :button-face or widget-button-face
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1708 (or (widget-get widget :button-face)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1709 (let ((parent (widget-get widget :parent)))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1710 (if parent
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1711 (widget-apply parent :button-face-get)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1712 widget-button-face))))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1713
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1714 (defun widget-default-sample-face-get (widget)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1715 ;; Use :sample-face.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1716 (widget-get widget :sample-face))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1717
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1718 (defun widget-default-delete (widget)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1719 ;; Remove widget from the buffer.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1720 (let ((from (widget-get widget :from))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1721 (to (widget-get widget :to))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1722 (inactive-extent (widget-get widget :inactive))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1723 (button-extent (widget-get widget :button-extent))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1724 (sample-extent (widget-get widget :sample-extent))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1725 (doc-extent (widget-get widget :doc-extent))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1726 before-change-functions
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1727 after-change-functions
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1728 (inhibit-read-only t))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1729 (widget-apply widget :value-delete)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1730 (when inactive-extent
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1731 (detach-extent inactive-extent))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1732 (when button-extent
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1733 (detach-extent button-extent))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1734 (when sample-extent
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1735 (detach-extent sample-extent))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1736 (when doc-extent
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1737 (detach-extent doc-extent))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1738 (when (< from to)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1739 ;; Kludge: this doesn't need to be true for empty formats.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1740 (delete-region from to))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1741 (set-marker from nil)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1742 (set-marker to nil))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1743 (widget-clear-undo))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1744
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1745 (defun widget-default-value-set (widget value)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1746 ;; Recreate widget with new value.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1747 (let* ((old-pos (point))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1748 (from (copy-marker (widget-get widget :from)))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1749 (to (copy-marker (widget-get widget :to)))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1750 (offset (if (and (<= from old-pos) (<= old-pos to))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1751 (if (>= old-pos (1- to))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1752 (- old-pos to 1)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1753 (- old-pos from)))))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1754 ;;??? Bug: this ought to insert the new value before deleting the old one,
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1755 ;; so that markers on either side of the value automatically
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1756 ;; stay on the same side. -- rms.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1757 (save-excursion
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1758 (goto-char (widget-get widget :from))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1759 (widget-apply widget :delete)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1760 (widget-put widget :value value)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1761 (widget-apply widget :create))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1762 (when offset
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1763 (if (< offset 0)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1764 (goto-char (+ (widget-get widget :to) offset 1))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1765 (goto-char (min (+ from offset) (1- (widget-get widget :to))))))))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1766
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1767 (defun widget-default-value-inline (widget)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1768 ;; Wrap value in a list unless it is inline.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1769 (if (widget-get widget :inline)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1770 (widget-value widget)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1771 (list (widget-value widget))))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1772
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1773 (defun widget-default-menu-tag-get (widget)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1774 ;; Use tag or value for menus.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1775 (or (widget-get widget :menu-tag)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1776 (widget-get widget :tag)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1777 (widget-princ-to-string (widget-get widget :value))))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1778
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1779 (defun widget-default-active (widget)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1780 "Return t iff this widget active (user modifiable)."
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1781 (and (not (widget-get widget :inactive))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1782 (let ((parent (widget-get widget :parent)))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1783 (or (null parent)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1784 (widget-apply parent :active)))))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1785
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1786 (defun widget-default-deactivate (widget)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1787 "Make WIDGET inactive for user modifications."
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1788 (widget-specify-inactive widget
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1789 (widget-get widget :from)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1790 (widget-get widget :to)))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1791
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1792 (defun widget-default-action (widget &optional event)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1793 ;; Notify the parent when a widget change
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1794 (let ((parent (widget-get widget :parent)))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1795 (when parent
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1796 (widget-apply parent :notify widget event))))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1797
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1798 (defun widget-default-notify (widget child &optional event)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1799 ;; Pass notification to parent.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1800 (widget-default-action widget event))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1801
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1802 (defun widget-default-prompt-value (widget prompt value unbound)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1803 ;; Read an arbitrary value. Stolen from `set-variable'.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1804 ;; (let ((initial (if unbound
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1805 ;; nil
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1806 ;; ;; It would be nice if we could do a `(cons val 1)' here.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1807 ;; (prin1-to-string (custom-quote value))))))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1808 (eval-minibuffer prompt ))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1809
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1810 ;;; The `item' Widget.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1811
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1812 (define-widget 'item 'default
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1813 "Constant items for inclusion in other widgets."
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1814 :convert-widget 'widget-value-convert-widget
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1815 :value-create 'widget-item-value-create
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1816 :value-delete 'ignore
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1817 :value-get 'widget-value-value-get
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1818 :match 'widget-item-match
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1819 :match-inline 'widget-item-match-inline
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1820 :action 'widget-item-action
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1821 :format "%t\n")
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1822
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1823 (defun widget-item-value-create (widget)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1824 ;; Insert the printed representation of the value.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1825 (let ((standard-output (current-buffer)))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1826 (princ (widget-get widget :value))))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1827
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1828 (defun widget-item-match (widget value)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1829 ;; Match if the value is the same.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1830 (equal (widget-get widget :value) value))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1831
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1832 (defun widget-item-match-inline (widget values)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1833 ;; Match if the value is the same.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1834 (let ((value (widget-get widget :value)))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1835 (and (listp value)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1836 (<= (length value) (length values))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1837 (let ((head (widget-sublist values 0 (length value))))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1838 (and (equal head value)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1839 (cons head (widget-sublist values (length value))))))))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1840
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1841 (defun widget-sublist (list start &optional end)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1842 "Return the sublist of LIST from START to END.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1843 If END is omitted, it defaults to the length of LIST."
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1844 (if (> start 0) (setq list (nthcdr start list)))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1845 (if end
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1846 (if (<= end start)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1847 nil
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1848 (setq list (copy-sequence list))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1849 (setcdr (nthcdr (- end start 1) list) nil)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1850 list)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1851 (copy-sequence list)))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1852
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1853 (defun widget-item-action (widget &optional event)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1854 ;; Just notify itself.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1855 (widget-apply widget :notify widget event))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1856
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1857 ;;; The `push-button' Widget.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1858
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1859 (defcustom widget-push-button-gui widget-glyph-enable
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1860 "If non nil, use GUI push buttons when available."
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1861 :group 'widgets
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1862 :type 'boolean)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1863
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1864 ;; Cache already created GUI objects.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1865 (defvar widget-push-button-cache nil)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1866
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1867 (defcustom widget-push-button-prefix "["
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1868 "String used as prefix for buttons."
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1869 :type 'string
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1870 :group 'widget-button)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1871
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1872 (defcustom widget-push-button-suffix "]"
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1873 "String used as suffix for buttons."
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1874 :type 'string
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1875 :group 'widget-button)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1876
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1877 (define-widget 'push-button 'item
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1878 "A pushable button."
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1879 :button-prefix ""
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1880 :button-suffix ""
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1881 :value-create 'widget-push-button-value-create
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1882 :format "%[%v%]")
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1883
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1884 (defun widget-push-button-value-create (widget)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1885 ;; Insert text representing the `on' and `off' states.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1886 (let* ((tag (or (widget-get widget :tag)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1887 (widget-get widget :value)))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1888 (tag-glyph (widget-get widget :tag-glyph))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1889 (text (concat widget-push-button-prefix
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1890 tag widget-push-button-suffix))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1891 (gui-glyphs (lax-plist-get widget-push-button-cache tag)))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1892 (cond (tag-glyph
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1893 (widget-glyph-insert widget text tag-glyph))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1894 ;; We must check for console-on-window-system-p here,
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1895 ;; because GUI will not work otherwise (it needs RGB
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1896 ;; components for colors, and they are not known on TTYs).
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1897 ((and widget-push-button-gui
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1898 (console-on-window-system-p))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1899 (unless gui-glyphs
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1900 (let* ((gui-button-shadow-thickness 1)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1901 (gui (make-gui-button tag 'widget-gui-action widget)))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1902 (setq
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1903 gui-glyphs
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1904 (list
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1905 (make-glyph `(,(nth 0 (aref gui 1)) [string :data ,text]))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1906 (make-glyph `(,(nth 1 (aref gui 1)) [string :data ,text]))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1907 (make-glyph `(,(nth 2 (aref gui 1)) [string :data ,text]))))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1908 (laxputf widget-push-button-cache tag gui-glyphs)))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1909 (widget-glyph-insert-glyph
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1910 widget (nth 0 gui-glyphs) (nth 1 gui-glyphs) (nth 2 gui-glyphs)))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1911 (t
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1912 (insert text)))))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1913
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1914 (defun widget-gui-action (widget)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1915 "Apply :action for WIDGET."
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1916 (widget-apply-action widget (this-command-keys)))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1917
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1918 ;;; The `link' Widget.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1919
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1920 (defcustom widget-link-prefix "["
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1921 "String used as prefix for links."
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1922 :type 'string
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1923 :group 'widget-button)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1924
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1925 (defcustom widget-link-suffix "]"
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1926 "String used as suffix for links."
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1927 :type 'string
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1928 :group 'widget-button)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1929
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1930 (define-widget 'link 'item
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1931 "An embedded link."
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1932 :button-prefix 'widget-link-prefix
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1933 :button-suffix 'widget-link-suffix
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1934 :help-echo "Follow the link"
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1935 :format "%[%t%]")
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1936
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1937 ;;; The `info-link' Widget.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1938
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1939 (define-widget 'info-link 'link
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1940 "A link to an info file."
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1941 :help-echo 'widget-info-link-help-echo
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1942 :action 'widget-info-link-action)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1943
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1944 (defun widget-info-link-help-echo (widget)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1945 (concat "Read the manual entry `" (widget-value widget) "'"))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1946
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1947 (defun widget-info-link-action (widget &optional event)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1948 "Open the info node specified by WIDGET."
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1949 (Info-goto-node (widget-value widget)))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1950
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1951 ;;; The `url-link' Widget.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1952
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1953 (define-widget 'url-link 'link
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1954 "A link to an www page."
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1955 :help-echo 'widget-url-link-help-echo
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1956 :action 'widget-url-link-action)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1957
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1958 (defun widget-url-link-help-echo (widget)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1959 (concat "Visit <URL:" (widget-value widget) ">"))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1960
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1961 (defun widget-url-link-action (widget &optional event)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1962 "Open the url specified by WIDGET."
219
262b8bb4a523 Import from CVS: tag r20-4b8
cvs
parents: 213
diff changeset
1963 (if (boundp 'browse-url-browser-function)
262b8bb4a523 Import from CVS: tag r20-4b8
cvs
parents: 213
diff changeset
1964 (funcall browse-url-browser-function (widget-value widget))
262b8bb4a523 Import from CVS: tag r20-4b8
cvs
parents: 213
diff changeset
1965 (error "Cannot follow URLs in this XEmacs")))
209
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1966
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1967 ;;; The `function-link' Widget.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1968
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1969 (define-widget 'function-link 'link
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1970 "A link to an Emacs function."
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1971 :action 'widget-function-link-action)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1972
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1973 (defun widget-function-link-action (widget &optional event)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1974 "Show the function specified by WIDGET."
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1975 (describe-function (widget-value widget)))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1976
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1977 ;;; The `variable-link' Widget.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1978
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1979 (define-widget 'variable-link 'link
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1980 "A link to an Emacs variable."
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1981 :action 'widget-variable-link-action)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1982
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1983 (defun widget-variable-link-action (widget &optional event)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1984 "Show the variable specified by WIDGET."
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1985 (describe-variable (widget-value widget)))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1986
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1987 ;;; The `file-link' Widget.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1988
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1989 (define-widget 'file-link 'link
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1990 "A link to a file."
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1991 :action 'widget-file-link-action)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1992
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1993 (defun widget-file-link-action (widget &optional event)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1994 "Find the file specified by WIDGET."
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1995 (find-file (widget-value widget)))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1996
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1997 ;;; The `emacs-library-link' Widget.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1998
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1999 (define-widget 'emacs-library-link 'link
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2000 "A link to an Emacs Lisp library file."
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2001 :help-echo 'widget-emacs-library-link-help-echo
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2002 :action 'widget-emacs-library-link-action)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2003
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2004 (defun widget-emacs-library-link-help-echo (widget)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2005 (concat "Visit " (widget-value widget)))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2006
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2007 (defun widget-emacs-library-link-action (widget &optional event)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2008 "Find the Emacs Library file specified by WIDGET."
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2009 (find-file (locate-library (widget-value widget))))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2010
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2011 ;;; The `emacs-commentary-link' Widget.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2012
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2013 (define-widget 'emacs-commentary-link 'link
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2014 "A link to Commentary in an Emacs Lisp library file."
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2015 :action 'widget-emacs-commentary-link-action)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2016
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2017 (defun widget-emacs-commentary-link-action (widget &optional event)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2018 "Find the Commentary section of the Emacs file specified by WIDGET."
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2019 (finder-commentary (widget-value widget)))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2020
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2021 ;;; The `editable-field' Widget.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2022
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2023 (define-widget 'editable-field 'default
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2024 "An editable text field."
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2025 :convert-widget 'widget-value-convert-widget
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2026 :keymap widget-field-keymap
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2027 :format "%v"
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2028 :value ""
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2029 :prompt-internal 'widget-field-prompt-internal
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2030 :prompt-history 'widget-field-history
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2031 :prompt-value 'widget-field-prompt-value
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2032 :action 'widget-field-action
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2033 :validate 'widget-field-validate
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2034 :valid-regexp ""
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2035 :error "No match"
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2036 :value-create 'widget-field-value-create
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2037 :value-delete 'widget-field-value-delete
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2038 :value-get 'widget-field-value-get
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2039 :match 'widget-field-match)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2040
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2041 (defvar widget-field-history nil
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2042 "History of field minibuffer edits.")
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2043
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2044 (defun widget-field-prompt-internal (widget prompt initial history)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2045 ;; Read string for WIDGET prompting with PROMPT.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2046 ;; INITIAL is the initial input and HISTORY is a symbol containing
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2047 ;; the earlier input.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2048 (read-string prompt initial history))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2049
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2050 (defun widget-field-prompt-value (widget prompt value unbound)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2051 ;; Prompt for a string.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2052 (let ((initial (if unbound
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2053 nil
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2054 (cons (widget-apply widget :value-to-internal
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2055 value) 0)))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2056 (history (widget-get widget :prompt-history)))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2057 (let ((answer (widget-apply widget
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2058 :prompt-internal prompt initial history)))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2059 (widget-apply widget :value-to-external answer))))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2060
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2061 (defvar widget-edit-functions nil)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2062
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2063 (defun widget-field-action (widget &optional event)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2064 ;; Edit the value in the minibuffer.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2065 (let* ((invalid (widget-apply widget :validate))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2066 (prompt (concat (widget-apply widget :menu-tag-get) ": "))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2067 (value (unless invalid
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2068 (widget-value widget)))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2069 (answer (widget-apply widget :prompt-value prompt value invalid)))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2070 (unless (equal value answer)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2071 ;; This is a hack. We can't properly validate the widget
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2072 ;; because validation requires the new value to be in the field.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2073 ;; However, widget-field-value-create will not function unless
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2074 ;; the new value matches. So, we check whether the thing
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2075 ;; matches, and if it does, use either the real or a dummy error
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2076 ;; message.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2077 (unless (widget-apply widget :match answer)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2078 (let ((error-message (or (widget-get widget :type-error)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2079 "Invalid field contents")))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2080 (widget-put widget :error error-message)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2081 (error error-message)))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2082 (widget-value-set widget answer)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2083 (widget-apply widget :notify widget event)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2084 (widget-setup))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2085 (run-hook-with-args 'widget-edit-functions widget)))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2086
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2087 ;(defun widget-field-action (widget &optional event)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2088 ; ;; Move to next field.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2089 ; (widget-forward 1)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2090 ; (run-hook-with-args 'widget-edit-functions widget))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2091
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2092 (defun widget-field-validate (widget)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2093 ;; Valid if the content matches `:valid-regexp'.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2094 (save-excursion
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2095 (let ((value (widget-apply widget :value-get))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2096 (regexp (widget-get widget :valid-regexp)))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2097 (if (string-match regexp value)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2098 nil
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2099 widget))))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2100
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2101 (defun widget-field-value-create (widget)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2102 ;; Create an editable text field.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2103 (let ((size (widget-get widget :size))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2104 (value (widget-get widget :value))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2105 (from (point))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2106 ;; This is changed to a real extent in `widget-setup'. We
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2107 ;; need the end points to behave differently until
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2108 ;; `widget-setup' is called. Should probably be replaced with
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2109 ;; a genuine extent, but some things break, then.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2110 (extent (cons (make-marker) (make-marker))))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2111 (widget-put widget :field-extent extent)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2112 (insert value)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2113 (and size
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2114 (< (length value) size)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2115 (insert-char ?\ (- size (length value))))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2116 (unless (memq widget widget-field-list)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2117 (push widget widget-field-new))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2118 (move-marker (cdr extent) (point))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2119 (set-marker-insertion-type (cdr extent) nil)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2120 (when (null size)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2121 (insert ?\n))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2122 (move-marker (car extent) from)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2123 (set-marker-insertion-type (car extent) t)))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2124
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2125 (defun widget-field-value-delete (widget)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2126 ;; Remove the widget from the list of active editing fields.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2127 (setq widget-field-list (delq widget widget-field-list))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2128 ;; These are nil if the :format string doesn't contain `%v'.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2129 (let ((extent (widget-get widget :field-extent)))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2130 (when extent
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2131 (detach-extent extent))))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2132
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2133 (defun widget-field-value-get (widget)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2134 ;; Return current text in editing field.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2135 (let ((from (widget-field-start widget))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2136 (to (widget-field-end widget))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2137 (buffer (widget-field-buffer widget))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2138 (size (widget-get widget :size))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2139 (secret (widget-get widget :secret))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2140 (old (current-buffer)))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2141 (cond
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2142 ((and from to)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2143 (set-buffer buffer)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2144 (while (and size
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2145 (not (zerop size))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2146 (> to from)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2147 (eq (char-after (1- to)) ?\ ))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2148 (setq to (1- to)))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2149 (let ((result (buffer-substring-no-properties from to)))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2150 (when secret
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2151 (let ((index 0))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2152 (while (< (+ from index) to)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2153 (aset result index
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2154 (get-char-property (+ from index) 'secret))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2155 (incf index))))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2156 (set-buffer old)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2157 result))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2158 (t
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2159 (widget-get widget :value)))))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2160
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2161 (defun widget-field-match (widget value)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2162 ;; Match any string.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2163 (stringp value))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2164
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2165 ;;; The `text' Widget.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2166
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2167 (define-widget 'text 'editable-field
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2168 :keymap widget-text-keymap
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2169 "A multiline text area.")
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2170
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2171 ;;; The `menu-choice' Widget.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2172
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2173 (define-widget 'menu-choice 'default
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2174 "A menu of options."
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2175 :convert-widget 'widget-types-convert-widget
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2176 :format "%[%t%]: %v"
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2177 :case-fold t
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2178 :tag "choice"
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2179 :void '(item :format "invalid (%t)\n")
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2180 :value-create 'widget-choice-value-create
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2181 :value-delete 'widget-children-value-delete
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2182 :value-get 'widget-choice-value-get
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2183 :value-inline 'widget-choice-value-inline
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2184 :mouse-down-action 'widget-choice-mouse-down-action
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2185 :action 'widget-choice-action
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2186 :error "Make a choice"
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2187 :validate 'widget-choice-validate
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2188 :match 'widget-choice-match
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2189 :match-inline 'widget-choice-match-inline)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2190
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2191 (defun widget-choice-value-create (widget)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2192 ;; Insert the first choice that matches the value.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2193 (let ((value (widget-get widget :value))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2194 (args (widget-get widget :args))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2195 current)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2196 (while args
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2197 (setq current (car args)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2198 args (cdr args))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2199 (when (widget-apply current :match value)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2200 (widget-put widget :children (list (widget-create-child-value
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2201 widget current value)))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2202 (widget-put widget :choice current)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2203 (setq args nil
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2204 current nil)))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2205 (when current
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2206 (let ((void (widget-get widget :void)))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2207 (widget-put widget :children (list (widget-create-child-and-convert
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2208 widget void :value value)))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2209 (widget-put widget :choice void)))))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2210
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2211 (defun widget-choice-value-get (widget)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2212 ;; Get value of the child widget.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2213 (widget-value (car (widget-get widget :children))))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2214
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2215 (defun widget-choice-value-inline (widget)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2216 ;; Get value of the child widget.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2217 (widget-apply (car (widget-get widget :children)) :value-inline))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2218
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2219 (defcustom widget-choice-toggle nil
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2220 "If non-nil, a binary choice will just toggle between the values.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2221 Otherwise, the user will explicitly have to choose between the values
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2222 when he invoked the menu."
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2223 :type 'boolean
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2224 :group 'widgets)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2225
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2226 (defun widget-choice-mouse-down-action (widget &optional event)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2227 ;; Return non-nil if we need a menu.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2228 (let ((args (widget-get widget :args))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2229 (old (widget-get widget :choice)))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2230 (cond ((not (console-on-window-system-p))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2231 ;; No place to pop up a menu.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2232 nil)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2233 ((< (length args) 2)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2234 ;; Empty or singleton list, just return the value.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2235 nil)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2236 ((> (length args) widget-menu-max-size)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2237 ;; Too long, prompt.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2238 nil)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2239 ((> (length args) 2)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2240 ;; Reasonable sized list, use menu.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2241 t)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2242 ((and widget-choice-toggle (memq old args))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2243 ;; We toggle.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2244 nil)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2245 (t
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2246 ;; Ask which of the two.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2247 t))))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2248
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2249 (defun widget-choice-action (widget &optional event)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2250 ;; Make a choice.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2251 (let ((args (widget-get widget :args))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2252 (old (widget-get widget :choice))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2253 (tag (widget-apply widget :menu-tag-get))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2254 (completion-ignore-case (widget-get widget :case-fold))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2255 current choices)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2256 ;; Remember old value.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2257 (if (and old (not (widget-apply widget :validate)))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2258 (let* ((external (widget-value widget))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2259 (internal (widget-apply old :value-to-internal external)))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2260 (widget-put old :value internal)))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2261 ;; Find new choice.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2262 (setq current
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2263 (cond ((= (length args) 0)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2264 nil)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2265 ((= (length args) 1)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2266 (nth 0 args))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2267 ((and widget-choice-toggle
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2268 (= (length args) 2)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2269 (memq old args))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2270 (if (eq old (nth 0 args))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2271 (nth 1 args)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2272 (nth 0 args)))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2273 (t
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2274 (while args
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2275 (setq current (car args)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2276 args (cdr args))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2277 (setq choices
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2278 (cons (cons (widget-apply current :menu-tag-get)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2279 current)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2280 choices)))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2281 (widget-choose tag (reverse choices) event))))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2282 (when current
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2283 (widget-value-set widget
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2284 (widget-apply current :value-to-external
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2285 (widget-get current :value)))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2286 (widget-setup)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2287 (widget-apply widget :notify widget event)))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2288 (run-hook-with-args 'widget-edit-functions widget))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2289
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2290 (defun widget-choice-validate (widget)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2291 ;; Valid if we have made a valid choice.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2292 (let ((void (widget-get widget :void))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2293 (choice (widget-get widget :choice))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2294 (child (car (widget-get widget :children))))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2295 (if (eq void choice)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2296 widget
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2297 (widget-apply child :validate))))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2298
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2299 (defun widget-choice-match (widget value)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2300 ;; Matches if one of the choices matches.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2301 (let ((args (widget-get widget :args))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2302 current found)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2303 (while (and args (not found))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2304 (setq current (car args)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2305 args (cdr args)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2306 found (widget-apply current :match value)))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2307 found))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2308
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2309 (defun widget-choice-match-inline (widget values)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2310 ;; Matches if one of the choices matches.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2311 (let ((args (widget-get widget :args))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2312 current found)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2313 (while (and args (null found))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2314 (setq current (car args)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2315 args (cdr args)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2316 found (widget-match-inline current values)))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2317 found))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2318
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2319 ;;; The `toggle' Widget.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2320
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2321 (define-widget 'toggle 'item
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2322 "Toggle between two states."
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2323 :format "%[%v%]\n"
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2324 :value-create 'widget-toggle-value-create
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2325 :action 'widget-toggle-action
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2326 :match (lambda (widget value) t)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2327 :on "on"
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2328 :off "off")
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2329
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2330 (defun widget-toggle-value-create (widget)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2331 ;; Insert text representing the `on' and `off' states.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2332 (if (widget-value widget)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2333 (widget-glyph-insert widget
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2334 (widget-get widget :on)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2335 (widget-get widget :on-glyph))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2336 (widget-glyph-insert widget
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2337 (widget-get widget :off)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2338 (widget-get widget :off-glyph))))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2339
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2340 (defun widget-toggle-action (widget &optional event)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2341 ;; Toggle value.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2342 (widget-value-set widget (not (widget-value widget)))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2343 (widget-apply widget :notify widget event)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2344 (run-hook-with-args 'widget-edit-functions widget))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2345
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2346 ;;; The `checkbox' Widget.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2347
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2348 (define-widget 'checkbox 'toggle
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2349 "A checkbox toggle."
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2350 :button-suffix ""
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2351 :button-prefix ""
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2352 :format "%[%v%]"
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2353 :on "[X]"
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2354 :on-glyph "check1"
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2355 :off "[ ]"
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2356 :off-glyph "check0"
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2357 :action 'widget-checkbox-action)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2358
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2359 (defun widget-checkbox-action (widget &optional event)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2360 "Toggle checkbox, notify parent, and set active state of sibling."
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2361 (widget-toggle-action widget event)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2362 (let ((sibling (widget-get-sibling widget)))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2363 (when sibling
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2364 (if (widget-value widget)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2365 (widget-apply sibling :activate)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2366 (widget-apply sibling :deactivate)))))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2367
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2368 ;;; The `checklist' Widget.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2369
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2370 (define-widget 'checklist 'default
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2371 "A multiple choice widget."
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2372 :convert-widget 'widget-types-convert-widget
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2373 :format "%v"
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2374 :offset 4
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2375 :entry-format "%b %v"
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2376 :menu-tag "checklist"
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2377 :greedy nil
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2378 :value-create 'widget-checklist-value-create
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2379 :value-delete 'widget-children-value-delete
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2380 :value-get 'widget-checklist-value-get
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2381 :validate 'widget-checklist-validate
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2382 :match 'widget-checklist-match
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2383 :match-inline 'widget-checklist-match-inline)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2384
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2385 (defun widget-checklist-value-create (widget)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2386 ;; Insert all values
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2387 (let ((alist (widget-checklist-match-find widget (widget-get widget :value)))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2388 (args (widget-get widget :args)))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2389 (while args
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2390 (widget-checklist-add-item widget (car args) (assq (car args) alist))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2391 (setq args (cdr args)))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2392 (widget-put widget :children (nreverse (widget-get widget :children)))))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2393
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2394 (defun widget-checklist-add-item (widget type chosen)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2395 ;; Create checklist item in WIDGET of type TYPE.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2396 ;; If the item is checked, CHOSEN is a cons whose cdr is the value.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2397 (and (eq (preceding-char) ?\n)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2398 (widget-get widget :indent)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2399 (insert-char ?\ (widget-get widget :indent)))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2400 (widget-specify-insert
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2401 (let* ((children (widget-get widget :children))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2402 (buttons (widget-get widget :buttons))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2403 (button-args (or (widget-get type :sibling-args)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2404 (widget-get widget :button-args)))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2405 (from (point))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2406 child button)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2407 (insert (widget-get widget :entry-format))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2408 (goto-char from)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2409 ;; Parse % escapes in format.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2410 (while (re-search-forward "%\\([bv%]\\)" nil t)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2411 (let ((escape (aref (match-string 1) 0)))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2412 (replace-match "" t t)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2413 (cond ((eq escape ?%)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2414 (insert "%"))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2415 ((eq escape ?b)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2416 (setq button (apply 'widget-create-child-and-convert
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2417 widget 'checkbox
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2418 :value (not (null chosen))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2419 button-args)))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2420 ((eq escape ?v)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2421 (setq child
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2422 (cond ((not chosen)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2423 (let ((child (widget-create-child widget type)))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2424 (widget-apply child :deactivate)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2425 child))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2426 ((widget-get type :inline)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2427 (widget-create-child-value
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2428 widget type (cdr chosen)))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2429 (t
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2430 (widget-create-child-value
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2431 widget type (car (cdr chosen)))))))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2432 (t
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2433 (error "Unknown escape `%c'" escape)))))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2434 ;; Update properties.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2435 (and button child (widget-put child :button button))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2436 (and button (widget-put widget :buttons (cons button buttons)))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2437 (and child (widget-put widget :children (cons child children))))))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2438
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2439 (defun widget-checklist-match (widget values)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2440 ;; All values must match a type in the checklist.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2441 (and (listp values)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2442 (null (cdr (widget-checklist-match-inline widget values)))))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2443
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2444 (defun widget-checklist-match-inline (widget values)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2445 ;; Find the values which match a type in the checklist.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2446 (let ((greedy (widget-get widget :greedy))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2447 (args (copy-sequence (widget-get widget :args)))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2448 found rest)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2449 (while values
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2450 (let ((answer (widget-checklist-match-up args values)))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2451 (cond (answer
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2452 (let ((vals (widget-match-inline answer values)))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2453 (setq found (append found (car vals))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2454 values (cdr vals)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2455 args (delq answer args))))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2456 (greedy
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2457 (setq rest (append rest (list (car values)))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2458 values (cdr values)))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2459 (t
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2460 (setq rest (append rest values)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2461 values nil)))))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2462 (cons found rest)))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2463
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2464 (defun widget-checklist-match-find (widget vals)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2465 ;; Find the vals which match a type in the checklist.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2466 ;; Return an alist of (TYPE MATCH).
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2467 (let ((greedy (widget-get widget :greedy))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2468 (args (copy-sequence (widget-get widget :args)))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2469 found)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2470 (while vals
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2471 (let ((answer (widget-checklist-match-up args vals)))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2472 (cond (answer
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2473 (let ((match (widget-match-inline answer vals)))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2474 (setq found (cons (cons answer (car match)) found)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2475 vals (cdr match)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2476 args (delq answer args))))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2477 (greedy
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2478 (setq vals (cdr vals)))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2479 (t
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2480 (setq vals nil)))))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2481 found))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2482
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2483 (defun widget-checklist-match-up (args vals)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2484 ;; Rerturn the first type from ARGS that matches VALS.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2485 (let (current found)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2486 (while (and args (null found))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2487 (setq current (car args)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2488 args (cdr args)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2489 found (widget-match-inline current vals)))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2490 (if found
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2491 current
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2492 nil)))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2493
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2494 (defun widget-checklist-value-get (widget)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2495 ;; The values of all selected items.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2496 (let ((children (widget-get widget :children))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2497 child result)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2498 (while children
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2499 (setq child (car children)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2500 children (cdr children))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2501 (if (widget-value (widget-get child :button))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2502 (setq result (append result (widget-apply child :value-inline)))))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2503 result))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2504
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2505 (defun widget-checklist-validate (widget)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2506 ;; Ticked chilren must be valid.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2507 (let ((children (widget-get widget :children))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2508 child button found)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2509 (while (and children (not found))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2510 (setq child (car children)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2511 children (cdr children)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2512 button (widget-get child :button)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2513 found (and (widget-value button)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2514 (widget-apply child :validate))))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2515 found))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2516
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2517 ;;; The `option' Widget
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2518
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2519 (define-widget 'option 'checklist
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2520 "An widget with an optional item."
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2521 :inline t)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2522
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2523 ;;; The `choice-item' Widget.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2524
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2525 (define-widget 'choice-item 'item
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2526 "Button items that delegate action events to their parents."
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2527 :action 'widget-parent-action
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2528 :format "%[%t%] \n")
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2529
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2530 ;;; The `radio-button' Widget.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2531
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2532 (define-widget 'radio-button 'toggle
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2533 "A radio button for use in the `radio' widget."
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2534 :notify 'widget-radio-button-notify
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2535 :format "%[%v%]"
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2536 :button-suffix ""
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2537 :button-prefix ""
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2538 :on "(*)"
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2539 :on-glyph '("radio1" nil "radio0")
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2540 :off "( )"
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2541 :off-glyph "radio0")
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2542
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2543 (defun widget-radio-button-notify (widget child &optional event)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2544 ;; Tell daddy.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2545 (widget-apply (widget-get widget :parent) :action widget event))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2546
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2547 ;;; The `radio-button-choice' Widget.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2548
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2549 (define-widget 'radio-button-choice 'default
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2550 "Select one of multiple options."
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2551 :convert-widget 'widget-types-convert-widget
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2552 :offset 4
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2553 :format "%v"
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2554 :entry-format "%b %v"
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2555 :menu-tag "radio"
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2556 :value-create 'widget-radio-value-create
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2557 :value-delete 'widget-children-value-delete
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2558 :value-get 'widget-radio-value-get
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2559 :value-inline 'widget-radio-value-inline
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2560 :value-set 'widget-radio-value-set
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2561 :error "You must push one of the buttons"
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2562 :validate 'widget-radio-validate
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2563 :match 'widget-choice-match
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2564 :match-inline 'widget-choice-match-inline
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2565 :action 'widget-radio-action)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2566
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2567 (defun widget-radio-value-create (widget)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2568 ;; Insert all values
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2569 (let ((args (widget-get widget :args))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2570 arg)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2571 (while args
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2572 (setq arg (car args)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2573 args (cdr args))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2574 (widget-radio-add-item widget arg))))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2575
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2576 (defun widget-radio-add-item (widget type)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2577 "Add to radio widget WIDGET a new radio button item of type TYPE."
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2578 ;; (setq type (widget-convert type))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2579 (and (eq (preceding-char) ?\n)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2580 (widget-get widget :indent)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2581 (insert-char ?\ (widget-get widget :indent)))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2582 (widget-specify-insert
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2583 (let* ((value (widget-get widget :value))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2584 (children (widget-get widget :children))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2585 (buttons (widget-get widget :buttons))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2586 (button-args (or (widget-get type :sibling-args)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2587 (widget-get widget :button-args)))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2588 (from (point))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2589 (chosen (and (null (widget-get widget :choice))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2590 (widget-apply type :match value)))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2591 child button)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2592 (insert (widget-get widget :entry-format))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2593 (goto-char from)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2594 ;; Parse % escapes in format.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2595 (while (re-search-forward "%\\([bv%]\\)" nil t)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2596 (let ((escape (aref (match-string 1) 0)))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2597 (replace-match "" t t)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2598 (cond ((eq escape ?%)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2599 (insert "%"))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2600 ((eq escape ?b)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2601 (setq button (apply 'widget-create-child-and-convert
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2602 widget 'radio-button
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2603 :value (not (null chosen))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2604 button-args)))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2605 ((eq escape ?v)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2606 (setq child (if chosen
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2607 (widget-create-child-value
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2608 widget type value)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2609 (widget-create-child widget type)))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2610 (unless chosen
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2611 (widget-apply child :deactivate)))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2612 (t
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2613 (error "Unknown escape `%c'" escape)))))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2614 ;; Update properties.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2615 (when chosen
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2616 (widget-put widget :choice type))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2617 (when button
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2618 (widget-put child :button button)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2619 (widget-put widget :buttons (nconc buttons (list button))))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2620 (when child
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2621 (widget-put widget :children (nconc children (list child))))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2622 child)))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2623
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2624 (defun widget-radio-value-get (widget)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2625 ;; Get value of the child widget.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2626 (let ((chosen (widget-radio-chosen widget)))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2627 (and chosen (widget-value chosen))))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2628
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2629 (defun widget-radio-chosen (widget)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2630 "Return the widget representing the chosen radio button."
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2631 (let ((children (widget-get widget :children))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2632 current found)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2633 (while children
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2634 (setq current (car children)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2635 children (cdr children))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2636 (let* ((button (widget-get current :button))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2637 (value (widget-apply button :value-get)))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2638 (when value
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2639 (setq found current
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2640 children nil))))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2641 found))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2642
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2643 (defun widget-radio-value-inline (widget)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2644 ;; Get value of the child widget.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2645 (let ((children (widget-get widget :children))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2646 current found)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2647 (while children
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2648 (setq current (car children)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2649 children (cdr children))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2650 (let* ((button (widget-get current :button))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2651 (value (widget-apply button :value-get)))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2652 (when value
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2653 (setq found (widget-apply current :value-inline)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2654 children nil))))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2655 found))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2656
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2657 (defun widget-radio-value-set (widget value)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2658 ;; We can't just delete and recreate a radio widget, since children
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2659 ;; can be added after the original creation and won't be recreated
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2660 ;; by `:create'.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2661 (let ((children (widget-get widget :children))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2662 current found)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2663 (while children
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2664 (setq current (car children)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2665 children (cdr children))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2666 (let* ((button (widget-get current :button))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2667 (match (and (not found)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2668 (widget-apply current :match value))))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2669 (widget-value-set button match)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2670 (if match
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2671 (progn
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2672 (widget-value-set current value)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2673 (widget-apply current :activate))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2674 (widget-apply current :deactivate))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2675 (setq found (or found match))))))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2676
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2677 (defun widget-radio-validate (widget)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2678 ;; Valid if we have made a valid choice.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2679 (let ((children (widget-get widget :children))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2680 current found button)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2681 (while (and children (not found))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2682 (setq current (car children)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2683 children (cdr children)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2684 button (widget-get current :button)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2685 found (widget-apply button :value-get)))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2686 (if found
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2687 (widget-apply current :validate)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2688 widget)))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2689
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2690 (defun widget-radio-action (widget child event)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2691 ;; Check if a radio button was pressed.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2692 (let ((children (widget-get widget :children))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2693 (buttons (widget-get widget :buttons))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2694 current)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2695 (when (memq child buttons)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2696 (while children
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2697 (setq current (car children)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2698 children (cdr children))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2699 (let* ((button (widget-get current :button)))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2700 (cond ((eq child button)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2701 (widget-value-set button t)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2702 (widget-apply current :activate))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2703 ((widget-value button)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2704 (widget-value-set button nil)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2705 (widget-apply current :deactivate)))))))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2706 ;; Pass notification to parent.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2707 (widget-apply widget :notify child event))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2708
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2709 ;;; The `insert-button' Widget.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2710
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2711 (define-widget 'insert-button 'push-button
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2712 "An insert button for the `editable-list' widget."
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2713 :tag "INS"
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2714 :help-echo "Insert a new item into the list at this position"
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2715 :action 'widget-insert-button-action)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2716
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2717 (defun widget-insert-button-action (widget &optional event)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2718 ;; Ask the parent to insert a new item.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2719 (widget-apply (widget-get widget :parent)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2720 :insert-before (widget-get widget :widget)))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2721
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2722 ;;; The `delete-button' Widget.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2723
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2724 (define-widget 'delete-button 'push-button
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2725 "A delete button for the `editable-list' widget."
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2726 :tag "DEL"
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2727 :help-echo "Delete this item from the list"
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2728 :action 'widget-delete-button-action)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2729
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2730 (defun widget-delete-button-action (widget &optional event)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2731 ;; Ask the parent to insert a new item.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2732 (widget-apply (widget-get widget :parent)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2733 :delete-at (widget-get widget :widget)))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2734
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2735 ;;; The `editable-list' Widget.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2736
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2737 (defcustom widget-editable-list-gui nil
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2738 "If non nil, use GUI push-buttons in editable list when available."
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2739 :type 'boolean
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2740 :group 'widgets)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2741
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2742 (define-widget 'editable-list 'default
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2743 "A variable list of widgets of the same type."
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2744 :convert-widget 'widget-types-convert-widget
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2745 :offset 12
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2746 :format "%v%i\n"
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2747 :format-handler 'widget-editable-list-format-handler
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2748 :entry-format "%i %d %v"
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2749 :menu-tag "editable-list"
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2750 :value-create 'widget-editable-list-value-create
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2751 :value-delete 'widget-children-value-delete
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2752 :value-get 'widget-editable-list-value-get
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2753 :validate 'widget-children-validate
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2754 :match 'widget-editable-list-match
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2755 :match-inline 'widget-editable-list-match-inline
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2756 :insert-before 'widget-editable-list-insert-before
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2757 :delete-at 'widget-editable-list-delete-at)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2758
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2759 (defun widget-editable-list-format-handler (widget escape)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2760 ;; We recognize the insert button.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2761 (let ((widget-push-button-gui widget-editable-list-gui))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2762 (cond ((eq escape ?i)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2763 (and (widget-get widget :indent)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2764 (insert-char ?\ (widget-get widget :indent)))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2765 (apply 'widget-create-child-and-convert
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2766 widget 'insert-button
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2767 (widget-get widget :append-button-args)))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2768 (t
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2769 (widget-default-format-handler widget escape)))))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2770
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2771 (defun widget-editable-list-value-create (widget)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2772 ;; Insert all values
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2773 (let* ((value (widget-get widget :value))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2774 (type (nth 0 (widget-get widget :args)))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2775 (inlinep (widget-get type :inline))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2776 children)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2777 (widget-put widget :value-pos (copy-marker (point)))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2778 (set-marker-insertion-type (widget-get widget :value-pos) t)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2779 (while value
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2780 (let ((answer (widget-match-inline type value)))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2781 (if answer
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2782 (setq children (cons (widget-editable-list-entry-create
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2783 widget
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2784 (if inlinep
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2785 (car answer)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2786 (car (car answer)))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2787 t)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2788 children)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2789 value (cdr answer))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2790 (setq value nil))))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2791 (widget-put widget :children (nreverse children))))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2792
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2793 (defun widget-editable-list-value-get (widget)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2794 ;; Get value of the child widget.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2795 (apply 'append (mapcar (lambda (child) (widget-apply child :value-inline))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2796 (widget-get widget :children))))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2797
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2798 (defun widget-editable-list-match (widget value)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2799 ;; Value must be a list and all the members must match the type.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2800 (and (listp value)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2801 (null (cdr (widget-editable-list-match-inline widget value)))))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2802
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2803 (defun widget-editable-list-match-inline (widget value)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2804 (let ((type (nth 0 (widget-get widget :args)))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2805 (ok t)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2806 found)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2807 (while (and value ok)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2808 (let ((answer (widget-match-inline type value)))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2809 (if answer
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2810 (setq found (append found (car answer))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2811 value (cdr answer))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2812 (setq ok nil))))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2813 (cons found value)))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2814
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2815 (defun widget-editable-list-insert-before (widget before)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2816 ;; Insert a new child in the list of children.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2817 (save-excursion
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2818 (let ((children (widget-get widget :children))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2819 (inhibit-read-only t)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2820 before-change-functions
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2821 after-change-functions)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2822 (cond (before
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2823 (goto-char (widget-get before :entry-from)))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2824 (t
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2825 (goto-char (widget-get widget :value-pos))))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2826 (let ((child (widget-editable-list-entry-create
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2827 widget nil nil)))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2828 (when (< (widget-get child :entry-from) (widget-get widget :from))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2829 (set-marker (widget-get widget :from)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2830 (widget-get child :entry-from)))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2831 (if (eq (car children) before)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2832 (widget-put widget :children (cons child children))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2833 (while (not (eq (car (cdr children)) before))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2834 (setq children (cdr children)))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2835 (setcdr children (cons child (cdr children)))))))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2836 (widget-setup)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2837 (widget-apply widget :notify widget))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2838
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2839 (defun widget-editable-list-delete-at (widget child)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2840 ;; Delete child from list of children.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2841 (save-excursion
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2842 (let ((buttons (copy-sequence (widget-get widget :buttons)))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2843 button
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2844 (inhibit-read-only t)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2845 before-change-functions
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2846 after-change-functions)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2847 (while buttons
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2848 (setq button (car buttons)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2849 buttons (cdr buttons))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2850 (when (eq (widget-get button :widget) child)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2851 (widget-put widget
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2852 :buttons (delq button (widget-get widget :buttons)))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2853 (widget-delete button))))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2854 (let ((entry-from (widget-get child :entry-from))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2855 (entry-to (widget-get child :entry-to))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2856 (inhibit-read-only t)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2857 before-change-functions
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2858 after-change-functions)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2859 (widget-delete child)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2860 (delete-region entry-from entry-to)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2861 (set-marker entry-from nil)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2862 (set-marker entry-to nil))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2863 (widget-put widget :children (delq child (widget-get widget :children))))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2864 (widget-setup)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2865 (widget-apply widget :notify widget))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2866
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2867 (defun widget-editable-list-entry-create (widget value conv)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2868 ;; Create a new entry to the list.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2869 (let ((type (nth 0 (widget-get widget :args)))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2870 (widget-push-button-gui widget-editable-list-gui)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2871 child delete insert)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2872 (widget-specify-insert
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2873 (save-excursion
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2874 (and (widget-get widget :indent)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2875 (insert-char ?\ (widget-get widget :indent)))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2876 (insert (widget-get widget :entry-format)))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2877 ;; Parse % escapes in format.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2878 (while (re-search-forward "%\\(.\\)" nil t)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2879 (let ((escape (aref (match-string 1) 0)))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2880 (replace-match "" t t)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2881 (cond ((eq escape ?%)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2882 (insert "%"))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2883 ((eq escape ?i)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2884 (setq insert (apply 'widget-create-child-and-convert
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2885 widget 'insert-button
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2886 (widget-get widget :insert-button-args))))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2887 ((eq escape ?d)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2888 (setq delete (apply 'widget-create-child-and-convert
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2889 widget 'delete-button
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2890 (widget-get widget :delete-button-args))))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2891 ((eq escape ?v)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2892 (if conv
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2893 (setq child (widget-create-child-value
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2894 widget type value))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2895 (setq child (widget-create-child widget type))))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2896 (t
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2897 (error "Unknown escape `%c'" escape)))))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2898 (widget-put widget
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2899 :buttons (cons delete
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2900 (cons insert
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2901 (widget-get widget :buttons))))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2902 (let ((entry-from (copy-marker (point-min)))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2903 (entry-to (copy-marker (point-max))))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2904 (set-marker-insertion-type entry-from t)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2905 (set-marker-insertion-type entry-to nil)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2906 (widget-put child :entry-from entry-from)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2907 (widget-put child :entry-to entry-to)))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2908 (widget-put insert :widget child)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2909 (widget-put delete :widget child)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2910 child))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2911
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2912 ;;; The `group' Widget.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2913
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2914 (define-widget 'group 'default
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2915 "A widget which group other widgets inside."
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2916 :convert-widget 'widget-types-convert-widget
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2917 :format "%v"
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2918 :value-create 'widget-group-value-create
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2919 :value-delete 'widget-children-value-delete
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2920 :value-get 'widget-editable-list-value-get
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2921 :validate 'widget-children-validate
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2922 :match 'widget-group-match
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2923 :match-inline 'widget-group-match-inline)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2924
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2925 (defun widget-group-value-create (widget)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2926 ;; Create each component.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2927 (let ((args (widget-get widget :args))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2928 (value (widget-get widget :value))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2929 arg answer children)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2930 (while args
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2931 (setq arg (car args)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2932 args (cdr args)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2933 answer (widget-match-inline arg value)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2934 value (cdr answer))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2935 (and (eq (preceding-char) ?\n)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2936 (widget-get widget :indent)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2937 (insert-char ?\ (widget-get widget :indent)))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2938 (push (cond ((null answer)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2939 (widget-create-child widget arg))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2940 ((widget-get arg :inline)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2941 (widget-create-child-value widget arg (car answer)))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2942 (t
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2943 (widget-create-child-value widget arg (car (car answer)))))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2944 children))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2945 (widget-put widget :children (nreverse children))))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2946
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2947 (defun widget-group-match (widget values)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2948 ;; Match if the components match.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2949 (and (listp values)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2950 (let ((match (widget-group-match-inline widget values)))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2951 (and match (null (cdr match))))))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2952
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2953 (defun widget-group-match-inline (widget vals)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2954 ;; Match if the components match.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2955 (let ((args (widget-get widget :args))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2956 argument answer found)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2957 (while args
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2958 (setq argument (car args)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2959 args (cdr args)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2960 answer (widget-match-inline argument vals))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2961 (if answer
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2962 (setq vals (cdr answer)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2963 found (append found (car answer)))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2964 (setq vals nil
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2965 args nil)))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2966 (if answer
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2967 (cons found vals)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2968 nil)))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2969
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2970 ;;; The `visibility' Widget.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2971
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2972 (define-widget 'visibility 'item
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2973 "An indicator and manipulator for hidden items."
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2974 :format "%[%v%]"
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2975 :button-prefix ""
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2976 :button-suffix ""
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2977 :on "Hide"
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2978 :off "Show"
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2979 :value-create 'widget-visibility-value-create
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2980 :action 'widget-toggle-action
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2981 :match (lambda (widget value) t))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2982
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2983 (defun widget-visibility-value-create (widget)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2984 ;; Insert text representing the `on' and `off' states.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2985 (let ((on (widget-get widget :on))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2986 (off (widget-get widget :off)))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2987 (if on
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2988 (setq on (concat widget-push-button-prefix
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2989 on
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2990 widget-push-button-suffix))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2991 (setq on ""))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2992 (if off
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2993 (setq off (concat widget-push-button-prefix
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2994 off
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2995 widget-push-button-suffix))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2996 (setq off ""))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2997 (if (widget-value widget)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2998 (widget-glyph-insert widget on '("down" "down-pushed"))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2999 (widget-glyph-insert widget off '("right" "right-pushed")))))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3000
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3001 ;;; The `documentation-link' Widget.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3002 ;;
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3003 ;; This is a helper widget for `documentation-string'.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3004
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3005 (define-widget 'documentation-link 'link
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3006 "Link type used in documentation strings."
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3007 :tab-order -1
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3008 :help-echo 'widget-documentation-link-echo-help
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3009 :action 'widget-documentation-link-action)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3010
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3011 (defun widget-documentation-link-echo-help (widget)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3012 "Tell what this link will describe."
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3013 (concat "Describe the `" (widget-get widget :value) "' symbol."))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3014
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3015 (defun widget-documentation-link-action (widget &optional event)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3016 "Display documentation for WIDGET's value. Ignore optional argument EVENT."
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3017 (let* ((string (widget-get widget :value))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3018 (symbol (intern string)))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3019 (if (and (fboundp symbol) (boundp symbol))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3020 ;; If there are two doc strings, give the user a way to pick one.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3021 (apropos (concat "\\`" (regexp-quote string) "\\'"))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3022 (if (fboundp symbol)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3023 (describe-function symbol)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3024 (describe-variable symbol)))))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3025
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3026 (defcustom widget-documentation-links t
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3027 "Add hyperlinks to documentation strings when non-nil."
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3028 :type 'boolean
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3029 :group 'widget-documentation)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3030
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3031 (defcustom widget-documentation-link-regexp "`\\([^\n`' ]+\\)'"
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3032 "Regexp for matching potential links in documentation strings.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3033 The first group should be the link itself."
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3034 :type 'regexp
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3035 :group 'widget-documentation)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3036
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3037 (defcustom widget-documentation-link-p 'intern-soft
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3038 "Predicate used to test if a string is useful as a link.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3039 The value should be a function. The function will be called one
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3040 argument, a string, and should return non-nil if there should be a
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3041 link for that string."
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3042 :type 'function
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3043 :options '(widget-documentation-link-p)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3044 :group 'widget-documentation)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3045
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3046 (defcustom widget-documentation-link-type 'documentation-link
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3047 "Widget type used for links in documentation strings."
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3048 :type 'symbol
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3049 :group 'widget-documentation)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3050
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3051 (defun widget-documentation-link-add (widget from to)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3052 (widget-specify-doc widget from to)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3053 (when widget-documentation-links
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3054 (let ((regexp widget-documentation-link-regexp)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3055 (predicate widget-documentation-link-p)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3056 (type widget-documentation-link-type)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3057 (buttons (widget-get widget :buttons)))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3058 (save-excursion
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3059 (goto-char from)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3060 (while (re-search-forward regexp to t)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3061 (let ((name (match-string 1))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3062 (begin (match-beginning 1))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3063 (end (match-end 1)))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3064 (when (funcall predicate name)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3065 (push (widget-convert-button type begin end :value name)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3066 buttons)))))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3067 (widget-put widget :buttons buttons)))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3068 (let ((indent (widget-get widget :indent)))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3069 (when (and indent (not (zerop indent)))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3070 (save-excursion
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3071 (save-restriction
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3072 (narrow-to-region from to)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3073 (goto-char (point-min))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3074 (while (search-forward "\n" nil t)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3075 (insert-char ?\ indent)))))))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3076
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3077 ;;; The `documentation-string' Widget.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3078
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3079 (define-widget 'documentation-string 'item
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3080 "A documentation string."
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3081 :format "%v"
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3082 :action 'widget-documentation-string-action
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3083 :value-delete 'widget-children-value-delete
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3084 :value-create 'widget-documentation-string-value-create)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3085
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3086 (defun widget-documentation-string-value-create (widget)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3087 ;; Insert documentation string.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3088 (let ((doc (widget-value widget))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3089 (indent (widget-get widget :indent))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3090 (shown (widget-get (widget-get widget :parent) :documentation-shown))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3091 (start (point)))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3092 (if (string-match "\n" doc)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3093 (let ((before (substring doc 0 (match-beginning 0)))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3094 (after (substring doc (match-beginning 0)))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3095 buttons)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3096 (insert before " ")
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3097 (widget-documentation-link-add widget start (point))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3098 (push (widget-create-child-and-convert
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3099 widget 'visibility
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3100 :help-echo (lambda (widget)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3101 (concat
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3102 (if (widget-value widget)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3103 "Hide" "Show")
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3104 " the rest of the documentation"))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3105 :off "More"
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3106 :action 'widget-parent-action
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3107 shown)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3108 buttons)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3109 (when shown
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3110 (setq start (point))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3111 (when indent
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3112 (insert-char ?\ indent))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3113 (insert after)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3114 (widget-documentation-link-add widget start (point)))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3115 (widget-put widget :buttons buttons))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3116 (insert doc)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3117 (widget-documentation-link-add widget start (point))))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3118 (insert "\n"))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3119
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3120 (defun widget-documentation-string-action (widget &rest ignore)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3121 ;; Toggle documentation.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3122 (let ((parent (widget-get widget :parent)))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3123 (widget-put parent :documentation-shown
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3124 (not (widget-get parent :documentation-shown))))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3125 ;; Redraw.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3126 (widget-value-set widget (widget-value widget)))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3127
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3128 ;;; The Sexp Widgets.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3129
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3130 (define-widget 'const 'item
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3131 "An immutable sexp."
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3132 :prompt-value 'widget-const-prompt-value
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3133 :format "%t\n%d")
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3134
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3135 (defun widget-const-prompt-value (widget prompt value unbound)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3136 ;; Return the value of the const.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3137 (widget-value widget))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3138
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3139 (define-widget 'function-item 'const
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3140 "An immutable function name."
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3141 :format "%v\n%h"
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3142 :documentation-property (lambda (symbol)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3143 (condition-case nil
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3144 (documentation symbol t)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3145 (error nil))))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3146
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3147 (define-widget 'variable-item 'const
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3148 "An immutable variable name."
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3149 :format "%v\n%h"
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3150 :documentation-property 'variable-documentation)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3151
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3152 (defvar widget-string-prompt-value-history nil
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3153 "History of input to `widget-string-prompt-value'.")
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3154
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3155 (define-widget 'string 'editable-field
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3156 "A string"
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3157 :tag "String"
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3158 :format "%{%t%}: %v"
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3159 :complete-function 'ispell-complete-word
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3160 :prompt-history 'widget-string-prompt-value-history)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3161
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3162 (define-widget 'regexp 'string
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3163 "A regular expression."
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3164 :match 'widget-regexp-match
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3165 :validate 'widget-regexp-validate
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3166 ;; Doesn't work well with terminating newline.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3167 ;; :value-face 'widget-single-line-field-face
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3168 :tag "Regexp")
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3169
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3170 (defun widget-regexp-match (widget value)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3171 ;; Match valid regexps.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3172 (and (stringp value)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3173 (condition-case nil
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3174 (prog1 t
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3175 (string-match value ""))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3176 (error nil))))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3177
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3178 (defun widget-regexp-validate (widget)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3179 "Check that the value of WIDGET is a valid regexp."
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3180 (let ((value (widget-value widget)))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3181 (condition-case data
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3182 (prog1 nil
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3183 (string-match value ""))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3184 (error (widget-put widget :error (error-message-string data))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3185 widget))))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3186
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3187 (define-widget 'file 'string
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3188 "A file widget.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3189 It will read a file name from the minibuffer when invoked."
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3190 :complete-function 'widget-file-complete
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3191 :prompt-value 'widget-file-prompt-value
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3192 :format "%{%t%}: %v"
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3193 ;; Doesn't work well with terminating newline.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3194 ;; :value-face 'widget-single-line-field-face
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3195 :tag "File")
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3196
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3197 (defun widget-file-complete ()
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3198 "Perform completion on file name preceding point."
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3199 (interactive)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3200 (let* ((end (point))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3201 (beg (save-excursion
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3202 (skip-chars-backward "^ ")
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3203 (point)))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3204 (pattern (buffer-substring beg end))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3205 (name-part (file-name-nondirectory pattern))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3206 (directory (file-name-directory pattern))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3207 (completion (file-name-completion name-part directory)))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3208 (cond ((eq completion t))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3209 ((null completion)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3210 (message "Can't find completion for \"%s\"" pattern)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3211 (ding))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3212 ((not (string= name-part completion))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3213 (delete-region beg end)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3214 (insert (expand-file-name completion directory)))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3215 (t
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3216 (message "Making completion list...")
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3217 (let ((list (file-name-all-completions name-part directory)))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3218 (setq list (sort list 'string<))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3219 (with-output-to-temp-buffer "*Completions*"
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3220 (display-completion-list list)))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3221 (message "Making completion list...%s" "done")))))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3222
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3223 (defun widget-file-prompt-value (widget prompt value unbound)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3224 ;; Read file from minibuffer.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3225 (abbreviate-file-name
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3226 (if unbound
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3227 (read-file-name prompt)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3228 (let ((prompt2 (format "%s (default %s) " prompt value))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3229 (dir (file-name-directory value))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3230 (file (file-name-nondirectory value))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3231 (must-match (widget-get widget :must-match)))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3232 (read-file-name prompt2 dir nil must-match file)))))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3233
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3234 ;;;(defun widget-file-action (widget &optional event)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3235 ;;; ;; Read a file name from the minibuffer.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3236 ;;; (let* ((value (widget-value widget))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3237 ;;; (dir (file-name-directory value))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3238 ;;; (file (file-name-nondirectory value))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3239 ;;; (menu-tag (widget-apply widget :menu-tag-get))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3240 ;;; (must-match (widget-get widget :must-match))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3241 ;;; (answer (read-file-name (concat menu-tag ": (default `" value "') ")
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3242 ;;; dir nil must-match file)))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3243 ;;; (widget-value-set widget (abbreviate-file-name answer))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3244 ;;; (widget-setup)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3245 ;;; (widget-apply widget :notify widget event)))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3246
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3247 (define-widget 'directory 'file
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3248 "A directory widget.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3249 It will read a directory name from the minibuffer when invoked."
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3250 :tag "Directory")
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3251
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3252 (defvar widget-symbol-prompt-value-history nil
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3253 "History of input to `widget-symbol-prompt-value'.")
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3254
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3255 (define-widget 'symbol 'editable-field
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3256 "A lisp symbol."
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3257 :value nil
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3258 :tag "Symbol"
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3259 :format "%{%t%}: %v"
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3260 :match (lambda (widget value) (symbolp value))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3261 :complete-function 'lisp-complete-symbol
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3262 :prompt-internal 'widget-symbol-prompt-internal
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3263 :prompt-match 'symbolp
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3264 :prompt-history 'widget-symbol-prompt-value-history
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3265 :value-to-internal (lambda (widget value)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3266 (if (symbolp value)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3267 (symbol-name value)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3268 value))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3269 :value-to-external (lambda (widget value)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3270 (if (stringp value)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3271 (intern value)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3272 value)))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3273
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3274 (defun widget-symbol-prompt-internal (widget prompt initial history)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3275 ;; Read file from minibuffer.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3276 (let ((answer (completing-read prompt obarray
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3277 (widget-get widget :prompt-match)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3278 nil initial history)))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3279 (if (and (stringp answer)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3280 (not (zerop (length answer))))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3281 answer
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3282 (error "No value"))))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3283
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3284 (defvar widget-function-prompt-value-history nil
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3285 "History of input to `widget-function-prompt-value'.")
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3286
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3287 (define-widget 'function 'sexp
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3288 "A lisp function."
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3289 :complete-function 'lisp-complete-symbol
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3290 :prompt-value 'widget-field-prompt-value
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3291 :prompt-internal 'widget-symbol-prompt-internal
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3292 :prompt-match 'fboundp
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3293 :prompt-history 'widget-function-prompt-value-history
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3294 :action 'widget-field-action
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3295 :tag "Function")
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3296
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3297 (defvar widget-variable-prompt-value-history nil
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3298 "History of input to `widget-variable-prompt-value'.")
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3299
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3300 (define-widget 'variable 'symbol
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3301 ;; Should complete on variables.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3302 "A lisp variable."
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3303 :prompt-match 'boundp
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3304 :prompt-history 'widget-variable-prompt-value-history
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3305 :tag "Variable")
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3306
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3307 ;; This part issues a warning when compiling without Mule. Is there a
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3308 ;; way of shutting it up?
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3309 ;;
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3310 ;; OK, I'll simply comment the whole thing out, until someone decides
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3311 ;; to do something with it.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3312 ;(defvar widget-coding-system-prompt-value-history nil
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3313 ; "History of input to `widget-coding-system-prompt-value'.")
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3314
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3315 ;(define-widget 'coding-system 'symbol
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3316 ; "A MULE coding-system."
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3317 ; :format "%{%t%}: %v"
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3318 ; :tag "Coding system"
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3319 ; :prompt-history 'widget-coding-system-prompt-value-history
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3320 ; :prompt-value 'widget-coding-system-prompt-value
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3321 ; :action 'widget-coding-system-action)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3322
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3323 ;(defun widget-coding-system-prompt-value (widget prompt value unbound)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3324 ; ;; Read coding-system from minibuffer.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3325 ; (intern
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3326 ; (completing-read (format "%s (default %s) " prompt value)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3327 ; (mapcar (lambda (sym)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3328 ; (list (symbol-name sym)))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3329 ; (coding-system-list)))))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3330
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3331 ;(defun widget-coding-system-action (widget &optional event)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3332 ; ;; Read a file name from the minibuffer.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3333 ; (let ((answer
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3334 ; (widget-coding-system-prompt-value
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3335 ; widget
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3336 ; (widget-apply widget :menu-tag-get)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3337 ; (widget-value widget)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3338 ; t)))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3339 ; (widget-value-set widget answer)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3340 ; (widget-apply widget :notify widget event)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3341 ; (widget-setup)))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3342
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3343 (define-widget 'sexp 'editable-field
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3344 "An arbitrary lisp expression."
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3345 :tag "Lisp expression"
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3346 :format "%{%t%}: %v"
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3347 :value nil
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3348 :validate 'widget-sexp-validate
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3349 :match (lambda (widget value) t)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3350 :value-to-internal 'widget-sexp-value-to-internal
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3351 :value-to-external (lambda (widget value) (read value))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3352 :prompt-history 'widget-sexp-prompt-value-history
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3353 :prompt-value 'widget-sexp-prompt-value)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3354
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3355 (defun widget-sexp-value-to-internal (widget value)
219
262b8bb4a523 Import from CVS: tag r20-4b8
cvs
parents: 213
diff changeset
3356 ;; Use cl-prettyprint for printer representation.
209
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3357 (let ((pp (if (symbolp value)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3358 (prin1-to-string value)
219
262b8bb4a523 Import from CVS: tag r20-4b8
cvs
parents: 213
diff changeset
3359 (widget-prettyprint-to-string value))))
209
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3360 (while (string-match "\n\\'" pp)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3361 (setq pp (substring pp 0 -1)))
219
262b8bb4a523 Import from CVS: tag r20-4b8
cvs
parents: 213
diff changeset
3362 (if (and (> (length pp) 40)
262b8bb4a523 Import from CVS: tag r20-4b8
cvs
parents: 213
diff changeset
3363 (not (string-match "\\`\n" pp)))
209
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3364 (concat "\n" pp)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3365 pp)))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3366
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3367 (defun widget-sexp-validate (widget)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3368 ;; Valid if we can read the string and there is no junk left after it.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3369 (save-excursion
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3370 (let ((buffer (set-buffer (get-buffer-create " *Widget Scratch*"))))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3371 (erase-buffer)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3372 (insert (widget-apply widget :value-get))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3373 (goto-char (point-min))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3374 (condition-case data
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3375 (let ((value (read buffer)))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3376 (if (eobp)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3377 (if (widget-apply widget :match value)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3378 nil
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3379 (widget-put widget :error (widget-get widget :type-error))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3380 widget)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3381 (widget-put widget
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3382 :error (format "Junk at end of expression: %s"
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3383 (buffer-substring (point)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3384 (point-max))))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3385 widget))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3386 (error (widget-put widget :error (error-message-string data))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3387 widget)))))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3388
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3389 (defvar widget-sexp-prompt-value-history nil
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3390 "History of input to `widget-sexp-prompt-value'.")
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3391
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3392 (defun widget-sexp-prompt-value (widget prompt value unbound)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3393 ;; Read an arbitrary sexp.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3394 (let ((found (read-string prompt
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3395 (if unbound nil (cons (prin1-to-string value) 0))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3396 (widget-get widget :prompt-history))))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3397 (save-excursion
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3398 (let ((buffer (set-buffer (get-buffer-create " *Widget Scratch*"))))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3399 (erase-buffer)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3400 (insert found)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3401 (goto-char (point-min))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3402 (let ((answer (read buffer)))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3403 (unless (eobp)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3404 (error "Junk at end of expression: %s"
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3405 (buffer-substring (point) (point-max))))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3406 answer)))))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3407
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3408 (define-widget 'restricted-sexp 'sexp
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3409 "A Lisp expression restricted to values that match.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3410 To use this type, you must define :match or :match-alternatives."
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3411 :type-error "The specified value is not valid"
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3412 :match 'widget-restricted-sexp-match
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3413 :value-to-internal (lambda (widget value)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3414 (if (widget-apply widget :match value)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3415 (prin1-to-string value)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3416 value)))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3417
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3418 (defun widget-restricted-sexp-match (widget value)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3419 (let ((alternatives (widget-get widget :match-alternatives))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3420 matched)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3421 (while (and alternatives (not matched))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3422 (if (cond ((functionp (car alternatives))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3423 (funcall (car alternatives) value))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3424 ((and (consp (car alternatives))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3425 (eq (car (car alternatives)) 'quote))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3426 (eq value (nth 1 (car alternatives)))))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3427 (setq matched t))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3428 (setq alternatives (cdr alternatives)))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3429 matched))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3430
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3431 (define-widget 'integer 'restricted-sexp
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3432 "An integer."
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3433 :tag "Integer"
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3434 :value 0
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3435 :type-error "This field should contain an integer"
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3436 :match-alternatives '(integerp))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3437
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3438 (define-widget 'number 'restricted-sexp
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3439 "A floating point number."
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3440 :tag "Number"
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3441 :value 0.0
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3442 :type-error "This field should contain a number"
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3443 :match-alternatives '(numberp))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3444
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3445 (define-widget 'character 'editable-field
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3446 "A character."
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3447 :tag "Character"
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3448 :value ?\0
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3449 :format "%{%t%}: %v"
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3450 :valid-regexp "\\`[\0-\377]\\'"
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3451 :error "This field should contain a single character"
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3452 :value-to-internal (lambda (widget value)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3453 (if (stringp value)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3454 value
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3455 (char-to-string value)))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3456 :value-to-external (lambda (widget value)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3457 (if (stringp value)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3458 (aref value 0)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3459 value))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3460 :match (lambda (widget value)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3461 (characterp value)))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3462
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3463 (define-widget 'list 'group
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3464 "A lisp list."
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3465 :tag "List"
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3466 :format "%{%t%}:\n%v")
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3467
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3468 (define-widget 'vector 'group
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3469 "A lisp vector."
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3470 :tag "Vector"
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3471 :format "%{%t%}:\n%v"
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3472 :match 'widget-vector-match
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3473 :value-to-internal (lambda (widget value) (append value nil))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3474 :value-to-external (lambda (widget value) (vconcat value)))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3475
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3476 (defun widget-vector-match (widget value)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3477 (and (vectorp value)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3478 (widget-group-match widget
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3479 (widget-apply widget :value-to-internal value))))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3480
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3481 (define-widget 'cons 'group
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3482 "A cons-cell."
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3483 :tag "Cons-cell"
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3484 :format "%{%t%}:\n%v"
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3485 :match 'widget-cons-match
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3486 :value-to-internal (lambda (widget value)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3487 (list (car value) (cdr value)))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3488 :value-to-external (lambda (widget value)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3489 (cons (car value) (cadr value))))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3490
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3491 (defun widget-cons-match (widget value)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3492 (and (consp value)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3493 (widget-group-match widget
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3494 (widget-apply widget :value-to-internal value))))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3495
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3496 (define-widget 'choice 'menu-choice
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3497 "A union of several sexp types."
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3498 :tag "Choice"
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3499 :format "%{%t%}: %[Value Menu%] %v"
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3500 :button-prefix 'widget-push-button-prefix
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3501 :button-suffix 'widget-push-button-suffix
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3502 :prompt-value 'widget-choice-prompt-value)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3503
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3504 (defun widget-choice-prompt-value (widget prompt value unbound)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3505 "Make a choice."
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3506 (let ((args (widget-get widget :args))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3507 (completion-ignore-case (widget-get widget :case-fold))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3508 current choices old)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3509 ;; Find the first arg that match VALUE.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3510 (let ((look args))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3511 (while look
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3512 (if (widget-apply (car look) :match value)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3513 (setq old (car look)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3514 look nil)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3515 (setq look (cdr look)))))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3516 ;; Find new choice.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3517 (setq current
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3518 (cond ((= (length args) 0)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3519 nil)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3520 ((= (length args) 1)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3521 (nth 0 args))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3522 ((and (= (length args) 2)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3523 (memq old args))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3524 (if (eq old (nth 0 args))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3525 (nth 1 args)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3526 (nth 0 args)))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3527 (t
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3528 (while args
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3529 (setq current (car args)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3530 args (cdr args))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3531 (setq choices
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3532 (cons (cons (widget-apply current :menu-tag-get)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3533 current)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3534 choices)))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3535 (let ((val (completing-read prompt choices nil t)))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3536 (if (stringp val)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3537 (let ((try (try-completion val choices)))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3538 (when (stringp try)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3539 (setq val try))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3540 (cdr (assoc val choices)))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3541 nil)))))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3542 (if current
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3543 (widget-prompt-value current prompt nil t)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3544 value)))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3545
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3546 (define-widget 'radio 'radio-button-choice
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3547 "A union of several sexp types."
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3548 :tag "Choice"
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3549 :format "%{%t%}:\n%v"
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3550 :prompt-value 'widget-choice-prompt-value)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3551
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3552 (define-widget 'repeat 'editable-list
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3553 "A variable length homogeneous list."
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3554 :tag "Repeat"
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3555 :format "%{%t%}:\n%v%i\n")
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3556
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3557 (define-widget 'set 'checklist
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3558 "A list of members from a fixed set."
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3559 :tag "Set"
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3560 :format "%{%t%}:\n%v")
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3561
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3562 (define-widget 'boolean 'toggle
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3563 "To be nil or non-nil, that is the question."
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3564 :tag "Boolean"
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3565 :prompt-value 'widget-boolean-prompt-value
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3566 :button-prefix 'widget-push-button-prefix
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3567 :button-suffix 'widget-push-button-suffix
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3568 :format "%{%t%}: %[Toggle%] %v\n"
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3569 :on "on (non-nil)"
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3570 :off "off (nil)")
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3571
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3572 (defun widget-boolean-prompt-value (widget prompt value unbound)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3573 ;; Toggle a boolean.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3574 (y-or-n-p prompt))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3575
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3576 ;;; The `color' Widget.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3577
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3578 (define-widget 'color 'editable-field
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3579 "Choose a color name (with sample)."
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3580 :format "%[%t%]: %v (%{sample%})\n"
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3581 :size 10
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3582 :tag "Color"
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3583 :value "black"
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3584 :complete 'widget-color-complete
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3585 :sample-face-get 'widget-color-sample-face-get
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3586 :notify 'widget-color-notify
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3587 :action 'widget-color-action)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3588
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3589 (defun widget-color-complete (widget)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3590 "Complete the color in WIDGET."
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3591 (let* ((prefix (buffer-substring-no-properties (widget-field-start widget)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3592 (point)))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3593 (list (read-color-completion-table))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3594 (completion (try-completion prefix list)))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3595 (cond ((eq completion t)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3596 (message "Exact match"))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3597 ((null completion)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3598 (error "Can't find completion for \"%s\"" prefix))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3599 ((not (string-equal prefix completion))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3600 (insert (substring completion (length prefix))))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3601 (t
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3602 (message "Making completion list...")
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3603 (let ((list (all-completions prefix list nil)))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3604 (with-output-to-temp-buffer "*Completions*"
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3605 (display-completion-list list)))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3606 (message "Making completion list...done")))))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3607
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3608 (defun widget-color-sample-face-get (widget)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3609 (or (widget-get widget :sample-face)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3610 (let ((color (widget-value widget))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3611 (face (make-face (gensym "sample-face-") nil t)))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3612 ;; Use the face object, not its name, to prevent lossage if gc
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3613 ;; happens before applying the face.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3614 (widget-put widget :sample-face face)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3615 (and color
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3616 (not (equal color ""))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3617 (valid-color-name-p color)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3618 (set-face-foreground face color))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3619 face)))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3620
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3621 (defvar widget-color-history nil
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3622 "History of entered colors.")
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3623
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3624 (defun widget-color-action (widget &optional event)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3625 ;; Prompt for a color.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3626 (let* ((tag (widget-apply widget :menu-tag-get))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3627 (answer (read-color (concat tag ": "))))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3628 (unless (zerop (length answer))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3629 (widget-value-set widget answer)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3630 (widget-setup)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3631 (widget-apply widget :notify widget event))))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3632
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3633 (defun widget-color-notify (widget child &optional event)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3634 "Update the sample, and notify the parent."
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3635 (let* ((face (widget-apply widget :sample-face-get))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3636 (color (widget-value widget)))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3637 (if (valid-color-name-p color)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3638 (set-face-foreground face color)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3639 (remove-face-property face 'foreground)))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3640 (widget-default-notify widget child event))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3641
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3642 ;; Is this a misnomer?
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3643 (defun widget-at (pos)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3644 "The button or field at POS."
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3645 (or (get-char-property pos 'button)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3646 (get-char-property pos 'field)))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3647
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3648 (defun widget-echo-help (pos)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3649 "Display the help echo for widget at POS."
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3650 (let* ((widget (widget-at pos))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3651 (help-echo (and widget (widget-get widget :help-echo))))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3652 (and (functionp help-echo)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3653 (setq help-echo (funcall help-echo widget)))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3654 (when (stringp help-echo)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3655 (display-message 'help-echo help-echo))))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3656
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3657 ;;; The End:
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3658
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3659 (provide 'wid-edit)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3660
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3661 ;; wid-edit.el ends here