]> code.delx.au - gnu-emacs/blobdiff - lisp/subr.el
(read-number): New function.
[gnu-emacs] / lisp / subr.el
index 641d81a6fb612f5d5a3bd90da46d6fccdd28fb2c..2c39a8447cf4090ee1b4b601d53122a4e135fb10 100644 (file)
@@ -1,6 +1,6 @@
 ;;; subr.el --- basic lisp subroutines for Emacs
 
-;; Copyright (C) 1985, 86, 92, 94, 95, 99, 2000, 2001, 2002, 2003
+;; Copyright (C) 1985, 86, 92, 94, 95, 99, 2000, 2001, 2002, 03, 2004
 ;;   Free Software Foundation, Inc.
 
 ;; Maintainer: FSF
@@ -210,18 +210,14 @@ If N is bigger than the length of X, return X."
           x))))
 
 (defun delete-dups (list)
-  "Destructively return LIST, with `equal' duplicates removed.
-LIST must be a proper list.  The value of LIST after a call to
-this function is undefined.  Use \(setq LIST (delete-dups LIST))
-if you want to store the return value in LIST.  Of several
-`equal' occurrences of an element in LIST, the last one is kept."
-  (while (member (car list) (cdr list))
-    (pop list))
+  "Destructively remove `equal' duplicates from LIST.
+Store the result in LIST and return it.  LIST must be a proper list.
+Of several `equal' occurrences of an element in LIST, the first
+one is kept."
   (let ((tail list))
     (while tail
-      (while (member (cadr tail) (cddr tail))
-       (setcdr tail (cddr tail)))
-      (pop tail)))
+      (setcdr tail (delete (car tail) (cdr tail)))
+      (setq tail (cdr tail))))
   list)
 
 (defun number-sequence (from &optional to inc)
@@ -1311,6 +1307,27 @@ Optional DEFAULT is a default password to use instead of empty input."
                  (setq pass new-pass))))))
       (message nil)
       (or pass default ""))))
+
+;; This should be used by `call-interactively' for `n' specs.
+(defun read-number (prompt &optional default)
+  (let ((n nil))
+    (when default
+      (setq prompt
+           (if (string-match "\\(\\):[^:]*" prompt)
+               (replace-match (format " [%s]" default) t t prompt 1)
+             (concat prompt (format " [%s] " default)))))
+    (while
+       (progn
+         (let ((str (read-from-minibuffer prompt nil nil nil nil
+                                          (number-to-string default))))
+           (setq n (cond
+                    ((zerop (length str)) default)
+                    ((stringp str) (read str)))))
+         (unless (numberp n)
+           (message "Please enter a number.")
+           (sit-for 1)
+           t)))
+    n))
 \f
 ;;; Atomic change groups.