annotate lisp/wid-edit.el @ 293:403535bfea94

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