- (let ((at-end
- (and (eq (process-buffer proc) (current-buffer))
- (= (point) (point-max)))))
- (save-excursion
- (set-buffer (process-buffer proc))
+ (save-excursion
+ (set-buffer (process-buffer proc))
+ (let* ((last-insertion (marker-position (process-mark proc)))
+ (delta (- (point) last-insertion))
+ (ie (and comint-last-input-end
+ (marker-position comint-last-input-end)))
+ (w (get-buffer-window (current-buffer)))
+ (ws (and w (window-start w))))
+ (goto-char last-insertion)
+ (insert-before-markers string)
+ (set-marker (process-mark proc) (point))
+ (if ws (set-window-start w ws t))
+ (if ie (set-marker comint-last-input-end ie))
+ (while (progn (skip-chars-backward "^\C-m" last-insertion)
+ (> (point) last-insertion))
+ (delete-region (1- (point)) (point)))