]> code.delx.au - gnu-emacs/blobdiff - lisp/wid-edit.el
(choose-completion-string): Use `minibufferp';
[gnu-emacs] / lisp / wid-edit.el
index 58cdab487f835224b391f5c666889e0ffc1c3869..ff65fb56e599bd4bb93ae0c9b4d9a458ab3f6151 100644 (file)
@@ -1,6 +1,6 @@
 ;;; 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
@@ -63,9 +63,6 @@
   "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)
@@ -236,8 +233,7 @@ minibuffer."
           ;; 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
@@ -271,7 +267,7 @@ minibuffer."
                 (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)
@@ -304,7 +300,8 @@ minibuffer."
 ;;
 ;; 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.")
@@ -417,16 +414,10 @@ new value.")
   "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))
@@ -568,9 +559,8 @@ The arguments MAPARG, and BUFFER default to nil and (current-buffer),
 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))
@@ -1002,19 +992,19 @@ This is much faster, but doesn't work reliably on Emacs 19.34.")
   "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)))
@@ -1025,12 +1015,13 @@ ARG may be negative to move backward."
     ;; 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)))
@@ -1102,12 +1093,12 @@ When not inside a field, move to the previous button or field."
 
 ;;; 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)
@@ -1673,7 +1664,7 @@ If END is omitted, it defaults to the length of LIST."
 
 (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.
 
@@ -2484,7 +2475,7 @@ Return an alist of (TYPE MATCH)."
 
 (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)))
@@ -2493,7 +2484,7 @@ Return an alist of (TYPE MATCH)."
                  (widget-get widget :append-button-args)))
          (t
           (widget-default-format-handler widget escape)))
-;;;     )
+    ;; )
   )
 
 (defun widget-editable-list-value-create (widget)
@@ -2594,7 +2585,7 @@ Return an alist of (TYPE MATCH)."
 (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
@@ -2623,18 +2614,18 @@ Return an alist of (TYPE MATCH)."
                               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.
@@ -3193,12 +3184,19 @@ To use this type, you must define :match or :match-alternatives."
   :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"
@@ -3244,7 +3242,7 @@ To use this type, you must define :match or :match-alternatives."
   :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)
@@ -3467,12 +3465,6 @@ To use this type, you must define :match or :match-alternatives."
         (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)