17

I have the following wrapped text, especially when you use a lot of windows:

Wrapped lines in Emacs

I'm wondering if the indentation of wrapped text could be changed like in Vim:

Indentation of wrapped lines in Vim

When figuring out, it seems the AutoFillMode is responsible for this. I was hoping this might be improved in Emacs 25. After upgraded to a compiled binary of Emacs 25, I see the same behaviour.

So I'm wondering if I could solve this in an another way?

Flux
  • 603
  • 3
  • 17
ReneFroger
  • 3,850
  • 23
  • 66
  • 1
    Perhaps the solution could take advantage of the wrap-prefix: http://www.gnu.org/software/emacs/manual/html_node/elisp/Truncation.html#Truncation See also wrap-prefix property: http://www.gnu.org/software/emacs/manual/html_node/elisp/Special-Properties.html – lawlist Aug 08 '15 at 17:47
  • 2
    Check out the adaptive-wrap package. – Kaushal Modi Aug 08 '15 at 18:01
  • You both are right, lawlist and kaushalmodi. Thanks for your help! – ReneFroger Aug 08 '15 at 19:37

1 Answers1

17

After M-x package-install RET adaptive-wrap RET:

(setq-default adaptive-wrap-extra-indent 2)
(add-hook 'visual-line-mode-hook #'adaptive-wrap-prefix-mode)
(global-visual-line-mode +1)
PythonNut
  • 10,363
  • 2
  • 30
  • 76
  • adaptive-wrap-prefix-mode is not a global mode by default. But you can make it global if you like and not tie it with the activation of visual-line-mode. – Kaushal Modi Aug 08 '15 at 18:49
  • Surprising to see how easily this could be achieved. Why is this not included in the default package of Emacs? – ReneFroger Aug 08 '15 at 19:38
  • The package itself is in ELPA, so that could be fairly easily arranged, at least from a legal standpoint. I'd much rather have Tetris be the external package and adaptive-wrap be built-in but such is life. – PythonNut Aug 08 '15 at 19:56
  • @kaushalmodi does adaptive-wrap make sense without visual-line-mode? – PythonNut Jan 06 '16 at 00:55
  • @PythonNut No it doesn't. visual-line-mode should be enabled for adaptive-wrap-prefix-mode to work. I use a slightly different approach than yours.. I just enable adaptive-wrap-prefix-mode globally. That's not recommended by the package author Stefan Monnier (based on personal email communication) as it costs non-negligible resources to enable this mode globally. But that hasn't affected my use cases. – Kaushal Modi Jan 06 '16 at 19:24
  • 2
    @PythonNut On further thought, I might start doing just what you do.. enable adaptive-wrap-prefix-mode using the visual-line-mode-hook :) – Kaushal Modi Jan 06 '16 at 19:27
  • @PythonNut Here's my updated config: I don't enable visual-line-mode globally. But now I enable adaptive-wrap-prefix-mode only when the former is enabled. Thanks for that nudge. – Kaushal Modi Jan 06 '16 at 19:36
  • @kaushalmodi yep. Thanks for the sanity check. :) – PythonNut Jan 06 '16 at 19:38
  • @PythonNut Note that setq won't work for adaptive-wrap-extra-indent as that's a buffer local var. You need to use setq-default instead. – Kaushal Modi Jan 06 '16 at 19:39
  • 1
    @kaushalmodi Thanks for the tip. I fixed this in my config a while ago (idk, there's some other stuff in that commit too :|), but I haven't updated my answer. Should be updated now. – PythonNut Jan 06 '16 at 19:44
  • I'd suggest putting the require' of things likeadaptive-wrap' and `diminish' in the hook function, unless those libraries are needed for the rest of the code you load. – Drew Nov 22 '17 at 16:32
  • First things first: really adaptive-wrap rather than Tetris? Are you nuts? Second: Stephen Berman is the author, not me. Third: why in with-eval-after-load whereas it should work both before and after loading (and you've loaded it just above anyway)? Finally: I'd remove the dimish business from your example, since it's not directly related. – Stefan Nov 30 '17 at 13:22
  • @Stefan I actually have no idea what you mean by "Tetris". – PythonNut Dec 01 '17 at 23:06
  • @PythonNut: For reference: ...I'd much rather have Tetris be the external package... – PythonNut Aug 8 '15 at 19:56 – Stefan Dec 02 '17 at 01:44