4

I've been using emacs for a long time but still have little understanding of elisp; I basically copy code I find on websites into my .emacs until it seems to do what I want.

I only recently discovered global-visual-line-mode (I had been using auto-fill), and now see based on this other answer and this one at stackoverflow that I also want adaptive-wrap-prefix-mode. It works great when I turn it on manually, but when I blindly add the code provided in the former answer to my .emacs, I get

File error: Cannot open load file, no such file or directory, adaptive-wrap

while blindly adding the code from the latter answer loads fine, but does not actually succeed in turning on adaptive-wrap-mode. I've played with variations and I'm sure the solution is simple, but I just don't see it. How do I just get it to turn on both global-visual-line-mode and adaptive-wrap-prefix-mode by default?

I would be happy if I could get them both running just for my markdown files.

Thanks in advance!

1 Answers1

3

You need to add

(package-initialize t)

at the beginning of your ~/emacs. IIRC Emacs-25 will tend to do that for you, but it's even better to do it manually.

The problem is simply that adaptive-wrap-mode is not defined until the ELPA packages have been initialized. If your ~/.emacs file doesn't initialize the ELPA packages with package-initialize, Emacs does it for you, but it can only notice it after your ~/.emacs is loaded, so the functions defined by the ELPA packages won't be available until after your ~/.emacs is loaded.

Stefan
  • 26,154
  • 3
  • 46
  • 84
  • 1
    Three comments: (a) Wow that worked! I love StackExchange! Thank you! (b) is there any reason not to use `(add-hook 'visual-line-mode-hook 'adaptive-wrap-prefix-mode)` instead of the fancy code those other two answers have? (c) I never would have guessed this - ELPA is also new to me (but handy). I feel like just as I'm learning how to run some part of emacs it changes on me, sometimes ... – Steve Petersen Aug 13 '16 at 14:50