;;; wid-edit.el --- Functions for creating and using widgets -*-byte-compile-dynamic: t;-*-
;;
-;; Copyright (C) 1996, 1997, 1999, 2000, 2001, 2002 Free Software Foundation, Inc.
+;; Copyright (C) 1996,97,1999,2000,01,02,2003 Free Software Foundation, Inc.
;;
;; Author: Per Abrahamsen <abraham@dina.kvl.dk>
;; Maintainer: FSF
"Character position of the end of event if that exists, or nil."
(posn-point (event-end event)))
-(autoload 'pp-to-string "pp")
-(autoload 'Info-goto-node "info")
-
(defun widget-button-release-event-p (event)
"Non-nil if EVENT is a mouse-button-release event object."
(and (eventp event)
;; Define SPC as a prefix char to get to this menu.
(define-key overriding-terminal-local-map " "
(setq map (make-sparse-keymap title)))
- (save-excursion
- (set-buffer (get-buffer-create " widget-choose"))
+ (with-current-buffer (get-buffer-create " widget-choose")
(erase-buffer)
(insert "Available choices:\n\n")
(while items
(while (not (or (and (>= char ?0) (< char next-digit))
(eq value 'keyboard-quit)))
;; Unread a SPC to lead to our new menu.
- (setq unread-command-events (cons ?\ unread-command-events))
+ (setq unread-command-events (cons ?\ unread-command-events))
(setq keys (read-key-sequence title))
(setq value
(lookup-key overriding-terminal-local-map keys t)
;;
;; These functions are for specifying text properties.
-(defvar widget-field-add-space t
+;; We can set it to nil now that get_local_map uses get_pos_property.
+(defconst widget-field-add-space nil
"Non-nil means add extra space at the end of editable text fields.
If you don't add the space, it will become impossible to edit a zero
size field.")
"Execute FORM without inheriting any text properties."
`(save-restriction
(let ((inhibit-read-only t)
- (inhibit-modification-hooks t)
- result)
- (insert "<>")
- (narrow-to-region (- (point) 2) (point))
- (goto-char (1+ (point-min)))
- (setq result (progn ,@form))
- (delete-region (point-min) (1+ (point-min)))
- (delete-region (1- (point-max)) (point-max))
- (goto-char (point-max))
- result)))
+ (inhibit-modification-hooks t))
+ (narrow-to-region (point) (point))
+ (prog1 (progn ,@form)
+ (goto-char (point-max))))))
(defface widget-inactive-face '((((class grayscale color)
(background dark))
respectively."
(let ((cur (point-min))
(widget nil)
- (parent nil)
(overlays (if buffer
- (save-excursion (set-buffer buffer) (overlay-lists))
+ (with-current-buffer buffer (overlay-lists))
(overlay-lists))))
(setq overlays (append (car overlays) (cdr overlays)))
(while (setq cur (pop overlays))
"Move point to the ARG next field or button.
ARG may be negative to move backward."
(or (bobp) (> arg 0) (backward-char))
- (let ((pos (point))
+ (let ((wrapped 0)
(number arg)
- (old (widget-tabable-at))
- new)
+ (old (widget-tabable-at)))
;; Forward.
(while (> arg 0)
(cond ((eobp)
- (goto-char (point-min)))
+ (goto-char (point-min))
+ (setq wrapped (1+ wrapped)))
(widget-use-overlay-change
(goto-char (next-overlay-change (point))))
(t
(forward-char 1)))
- (and (eq pos (point))
+ (and (= wrapped 2)
(eq arg number)
(error "No buttons or fields found"))
(let ((new (widget-tabable-at)))
;; Backward.
(while (< arg 0)
(cond ((bobp)
- (goto-char (point-max)))
+ (goto-char (point-max))
+ (setq wrapped (1+ wrapped)))
(widget-use-overlay-change
(goto-char (previous-overlay-change (point))))
(t
(backward-char 1)))
- (and (eq pos (point))
+ (and (= wrapped 2)
(eq arg number)
(error "No buttons or fields found"))
(let ((new (widget-tabable-at)))
;;; Setting up the buffer.
-(defvar widget-field-new nil)
-;; List of all newly created editable fields in the buffer.
+(defvar widget-field-new nil
+ "List of all newly created editable fields in the buffer.")
(make-variable-buffer-local 'widget-field-new)
-(defvar widget-field-list nil)
-;; List of all editable fields in the buffer.
+(defvar widget-field-list nil
+ "List of all editable fields in the buffer.")
(make-variable-buffer-local 'widget-field-list)
(defun widget-at (&optional pos)
(defun widget-info-link-action (widget &optional event)
"Open the info node specified by WIDGET."
- (Info-goto-node (widget-value widget)))
+ (info (widget-value widget)))
;;; The `url-link' Widget.
(defun widget-editable-list-format-handler (widget escape)
;; We recognize the insert button.
-;;; (let ((widget-push-button-gui widget-editable-list-gui))
+ ;; (let ((widget-push-button-gui widget-editable-list-gui))
(cond ((eq escape ?i)
(and (widget-get widget :indent)
(insert-char ?\ (widget-get widget :indent)))
(widget-get widget :append-button-args)))
(t
(widget-default-format-handler widget escape)))
-;;; )
+ ;; )
)
(defun widget-editable-list-value-create (widget)
(defun widget-editable-list-entry-create (widget value conv)
;; Create a new entry to the list.
(let ((type (nth 0 (widget-get widget :args)))
-;;; (widget-push-button-gui widget-editable-list-gui)
+ ;; (widget-push-button-gui widget-editable-list-gui)
child delete insert)
(widget-specify-insert
(save-excursion
widget type (widget-default-get type)))))
(t
(error "Unknown escape `%c'" escape)))))
- (widget-put widget
- :buttons (cons delete
- (cons insert
- (widget-get widget :buttons))))
+ (let ((buttons (widget-get widget :buttons)))
+ (if insert (push insert buttons))
+ (if delete (push delete buttons))
+ (widget-put widget :buttons buttons))
(let ((entry-from (point-min-marker))
(entry-to (point-max-marker)))
(set-marker-insertion-type entry-from t)
(set-marker-insertion-type entry-to nil)
(widget-put child :entry-from entry-from)
(widget-put child :entry-to entry-to)))
- (widget-put insert :widget child)
- (widget-put delete :widget child)
+ (if insert (widget-put insert :widget child))
+ (if delete (widget-put delete :widget child))
child))
;;; The `group' Widget.
:match-alternatives '(integerp))
(define-widget 'number 'restricted-sexp
- "A floating point number."
+ "A number (floating point or integer)."
:tag "Number"
:value 0.0
- :type-error "This field should contain a number"
+ :type-error "This field should contain a number (floating point or integer)"
:match-alternatives '(numberp))
+(define-widget 'float 'restricted-sexp
+ "A floating point number."
+ :tag "Floating point number"
+ :value 0.0
+ :type-error "This field should contain a floating point number"
+ :match-alternatives '(floatp))
+
(define-widget 'character 'editable-field
"A character."
:tag "Character"
:value-to-internal (lambda (widget value)
(list (car value) (cdr value)))
:value-to-external (lambda (widget value)
- (cons (nth 0 value) (nth 1 value))))
+ (apply 'cons value)))
(defun widget-cons-match (widget value)
(and (consp value)
(prompt (concat tag ": "))
(value (widget-value widget))
(start (widget-field-start widget))
- (pos (cond ((< (point) start)
- 0)
- ((> (point) (+ start (length value)))
- (length value))
- (t
- (- (point) start))))
(answer (facemenu-read-color prompt)))
(unless (zerop (length answer))
(widget-value-set widget answer)