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