1

My default line wrapping is 'truncate long lines'.

How can I change it to 'wrap line at window edge' ?

rpluim
  • 4,605
  • 8
  • 22
  • What have you tried? Where have you looked? – Stefan Jun 19 '20 at 03:22
  • The `truncate-lines` answer below is correct, but offers no additional bells/whistles. You may also be interested in `visual-line-mode`, which sets the variable of `truncate-lines` and does some other things as well: https://www.gnu.org/software/emacs/manual/html_node/emacs/Visual-Line-Mode.html – lawlist Jun 19 '20 at 04:54

2 Answers2

3

Are you sure that the default is to truncate long lines? This is controlled by the value of the variable truncate-lines whose default is nil. So by default any buffer that does not modify that value should be wrapped at window edge.

Check with C-h v truncate-lines RET to see what the default value is. Here for example is what I get in a c-mode buffer:

truncate-lines is a variable defined in ‘src/buffer.c’.
Its value is t
Original value was nil
Local in buffer foo; global value is nil

I suspect that you will find that the global value is nil in your case too.

The trouble is that a lot of modes do turn truncate-lines on, so AFAIK you have to play whack-a-mole with each mode whose behavior you want to change. E.g. for fundamental mode or text mode, you shouldn't have to do anything. But for org mode, c mode, python mode and many others, the mode function explicitly changes the default value of truncate-lines to t.

Maybe there is a better way, but the standard way of undoing this is to add a function to the mode hook that will undo the change. E.g. for python mode, you have to do this:

(add-hook 'python-mode-hook #'toggle-truncate-lines)

and you have to do that for each mode that turns truncate-lines on and you want it off.

That said, there are some good reasons to keep things as they are: e.g. for program files, you often keep them under source control and you use ediff to compare different versions: truncate-lines makes those diffs easier to read. Also, if you have lines that wrap, ask yourself why: text (ordinary as well as program text) is easier to read if you can take it in at a glance without having to move your eyes (or worse, your whole head) in order to get the whole expanse in: using shorter lines makes the truncate-lines setting moot.

See also the emacs documentation on truncate-lines, in particular this last bit:

If a split window becomes too narrow, Emacs may automatically enable line truncation. *Note Split Window::, for the variable ‘truncate-partial-width-windows’ which controls this.

You might find that leaving truncate-lines alone makes sense; and in the rare cases where it does not, use the menu to change it: click Options/Line Wrapping in This Buffer/Wrap at Window Edge. That will set it for the current buffer.

phils
  • 48,657
  • 3
  • 76
  • 115
NickD
  • 27,023
  • 3
  • 23
  • 42
0

Thank you for your answer. My global setting is as follows:

(custom-set-variables '(truncate-lines nil))

And in my org-mode truncate-lines as follows:

truncate-lines is a variable defined in ‘C source code’. Its value is t Original value was nil

As you suggested I've added the following then it worked.

(add-hook 'org-mode-hook #'toggle-truncate-lines) truncate-lines is a variable defined in ‘C source code’. Its value is t Original value was nil

Thank you !

  • 1
    See [What should I do when someone answers my question?](https://emacs.stackexchange.com/help/someone-answers). – NickD Jun 20 '20 at 04:36