annotate lisp/wid-edit.el @ 17692:426dde653028 gnumach-release-1-1 gnumach-release-1-1-1 libc-970508 libc-970509 libc-970510 libc-970511 libc-970512 libc-970513 libc-970514 libc-970515 libc-970516 libc-970517 libc-970518 libc-970519 libc-970520 libc-970521 libc-970522 libc-970523 libc-970524 libc-970525 libc-970526 libc-970527 libc-970528 libc-970529 libc-970530 libc-970531 libc-970601 libc-970602 libc-970603 libc-970604 libc-970605

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