aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRichard M. Stallman1999-01-18 01:02:58 +0000
committerRichard M. Stallman1999-01-18 01:02:58 +0000
commitfc56773e1ff573c2485033fe7a1507230514ab77 (patch)
treea494405cef3ceafcb4aa314103188e8a8014d470
parent7fd4783900718ddcc13d6df17c1da5ae62f13edd (diff)
downloademacs-fc56773e1ff573c2485033fe7a1507230514ab77.tar.gz
emacs-fc56773e1ff573c2485033fe7a1507230514ab77.zip
(plist, alist): New widget types.
(coding-system): Define this unconditionally.
-rw-r--r--lisp/wid-edit.el164
1 files changed, 127 insertions, 37 deletions
diff --git a/lisp/wid-edit.el b/lisp/wid-edit.el
index 70d61a99d23..f5131830151 100644
--- a/lisp/wid-edit.el
+++ b/lisp/wid-edit.el
@@ -2905,7 +2905,7 @@ link for that string."
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
@@ -3096,41 +3096,40 @@ It will read a directory name from the minibuffer when invoked."
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"
@@ -3218,7 +3217,7 @@ To use this type, you must define :match or :match-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"
@@ -3286,7 +3285,98 @@ To use this type, you must define :match or :match-alternatives."
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))))
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))
3289 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"
@@ -3336,7 +3426,7 @@ To use this type, you must define :match or :match-alternatives."
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"
@@ -3366,7 +3456,7 @@ To use this type, you must define :match or :match-alternatives."
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
@@ -3450,7 +3540,7 @@ To use this type, you must define :match or :match-alternatives."
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 ()