changeset 10722:8ba6f9709cff

(next-history-element): Do nothing if n is 0. Handle errors properly when history list is empty.
author Richard M. Stallman <rms@gnu.org>
date Sun, 12 Feb 1995 08:27:38 +0000
parents 3d056c5a8319
children 73bcb70f4790
files lisp/simple.el
diffstat 1 files changed, 20 insertions(+), 16 deletions(-) [+]
line wrap: on
line diff
--- a/lisp/simple.el	Sun Feb 12 04:54:34 1995 +0000
+++ b/lisp/simple.el	Sun Feb 12 08:27:38 1995 +0000
@@ -559,22 +559,26 @@
 (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."