diff -u -r1.425 slime.el
--- slime.el    19 Nov 2004 18:55:39 -0000      1.425
+++ slime.el    24 Nov 2004 06:26:42 -0000
@@ -343,6 +343,11 @@
   :prefix "slime-repl-"
   :group 'slime)
  
+(defcustom slime-repl-wrap-history nil
+  "T to wrap history around when the end is reached."
+  :type 'boolean
+  :group 'slime-repl)
+
 (defcustom slime-repl-shortcut-dispatch-char ?\,
   "Character used to distinguish repl commands from lisp forms."
   :type '(character)
@@ -2813,9 +2818,11 @@
 (defvar slime-repl-history-pattern nil
   "The regexp most recently used for finding input history.")
  
-(defun slime-repl-history-replace (direction regexp)
+(defun slime-repl-history-replace (direction regexp &optional (treat-ends-specially nil))
   "Replace the current input with the next line in DIRECTION matching REGEXP.
-DIRECTION is 'forward' or 'backward' (in the history list)."
+DIRECTION is 'forward' or 'backward' (in the history list).
+If DELETE-AT-END-P is non-nil then remove the string if the end of the history is
+reached."
   (let* ((step (ecase direction
                  (forward -1)
                  (backward 1)))
@@ -2831,7 +2838,19 @@
                  (slime-repl-replace-input string)
                  (setq slime-repl-input-history-position pos)
                  (return)))
-          finally (message "End of history; no matching item"))))
+          finally (if treat-ends-specially
+                      (slime-repl-do-end-of-history direction)
+                    (message "End of history; no matching item")))))
+
+(defun slime-repl-do-end-of-history (direction)
+  (slime-repl-replace-input "")
+  (setq slime-repl-input-history-position
+        (labels ((xor (a b)
+                      (or (and a b)
+                          (and (not a) (not b)))))
+          (if (xor (eq direction 'backward) slime-repl-wrap-history)
+              -1
+            (length slime-repl-input-history)))))
  
 (defun slime-repl-matching-input-regexp ()
   (if (memq last-command
@@ -2841,11 +2860,11 @@
  
 (defun slime-repl-previous-input ()
   (interactive)
-  (slime-repl-history-replace 'backward (slime-repl-matching-input-regexp)))
+  (slime-repl-history-replace 'backward (slime-repl-matching-input-regexp) t))
  
 (defun slime-repl-next-input ()
   (interactive)
-  (slime-repl-history-replace 'forward (slime-repl-matching-input-regexp)))
+  (slime-repl-history-replace 'forward (slime-repl-matching-input-regexp) t))
  
 (defun slime-repl-previous-matching-input (regexp)
   (interactive "sPrevious element matching (regexp): ")
