TransWikia.com

How to wrap lines at window edge

Emacs Asked by lambda-pumpkin on September 2, 2021

My default line wrapping is ‘truncate long lines’.

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

2 Answers

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 !

Answered by lambda-pumpkin on September 2, 2021

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.

Answered by NickD on September 2, 2021

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP