Mercurial > emacs
comparison lisp/wid-edit.el @ 19022:904dcdbb8576
Synched with 1.9951.
author | Per Abrahamsen <abraham@dina.kvl.dk> |
---|---|
date | Mon, 28 Jul 1997 15:46:57 +0000 |
parents | ac27714a02cf |
children | e4b14e6fd28f |
comparison
equal
deleted
inserted
replaced
19021:6f150e46a5fd | 19022:904dcdbb8576 |
---|---|
2 ;; | 2 ;; |
3 ;; Copyright (C) 1996, 1997 Free Software Foundation, Inc. | 3 ;; Copyright (C) 1996, 1997 Free Software Foundation, Inc. |
4 ;; | 4 ;; |
5 ;; Author: Per Abrahamsen <abraham@dina.kvl.dk> | 5 ;; Author: Per Abrahamsen <abraham@dina.kvl.dk> |
6 ;; Keywords: extensions | 6 ;; Keywords: extensions |
7 ;; Version: 1.9945 | 7 ;; Version: 1.9951 |
8 ;; X-URL: http://www.dina.kvl.dk/~abraham/custom/ | 8 ;; X-URL: http://www.dina.kvl.dk/~abraham/custom/ |
9 | 9 |
10 ;; This file is part of GNU Emacs. | 10 ;; This file is part of GNU Emacs. |
11 | 11 |
12 ;; GNU Emacs is free software; you can redistribute it and/or modify | 12 ;; GNU Emacs is free software; you can redistribute it and/or modify |
36 ;;; Compatibility. | 36 ;;; Compatibility. |
37 | 37 |
38 (eval-and-compile | 38 (eval-and-compile |
39 (autoload 'pp-to-string "pp") | 39 (autoload 'pp-to-string "pp") |
40 (autoload 'Info-goto-node "info") | 40 (autoload 'Info-goto-node "info") |
41 (autoload 'finder-commentary "finder" nil t) | |
41 | 42 |
42 (when (string-match "XEmacs" emacs-version) | 43 (when (string-match "XEmacs" emacs-version) |
43 (condition-case nil | 44 (condition-case nil |
44 (require 'overlay) | 45 (require 'overlay) |
45 (error (load-library "x-overlay")))) | 46 (error (load-library "x-overlay")))) |
98 "Convert an error value to an error message." | 99 "Convert an error value to an error message." |
99 (let ((buf (get-buffer-create " *error-message*"))) | 100 (let ((buf (get-buffer-create " *error-message*"))) |
100 (erase-buffer buf) | 101 (erase-buffer buf) |
101 (display-error obj buf) | 102 (display-error obj buf) |
102 (buffer-string buf))))) | 103 (buffer-string buf))))) |
103 | |
104 (when (let ((a "foo")) | |
105 (put-text-property 1 2 'foo 1 a) | |
106 (put-text-property 1 2 'bar 2 a) | |
107 (set-text-properties 1 2 nil a) | |
108 (text-properties-at 1 a)) | |
109 ;; XEmacs 20.2 and earlier had a buggy set-text-properties. | |
110 (defun set-text-properties (start end props &optional buffer-or-string) | |
111 "Completely replace properties of text from START to END. | |
112 The third argument PROPS is the new property list. | |
113 The optional fourth argument, BUFFER-OR-STRING, | |
114 is the string or buffer containing the text." | |
115 (map-extents #'(lambda (extent ignored) | |
116 (remove-text-properties | |
117 start end | |
118 (list (extent-property extent 'text-prop) | |
119 nil) | |
120 buffer-or-string) | |
121 nil) | |
122 buffer-or-string start end nil nil 'text-prop) | |
123 (add-text-properties start end props buffer-or-string))) | |
124 | 104 |
125 ;;; Customization. | 105 ;;; Customization. |
126 | 106 |
127 (defgroup widgets nil | 107 (defgroup widgets nil |
128 "Customization support for the Widget Library." | 108 "Customization support for the Widget Library." |
350 | 330 |
351 ;;; Widget text specifications. | 331 ;;; Widget text specifications. |
352 ;; | 332 ;; |
353 ;; These functions are for specifying text properties. | 333 ;; These functions are for specifying text properties. |
354 | 334 |
355 (defun widget-specify-none (from to) | |
356 ;; Clear all text properties between FROM and TO. | |
357 (set-text-properties from to nil)) | |
358 | |
359 (defun widget-specify-text (from to) | |
360 ;; Default properties. | |
361 (add-text-properties from to (list 'read-only t | |
362 'front-sticky t | |
363 'rear-nonsticky nil | |
364 'start-open nil | |
365 'end-open nil))) | |
366 | |
367 (defcustom widget-field-add-space | 335 (defcustom widget-field-add-space |
368 (or (< emacs-major-version 20) | 336 (or (< emacs-major-version 20) |
369 (and (eq emacs-major-version 20) | 337 (and (eq emacs-major-version 20) |
370 (< emacs-minor-version 3)) | 338 (< emacs-minor-version 3)) |
371 (not (string-match "XEmacs" emacs-version))) | 339 (not (string-match "XEmacs" emacs-version))) |
376 size field." | 344 size field." |
377 :type 'boolean | 345 :type 'boolean |
378 :group 'widgets) | 346 :group 'widgets) |
379 | 347 |
380 (defcustom widget-field-use-before-change | 348 (defcustom widget-field-use-before-change |
381 (or (> emacs-minor-version 34) | 349 (and (or (> emacs-minor-version 34) |
382 (>= emacs-major-version 20) | 350 (> emacs-major-version 19)) |
383 (string-match "XEmacs" emacs-version)) | 351 (not (string-match "XEmacs" emacs-version))) |
384 "Non-nil means use `before-change-functions' to track editable fields. | 352 "Non-nil means use `before-change-functions' to track editable fields. |
385 This enables the use of undo, but doesn't work on Emacs 19.34 and earlier. | 353 This enables the use of undo, but doesn't work on Emacs 19.34 and earlier. |
386 Using before hooks also means that the :notify function can't know the | 354 Using before hooks also means that the :notify function can't know the |
387 new value." | 355 new value." |
388 :type 'boolean | 356 :type 'boolean |
389 :group 'widgets) | 357 :group 'widgets) |
390 | 358 |
391 (defun widget-specify-field (widget from to) | 359 (defun widget-specify-field (widget from to) |
392 "Specify editable button for WIDGET between FROM and TO." | 360 "Specify editable button for WIDGET between FROM and TO." |
393 (put-text-property from to 'read-only nil) | |
394 ;; Terminating space is not part of the field, but necessary in | 361 ;; Terminating space is not part of the field, but necessary in |
395 ;; order for local-map to work. Remove next sexp if local-map works | 362 ;; order for local-map to work. Remove next sexp if local-map works |
396 ;; at the end of the overlay. | 363 ;; at the end of the overlay. |
397 (save-excursion | 364 (save-excursion |
398 (goto-char to) | 365 (goto-char to) |
399 (cond ((null (widget-get widget :size)) | 366 (cond ((null (widget-get widget :size)) |
400 (forward-char 1)) | 367 (forward-char 1)) |
401 (widget-field-add-space | 368 (widget-field-add-space |
402 (insert-and-inherit " "))) | 369 (insert-and-inherit " "))) |
403 (setq to (point))) | 370 (setq to (point))) |
404 (if (or widget-field-add-space | |
405 (null (widget-get widget :size))) | |
406 (add-text-properties (1- to) to | |
407 '(front-sticky nil start-open t read-only to)) | |
408 (add-text-properties to (1+ to) | |
409 '(front-sticky nil start-open t read-only to))) | |
410 (add-text-properties (1- from) from | |
411 '(rear-nonsticky t end-open t read-only from)) | |
412 (let ((map (widget-get widget :keymap)) | 371 (let ((map (widget-get widget :keymap)) |
413 (face (or (widget-get widget :value-face) 'widget-field-face)) | 372 (face (or (widget-get widget :value-face) 'widget-field-face)) |
414 (help-echo (widget-get widget :help-echo)) | 373 (help-echo (widget-get widget :help-echo)) |
415 (overlay (make-overlay from to nil | 374 (overlay (make-overlay from to nil |
416 nil (or (not widget-field-add-space) | 375 nil (or (not widget-field-add-space) |
459 (overlay-put overlay 'face face) | 418 (overlay-put overlay 'face face) |
460 (widget-put widget :sample-overlay overlay))) | 419 (widget-put widget :sample-overlay overlay))) |
461 | 420 |
462 (defun widget-specify-doc (widget from to) | 421 (defun widget-specify-doc (widget from to) |
463 ;; Specify documentation for WIDGET between FROM and TO. | 422 ;; Specify documentation for WIDGET between FROM and TO. |
464 (add-text-properties from to (list 'widget-doc widget | 423 (let ((overlay (make-overlay from to nil t nil))) |
465 'face widget-documentation-face))) | 424 (overlay-put overlay 'widget-doc widget) |
425 (overlay-put overlay 'face widget-documentation-face) | |
426 (widget-put widget :doc-overlay overlay))) | |
466 | 427 |
467 (defmacro widget-specify-insert (&rest form) | 428 (defmacro widget-specify-insert (&rest form) |
468 ;; Execute FORM without inheriting any text properties. | 429 ;; Execute FORM without inheriting any text properties. |
469 (` | 430 (` |
470 (save-restriction | 431 (save-restriction |
472 result | 433 result |
473 before-change-functions | 434 before-change-functions |
474 after-change-functions) | 435 after-change-functions) |
475 (insert "<>") | 436 (insert "<>") |
476 (narrow-to-region (- (point) 2) (point)) | 437 (narrow-to-region (- (point) 2) (point)) |
477 (widget-specify-none (point-min) (point-max)) | |
478 (goto-char (1+ (point-min))) | 438 (goto-char (1+ (point-min))) |
479 (setq result (progn (,@ form))) | 439 (setq result (progn (,@ form))) |
480 (delete-region (point-min) (1+ (point-min))) | 440 (delete-region (point-min) (1+ (point-min))) |
481 (delete-region (1- (point-max)) (point-max)) | 441 (delete-region (1- (point-max)) (point-max)) |
482 (goto-char (point-max)) | 442 (goto-char (point-max)) |
885 "Call `insert' with ARGS and make the text read only." | 845 "Call `insert' with ARGS and make the text read only." |
886 (let ((inhibit-read-only t) | 846 (let ((inhibit-read-only t) |
887 before-change-functions | 847 before-change-functions |
888 after-change-functions | 848 after-change-functions |
889 (from (point))) | 849 (from (point))) |
890 (apply 'insert args) | 850 (apply 'insert args))) |
891 (widget-specify-text from (point)))) | |
892 | 851 |
893 (defun widget-convert-text (type from to | 852 (defun widget-convert-text (type from to |
894 &optional button-from button-to | 853 &optional button-from button-to |
895 &rest args) | 854 &rest args) |
896 "Return a widget of type TYPE with endpoint FROM TO. | 855 "Return a widget of type TYPE with endpoint FROM TO. |
900 button end points. | 859 button end points. |
901 Optional ARGS are extra keyword arguments for TYPE." | 860 Optional ARGS are extra keyword arguments for TYPE." |
902 (let ((widget (apply 'widget-convert type :delete 'widget-leave-text args)) | 861 (let ((widget (apply 'widget-convert type :delete 'widget-leave-text args)) |
903 (from (copy-marker from)) | 862 (from (copy-marker from)) |
904 (to (copy-marker to))) | 863 (to (copy-marker to))) |
905 (widget-specify-text from to) | |
906 (set-marker-insertion-type from t) | 864 (set-marker-insertion-type from t) |
907 (set-marker-insertion-type to nil) | 865 (set-marker-insertion-type to nil) |
908 (widget-put widget :from from) | 866 (widget-put widget :from from) |
909 (widget-put widget :to to) | 867 (widget-put widget :to to) |
910 (when button-from | 868 (when button-from |
923 "Remove markers and overlays from WIDGET and its children." | 881 "Remove markers and overlays from WIDGET and its children." |
924 (let ((from (widget-get widget :from)) | 882 (let ((from (widget-get widget :from)) |
925 (to (widget-get widget :to)) | 883 (to (widget-get widget :to)) |
926 (button (widget-get widget :button-overlay)) | 884 (button (widget-get widget :button-overlay)) |
927 (sample (widget-get widget :sample-overlay)) | 885 (sample (widget-get widget :sample-overlay)) |
886 (doc (widget-get widget :doc-overlay)) | |
928 (field (widget-get widget :field-overlay)) | 887 (field (widget-get widget :field-overlay)) |
929 (children (widget-get widget :children))) | 888 (children (widget-get widget :children))) |
930 (set-marker from nil) | 889 (set-marker from nil) |
931 (set-marker to nil) | 890 (set-marker to nil) |
932 (when button | 891 (when button |
933 (delete-overlay button)) | 892 (delete-overlay button)) |
934 (when sample | 893 (when sample |
935 (delete-overlay sample)) | 894 (delete-overlay sample)) |
895 (when doc | |
896 (delete-overlay doc)) | |
936 (when field | 897 (when field |
937 (delete-overlay field)) | 898 (delete-overlay field)) |
938 (mapcar 'widget-leave-text children))) | 899 (mapcar 'widget-leave-text children))) |
939 | 900 |
940 ;;; Keymap and Commands. | 901 ;;; Keymap and Commands. |
1124 widget | 1085 widget |
1125 nil) | 1086 nil) |
1126 widget)) | 1087 widget)) |
1127 nil))) | 1088 nil))) |
1128 | 1089 |
1090 (defcustom widget-use-overlay-change (string-match "XEmacs" emacs-version) | |
1091 "If non-nil, use overlay change functions to tab around in the buffer. | |
1092 This is much faster, but doesn't work reliably on Emacs 19.34." | |
1093 :type 'boolean | |
1094 :group 'widgets) | |
1095 | |
1129 (defun widget-move (arg) | 1096 (defun widget-move (arg) |
1130 "Move point to the ARG next field or button. | 1097 "Move point to the ARG next field or button. |
1131 ARG may be negative to move backward." | 1098 ARG may be negative to move backward." |
1132 (or (bobp) (> arg 0) (backward-char)) | 1099 (or (bobp) (> arg 0) (backward-char)) |
1133 (let ((pos (point)) | 1100 (let ((pos (point)) |
1134 (number arg) | 1101 (number arg) |
1135 (old (widget-tabable-at)) | 1102 (old (widget-tabable-at)) |
1136 new) | 1103 new) |
1137 ;; Forward. | 1104 ;; Forward. |
1138 (while (> arg 0) | 1105 (while (> arg 0) |
1139 (if (eobp) | 1106 (cond ((eobp) |
1140 (goto-char (point-min)) | 1107 (goto-char (point-min))) |
1141 (forward-char 1)) | 1108 (widget-use-overlay-change |
1109 (goto-char (next-overlay-change (point)))) | |
1110 (t | |
1111 (forward-char 1))) | |
1142 (and (eq pos (point)) | 1112 (and (eq pos (point)) |
1143 (eq arg number) | 1113 (eq arg number) |
1144 (error "No buttons or fields found")) | 1114 (error "No buttons or fields found")) |
1145 (let ((new (widget-tabable-at))) | 1115 (let ((new (widget-tabable-at))) |
1146 (when new | 1116 (when new |
1147 (unless (eq new old) | 1117 (unless (eq new old) |
1148 (setq arg (1- arg)) | 1118 (setq arg (1- arg)) |
1149 (setq old new))))) | 1119 (setq old new))))) |
1150 ;; Backward. | 1120 ;; Backward. |
1151 (while (< arg 0) | 1121 (while (< arg 0) |
1152 (if (bobp) | 1122 (cond ((bobp) |
1153 (goto-char (point-max)) | 1123 (goto-char (point-max))) |
1154 (backward-char 1)) | 1124 (widget-use-overlay-change |
1125 (goto-char (previous-overlay-change (point)))) | |
1126 (t | |
1127 (backward-char 1))) | |
1155 (and (eq pos (point)) | 1128 (and (eq pos (point)) |
1156 (eq arg number) | 1129 (eq arg number) |
1157 (error "No buttons or fields found")) | 1130 (error "No buttons or fields found")) |
1158 (let ((new (widget-tabable-at))) | 1131 (let ((new (widget-tabable-at))) |
1159 (when new | 1132 (when new |
1185 (interactive) | 1158 (interactive) |
1186 (let* ((field (widget-field-find (point))) | 1159 (let* ((field (widget-field-find (point))) |
1187 (start (and field (widget-field-start field)))) | 1160 (start (and field (widget-field-start field)))) |
1188 (if (and start (not (eq start (point)))) | 1161 (if (and start (not (eq start (point)))) |
1189 (goto-char start) | 1162 (goto-char start) |
1190 (call-interactively 'beginning-of-line)))) | 1163 (call-interactively 'beginning-of-line))) |
1164 ;; XEmacs: preserve the region | |
1165 (setq zmacs-region-stays t)) | |
1191 | 1166 |
1192 (defun widget-end-of-line () | 1167 (defun widget-end-of-line () |
1193 "Go to end of field or end of line, whichever is first." | 1168 "Go to end of field or end of line, whichever is first." |
1194 (interactive) | 1169 (interactive) |
1195 (let* ((field (widget-field-find (point))) | 1170 (let* ((field (widget-field-find (point))) |
1196 (end (and field (widget-field-end field)))) | 1171 (end (and field (widget-field-end field)))) |
1197 (if (and end (not (eq end (point)))) | 1172 (if (and end (not (eq end (point)))) |
1198 (goto-char end) | 1173 (goto-char end) |
1199 (call-interactively 'end-of-line)))) | 1174 (call-interactively 'end-of-line))) |
1175 ;; XEmacs: preserve the region | |
1176 (setq zmacs-region-stays t)) | |
1200 | 1177 |
1201 (defun widget-kill-line () | 1178 (defun widget-kill-line () |
1202 "Kill to end of field or end of line, whichever is first." | 1179 "Kill to end of field or end of line, whichever is first." |
1203 (interactive) | 1180 (interactive) |
1204 (let* ((field (widget-field-find (point))) | 1181 (let* ((field (widget-field-find (point))) |
1248 (widget-specify-field field | 1225 (widget-specify-field field |
1249 (marker-position from) (marker-position to)) | 1226 (marker-position from) (marker-position to)) |
1250 (set-marker from nil) | 1227 (set-marker from nil) |
1251 (set-marker to nil)))) | 1228 (set-marker to nil)))) |
1252 (widget-clear-undo) | 1229 (widget-clear-undo) |
1253 ;; We need to maintain text properties and size of the editing fields. | 1230 (widget-add-change)) |
1254 (make-local-variable 'after-change-functions) | |
1255 (setq after-change-functions | |
1256 (if widget-field-list '(widget-after-change) nil)) | |
1257 (when widget-field-use-before-change | |
1258 (make-local-variable 'before-change-functions) | |
1259 (setq before-change-functions | |
1260 (if widget-field-list '(widget-before-change) nil)))) | |
1261 | 1231 |
1262 (defvar widget-field-last nil) | 1232 (defvar widget-field-last nil) |
1263 ;; Last field containing point. | 1233 ;; Last field containing point. |
1264 (make-variable-buffer-local 'widget-field-last) | 1234 (make-variable-buffer-local 'widget-field-last) |
1265 | 1235 |
1300 (when found | 1270 (when found |
1301 (debug "Overlapping fields")) | 1271 (debug "Overlapping fields")) |
1302 (setq found field)))) | 1272 (setq found field)))) |
1303 found)) | 1273 found)) |
1304 | 1274 |
1305 (defun widget-before-change (from &rest ignore) | 1275 (defun widget-before-change (from to) |
1306 ;; This is how, for example, a variable changes its state to `modified'. | 1276 ;; This is how, for example, a variable changes its state to `modified'. |
1307 ;; when it is being edited. | 1277 ;; when it is being edited. |
1308 (condition-case nil | 1278 (let ((from-field (widget-field-find from)) |
1309 (let ((field (widget-field-find from))) | 1279 (to-field (widget-field-find to))) |
1310 (widget-apply field :notify field)) | 1280 (cond ((not (eq from-field to-field)) |
1311 (error (debug "Before Change")))) | 1281 (add-hook 'post-command-hook 'widget-add-change nil t) |
1282 (error "Change should be restricted to a single field")) | |
1283 ((null from-field) | |
1284 (add-hook 'post-command-hook 'widget-add-change nil t) | |
1285 (error "Attempt to change text outside editable field")) | |
1286 (widget-field-use-before-change | |
1287 (condition-case nil | |
1288 (widget-apply from-field :notify from-field) | |
1289 (error (debug "Before Change"))))))) | |
1290 | |
1291 (defun widget-add-change () | |
1292 (make-local-hook 'post-command-hook) | |
1293 (remove-hook 'post-command-hook 'widget-add-change t) | |
1294 (make-local-hook 'before-change-functions) | |
1295 (add-hook 'before-change-functions 'widget-before-change nil t) | |
1296 (make-local-hook 'after-change-functions) | |
1297 (add-hook 'after-change-functions 'widget-after-change nil t)) | |
1312 | 1298 |
1313 (defun widget-after-change (from to old) | 1299 (defun widget-after-change (from to old) |
1314 ;; Adjust field size and text properties. | 1300 ;; Adjust field size and text properties. |
1315 (condition-case nil | 1301 (condition-case nil |
1316 (let ((field (widget-field-find from)) | 1302 (let ((field (widget-field-find from)) |
1502 (when value-pos | 1488 (when value-pos |
1503 (goto-char value-pos) | 1489 (goto-char value-pos) |
1504 (widget-apply widget :value-create))) | 1490 (widget-apply widget :value-create))) |
1505 (let ((from (copy-marker (point-min))) | 1491 (let ((from (copy-marker (point-min))) |
1506 (to (copy-marker (point-max)))) | 1492 (to (copy-marker (point-max)))) |
1507 (widget-specify-text from to) | |
1508 (set-marker-insertion-type from t) | 1493 (set-marker-insertion-type from t) |
1509 (set-marker-insertion-type to nil) | 1494 (set-marker-insertion-type to nil) |
1510 (widget-put widget :from from) | 1495 (widget-put widget :from from) |
1511 (widget-put widget :to to))) | 1496 (widget-put widget :to to))) |
1512 (widget-clear-undo)) | 1497 (widget-clear-undo)) |
1568 (let ((from (widget-get widget :from)) | 1553 (let ((from (widget-get widget :from)) |
1569 (to (widget-get widget :to)) | 1554 (to (widget-get widget :to)) |
1570 (inactive-overlay (widget-get widget :inactive)) | 1555 (inactive-overlay (widget-get widget :inactive)) |
1571 (button-overlay (widget-get widget :button-overlay)) | 1556 (button-overlay (widget-get widget :button-overlay)) |
1572 (sample-overlay (widget-get widget :sample-overlay)) | 1557 (sample-overlay (widget-get widget :sample-overlay)) |
1558 (doc-overlay (widget-get widget :doc-overlay)) | |
1573 before-change-functions | 1559 before-change-functions |
1574 after-change-functions | 1560 after-change-functions |
1575 (inhibit-read-only t)) | 1561 (inhibit-read-only t)) |
1576 (widget-apply widget :value-delete) | 1562 (widget-apply widget :value-delete) |
1577 (when inactive-overlay | 1563 (when inactive-overlay |
1578 (delete-overlay inactive-overlay)) | 1564 (delete-overlay inactive-overlay)) |
1579 (when button-overlay | 1565 (when button-overlay |
1580 (delete-overlay button-overlay)) | 1566 (delete-overlay button-overlay)) |
1581 (when sample-overlay | 1567 (when sample-overlay |
1582 (delete-overlay sample-overlay)) | 1568 (delete-overlay sample-overlay)) |
1569 (when doc-overlay | |
1570 (delete-overlay doc-overlay)) | |
1583 (when (< from to) | 1571 (when (< from to) |
1584 ;; Kludge: this doesn't need to be true for empty formats. | 1572 ;; Kludge: this doesn't need to be true for empty formats. |
1585 (delete-region from to)) | 1573 (delete-region from to)) |
1586 (set-marker from nil) | 1574 (set-marker from nil) |
1587 (set-marker to nil)) | 1575 (set-marker to nil)) |
1819 :action 'widget-emacs-library-link-action) | 1807 :action 'widget-emacs-library-link-action) |
1820 | 1808 |
1821 (defun widget-emacs-library-link-action (widget &optional event) | 1809 (defun widget-emacs-library-link-action (widget &optional event) |
1822 "Find the Emacs Library file specified by WIDGET." | 1810 "Find the Emacs Library file specified by WIDGET." |
1823 (find-file (locate-library (widget-value widget)))) | 1811 (find-file (locate-library (widget-value widget)))) |
1812 | |
1813 ;;; The `emacs-commentary-link' Widget. | |
1814 | |
1815 (define-widget 'emacs-commentary-link 'link | |
1816 "A link to Commentary in an Emacs Lisp library file." | |
1817 :action 'widget-emacs-commentary-link-action) | |
1818 | |
1819 (defun widget-emacs-commentary-link-action (widget &optional event) | |
1820 "Find the Commentary section of the Emacs file specified by WIDGET." | |
1821 (finder-commentary (widget-value widget))) | |
1824 | 1822 |
1825 ;;; The `editable-field' Widget. | 1823 ;;; The `editable-field' Widget. |
1826 | 1824 |
1827 (define-widget 'editable-field 'default | 1825 (define-widget 'editable-field 'default |
1828 "An editable text field." | 1826 "An editable text field." |
2607 (let ((child (widget-editable-list-entry-create | 2605 (let ((child (widget-editable-list-entry-create |
2608 widget nil nil))) | 2606 widget nil nil))) |
2609 (when (< (widget-get child :entry-from) (widget-get widget :from)) | 2607 (when (< (widget-get child :entry-from) (widget-get widget :from)) |
2610 (set-marker (widget-get widget :from) | 2608 (set-marker (widget-get widget :from) |
2611 (widget-get child :entry-from))) | 2609 (widget-get child :entry-from))) |
2612 (widget-specify-text (widget-get child :entry-from) | |
2613 (widget-get child :entry-to)) | |
2614 (if (eq (car children) before) | 2610 (if (eq (car children) before) |
2615 (widget-put widget :children (cons child children)) | 2611 (widget-put widget :children (cons child children)) |
2616 (while (not (eq (car (cdr children)) before)) | 2612 (while (not (eq (car (cdr children)) before)) |
2617 (setq children (cdr children))) | 2613 (setq children (cdr children))) |
2618 (setcdr children (cons child (cdr children))))))) | 2614 (setcdr children (cons child (cdr children))))))) |
2682 :buttons (cons delete | 2678 :buttons (cons delete |
2683 (cons insert | 2679 (cons insert |
2684 (widget-get widget :buttons)))) | 2680 (widget-get widget :buttons)))) |
2685 (let ((entry-from (copy-marker (point-min))) | 2681 (let ((entry-from (copy-marker (point-min))) |
2686 (entry-to (copy-marker (point-max)))) | 2682 (entry-to (copy-marker (point-max)))) |
2687 (widget-specify-text entry-from entry-to) | |
2688 (set-marker-insertion-type entry-from t) | 2683 (set-marker-insertion-type entry-from t) |
2689 (set-marker-insertion-type entry-to nil) | 2684 (set-marker-insertion-type entry-to nil) |
2690 (widget-put child :entry-from entry-from) | 2685 (widget-put child :entry-from entry-from) |
2691 (widget-put child :entry-to entry-to))) | 2686 (widget-put child :entry-to entry-to))) |
2692 (widget-put insert :widget child) | 2687 (widget-put insert :widget child) |
2941 | 2936 |
2942 (define-widget 'regexp 'string | 2937 (define-widget 'regexp 'string |
2943 "A regular expression." | 2938 "A regular expression." |
2944 :match 'widget-regexp-match | 2939 :match 'widget-regexp-match |
2945 :validate 'widget-regexp-validate | 2940 :validate 'widget-regexp-validate |
2946 :value-face 'widget-single-line-field-face | 2941 ;; Doesn't work well with terminating newline. |
2942 ;; :value-face 'widget-single-line-field-face | |
2947 :tag "Regexp") | 2943 :tag "Regexp") |
2948 | 2944 |
2949 (defun widget-regexp-match (widget value) | 2945 (defun widget-regexp-match (widget value) |
2950 ;; Match valid regexps. | 2946 ;; Match valid regexps. |
2951 (and (stringp value) | 2947 (and (stringp value) |
2967 "A file widget. | 2963 "A file widget. |
2968 It will read a file name from the minibuffer when invoked." | 2964 It will read a file name from the minibuffer when invoked." |
2969 :complete-function 'widget-file-complete | 2965 :complete-function 'widget-file-complete |
2970 :prompt-value 'widget-file-prompt-value | 2966 :prompt-value 'widget-file-prompt-value |
2971 :format "%{%t%}: %v" | 2967 :format "%{%t%}: %v" |
2972 :value-face 'widget-single-line-field-face | 2968 ;; Doesn't work well with terminating newline. |
2969 ;; :value-face 'widget-single-line-field-face | |
2973 :tag "File") | 2970 :tag "File") |
2974 | 2971 |
2975 (defun widget-file-complete () | 2972 (defun widget-file-complete () |
2976 "Perform completion on file name preceding point." | 2973 "Perform completion on file name preceding point." |
2977 (interactive) | 2974 (interactive) |
3384 (with-output-to-temp-buffer "*Completions*" | 3381 (with-output-to-temp-buffer "*Completions*" |
3385 (display-completion-list list))) | 3382 (display-completion-list list))) |
3386 (message "Making completion list...done"))))) | 3383 (message "Making completion list...done"))))) |
3387 | 3384 |
3388 (defun widget-color-sample-face-get (widget) | 3385 (defun widget-color-sample-face-get (widget) |
3389 (let ((symbol (intern (concat "fg:" (widget-value widget))))) | 3386 (let* ((value (condition-case nil |
3387 (widget-value widget) | |
3388 (error (widget-get widget :value)))) | |
3389 (symbol (intern (concat "fg:" value)))) | |
3390 (if (string-match "XEmacs" emacs-version) | 3390 (if (string-match "XEmacs" emacs-version) |
3391 (prog1 symbol | 3391 (prog1 symbol |
3392 (or (find-face symbol) | 3392 (or (find-face symbol) |
3393 (set-face-foreground (make-face symbol) (widget-value widget)))) | 3393 (set-face-foreground (make-face symbol) value))) |
3394 (condition-case nil | 3394 (condition-case nil |
3395 (facemenu-get-face symbol) | 3395 (facemenu-get-face symbol) |
3396 (error 'default))))) | 3396 (error 'default))))) |
3397 | 3397 |
3398 (defvar widget-color-choice-list nil) | 3398 (defvar widget-color-choice-list nil) |
3412 | 3412 |
3413 (defun widget-color-action (widget &optional event) | 3413 (defun widget-color-action (widget &optional event) |
3414 ;; Prompt for a color. | 3414 ;; Prompt for a color. |
3415 (let* ((tag (widget-apply widget :menu-tag-get)) | 3415 (let* ((tag (widget-apply widget :menu-tag-get)) |
3416 (prompt (concat tag ": ")) | 3416 (prompt (concat tag ": ")) |
3417 (answer (cond ((string-match "XEmacs" emacs-version) | 3417 (value (widget-value widget)) |
3418 (read-color prompt)) | 3418 (start (widget-field-start widget)) |
3419 ((fboundp 'x-defined-colors) | 3419 (pos (cond ((< (point) start) |
3420 (completing-read (concat tag ": ") | 3420 0) |
3421 (widget-color-choice-list) | 3421 ((> (point) (+ start (length value))) |
3422 nil nil nil 'widget-color-history)) | 3422 (length value)) |
3423 (t | 3423 (t |
3424 (read-string prompt (widget-value widget)))))) | 3424 (- (point) start)))) |
3425 (answer (if (commandp 'read-color) | |
3426 (read-color prompt) | |
3427 (completing-read (concat tag ": ") | |
3428 (widget-color-choice-list) | |
3429 nil nil | |
3430 (cons value pos) | |
3431 'widget-color-history)))) | |
3425 (unless (zerop (length answer)) | 3432 (unless (zerop (length answer)) |
3426 (widget-value-set widget answer) | 3433 (widget-value-set widget answer) |
3427 (widget-setup) | 3434 (widget-setup) |
3428 (widget-apply widget :notify widget event)))) | 3435 (widget-apply widget :notify widget event)))) |
3429 | 3436 |