diff options
| author | Per Abrahamsen | 1997-07-04 12:52:14 +0000 |
|---|---|---|
| committer | Per Abrahamsen | 1997-07-04 12:52:14 +0000 |
| commit | 0f648ca2b97df2b5e925a4be1b23d5c41a703c71 (patch) | |
| tree | dcebb08ad1b2c1b0af6358f9864970fcf9d467d6 | |
| parent | 06382f34df4da68f7e696066468dd3f335c4d0df (diff) | |
| download | emacs-0f648ca2b97df2b5e925a4be1b23d5c41a703c71.tar.gz emacs-0f648ca2b97df2b5e925a4be1b23d5c41a703c71.zip | |
Synched with 1.9945.
| -rw-r--r-- | lisp/wid-edit.el | 113 |
1 files changed, 51 insertions, 62 deletions
diff --git a/lisp/wid-edit.el b/lisp/wid-edit.el index c84a6894bb9..31b8be64ddd 100644 --- a/lisp/wid-edit.el +++ b/lisp/wid-edit.el | |||
| @@ -4,7 +4,7 @@ | |||
| 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.9944 | 7 | ;; Version: 1.9945 |
| 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. |
| @@ -450,11 +450,11 @@ new value." | |||
| 450 | 450 | ||
| 451 | (defun widget-specify-sample (widget from to) | 451 | (defun widget-specify-sample (widget from to) |
| 452 | ;; Specify sample for WIDGET between FROM and TO. | 452 | ;; Specify sample for WIDGET between FROM and TO. |
| 453 | (let ((face (widget-apply widget :sample-face-get))) | 453 | (let ((face (widget-apply widget :sample-face-get)) |
| 454 | (when face | 454 | (overlay (make-overlay from to nil t nil))) |
| 455 | (add-text-properties from to (list 'start-open t | 455 | (overlay-put overlay 'face face) |
| 456 | 'end-open t | 456 | (widget-put widget :sample-overlay overlay))) |
| 457 | 'face face))))) | 457 | |
| 458 | (defun widget-specify-doc (widget from to) | 458 | (defun widget-specify-doc (widget from to) |
| 459 | ;; Specify documentation for WIDGET between FROM and TO. | 459 | ;; Specify documentation for WIDGET between FROM and TO. |
| 460 | (add-text-properties from to (list 'widget-doc widget | 460 | (add-text-properties from to (list 'widget-doc widget |
| @@ -920,12 +920,15 @@ button end points." | |||
| 920 | (let ((from (widget-get widget :from)) | 920 | (let ((from (widget-get widget :from)) |
| 921 | (to (widget-get widget :to)) | 921 | (to (widget-get widget :to)) |
| 922 | (button (widget-get widget :button-overlay)) | 922 | (button (widget-get widget :button-overlay)) |
| 923 | (sample (widget-get widget :sample-overlay)) | ||
| 923 | (field (widget-get widget :field-overlay)) | 924 | (field (widget-get widget :field-overlay)) |
| 924 | (children (widget-get widget :children))) | 925 | (children (widget-get widget :children))) |
| 925 | (set-marker from nil) | 926 | (set-marker from nil) |
| 926 | (set-marker to nil) | 927 | (set-marker to nil) |
| 927 | (when button | 928 | (when button |
| 928 | (delete-overlay button)) | 929 | (delete-overlay button)) |
| 930 | (when sample | ||
| 931 | (delete-overlay sample)) | ||
| 929 | (when field | 932 | (when field |
| 930 | (delete-overlay field)) | 933 | (delete-overlay field)) |
| 931 | (mapcar 'widget-leave-text children))) | 934 | (mapcar 'widget-leave-text children))) |
| @@ -1562,6 +1565,7 @@ If that does not exists, call the value of `widget-complete-field'." | |||
| 1562 | (to (widget-get widget :to)) | 1565 | (to (widget-get widget :to)) |
| 1563 | (inactive-overlay (widget-get widget :inactive)) | 1566 | (inactive-overlay (widget-get widget :inactive)) |
| 1564 | (button-overlay (widget-get widget :button-overlay)) | 1567 | (button-overlay (widget-get widget :button-overlay)) |
| 1568 | (sample-overlay (widget-get widget :sample-overlay)) | ||
| 1565 | before-change-functions | 1569 | before-change-functions |
| 1566 | after-change-functions | 1570 | after-change-functions |
| 1567 | (inhibit-read-only t)) | 1571 | (inhibit-read-only t)) |
| @@ -1570,6 +1574,8 @@ If that does not exists, call the value of `widget-complete-field'." | |||
| 1570 | (delete-overlay inactive-overlay)) | 1574 | (delete-overlay inactive-overlay)) |
| 1571 | (when button-overlay | 1575 | (when button-overlay |
| 1572 | (delete-overlay button-overlay)) | 1576 | (delete-overlay button-overlay)) |
| 1577 | (when sample-overlay | ||
| 1578 | (delete-overlay sample-overlay)) | ||
| 1573 | (when (< from to) | 1579 | (when (< from to) |
| 1574 | ;; Kludge: this doesn't need to be true for empty formats. | 1580 | ;; Kludge: this doesn't need to be true for empty formats. |
| 1575 | (delete-region from to)) | 1581 | (delete-region from to)) |
| @@ -3345,12 +3351,37 @@ To use this type, you must define :match or :match-alternatives." | |||
| 3345 | 3351 | ||
| 3346 | ;;; The `color' Widget. | 3352 | ;;; The `color' Widget. |
| 3347 | 3353 | ||
| 3348 | (define-widget 'color-item 'choice-item | 3354 | (define-widget 'color 'editable-field |
| 3349 | "A color name (with sample)." | 3355 | "Choose a color name (with sample)." |
| 3350 | :format "%v (%{sample%})\n" | 3356 | :format "%t: %v (%{sample%})\n" |
| 3351 | :sample-face-get 'widget-color-item-button-face-get) | 3357 | :size 10 |
| 3358 | :tag "Color" | ||
| 3359 | :value "black" | ||
| 3360 | :complete 'widget-color-complete | ||
| 3361 | :sample-face-get 'widget-color-sample-face-get | ||
| 3362 | :notify 'widget-color-notify | ||
| 3363 | :action 'widget-color-action) | ||
| 3364 | |||
| 3365 | (defun widget-color-complete (widget) | ||
| 3366 | "Complete the color in WIDGET." | ||
| 3367 | (let* ((prefix (buffer-substring-no-properties (widget-field-start widget) | ||
| 3368 | (point))) | ||
| 3369 | (list (widget-color-choice-list)) | ||
| 3370 | (completion (try-completion prefix list))) | ||
| 3371 | (cond ((eq completion t) | ||
| 3372 | (message "Exact match.")) | ||
| 3373 | ((null completion) | ||
| 3374 | (error "Can't find completion for \"%s\"" prefix)) | ||
| 3375 | ((not (string-equal prefix completion)) | ||
| 3376 | (insert-and-inherit (substring completion (length prefix)))) | ||
| 3377 | (t | ||
| 3378 | (message "Making completion list...") | ||
| 3379 | (let ((list (all-completions prefix list nil))) | ||
| 3380 | (with-output-to-temp-buffer "*Completions*" | ||
| 3381 | (display-completion-list list))) | ||
| 3382 | (message "Making completion list...done"))))) | ||
| 3352 | 3383 | ||
| 3353 | (defun widget-color-item-button-face-get (widget) | 3384 | (defun widget-color-sample-face-get (widget) |
| 3354 | (let ((symbol (intern (concat "fg:" (widget-value widget))))) | 3385 | (let ((symbol (intern (concat "fg:" (widget-value widget))))) |
| 3355 | (if (string-match "XEmacs" emacs-version) | 3386 | (if (string-match "XEmacs" emacs-version) |
| 3356 | (prog1 symbol | 3387 | (prog1 symbol |
| @@ -3360,42 +3391,18 @@ To use this type, you must define :match or :match-alternatives." | |||
| 3360 | (facemenu-get-face symbol) | 3391 | (facemenu-get-face symbol) |
| 3361 | (error 'default))))) | 3392 | (error 'default))))) |
| 3362 | 3393 | ||
| 3363 | (define-widget 'color 'push-button | ||
| 3364 | "Choose a color name (with sample)." | ||
| 3365 | :format "%[%t%]: %v" | ||
| 3366 | :tag "Color" | ||
| 3367 | :value "black" | ||
| 3368 | :value-create 'widget-color-value-create | ||
| 3369 | :value-delete 'widget-children-value-delete | ||
| 3370 | :value-get 'widget-color-value-get | ||
| 3371 | :value-set 'widget-color-value-set | ||
| 3372 | :action 'widget-color-action | ||
| 3373 | :match 'widget-field-match | ||
| 3374 | :tag "Color") | ||
| 3375 | |||
| 3376 | (defvar widget-color-choice-list nil) | 3394 | (defvar widget-color-choice-list nil) |
| 3377 | ;; Variable holding the possible colors. | 3395 | ;; Variable holding the possible colors. |
| 3378 | 3396 | ||
| 3379 | (defun widget-color-choice-list () | 3397 | (defun widget-color-choice-list () |
| 3380 | (unless widget-color-choice-list | 3398 | (unless widget-color-choice-list |
| 3381 | (setq widget-color-choice-list | 3399 | (setq widget-color-choice-list |
| 3382 | (mapcar '(lambda (color) (list color)) | 3400 | (if (fboundp 'read-color-completion-table) |
| 3383 | (x-defined-colors)))) | 3401 | (read-color-completion-table) |
| 3402 | (mapcar '(lambda (color) (list color)) | ||
| 3403 | (x-defined-colors))))) | ||
| 3384 | widget-color-choice-list) | 3404 | widget-color-choice-list) |
| 3385 | 3405 | ||
| 3386 | (defun widget-color-value-create (widget) | ||
| 3387 | (let ((child (widget-create-child-and-convert | ||
| 3388 | widget 'color-item (widget-get widget :value)))) | ||
| 3389 | (widget-put widget :children (list child)))) | ||
| 3390 | |||
| 3391 | (defun widget-color-value-get (widget) | ||
| 3392 | ;; Pass command to first child. | ||
| 3393 | (widget-apply (car (widget-get widget :children)) :value-get)) | ||
| 3394 | |||
| 3395 | (defun widget-color-value-set (widget value) | ||
| 3396 | ;; Pass command to first child. | ||
| 3397 | (widget-apply (car (widget-get widget :children)) :value-set value)) | ||
| 3398 | |||
| 3399 | (defvar widget-color-history nil | 3406 | (defvar widget-color-history nil |
| 3400 | "History of entered colors") | 3407 | "History of entered colors") |
| 3401 | 3408 | ||
| @@ -3416,29 +3423,11 @@ To use this type, you must define :match or :match-alternatives." | |||
| 3416 | (widget-setup) | 3423 | (widget-setup) |
| 3417 | (widget-apply widget :notify widget event)))) | 3424 | (widget-apply widget :notify widget event)))) |
| 3418 | 3425 | ||
| 3419 | ;;; The alternative `editable-color' widget and its subroutine. | 3426 | (defun widget-color-notify (widget child &optional event) |
| 3420 | 3427 | "Update the sample, and notofy the parent." | |
| 3421 | (define-widget 'color-sample 'choice-item | 3428 | (overlay-put (widget-get widget :sample-overlay) |
| 3422 | "A color name (with sample)." | 3429 | 'face (widget-apply widget :sample-face-get)) |
| 3423 | :format "(%{sample%})" | 3430 | (widget-default-notify widget child event)) |
| 3424 | :sample-face-get 'widget-color-item-button-face-get) | ||
| 3425 | |||
| 3426 | (define-widget 'editable-color 'editable-field | ||
| 3427 | "A color name, editable" | ||
| 3428 | :tag "Color" | ||
| 3429 | :format "%{%t%}: %v" | ||
| 3430 | :complete-function 'widget-color-complete | ||
| 3431 | :value-create 'widget-editable-color-value-create | ||
| 3432 | :prompt-match '(lambda (color) (member color widget-color-choice-list)) | ||
| 3433 | :prompt-history 'widget-string-prompt-value-history) | ||
| 3434 | |||
| 3435 | (defun widget-editable-color-value-create (widget) | ||
| 3436 | (widget-field-value-create widget) | ||
| 3437 | (forward-line -1) | ||
| 3438 | (end-of-line) | ||
| 3439 | (let ((child (widget-create-child-and-convert | ||
| 3440 | widget 'color-sample (widget-get widget :value)))) | ||
| 3441 | (widget-put widget :children (list child)))) | ||
| 3442 | 3431 | ||
| 3443 | ;;; The Help Echo | 3432 | ;;; The Help Echo |
| 3444 | 3433 | ||