annotate lisp/wid-edit.el @ 404:2f8bb876ab1d r21-2-32

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