7

Whenever I open an org file, I have to activate auto-fill-mode and go through every signle line that I need to read and press RET to get a filled paragraph. Is there any way to globally set auto-fill-mode and applied to all the paragraphs in an org file while opening the file?

Best.

3 Answers 3

7

If you want to globally set auto-fill-mode, as you say, the solution would be to put this in your .emacs.s/init.el (or equivalent):

(add-hook 'org-mode-hook 'turn-on-auto-fill)

This means that all files that are viewed in org-mode (usually, files ending in .org) will have auto-fill-mode switched on.

If you do that, you will only use @Tyler's answer once: To format the old paragraphs. After that, auto-fill-mode will keep adding RET as you type. You can use the occasional Meta-Q (fill-paragraph) to refill.

1
  • Can this remove newlines in between TODOs?
    – alper
    Oct 25, 2022 at 11:30
6

If you want a single org file that you share with others to get auto-filled put this as the first line:

# -*- eval: (auto-fill-mode 1) -*-

This will cause auto-fill minor mode to be used when the file is opened. This is part of a feature called 'local file variables'. It is often used to set tab width for code files. Emacs manual page on file variables

1
  • 1
    didn't know you could eval elisp on file load, nice!
    – chris
    May 6, 2020 at 18:35
3

If you want to fill all the lines in a region, use the command M-x fill-region. To mark the entire buffer (so the region includes the entire file), use the command M-x mark-whole-buffer, which is also bound to the keybinding C-x h.

If you only want to temporarily wrap the lines for easier reading, you can use visual-line-mode, combined with visual-fill-column (available as a package on MELPA) to visually wrap the lines without actually adding linebreaks to your file.

2
  • Thanks, I did as you said and I still get line with an right-arrow on the edge of emacs windows which in case of clicking on it will scroll horizontally to the right showing the rest of the line and hiding the begining of the line.
    – nima
    May 23, 2019 at 17:59
  • I want something like the normal emacs buffer which places curved arrows at the end of the line.
    – nima
    May 23, 2019 at 18:02

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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