annotate lisp/custom/wid-edit.el @ 161:28f395d8dc7a r20-3b7

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