]> git.eshelyaron.com Git - emacs.git/commitdiff
(next-history-element): Do nothing if n is 0.
authorRichard M. Stallman <rms@gnu.org>
Sun, 12 Feb 1995 08:27:38 +0000 (08:27 +0000)
committerRichard M. Stallman <rms@gnu.org>
Sun, 12 Feb 1995 08:27:38 +0000 (08:27 +0000)
Handle errors properly when history list is empty.

lisp/simple.el

index c958736834f62230a6e28302e47790e14418298b..df5c655b3c92c273ea9f2d9cde59b5f40aefa06c 100644 (file)
@@ -559,22 +559,26 @@ If N is negative, find the previous or Nth previous match."
 (defun next-history-element (n)
   "Insert the next element of the minibuffer history into the minibuffer."
   (interactive "p")
-  (let ((narg (min (max 1 (- minibuffer-history-position n))
-                  (length (symbol-value minibuffer-history-variable)))))
-    (if (= minibuffer-history-position narg)
-       (error (if (= minibuffer-history-position 1)
-                  "End of history; no next item"
-                "Beginning of history; no preceding item"))
-      (erase-buffer)
-      (setq minibuffer-history-position narg)
-      (let ((elt (nth (1- minibuffer-history-position)
-                     (symbol-value minibuffer-history-variable))))
-       (insert
-        (if minibuffer-history-sexp-flag
-            (let ((print-level nil))
-              (prin1-to-string elt))
-          elt)))
-      (goto-char (point-min)))))
+  (or (zerop n)
+      (let ((narg (min (max 1 (- minibuffer-history-position n))
+                      (length (symbol-value minibuffer-history-variable)))))
+           (if (or (zerop narg)
+                   (= minibuffer-history-position narg))
+               (error (if (if (zerop narg)
+                              (> n 0)
+                            (= minibuffer-history-position 1))
+                      "End of history; no next item"
+                    "Beginning of history; no preceding item"))
+         (erase-buffer)
+         (setq minibuffer-history-position narg)
+         (let ((elt (nth (1- minibuffer-history-position)
+                         (symbol-value minibuffer-history-variable))))
+           (insert
+            (if minibuffer-history-sexp-flag
+                (let ((print-level nil))
+                  (prin1-to-string elt))
+              elt)))
+         (goto-char (point-min))))))
 
 (defun previous-history-element (n)
   "Inserts the previous element of the minibuffer history into the minibuffer."