7

Almost every text editor is able to truncate lines by default, but in Emacs I'm still using the cumbersome M-x toggle-truncate-lines in every buffer with long lines. Unfortunately, buffers with long lines are very common, so one has to do M-x toggle-truncate-lines constantly.

Solutions currently posted on StackOverflow do not work (e.g., link):

  • (setq-default truncate-lines t) in init.el does not have any effect.
  • (custom-set-variables '(truncate-lines t)) in init.el does not have any effect.
  • (global-set-key "\C-x\ w" 'toggle-truncate-lines) does not really solve the problem.

I must be overlooking something here; what's the actual setting for truncating long lines by default?

1
  • The answer given so far is correct, but solves it the issue? Aug 5, 2019 at 7:08

2 Answers 2

8

truncate-lines possibly overridden

The built-in help for truncate-lines mention that it is overridden by the variable truncate-partial-width-windows. You might want to check if it is set by using <C-h> v and typing truncate-partial-width-windows.

Relevant portion of built-in help for truncate-lines

...
Note that this is overridden by the variable
`truncate-partial-width-windows' if that variable is non-nil
and this buffer is not full-frame width.
...
2
  • (global-visual-line-mode) works as expected. stackoverflow.com/questions/950340/…
    – Jiacai Liu
    Feb 8, 2020 at 1:18
  • @JiacaiLiu, it does, if you expect something else than scrolling, which is what the OP is actually after (referring to the default behavior of "almost every text editor" :) ). "Truncating lines" and its relation to horizontal scrolling seems to be yet another arcane emacs (mis)feature to turn a common and trivial thing into something properly confusing and frustrating. ;)
    – Sz.
    Aug 24, 2023 at 22:54
0

You might be looking for the nil value of truncate-lines.

If you want the line to wrap around, producing this:

emacs wrapping

Then you want (setq truncate-lines nil).

(Based on your "almost every editor" comment, this was probably your desired behaviour. It's confusing in Emacs because M-x toggle-truncate-lines toggles the state, and doesn't clarify which state is considered 'truncated'.)

1
  • I honestly can't imagine confusion over which state is "truncated".
    – phils
    Dec 5, 2023 at 2:13

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.