(comint-get-next-from-history): New command.
(comint-accumulate, comint-goto-process-mark): Likewise.
(comint-set-process-mark, comint-bol-or-process-mark): Likewise.
(comint-save-input-ring-index): New permanent local var.
(comint-accum-marker): Likewise.
(comint-send-input): Clear comint-input-ring-index
and comint-accum-marker.
(comint-previous-matching-input-from-input):
Use comint-accum-marker if set.
(comint-previous-matching-input): Likewise.
(comint-mode): Make those vars buffer-local and initialize.
(comint-mode-map): Make C-c C-a run comint-bol-or-process-mark.
Bind C-c SPC to comint-accumulate. Bind C-c C-q to
comint-get-next-from-history.