2

I want to be able to fill a whole paragraph with fill-paragraph, first line included, between the left-margin and fill-column values (adaptive-fill-mode is disabled).

I am able to do this, but I noticed that if the first line has an hanging indentation (meaning it has a different indentation from the left-margin variable), I am unable to remove it, unless I manually go to the first line, removing it. I want to be able to remove the hanging indentation by just running fill-paragraph.

Example of hanging indentation, considering left-margin equal to 0:

  this is an example
of an hanging indentation
in a paragraph.

What I want to happen when I run fill-paragraph:

this is an example
of an hanging indentation
in a paragraph.

But I am unable to recreate such a behaviour. The documentation on the topic barely mentions hanging indentations, and is not helpful on how to disable them.

  • Minor nit: That's not a hanging indentation. A hanging indentation is when the first line is not indented, while subsequent lines are. – Harald Hanche-Olsen Sep 2 '16 at 17:47
  • I see, so maybe that is the reason I can't find docs on the topic. Do you know the name of such a behaviour? – Andrea Sep 2 '16 at 18:43
  • Your sample paragraph only has regular indentation. It's not uncommon, after all, to indent the first line of a paragraph, which I assume is why fill-paragraph preserves any indentation it finds in the first line. – Harald Hanche-Olsen Sep 2 '16 at 21:15
1

Since it seems like there is no option to remove them, I created a hack to work around this.

(defun my-fill-paragraph (&optional justify)
  (interactive "P")
  (backward-paragraph)
  (skip-chars-forward " \n\t")
  (indent-to-left-margin)
  (fill-paragraph))

(setq fill-paragraph-function 'my-fill-paragraph)

What this does is moving at the beginning of the paragraph, skip any whitespace and newline and then indent the first line of the paragraph to left-margin. After that, it just runs fill-paragraph normally with the new indentation.

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.