0

When I have a line greater than 80 columns and press enter at the end of the line it breaks the line. So in order to break the line I had to go to end of the long line and press enter.

Instead could it break lines in the buffer before each save, rather than going end of the long line and press enter?

From the auto-fill-mode docs:

When Auto Fill mode is enabled, inserting a space at a column beyond `current-fill-column' automatically breaks the line at a previous space.

I want to apply breaking long lines before each save.I was wondering is it possible to apply auto-fill before each save in the complete buffer?

3
  • You probably mean: "... before each save" - no?
    – NickD
    Aug 2 at 13:48
  • @NickD Ah yes sir fixed in my question , or it could be bind to another keybinding
    – alper
    Aug 2 at 14:22
  • 1
    I think that you might be looking to run fill-paragraph or fill-region instead of auto-fill?
    – Ajned
    Aug 2 at 17:56

1 Answer 1

1

I think this is what you are after; let me know if not.

(defun fill-buffer ()
  "Fill whole buffer"
  (interactive)
  (fill-region (point-min) (point-max)))
(add-hook 'before-save-hook 'fill-buffer)
0

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.