Mercurial > emacs
comparison lisp/cus-edit.el @ 61307:0592ebb75598
(face): Derive from symbol widget. Display sample
of the current face on the fly.
(widget-face-sample-face-get, widget-face-notify): New functions.
(widget-face-value-create): Remove.
author | David Ponce <david@dponce.com> |
---|---|
date | Tue, 05 Apr 2005 06:40:12 +0000 |
parents | 7090a1e062e2 |
children | 31aa9a390538 |
comparison
equal
deleted
inserted
replaced
61306:497964065ff1 | 61307:0592ebb75598 |
---|---|
3294 ;;; The `face' Widget. | 3294 ;;; The `face' Widget. |
3295 | 3295 |
3296 (defvar widget-face-prompt-value-history nil | 3296 (defvar widget-face-prompt-value-history nil |
3297 "History of input to `widget-face-prompt-value'.") | 3297 "History of input to `widget-face-prompt-value'.") |
3298 | 3298 |
3299 (define-widget 'face 'restricted-sexp | 3299 (define-widget 'face 'symbol |
3300 "A Lisp face name." | 3300 "A Lisp face name (with sample)." |
3301 :format "%t: (%{sample%}) %v" | |
3302 :tag "Face" | |
3303 :value 'default | |
3304 :sample-face-get 'widget-face-sample-face-get | |
3305 :notify 'widget-face-notify | |
3306 :match (lambda (widget value) (facep value)) | |
3301 :complete-function (lambda () | 3307 :complete-function (lambda () |
3302 (interactive) | 3308 (interactive) |
3303 (lisp-complete-symbol 'facep)) | 3309 (lisp-complete-symbol 'facep)) |
3304 :prompt-value 'widget-field-prompt-value | |
3305 :prompt-internal 'widget-symbol-prompt-internal | |
3306 :prompt-match 'facep | 3310 :prompt-match 'facep |
3307 :prompt-history 'widget-face-prompt-value-history | 3311 :prompt-history 'widget-face-prompt-value-history |
3308 :value-create 'widget-face-value-create | |
3309 :action 'widget-field-action | |
3310 :match-alternatives '(facep) | |
3311 :validate (lambda (widget) | 3312 :validate (lambda (widget) |
3312 (unless (facep (widget-value widget)) | 3313 (unless (facep (widget-value widget)) |
3313 (widget-put widget :error (format "Invalid face: %S" | 3314 (widget-put widget |
3314 (widget-value widget))) | 3315 :error (format "Invalid face: %S" |
3315 widget)) | 3316 (widget-value widget))) |
3316 :value 'ignore | 3317 widget))) |
3317 :tag "Function") | 3318 |
3318 | 3319 (defun widget-face-sample-face-get (widget) |
3319 | 3320 (let ((value (widget-value widget))) |
3320 ;;; There is a bug here: the sample doesn't get redisplayed | 3321 (if (facep value) |
3321 ;;; in the new font when you specify one. Does anyone know how to | 3322 value |
3322 ;;; make that work? -- rms. | 3323 'default))) |
3323 | 3324 |
3324 (defun widget-face-value-create (widget) | 3325 (defun widget-face-notify (widget child &optional event) |
3325 "Create an editable face name field." | 3326 "Update the sample, and notify the parent." |
3326 (let ((buttons (widget-get widget :buttons)) | 3327 (overlay-put (widget-get widget :sample-overlay) |
3327 (symbol (widget-get widget :value))) | 3328 'face (widget-apply widget :sample-face-get)) |
3328 ;; Sample. | 3329 (widget-default-notify widget child event)) |
3329 (push (widget-create-child-and-convert widget 'item | |
3330 :format "(%{%t%})" | |
3331 :sample-face symbol | |
3332 :tag "sample") | |
3333 buttons) | |
3334 (insert " ") | |
3335 ;; Update buttons. | |
3336 (widget-put widget :buttons buttons)) | |
3337 | |
3338 (let ((size (widget-get widget :size)) | |
3339 (value (widget-get widget :value)) | |
3340 (from (point)) | |
3341 ;; This is changed to a real overlay in `widget-setup'. We | |
3342 ;; need the end points to behave differently until | |
3343 ;; `widget-setup' is called. | |
3344 (overlay (cons (make-marker) (make-marker)))) | |
3345 (widget-put widget :field-overlay overlay) | |
3346 (insert value) | |
3347 (and size | |
3348 (< (length value) size) | |
3349 (insert-char ?\ (- size (length value)))) | |
3350 (unless (memq widget widget-field-list) | |
3351 (setq widget-field-new (cons widget widget-field-new))) | |
3352 (move-marker (cdr overlay) (point)) | |
3353 (set-marker-insertion-type (cdr overlay) nil) | |
3354 (when (null size) | |
3355 (insert ?\n)) | |
3356 (move-marker (car overlay) from) | |
3357 (set-marker-insertion-type (car overlay) t))) | |
3358 | 3330 |
3359 | 3331 |
3360 ;;; The `hook' Widget. | 3332 ;;; The `hook' Widget. |
3361 | 3333 |
3362 (define-widget 'hook 'list | 3334 (define-widget 'hook 'list |