GNU Emacs

38.4 Shell Prompts

A prompt is text output by a program to show that it is ready to accept new user input. Normally, Comint mode (and thus Shell mode) automatically figures out which part of the buffer is a prompt, based on the output of the subprocess. (Specifically, it assumes that any received output line which doesn’t end with a newline is a prompt.)

Comint mode divides the buffer into two types of fields: input fields (where user input is typed) and output fields (everywhere else). Prompts are part of the output fields. Most Emacs motion commands do not cross field boundaries, unless they move over multiple lines. For instance, when point is in the input field on a shell command line, C-a puts point at the beginning of the input field, after the prompt. Internally, the fields are implemented using the field text property (see Text Properties in the Emacs Lisp Reference Manual).

If you change the variable comint-use-prompt-regexp to a non- nil value, then Comint mode will recognize prompts using a regular expression (see Syntax of Regular Expressions). In Shell mode, the regular expression is specified by the variable shell-prompt-pattern. The default value of comint-use-prompt-regexp is nil, because this method for recognizing prompts is unreliable, but you may want to set it to a non- nil value in unusual circumstances. In that case, Emacs does not divide the Comint buffer into fields, so the general motion commands behave as they normally do in buffers without special text properties. However, you can use the paragraph motion commands to conveniently navigate the buffer (see Paragraphs); in Shell mode, Emacs uses shell-prompt-pattern as paragraph boundaries.