+ (if (and comint-input-ring-index
+ (or ;; leaving the "end" of the ring
+ (and (< arg 0) ; going down
+ (eq comint-input-ring-index 0))
+ (and (> arg 0) ; going up
+ (eq comint-input-ring-index
+ (1- (ring-length comint-input-ring)))))
+ comint-stored-incomplete-input)
+ (comint-restore-input)
+ (comint-previous-matching-input "." arg)))