I'm using Emacs to write ocaml programs, and the automatic indentation works fine : suppose I write if in the middle of a line, then skip a line and write then ; the keyword then is automatically aligned with my if.

But if I later decide to add some code before the if, and the position of the if thus changes, then remains aligned with the previous position of the if until I manually add (and immediately remove) a lineskip on the line that has my then so that the indentation is recalculated.

Is there a way to ask Emacs to reindent all lines in my document without having to add-and-remove lineskips everywhere to force Emacs to recalculate the correct indentation line by line?

  • I had never heard the word` lineskip` used in this way. Usually we call it "newline" or "LF".
    – Stefan
    Nov 9 '18 at 14:00
  • 1
    Have you tried the indent-buffer interactive function (M-x indent-buffer)? indent-region may also be useful.
    – ebpa
    Nov 9 '18 at 14:01

Normally, the TAB key (indent-for-tab-command) reindents the current line and C-M-\ (indent-region) reindents the region.


For a completely automated solution use the package aggressive-indent.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.