Next: , Previous: Turning the volume down, Up: Common requests

5.26 How do I tell Emacs to automatically indent a new line to the indentation of the previous line?

Such behavior is automatic (in Text mode) in Emacs 20 and later. From the etc/NEWS file for Emacs 20.2:

     ** In Text mode, now only blank lines separate paragraphs.  This makes
     it possible to get the full benefit of Adaptive Fill mode in Text mode,
     and other modes derived from it (such as Mail mode).  <TAB> in Text
     mode now runs the command indent-relative; this makes a practical
     difference only when you use indented paragraphs.
     
     If you want spaces at the beginning of a line to start a paragraph, use
     the new mode, Paragraph Indent Text mode.

If you have auto-fill-mode turned on (see Turning on auto-fill by default), you can tell Emacs to prefix every line with a certain character sequence, the fill prefix. Type the prefix at the beginning of a line, position point after it, and then type C-x . (set-fill-prefix) to set the fill prefix. Thereafter, auto-filling will automatically put the fill prefix at the beginning of new lines, and M-q (fill-paragraph) will maintain any fill prefix when refilling the paragraph.

If you have paragraphs with different levels of indentation, you will have to set the fill prefix to the correct value each time you move to a new paragraph. There are many packages available to deal with this (see Packages that do not come with Emacs). Look for “fill” and “indent” keywords for guidance.