comparison lisp/wid-edit.el @ 90261:7beb78bc1f8e

Revision: miles@gnu.org--gnu-2005/emacs--unicode--0--patch-97 Merge from emacs--cvs-trunk--0 Patches applied: * emacs--cvs-trunk--0 (patch 616-696) - Add lisp/mh-e/.arch-inventory - Update from CVS - Merge from gnus--rel--5.10 - Update from CVS: lisp/smerge-mode.el: Add 'tools' to file keywords. - lisp/gnus/ChangeLog: Remove duplicate entry * gnus--rel--5.10 (patch 147-181) - Update from CVS - Merge from emacs--cvs-trunk--0 - Update from CVS: lisp/mml.el (mml-preview): Doc fix. - Update from CVS: texi/message.texi: Fix default values. - Update from CVS: texi/gnus.texi (RSS): Addition.
author Miles Bader <miles@gnu.org>
date Mon, 16 Jan 2006 08:37:27 +0000
parents 0ca0d9181b5e ca3d61094d2b
children 7432ca837c8d
comparison
equal deleted inserted replaced
90260:0ca0d9181b5e 90261:7beb78bc1f8e
401 (overlay-put overlay 'keymap (widget-get widget :keymap)) 401 (overlay-put overlay 'keymap (widget-get widget :keymap))
402 (overlay-put overlay 'evaporate t) 402 (overlay-put overlay 'evaporate t)
403 ;; We want to avoid the face with image buttons. 403 ;; We want to avoid the face with image buttons.
404 (unless (widget-get widget :suppress-face) 404 (unless (widget-get widget :suppress-face)
405 (overlay-put overlay 'face (widget-apply widget :button-face-get)) 405 (overlay-put overlay 'face (widget-apply widget :button-face-get))
406 ; Text terminals cannot change mouse pointer shape, so use mouse 406 (overlay-put overlay 'mouse-face
407 ; face instead. 407 (widget-apply widget :mouse-face-get)))
408 (or (display-graphic-p)
409 (overlay-put overlay 'mouse-face widget-mouse-face)))
410 (overlay-put overlay 'pointer 'hand) 408 (overlay-put overlay 'pointer 'hand)
411 (overlay-put overlay 'follow-link follow-link) 409 (overlay-put overlay 'follow-link follow-link)
412 (overlay-put overlay 'help-echo help-echo))) 410 (overlay-put overlay 'help-echo help-echo)))
413 411
414 (defun widget-mouse-help (window overlay point) 412 (defun widget-mouse-help (window overlay point)
662 660
663 (defun widget-move-and-invoke (event) 661 (defun widget-move-and-invoke (event)
664 "Move to where you click, and if it is an active field, invoke it." 662 "Move to where you click, and if it is an active field, invoke it."
665 (interactive "e") 663 (interactive "e")
666 (mouse-set-point event) 664 (mouse-set-point event)
667 (if (widget-event-point event) 665 (let ((pos (widget-event-point event)))
668 (let* ((pos (widget-event-point event)) 666 (if (and pos (get-char-property pos 'button))
669 (button (get-char-property pos 'button))) 667 (widget-button-click event))))
670 (if button
671 (widget-button-click event)))))
672 668
673 ;;; Buttons. 669 ;;; Buttons.
674 670
675 (defgroup widget-button nil 671 (defgroup widget-button nil
676 "The look of various kinds of buttons." 672 "The look of various kinds of buttons."
855 851
856 ;;;###autoload 852 ;;;###autoload
857 (defvar widget-keymap 853 (defvar widget-keymap
858 (let ((map (make-sparse-keymap))) 854 (let ((map (make-sparse-keymap)))
859 (define-key map "\t" 'widget-forward) 855 (define-key map "\t" 'widget-forward)
856 (define-key map "\e\t" 'widget-backward)
860 (define-key map [(shift tab)] 'widget-backward) 857 (define-key map [(shift tab)] 'widget-backward)
861 (define-key map [backtab] 'widget-backward) 858 (define-key map [backtab] 'widget-backward)
862 (define-key map [down-mouse-2] 'widget-button-click) 859 (define-key map [down-mouse-2] 'widget-button-click)
863 (define-key map "\C-m" 'widget-button-press) 860 (define-key map "\C-m" 'widget-button-press)
864 map) 861 map)
1204 (let ((overlay (widget-get widget :field-overlay))) 1201 (let ((overlay (widget-get widget :field-overlay)))
1205 ;; Don't subtract one if local-map works at the end of the overlay, 1202 ;; Don't subtract one if local-map works at the end of the overlay,
1206 ;; or if a special `boundary' field has been added after the widget 1203 ;; or if a special `boundary' field has been added after the widget
1207 ;; field. 1204 ;; field.
1208 (if (overlayp overlay) 1205 (if (overlayp overlay)
1209 (if (and (not (eq (with-current-buffer 1206 ;; Don't proceed if overlay has been removed from buffer.
1210 (widget-field-buffer widget) 1207 (when (overlay-buffer overlay)
1211 (save-restriction 1208 (if (and (not (eq (with-current-buffer
1212 ;; `widget-narrow-to-field' can be 1209 (widget-field-buffer widget)
1213 ;; active when this function is called 1210 (save-restriction
1214 ;; from an change-functions hook. So 1211 ;; `widget-narrow-to-field' can be
1215 ;; temporarily remove field narrowing 1212 ;; active when this function is called
1216 ;; before to call `get-char-property'. 1213 ;; from an change-functions hook. So
1217 (widen) 1214 ;; temporarily remove field narrowing
1218 (get-char-property (overlay-end overlay) 1215 ;; before to call `get-char-property'.
1219 'field))) 1216 (widen)
1220 'boundary)) 1217 (get-char-property (overlay-end overlay)
1221 (or widget-field-add-space 1218 'field)))
1222 (null (widget-get widget :size)))) 1219 'boundary))
1223 (1- (overlay-end overlay)) 1220 (or widget-field-add-space
1224 (overlay-end overlay)) 1221 (null (widget-get widget :size))))
1222 (1- (overlay-end overlay))
1223 (overlay-end overlay)))
1225 (cdr overlay)))) 1224 (cdr overlay))))
1226 1225
1227 (defun widget-field-find (pos) 1226 (defun widget-field-find (pos)
1228 "Return the field at POS. 1227 "Return the field at POS.
1229 Unlike (get-char-property POS 'field), this works with empty fields too." 1228 Unlike (get-char-property POS 'field), this works with empty fields too."
1393 :create 'widget-default-create 1392 :create 'widget-default-create
1394 :indent nil 1393 :indent nil
1395 :offset 0 1394 :offset 0
1396 :format-handler 'widget-default-format-handler 1395 :format-handler 'widget-default-format-handler
1397 :button-face-get 'widget-default-button-face-get 1396 :button-face-get 'widget-default-button-face-get
1397 :mouse-face-get 'widget-default-mouse-face-get
1398 :sample-face-get 'widget-default-sample-face-get 1398 :sample-face-get 'widget-default-sample-face-get
1399 :delete 'widget-default-delete 1399 :delete 'widget-default-delete
1400 :copy 'identity 1400 :copy 'identity
1401 :value-set 'widget-default-value-set 1401 :value-set 'widget-default-value-set
1402 :value-inline 'widget-default-value-inline 1402 :value-inline 'widget-default-value-inline
1537 (let ((parent (widget-get widget :parent))) 1537 (let ((parent (widget-get widget :parent)))
1538 (if parent 1538 (if parent
1539 (widget-apply parent :button-face-get) 1539 (widget-apply parent :button-face-get)
1540 widget-button-face)))) 1540 widget-button-face))))
1541 1541
1542 (defun widget-default-mouse-face-get (widget)
1543 ;; Use :mouse-face or widget-mouse-face
1544 (or (widget-get widget :mouse-face)
1545 (let ((parent (widget-get widget :parent)))
1546 (if parent
1547 (widget-apply parent :mouse-face-get)
1548 widget-mouse-face))))
1549
1542 (defun widget-default-sample-face-get (widget) 1550 (defun widget-default-sample-face-get (widget)
1543 ;; Use :sample-face. 1551 ;; Use :sample-face.
1544 (widget-get widget :sample-face)) 1552 (widget-get widget :sample-face))
1545 1553
1546 (defun widget-default-delete (widget) 1554 (defun widget-default-delete (widget)
2163 (widget-toggle-action widget event) 2171 (widget-toggle-action widget event)
2164 (let ((sibling (widget-get-sibling widget))) 2172 (let ((sibling (widget-get-sibling widget)))
2165 (when sibling 2173 (when sibling
2166 (if (widget-value widget) 2174 (if (widget-value widget)
2167 (widget-apply sibling :activate) 2175 (widget-apply sibling :activate)
2168 (widget-apply sibling :deactivate))))) 2176 (widget-apply sibling :deactivate))
2177 (widget-clear-undo))))
2169 2178
2170 ;;; The `checklist' Widget. 2179 ;;; The `checklist' Widget.
2171 2180
2172 (define-widget 'checklist 'default 2181 (define-widget 'checklist 'default
2173 "A multiple choice widget." 2182 "A multiple choice widget."
3026 (error (widget-put widget :error (error-message-string data)) 3035 (error (widget-put widget :error (error-message-string data))
3027 widget))) 3036 widget)))
3028 3037
3029 (define-widget 'file 'string 3038 (define-widget 'file 'string
3030 "A file widget. 3039 "A file widget.
3031 It will read a file name from the minibuffer when invoked." 3040 It reads a file name from an editable text field."
3032 :complete-function 'widget-file-complete 3041 :complete-function 'widget-file-complete
3033 :prompt-value 'widget-file-prompt-value 3042 :prompt-value 'widget-file-prompt-value
3034 :format "%{%t%}: %v" 3043 :format "%{%t%}: %v"
3035 ;; Doesn't work well with terminating newline. 3044 ;; Doesn't work well with terminating newline.
3036 ;; :value-face 'widget-single-line-field 3045 ;; :value-face 'widget-single-line-field
3088 ;;; (widget-apply widget :notify widget event))) 3097 ;;; (widget-apply widget :notify widget event)))
3089 3098
3090 ;; Fixme: use file-name-as-directory. 3099 ;; Fixme: use file-name-as-directory.
3091 (define-widget 'directory 'file 3100 (define-widget 'directory 'file
3092 "A directory widget. 3101 "A directory widget.
3093 It will read a directory name from the minibuffer when invoked." 3102 It reads a directory name from an editable text field."
3094 :tag "Directory") 3103 :tag "Directory")
3095 3104
3096 (defvar widget-symbol-prompt-value-history nil 3105 (defvar widget-symbol-prompt-value-history nil
3097 "History of input to `widget-symbol-prompt-value'.") 3106 "History of input to `widget-symbol-prompt-value'.")
3098 3107
3195 (widget-value widget) 3204 (widget-value widget)
3196 t))) 3205 t)))
3197 (widget-value-set widget answer) 3206 (widget-value-set widget answer)
3198 (widget-apply widget :notify widget event) 3207 (widget-apply widget :notify widget event)
3199 (widget-setup))) 3208 (widget-setup)))
3209
3210 ;;; I'm not sure about what this is good for? KFS.
3211 (defvar widget-key-sequence-prompt-value-history nil
3212 "History of input to `widget-key-sequence-prompt-value'.")
3213
3214 (defvar widget-key-sequence-default-value [ignore]
3215 "Default value for an empty key sequence.")
3216
3217 (defvar widget-key-sequence-map
3218 (let ((map (make-sparse-keymap)))
3219 (set-keymap-parent map widget-field-keymap)
3220 (define-key map [(control ?q)] 'widget-key-sequence-read-event)
3221 map))
3222
3223 (define-widget 'key-sequence 'restricted-sexp
3224 "A key sequence."
3225 :prompt-value 'widget-field-prompt-value
3226 :prompt-internal 'widget-symbol-prompt-internal
3227 ; :prompt-match 'fboundp ;; What was this good for? KFS
3228 :prompt-history 'widget-key-sequence-prompt-value-history
3229 :action 'widget-field-action
3230 :match-alternatives '(stringp vectorp)
3231 :format "%{%t%}: %v"
3232 :validate 'widget-key-sequence-validate
3233 :value-to-internal 'widget-key-sequence-value-to-internal
3234 :value-to-external 'widget-key-sequence-value-to-external
3235 :value widget-key-sequence-default-value
3236 :keymap widget-key-sequence-map
3237 :help-echo "C-q: insert KEY, EVENT, or CODE; RET: enter value"
3238 :tag "Key sequence")
3239
3240 (defun widget-key-sequence-read-event (ev)
3241 (interactive (list
3242 (let ((inhibit-quit t) quit-flag)
3243 (read-event "Insert KEY, EVENT, or CODE: "))))
3244 (let ((ev2 (and (memq 'down (event-modifiers ev))
3245 (read-event)))
3246 (tr (and (keymapp function-key-map)
3247 (lookup-key function-key-map (vector ev)))))
3248 (when (and (integerp ev)
3249 (or (and (<= ?0 ev) (< ev (+ ?0 (min 10 read-quoted-char-radix))))
3250 (and (<= ?a (downcase ev))
3251 (< (downcase ev) (+ ?a -10 (min 36 read-quoted-char-radix))))))
3252 (setq unread-command-events (cons ev unread-command-events)
3253 ev (read-quoted-char (format "Enter code (radix %d)" read-quoted-char-radix))
3254 tr nil)
3255 (if (and (integerp ev) (not (char-valid-p ev)))
3256 (insert (char-to-string ev)))) ;; throw invalid char error
3257 (setq ev (key-description (list ev)))
3258 (when (arrayp tr)
3259 (setq tr (key-description (list (aref tr 0))))
3260 (if (y-or-n-p (format "Key %s is translated to %s -- use %s? " ev tr tr))
3261 (setq ev tr ev2 nil)))
3262 (insert (if (= (char-before) ?\s) "" " ") ev " ")
3263 (if ev2
3264 (insert (key-description (list ev2)) " "))))
3265
3266 (defun widget-key-sequence-validate (widget)
3267 (unless (or (stringp (widget-value widget))
3268 (vectorp (widget-value widget)))
3269 (widget-put widget :error (format "Invalid key sequence: %S"
3270 (widget-value widget)))
3271 widget))
3272
3273 (defun widget-key-sequence-value-to-internal (widget value)
3274 (if (widget-apply widget :match value)
3275 (if (equal value widget-key-sequence-default-value)
3276 ""
3277 (key-description value))
3278 value))
3279
3280 (defun widget-key-sequence-value-to-external (widget value)
3281 (if (stringp value)
3282 (if (string-match "\\`[[:space:]]*\\'" value)
3283 widget-key-sequence-default-value
3284 (read-kbd-macro value))
3285 value))
3286
3200 3287
3201 (define-widget 'sexp 'editable-field 3288 (define-widget 'sexp 'editable-field
3202 "An arbitrary Lisp expression." 3289 "An arbitrary Lisp expression."
3203 :tag "Lisp expression" 3290 :tag "Lisp expression"
3204 :format "%{%t%}: %v" 3291 :format "%{%t%}: %v"
3589 ;;; The `color' Widget. 3676 ;;; The `color' Widget.
3590 3677
3591 ;; Fixme: match 3678 ;; Fixme: match
3592 (define-widget 'color 'editable-field 3679 (define-widget 'color 'editable-field
3593 "Choose a color name (with sample)." 3680 "Choose a color name (with sample)."
3594 :format "%t: %v (%{sample%})\n" 3681 :format "%{%t%}: %v (%{sample%})\n"
3595 :size 10 3682 :size 10
3596 :tag "Color" 3683 :tag "Color"
3597 :value "black" 3684 :value "black"
3598 :complete 'widget-color-complete 3685 :complete 'widget-color-complete
3599 :sample-face-get 'widget-color-sample-face-get 3686 :sample-face-get 'widget-color-sample-face-get