Emacs: How to keep the indentation level of a very long wrapped line

The package adaptive-wrap, which can be installed via the ELPA packaging system, should do what you want.

After having installed the package, just run the following commands:

  • M-xvisual-line-modeRET (to wrap long lines)
  • M-xadaptive-wrap-prefix-modeRET (to make wrapped lines indent nicely)

I also have the following snippet in my init.el file to automatically activate adaptive-wrap-prefix-mode along with visual-line-mode:

(when (fboundp 'adaptive-wrap-prefix-mode)
  (defun my-activate-adaptive-wrap-prefix-mode ()
    "Toggle `visual-line-mode' and `adaptive-wrap-prefix-mode' simultaneously."
    (adaptive-wrap-prefix-mode (if visual-line-mode 1 -1)))
  (add-hook 'visual-line-mode-hook 'my-activate-adaptive-wrap-prefix-mode))

Leave a Comment

tech