Mercurial > emacs
comparison lisp/wid-edit.el @ 24107:c222b0bea4f0
(plist, alist): New widget types.
(coding-system): Define this unconditionally.
author | Richard M. Stallman <rms@gnu.org> |
---|---|
date | Mon, 18 Jan 1999 01:02:58 +0000 |
parents | b6c86c56e760 |
children | df6194854007 |
comparison
equal
deleted
inserted
replaced
24106:ea58bb66d0e3 | 24107:c222b0bea4f0 |
---|---|
2903 (let ((parent (widget-get widget :parent))) | 2903 (let ((parent (widget-get widget :parent))) |
2904 (widget-put parent :documentation-shown | 2904 (widget-put parent :documentation-shown |
2905 (not (widget-get parent :documentation-shown)))) | 2905 (not (widget-get parent :documentation-shown)))) |
2906 ;; Redraw. | 2906 ;; Redraw. |
2907 (widget-value-set widget (widget-value widget))) | 2907 (widget-value-set widget (widget-value widget))) |
2908 | 2908 |
2909 ;;; The Sexp Widgets. | 2909 ;;; The Sexp Widgets. |
2910 | 2910 |
2911 (define-widget 'const 'item | 2911 (define-widget 'const 'item |
2912 "An immutable sexp." | 2912 "An immutable sexp." |
2913 :prompt-value 'widget-const-prompt-value | 2913 :prompt-value 'widget-const-prompt-value |
3094 "A Lisp variable." | 3094 "A Lisp variable." |
3095 :prompt-match 'boundp | 3095 :prompt-match 'boundp |
3096 :prompt-history 'widget-variable-prompt-value-history | 3096 :prompt-history 'widget-variable-prompt-value-history |
3097 :tag "Variable") | 3097 :tag "Variable") |
3098 | 3098 |
3099 (when (featurep 'mule) | 3099 (defvar widget-coding-system-prompt-value-history nil |
3100 (defvar widget-coding-system-prompt-value-history nil | 3100 "History of input to `widget-coding-system-prompt-value'.") |
3101 "History of input to `widget-coding-system-prompt-value'.") | |
3102 | 3101 |
3103 (define-widget 'coding-system 'symbol | 3102 (define-widget 'coding-system 'symbol |
3104 "A MULE coding-system." | 3103 "A MULE coding-system." |
3105 :format "%{%t%}: %v" | 3104 :format "%{%t%}: %v" |
3106 :tag "Coding system" | 3105 :tag "Coding system" |
3107 :prompt-history 'widget-coding-system-prompt-value-history | 3106 :prompt-history 'widget-coding-system-prompt-value-history |
3108 :prompt-value 'widget-coding-system-prompt-value | 3107 :prompt-value 'widget-coding-system-prompt-value |
3109 :action 'widget-coding-system-action) | 3108 :action 'widget-coding-system-action) |
3110 | 3109 |
3111 (defun widget-coding-system-prompt-value (widget prompt value unbound) | 3110 (defun widget-coding-system-prompt-value (widget prompt value unbound) |
3112 ;; Read coding-system from minibuffer. | 3111 ;; Read coding-system from minibuffer. |
3113 (intern | 3112 (intern |
3114 (completing-read (format "%s (default %s) " prompt value) | 3113 (completing-read (format "%s (default %s) " prompt value) |
3115 (mapcar (function | 3114 (mapcar (function |
3116 (lambda (sym) | 3115 (lambda (sym) |
3117 (list (symbol-name sym)) | 3116 (list (symbol-name sym)) |
3118 )) | 3117 )) |
3119 (coding-system-list))))) | 3118 (coding-system-list))))) |
3120 | 3119 |
3121 (defun widget-coding-system-action (widget &optional event) | 3120 (defun widget-coding-system-action (widget &optional event) |
3122 ;; Read a file name from the minibuffer. | 3121 ;; Read a file name from the minibuffer. |
3123 (let ((answer | 3122 (let ((answer |
3124 (widget-coding-system-prompt-value | 3123 (widget-coding-system-prompt-value |
3125 widget | 3124 widget |
3126 (widget-apply widget :menu-tag-get) | 3125 (widget-apply widget :menu-tag-get) |
3127 (widget-value widget) | 3126 (widget-value widget) |
3128 t))) | 3127 t))) |
3129 (widget-value-set widget answer) | 3128 (widget-value-set widget answer) |
3130 (widget-apply widget :notify widget event) | 3129 (widget-apply widget :notify widget event) |
3131 (widget-setup))) | 3130 (widget-setup))) |
3132 ) | 3131 ) |
3133 | 3132 |
3134 (define-widget 'sexp 'editable-field | 3133 (define-widget 'sexp 'editable-field |
3135 "An arbitrary Lisp expression." | 3134 "An arbitrary Lisp expression." |
3136 :tag "Lisp expression" | 3135 :tag "Lisp expression" |
3137 :format "%{%t%}: %v" | 3136 :format "%{%t%}: %v" |
3138 :value nil | 3137 :value nil |
3216 (eq (car (car alternatives)) 'quote)) | 3215 (eq (car (car alternatives)) 'quote)) |
3217 (eq value (nth 1 (car alternatives))))) | 3216 (eq value (nth 1 (car alternatives))))) |
3218 (setq matched t)) | 3217 (setq matched t)) |
3219 (setq alternatives (cdr alternatives))) | 3218 (setq alternatives (cdr alternatives))) |
3220 matched)) | 3219 matched)) |
3221 | 3220 |
3222 (define-widget 'integer 'restricted-sexp | 3221 (define-widget 'integer 'restricted-sexp |
3223 "An integer." | 3222 "An integer." |
3224 :tag "Integer" | 3223 :tag "Integer" |
3225 :value 0 | 3224 :value 0 |
3226 :type-error "This field should contain an integer" | 3225 :type-error "This field should contain an integer" |
3284 | 3283 |
3285 (defun widget-cons-match (widget value) | 3284 (defun widget-cons-match (widget value) |
3286 (and (consp value) | 3285 (and (consp value) |
3287 (widget-group-match widget | 3286 (widget-group-match widget |
3288 (widget-apply widget :value-to-internal value)))) | 3287 (widget-apply widget :value-to-internal value)))) |
3289 | 3288 |
3289 ;;; The `plist' Widget. | |
3290 ;; | |
3291 ;; Property lists. | |
3292 | |
3293 (define-widget 'plist 'list | |
3294 "A property list." | |
3295 :key-type '(symbol :tag "Key") | |
3296 :value-type '(sexp :tag "Value") | |
3297 :convert-widget 'widget-plist-convert-widget | |
3298 :tag "Plist") | |
3299 | |
3300 (defvar widget-plist-value-type) ;Dynamic variable | |
3301 | |
3302 (defun widget-plist-convert-widget (widget) | |
3303 ;; Handle `:options'. | |
3304 (let* ((options (widget-get widget :options)) | |
3305 (key-type (widget-get widget :key-type)) | |
3306 (widget-plist-value-type (widget-get widget :value-type)) | |
3307 (other `(editable-list :inline t | |
3308 (group :inline t | |
3309 ,key-type | |
3310 ,widget-plist-value-type))) | |
3311 (args (if options | |
3312 (list `(checklist :inline t | |
3313 :greedy t | |
3314 ,@(mapcar 'widget-plist-convert-option | |
3315 options)) | |
3316 other) | |
3317 (list other)))) | |
3318 (widget-put widget :args args) | |
3319 widget)) | |
3320 | |
3321 (defun widget-plist-convert-option (option) | |
3322 ;; Convert a single plist option. | |
3323 (let (key-type value-type) | |
3324 (if (listp option) | |
3325 (let ((key (nth 0 option))) | |
3326 (setq value-type (nth 1 option)) | |
3327 (if (listp key) | |
3328 (setq key-type ,key) | |
3329 (setq key-type `(const ,key)))) | |
3330 (setq key-type `(const ,option) | |
3331 value-type widget-plist-value-type)) | |
3332 `(group :format "Key: %v" :inline t ,key-type ,value-type))) | |
3333 | |
3334 | |
3335 ;;; The `alist' Widget. | |
3336 ;; | |
3337 ;; Association lists. | |
3338 | |
3339 (define-widget 'alist 'list | |
3340 "An association list." | |
3341 :key-type '(string :tag "Key") | |
3342 :value-type '(sexp :tag "Value") | |
3343 :convert-widget 'widget-alist-convert-widget | |
3344 :tag "Alist") | |
3345 | |
3346 (defvar widget-alist-value-type) ;Dynamic variable | |
3347 | |
3348 (defun widget-alist-convert-widget (widget) | |
3349 ;; Handle `:options'. | |
3350 (let* ((options (widget-get widget :options)) | |
3351 (key-type (widget-get widget :key-type)) | |
3352 (widget-alist-value-type (widget-get widget :value-type)) | |
3353 (other `(editable-list :inline t | |
3354 (cons :format "%v" | |
3355 ,key-type | |
3356 ,widget-alist-value-type))) | |
3357 (args (if options | |
3358 (list `(checklist :inline t | |
3359 :greedy t | |
3360 ,@(mapcar 'widget-alist-convert-option | |
3361 options)) | |
3362 other) | |
3363 (list other)))) | |
3364 (widget-put widget :args args) | |
3365 widget)) | |
3366 | |
3367 (defun widget-alist-convert-option (option) | |
3368 ;; Convert a single alist option. | |
3369 (let (key-type value-type) | |
3370 (if (listp option) | |
3371 (let ((key (nth 0 option))) | |
3372 (setq value-type (nth 1 option)) | |
3373 (if (listp key) | |
3374 (setq key-type ,key) | |
3375 (setq key-type `(const ,key)))) | |
3376 (setq key-type `(const ,option) | |
3377 value-type widget-alist-value-type)) | |
3378 `(cons :format "Key: %v" ,key-type ,value-type))) | |
3379 | |
3290 (define-widget 'choice 'menu-choice | 3380 (define-widget 'choice 'menu-choice |
3291 "A union of several sexp types." | 3381 "A union of several sexp types." |
3292 :tag "Choice" | 3382 :tag "Choice" |
3293 :format "%{%t%}: %[Value Menu%] %v" | 3383 :format "%{%t%}: %[Value Menu%] %v" |
3294 :button-prefix 'widget-push-button-prefix | 3384 :button-prefix 'widget-push-button-prefix |
3334 (cdr (assoc val choices))) | 3424 (cdr (assoc val choices))) |
3335 nil))))) | 3425 nil))))) |
3336 (if current | 3426 (if current |
3337 (widget-prompt-value current prompt nil t) | 3427 (widget-prompt-value current prompt nil t) |
3338 value))) | 3428 value))) |
3339 | 3429 |
3340 (define-widget 'radio 'radio-button-choice | 3430 (define-widget 'radio 'radio-button-choice |
3341 "A union of several sexp types." | 3431 "A union of several sexp types." |
3342 :tag "Choice" | 3432 :tag "Choice" |
3343 :format "%{%t%}:\n%v" | 3433 :format "%{%t%}:\n%v" |
3344 :prompt-value 'widget-choice-prompt-value) | 3434 :prompt-value 'widget-choice-prompt-value) |
3364 :off "off (nil)") | 3454 :off "off (nil)") |
3365 | 3455 |
3366 (defun widget-boolean-prompt-value (widget prompt value unbound) | 3456 (defun widget-boolean-prompt-value (widget prompt value unbound) |
3367 ;; Toggle a boolean. | 3457 ;; Toggle a boolean. |
3368 (y-or-n-p prompt)) | 3458 (y-or-n-p prompt)) |
3369 | 3459 |
3370 ;;; The `color' Widget. | 3460 ;;; The `color' Widget. |
3371 | 3461 |
3372 (define-widget 'color 'editable-field | 3462 (define-widget 'color 'editable-field |
3373 "Choose a color name (with sample)." | 3463 "Choose a color name (with sample)." |
3374 :format "%t: %v (%{sample%})\n" | 3464 :format "%t: %v (%{sample%})\n" |
3448 (defun widget-color-notify (widget child &optional event) | 3538 (defun widget-color-notify (widget child &optional event) |
3449 "Update the sample, and notofy the parent." | 3539 "Update the sample, and notofy the parent." |
3450 (overlay-put (widget-get widget :sample-overlay) | 3540 (overlay-put (widget-get widget :sample-overlay) |
3451 'face (widget-apply widget :sample-face-get)) | 3541 'face (widget-apply widget :sample-face-get)) |
3452 (widget-default-notify widget child event)) | 3542 (widget-default-notify widget child event)) |
3453 | 3543 |
3454 ;;; The Help Echo | 3544 ;;; The Help Echo |
3455 | 3545 |
3456 (defun widget-echo-help-mouse () | 3546 (defun widget-echo-help-mouse () |
3457 "Display the help message for the widget under the mouse. | 3547 "Display the help message for the widget under the mouse. |
3458 Enable with (run-with-idle-timer 1 t 'widget-echo-help-mouse)" | 3548 Enable with (run-with-idle-timer 1 t 'widget-echo-help-mouse)" |