2

Whenever I open up an .org file in spacemacs, the truncate-lines variable is set to t.

How can I make truncate-lines be set to nil by default in org-mode in the org-layer for spacemacs?

I would like lines to be wrapped in org-mode when they are about to go over the edge of the screen.


I've read different things online that talk about how to fix this problem.

One suggestion is to set the org-startup-truncated variable to nil in dotspacemacs/user-config.

I've tried doing that like this:

(defun dotspacemacs/user-config ()
  (setq org-startup-truncated nil))

However, that doesn't appear to work. When I open up a .org file, truncate-lines is still set to t.

I've also tried adding a hook to org mode to to call spacemacs/toggle-truncate-lines-off automatically:

(defun dotspacemacs/user-config ()
  (add-hook 'org-mode-hook 'spacemacs/toggle-truncate-lines-off))

This also doesn't appear to work. When I open up a .org file, truncate-lines is still set to t.

However, after opening a .org file, I am able to manually run the spacemacs/toggle-truncate-lines-off in order to set truncate-lines to nil.

Just in case, here is my .spacemacs file. You can see my multiple attempts at setting truncate-lines.

illabout
  • 285
  • 2
  • 14

2 Answers2

3

The short answer (not so good) for turning off truncate-line is:

(add-hook 'org-mode-hook #'spacemacs/toggle-truncate-lines-off)

But if what you want is line wrap in org mode. This is not a good solution because:

  1. truncate-line starts the new line at the beginning of the window, but not the beginning of the previous line.
  2. It also adds small arrows on both side of window edge which is annoy in my experience.
  3. The j and k doesn't work for continued lines, even worse, in Spacemacs' org mode gj and gk are mapped to headline forward/backward.

A better solution is to use visual line mode with word wrap disabled. Visual line mode solves all above problems, but it enables word-wrap. Disabling word wrap makes it behaves more like truncate-line. Here's an example:

(defun org-line-wrap ()
  (spacemacs/toggle-visual-line-navigation-on)
  (setq-local word-wrap nil))

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

BTW if you're confuse for something, you can use C-h v to check variable documentation.

darkbaby123
  • 131
  • 4
-1

use

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

or replace truncate-lines with another wrap style.

Stefan
  • 26,154
  • 3
  • 46
  • 84
kuli
  • 31
  • 1
  • 1
    Hooks take symbols rather than expressions, so your `add-hook` won't work. OP also asked for spacemacs-specific suggestions. – Dan Oct 17 '17 at 12:57