Function: comint-next-prompt

comint-next-prompt is an interactive and byte-compiled function defined in comint.el.gz.

Signature

(comint-next-prompt N)

Documentation

Move to end of Nth next prompt in the buffer.

If comint-use-prompt-regexp is nil, then this means the beginning of the Nth next input field, otherwise, it means the Nth occurrence of text matching comint-prompt-regexp.

View in manual

Key Bindings

Source Code

;; Defined in /usr/src/emacs/lisp/comint.el.gz
(defun comint-next-prompt (n)
  "Move to end of Nth next prompt in the buffer.
If `comint-use-prompt-regexp' is nil, then this means the beginning of
the Nth next `input' field, otherwise, it means the Nth occurrence of
text matching `comint-prompt-regexp'."
  (interactive "p")
  (if comint-use-prompt-regexp
      ;; Use comint-prompt-regexp
      (let ((paragraph-start comint-prompt-regexp))
	(end-of-line (if (> n 0) 1 0))
	(forward-paragraph n)
	(comint-skip-prompt))
    ;; Use input fields
    (let ((pos (point))
	  (input-pos nil)
	  prev-pos)
      (while (/= n 0)
	(setq prev-pos pos)
	(setq pos
	      (if (> n 0)
		  (next-single-char-property-change pos 'field)
		(previous-single-char-property-change pos 'field)))
	(cond ((= pos prev-pos)
	       ;; Ran off the end of the buffer.
	       (when (> n 0)
		 ;; There's always an input field at the end of the
		 ;; buffer, but it has a `field' property of nil.
		 (setq input-pos (point-max)))
	       ;; stop iterating
	       (setq n 0))
	      ((null (get-char-property pos 'field))
	       (setq n (if (< n 0) (1+ n) (1- n)))
	       (setq input-pos pos))))
      (when input-pos
	(goto-char input-pos)))))