comparison lisp/cus-edit.el @ 219:262b8bb4a523 r20-4b8

Import from CVS: tag r20-4b8
author cvs
date Mon, 13 Aug 2007 10:09:35 +0200
parents 1f0dabaa0855
children 2c611d1463a6
comparison
equal deleted inserted replaced
218:c9f226976f56 219:262b8bb4a523
181 181
182 (defgroup unix nil 182 (defgroup unix nil
183 "Front-ends/assistants for, or emulators of, UNIX features." 183 "Front-ends/assistants for, or emulators of, UNIX features."
184 :group 'environment) 184 :group 'environment)
185 185
186 (defgroup vms nil
187 "Support code for vms."
188 :group 'environment)
189
190 (defgroup i18n nil 186 (defgroup i18n nil
191 "Internationalization and alternate character-set support." 187 "Internationalization and alternate character-set support."
192 :group 'environment 188 :group 'environment
193 :group 'editing) 189 :group 'editing)
194 190
332 (defgroup processes-basics nil 328 (defgroup processes-basics nil
333 "Basic stuff dealing with processes." 329 "Basic stuff dealing with processes."
334 :group 'processes) 330 :group 'processes)
335 331
336 (defgroup mule nil 332 (defgroup mule nil
337 "MULE Emacs internationalization." 333 "Mule XEmacs internationalization."
338 :group 'i18n) 334 :group 'i18n)
339 335
340 (defgroup windows nil 336 (defgroup windows nil
341 "Windows within a frame." 337 "Windows within a frame."
342 :group 'environment) 338 :group 'environment)
349 (if (or (memq sexp '(t nil)) 345 (if (or (memq sexp '(t nil))
350 (keywordp sexp) 346 (keywordp sexp)
351 (eq (car-safe sexp) 'lambda) 347 (eq (car-safe sexp) 'lambda)
352 (stringp sexp) 348 (stringp sexp)
353 (numberp sexp) 349 (numberp sexp)
354 (characterp sexp)) 350 (characterp sexp)
351 (vectorp sexp)
352 (bit-vector-p sexp))
355 sexp 353 sexp
356 (list 'quote sexp))) 354 (list 'quote sexp)))
357 355
358 (defun custom-split-regexp-maybe (regexp) 356 (defun custom-split-regexp-maybe (regexp)
359 "If REGEXP is a string, split it to a list at `\\|'. 357 "If REGEXP is a string, split it to a list at `\\|'.
422 "Display menu entries as words instead of symbols if non nil." 420 "Display menu entries as words instead of symbols if non nil."
423 :group 'custom-menu 421 :group 'custom-menu
424 :type 'boolean) 422 :type 'boolean)
425 423
426 (defcustom custom-unlispify-remove-prefixes t 424 (defcustom custom-unlispify-remove-prefixes t
427 "Non-nil means remove group prefixes from option names in buffers and menus." 425 "Non-nil means remove group prefixes from option names in buffers and menus.
426 This only has an effect when `custom-unlispify-tag-names' or
427 `custom-unlispify-menu-entries' is on."
428 :group 'custom-menu 428 :group 'custom-menu
429 :type 'boolean) 429 :type 'boolean)
430 430
431 (defun custom-unlispify-menu-entry (symbol &optional no-suffix) 431 (defun custom-unlispify-menu-entry (symbol &optional no-suffix)
432 "Convert symbol into a menu entry." 432 "Convert symbol into a menu entry."
964 964
965 965
966 ;;; Buffer. 966 ;;; Buffer.
967 967
968 (defcustom custom-buffer-style 'links 968 (defcustom custom-buffer-style 'links
969 "Control the presentation style for customization buffers. 969 "*Control the presentation style for customization buffers.
970 The value should be a symbol, one of: 970 The value should be a symbol, one of:
971 971
972 brackets: groups nest within each other with big horizontal brackets. 972 brackets: groups nest within each other with big horizontal brackets.
973 links: groups have links to subgroups." 973 links: groups have links to subgroups."
974 :type '(radio (const :tag "brackets: Groups nest within each others" brackets) 974 :type '(radio (const :tag "brackets: Groups nest within each others" brackets)
975 (const :tag "links: Group have links to subgroups" links)) 975 (const :tag "links: Group have links to subgroups" links))
976 :group 'custom-buffer)
977
978 (defcustom custom-buffer-done-function 'kill-buffer
979 "*Function to be used to remove the buffer when the user is done with it.
980 Choices include `kill-buffer' (the default) and `bury-buffer'.
981 The function will be called with one argument, the buffer to remove."
982 :type '(radio (function-item kill-buffer)
983 (function-item bury-buffer)
984 (function :tag "Other" nil))
976 :group 'custom-buffer) 985 :group 'custom-buffer)
977 986
978 (defcustom custom-buffer-indent 3 987 (defcustom custom-buffer-indent 3
979 "Number of spaces to indent nested groups." 988 "Number of spaces to indent nested groups."
980 :type 'integer 989 :type 'integer
1011 This button will have a menu with all three reset operations." 1020 This button will have a menu with all three reset operations."
1012 :type 'boolean 1021 :type 'boolean
1013 :group 'custom-buffer) 1022 :group 'custom-buffer)
1014 1023
1015 (defconst custom-skip-messages 5) 1024 (defconst custom-skip-messages 5)
1025
1026 (defun Custom-buffer-done ()
1027 "Remove current buffer.
1028 This works by calling the function specified by
1029 `custom-buffer-done-function'."
1030 (interactive)
1031 (funcall custom-buffer-done-function (current-buffer)))
1016 1032
1017 (defun custom-buffer-create-internal (options &optional description) 1033 (defun custom-buffer-create-internal (options &optional description)
1018 (message "Creating customization buffer...") 1034 (message "Creating customization buffer...")
1019 (custom-mode) 1035 (custom-mode)
1020 (widget-insert "This is a customization buffer") 1036 (widget-insert "This is a customization buffer")
1075 :action 'Custom-reset-standard)) 1091 :action 'Custom-reset-standard))
1076 (widget-insert " ") 1092 (widget-insert " ")
1077 (widget-create 'push-button 1093 (widget-create 'push-button
1078 :tag "Done" 1094 :tag "Done"
1079 :tag-glyph '("done-up" "done-down") 1095 :tag-glyph '("done-up" "done-down")
1080 :help-echo "Bury the buffer" 1096 :help-echo "Remove the buffer"
1081 :action (lambda (widget &optional event) 1097 :action (lambda (widget &optional event)
1082 (bury-buffer))) 1098 (Custom-buffer-done)))
1083 (widget-insert "\n\n") 1099 (widget-insert "\n\n")
1084 (message "Creating customization items...") 1100 (message "Creating customization items...")
1085 (setq custom-options 1101 (setq custom-options
1086 (if (= (length options) 1) 1102 (if (= (length options) 1)
1087 (mapcar (lambda (entry) 1103 (mapcar (lambda (entry)
1238 ;; widgets to be hidden. 1254 ;; widgets to be hidden.
1239 1255
1240 (widget-put (get 'item 'widget-type) :custom-show t) 1256 (widget-put (get 'item 'widget-type) :custom-show t)
1241 (widget-put (get 'editable-field 'widget-type) 1257 (widget-put (get 'editable-field 'widget-type)
1242 :custom-show (lambda (widget value) 1258 :custom-show (lambda (widget value)
1243 (let ((pp (pp-to-string value))) 1259 ;; This used to call pp-to-string
1260 (let ((pp (widget-prettyprint-to-string value)))
1244 (cond ((string-match "\n" pp) 1261 (cond ((string-match "\n" pp)
1245 nil) 1262 nil)
1246 ((> (length pp) 40) 1263 ((> (length pp) 40)
1247 nil) 1264 nil)
1248 (t t))))) 1265 (t t)))))
1721 1738
1722 (defface custom-variable-button-face '((t (:underline t :bold t))) 1739 (defface custom-variable-button-face '((t (:underline t :bold t)))
1723 "Face used for pushable variable tags." 1740 "Face used for pushable variable tags."
1724 :group 'custom-faces) 1741 :group 'custom-faces)
1725 1742
1743 (defcustom custom-variable-default-form 'edit
1744 "Default form of displaying variable values."
1745 :type '(choice (const edit)
1746 (const lisp))
1747 :group 'custom-buffer)
1748
1726 (define-widget 'custom-variable 'custom 1749 (define-widget 'custom-variable 'custom
1727 "Customize variable." 1750 "Customize variable."
1728 :format "%v" 1751 :format "%v"
1729 :help-echo "Set or reset this variable" 1752 :help-echo "Set or reset this variable"
1730 :documentation-property 'variable-documentation 1753 :documentation-property 'variable-documentation
1731 :custom-category 'option 1754 :custom-category 'option
1732 :custom-state nil 1755 :custom-state nil
1733 :custom-menu 'custom-variable-menu-create 1756 :custom-menu 'custom-variable-menu-create
1734 :custom-form 'edit 1757 :custom-form nil ; defaults to value of `custom-variable-default-form'
1735 :value-create 'custom-variable-value-create 1758 :value-create 'custom-variable-value-create
1736 :action 'custom-variable-action 1759 :action 'custom-variable-action
1737 :custom-set 'custom-variable-set 1760 :custom-set 'custom-variable-set
1738 :custom-save 'custom-variable-save 1761 :custom-save 'custom-variable-save
1739 :custom-reset-current 'custom-redraw 1762 :custom-reset-current 'custom-redraw
1757 tmp)) 1780 tmp))
1758 1781
1759 (defun custom-variable-value-create (widget) 1782 (defun custom-variable-value-create (widget)
1760 "Here is where you edit the variables value." 1783 "Here is where you edit the variables value."
1761 (custom-load-widget widget) 1784 (custom-load-widget widget)
1785 (unless (widget-get widget :custom-form)
1786 (widget-put widget :custom-form custom-variable-default-form))
1762 (let* ((buttons (widget-get widget :buttons)) 1787 (let* ((buttons (widget-get widget :buttons))
1763 (children (widget-get widget :children)) 1788 (children (widget-get widget :children))
1764 (form (widget-get widget :custom-form)) 1789 (form (widget-get widget :custom-form))
1765 (state (widget-get widget :custom-state)) 1790 (state (widget-get widget :custom-state))
1766 (symbol (widget-get widget :value)) 1791 (symbol (widget-get widget :value))
2158 2183
2159 (defface custom-face-tag-face '((t (:underline t))) 2184 (defface custom-face-tag-face '((t (:underline t)))
2160 "Face used for face tags." 2185 "Face used for face tags."
2161 :group 'custom-faces) 2186 :group 'custom-faces)
2162 2187
2188 (defcustom custom-face-default-form 'selected
2189 "Default form of displaying face definition."
2190 :type '(choice (const all)
2191 (const selected)
2192 (const lisp))
2193 :group 'custom-buffer)
2194
2163 (define-widget 'custom-face 'custom 2195 (define-widget 'custom-face 'custom
2164 "Customize face." 2196 "Customize face."
2165 :sample-face 'custom-face-tag-face 2197 :sample-face 'custom-face-tag-face
2166 :help-echo "Set or reset this face" 2198 :help-echo "Set or reset this face"
2167 :documentation-property '(lambda (face) 2199 :documentation-property '(lambda (face)
2168 (face-doc-string face)) 2200 (face-doc-string face))
2169 :value-create 'custom-face-value-create 2201 :value-create 'custom-face-value-create
2170 :action 'custom-face-action 2202 :action 'custom-face-action
2171 :custom-category 'face 2203 :custom-category 'face
2172 :custom-form 'selected 2204 :custom-form nil ; defaults to value of `custom-face-default-form'
2173 :custom-set 'custom-face-set 2205 :custom-set 'custom-face-set
2174 :custom-save 'custom-face-save 2206 :custom-save 'custom-face-save
2175 :custom-reset-current 'custom-redraw 2207 :custom-reset-current 'custom-redraw
2176 :custom-reset-saved 'custom-face-reset-saved 2208 :custom-reset-saved 'custom-face-reset-saved
2177 :custom-reset-standard 'custom-face-reset-standard 2209 :custom-reset-standard 'custom-face-reset-standard
2270 (unless (eq (preceding-char) ?\n) 2302 (unless (eq (preceding-char) ?\n)
2271 (insert "\n")) 2303 (insert "\n"))
2272 (unless (eq state 'hidden) 2304 (unless (eq state 'hidden)
2273 (message "Creating face editor...") 2305 (message "Creating face editor...")
2274 (custom-load-widget widget) 2306 (custom-load-widget widget)
2307 (unless (widget-get widget :custom-form)
2308 (widget-put widget :custom-form custom-face-default-form))
2275 (let* ((symbol (widget-value widget)) 2309 (let* ((symbol (widget-value widget))
2276 (spec (or (get symbol 'saved-face) 2310 (spec (or (get symbol 'saved-face)
2277 (get symbol 'face-defface-spec) 2311 (get symbol 'face-defface-spec)
2278 ;; Attempt to construct it. 2312 ;; Attempt to construct it.
2279 (list (list t (face-custom-attributes-get 2313 (list (list t (face-custom-attributes-get
2499 options)) 2533 options))
2500 other) 2534 other)
2501 (list other)))) 2535 (list other))))
2502 (widget-put widget :args args) 2536 (widget-put widget :args args)
2503 widget)) 2537 widget))
2538
2539 ;;; The `plist' Widget.
2540
2541 (define-widget 'plist 'list
2542 "A property list."
2543 :match (lambda (widget value)
2544 (valid-plist-p value))
2545 :convert-widget 'custom-plist-convert-widget
2546 :tag "Property List")
2547
2548 ;; #### Should handle options better.
2549 (defun custom-plist-convert-widget (widget)
2550 (let* ((options (widget-get widget :options))
2551 (other `(editable-list :inline t
2552 (group :inline t
2553 (symbol :format "%t: %v "
2554 :size 10
2555 :tag "Property")
2556 (sexp :tag "Value"))))
2557 (args
2558 (if options
2559 `((checklist :inline t
2560 ,@(mapcar 'custom-plist-process-option options))
2561 ,other)
2562 (list other))))
2563 (widget-put widget :args args)
2564 widget))
2565
2566 (defun custom-plist-process-option (entry)
2567 `(group :inline t
2568 (const :tag "Property"
2569 :format "%t: %v "
2570 :size 10
2571 ,entry)
2572 (sexp :tag "Value")))
2504 2573
2505 ;;; The `custom-group-link' Widget. 2574 ;;; The `custom-group-link' Widget.
2506 2575
2507 (define-widget 'custom-group-link 'link 2576 (define-widget 'custom-group-link 'link
2508 "Show parent in other window when activated." 2577 "Show parent in other window when activated."
3141 (unless custom-mode-map 3210 (unless custom-mode-map
3142 (setq custom-mode-map (make-sparse-keymap)) 3211 (setq custom-mode-map (make-sparse-keymap))
3143 (set-keymap-parents custom-mode-map widget-keymap) 3212 (set-keymap-parents custom-mode-map widget-keymap)
3144 (suppress-keymap custom-mode-map) 3213 (suppress-keymap custom-mode-map)
3145 (define-key custom-mode-map " " 'scroll-up) 3214 (define-key custom-mode-map " " 'scroll-up)
3146 (define-key custom-mode-map "\177" 'scroll-down) 3215 (define-key custom-mode-map [delete] 'scroll-down)
3147 (define-key custom-mode-map "q" 'bury-buffer) 3216 (define-key custom-mode-map "q" 'Custom-buffer-done)
3148 (define-key custom-mode-map "u" 'Custom-goto-parent) 3217 (define-key custom-mode-map "u" 'Custom-goto-parent)
3149 (define-key custom-mode-map "n" 'widget-forward) 3218 (define-key custom-mode-map "n" 'widget-forward)
3150 (define-key custom-mode-map "p" 'widget-backward) 3219 (define-key custom-mode-map "p" 'widget-backward))
3151 ;; (define-key custom-mode-map [mouse-1] 'Custom-move-and-invoke)
3152 )
3153
3154 (defun Custom-move-and-invoke (event)
3155 "Move to where you click, and if it is an active field, invoke it."
3156 (interactive "e")
3157 (mouse-set-point event)
3158 (if (widget-event-point event)
3159 (let* ((pos (widget-event-point event))
3160 (button (get-char-property pos 'button)))
3161 (if button
3162 (widget-button-click event)))))
3163 3220
3164 (easy-menu-define Custom-mode-menu 3221 (easy-menu-define Custom-mode-menu
3165 custom-mode-map 3222 custom-mode-map
3166 "Menu used in customization buffers." 3223 "Menu used in customization buffers."
3167 `("Custom" 3224 `("Custom"
3202 Move to next button or editable field. \\[widget-forward] 3259 Move to next button or editable field. \\[widget-forward]
3203 Move to previous button or editable field. \\[widget-backward] 3260 Move to previous button or editable field. \\[widget-backward]
3204 \\<widget-field-keymap>\ 3261 \\<widget-field-keymap>\
3205 Complete content of editable text field. \\[widget-complete] 3262 Complete content of editable text field. \\[widget-complete]
3206 \\<custom-mode-map>\ 3263 \\<custom-mode-map>\
3207 Invoke button under the mouse pointer. \\[Custom-move-and-invoke]
3208 Invoke button under point. \\[widget-button-press] 3264 Invoke button under point. \\[widget-button-press]
3209 Set all modifications. \\[Custom-set] 3265 Set all modifications. \\[Custom-set]
3210 Make all modifications default. \\[Custom-save] 3266 Make all modifications default. \\[Custom-save]
3211 Reset all modified options. \\[Custom-reset-current] 3267 Reset all modified options. \\[Custom-reset-current]
3212 Reset all modified or set options. \\[Custom-reset-saved] 3268 Reset all modified or set options. \\[Custom-reset-saved]