annotate lisp/wid-edit.el @ 267:966663fcf606 r20-5b32

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