0

Out-of-the-box Emacs (28.2, in case it matters) will use a "continuation mode" for text files. Long lines within a paragraph wrap around at the end of the frame.

emacs text-mode text wraps around

Out-of-the-box Org-mode will expect either scrolling...

org-mode expects scrolling

... or else the use of fill-paragraph.

org-mode with fill-paragraph

For text-heavy documents that I'm repeatedly editing, I prefer not to continuously fill-paragraph. In these cases I prefer to edit using the full frame width for my monitor.

How can I avoid fill-paragraph in org-mode?

Related

  1. This question has been asked before.

I can indeed set in my .emacs either

(setq 'truncate-lines nil)

or

(setq 'truncate-lines t)

but the latter does not do what I describe above. Ideally I'd isolate this in a hook for just org-mode, but first I need to understand why truncate-lines doesn't do what it's supposed to do.

  1. This one-line will do the trick, at the price of inserting it in each file.
  2. Make visual-line-mode more compatible with org-mode.
2
  • Do not quote the symbol: (setq truncate-lines nil). From 2. it follows that if you add this setting to org-mode-hook, you should be golden - no? After all, that's basically what the one-line trick does.
    – NickD
    Feb 21, 2023 at 21:19
  • @NickD Not sure. Even if it's possible to (implicitly) insert # -*- truncate-lines: nil -*- using a hook, that would still be a tad unclean.
    – Sam7919
    Feb 21, 2023 at 22:32

3 Answers 3

2

While the answer by NickD does exactly what is asked, I'd recommend enabling visual-line-mode instead:

(add-hook 'org-mode-hook 'visual-line-mode)

This also sets (setq truncate-lines nil), but in addition redefines some editing commands to act on visual lines instead of logical lines (kill-line, move-beginning-of-line, move-end-of-line), turns on word-wrap, ensures line-move-visual is t, changes fringe indicators to visual-line-fringe-indicators (default: none), and makes a few other adjustments which make the user experience nicer when lines are wrapped.

Result of using (add-hook 'org-mode-hook 'visual-line-mode)

2
  • 1
    I'm not sure what you mean by "redefines editing commands to act on visual lines instead of logical lines". Both settings make up/down cursor movement act on visual lines. Regardless, this feels like the right solution. I went ahead and added a picture to spare everyone having to try it. I hope you don't mind.
    – Sam7919
    Feb 22, 2023 at 14:44
  • 1
    Thanks. I made a further edit to clarify.
    – orgtre
    Feb 22, 2023 at 16:43
1

Make truncate-lines to be nil in Org mode buffers by adding the setting (corrected by deleting the quote, which would cause errors otherwise):

(add-hook 'org-mode-hook (lambda () (setq truncate-lines nil)))

That will cause truncate-lines to be buffer-local and have the value nil in all Org mode buffers.

0

Ideally I'd isolate this in a hook for just org-mode, but first I need to understand why truncate-lines doesn't do what it's supposed to do.

You need to be using setq-default in your .emacs, like this

(setq-default truncate-lines nil)

Also, one of the suggestions that helped me the most when i was learning emacs (from either the org-mode manual or the emacs manual) was to just entirely replace how i was manually ending my lines with RET with M-q. Every time I would reach over to end a line, instead I would M-q. Then the only time you are reaching to hit RET is when you want to insert an empty line (unless you remember that C-j C-n exists).

If you want to make fill-paragraph more useful on your wide screen you can do

(setq fill-column 240)

for 3x the width (the default value is 80). I wouldn't recommend using this for all buffers, so instead of setq-default you probably want to add that to your org-mode hook, like this

(defun my-org-mode-hook ()
  "My custom hook for org-mode."
  (setq fill-column 240))

(add-hook 'org-mode-hook 'my-org-mode-hook)

Remember you can modify any of the values, so if 240 is too wide try something else. You can also put other org specific settings in there as well (and you should! It's best to keep related customizations together).

2
  • Do not quote the symbol in setq: (setq fill-column 240). If you try to evaluate the form you give above, you get an error: (setq 'fill-column 240) ==> Lisp error: (wrong-type-argument symbolp 'fill-column). Ditto for setq-default.
    – NickD
    Feb 21, 2023 at 21:17
  • Absolutely correct, and its even in the name "setQ" for "set (quoted)". I feel rather silly, but thanks. Feb 21, 2023 at 21:28

Your Answer

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

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