# Soft-wrapping with hanging indent

**URL:** <https://forum.systemcrafters.net/t/soft-wrapping-with-hanging-indent/1877>\
**Category:** Emacs\
**Tags:** emacs\
**Created:** [January 12, 2026, 9:49pm UTC](https://forum.systemcrafters.net/t/soft-wrapping-with-hanging-indent/1877 "2026-01-12T21:49:12Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![bos](https://avatars.discourse-cdn.com/v4/letter/b/ccd318/32.png) [@bos](https://forum.systemcrafters.net/u/bos)\
**Post date:** [January 12, 2026, 9:49pm UTC](https://forum.systemcrafters.net/t/soft-wrapping-with-hanging-indent/1877/1 "2026-01-12T21:49:13Z")

</div>

Hi all,

I am new to emacs and configuring it for LaTeX. In VSCode I can set a “hanging” indent when I soft wrap:

`This is an example sentence which flows past my`  
` editor margin and ends here.`

How can I achieve the same behavior in emacs? I would like it purely with soft-wrapping.

I enabled `visual-line-mode `and `adaptive-wrap-prefix-mode` and eval’d `(setq adaptive-wrap-extra-indent 4)` but my result looks like:

`This is an example sentence which flows past my`  
`editor margin and ends here.`

Any insights how to config this correctly?

---

<div class="post-metadata">

**Author:** ![dgr](https://yyz1.discourse-cdn.com/flex029/user_avatar/forum.systemcrafters.net/dgr/32/394_2.png) [@dgr](https://forum.systemcrafters.net/u/dgr)\
**Post date:** [January 13, 2026, 1:11pm UTC](https://forum.systemcrafters.net/t/soft-wrapping-with-hanging-indent/1877/2 "2026-01-13T13:11:56Z")

</div>

What do you get if you try:

```lisp
(global-visual-line-mode 1)
(with-eval-after-load 'adaptive-wrap
  (setq adaptive-wrap-extra-indent 4)
  (add-hook 'visual-line-mode-hook #'adaptive-wrap-prefix-mode))

```

---

<div class="post-metadata">

**Author:** ![ashraz](https://yyz1.discourse-cdn.com/flex029/user_avatar/forum.systemcrafters.net/ashraz/32/509_2.png) [@ashraz](https://forum.systemcrafters.net/u/ashraz)\
**Post date:** [January 13, 2026, 1:29pm UTC](https://forum.systemcrafters.net/t/soft-wrapping-with-hanging-indent/1877/3 "2026-01-13T13:29:27Z")

</div>

If you use Emacs 30 (or higher), then you can use `visual-line-mode` together with `visual-wrap-prefix-mode`, no need for any external package:

```lisp
(defun enable-line-prefix-wrap (&optional indent)
  "Enable `visual-line-mode' and `visual-wrap-prefix-mode' in the
current buffer.

The optional setting INDENT is the amount of indentation."
  (interactive "P")
  (visual-line-mode 1)
  (setq-local visual-wrap-extra-indent (or indent 4))
  (visual-wrap-prefix-mode 1))

```

Use via `M-x enable-line-prefix-wrap RET`. Or add it to a hook.

# Demonstration

This demonstration uses `emacs -Q`. Beside the aforementioned function, only the follwing Emacs Lisp code has been executed:

```lisp
(setq frame-title-format “Demonstration”)
(column-numbers-mode) ; see the cursor position in both screenshots

```

## Before

 ![Before](https://canada1.discourse-cdn.com/flex029/uploads/systemcrafters/original/2X/a/a23aab4b4334f044282825ec81d0ce81da478c6e.png)

## After

 ![After](https://canada1.discourse-cdn.com/flex029/uploads/systemcrafters/original/2X/b/bf8ee253f7150f4da87a3f29c14fadb501a29d5d.png)

---

<div class="post-metadata">

**Author:** ![bos](https://avatars.discourse-cdn.com/v4/letter/b/ccd318/32.png) [@bos](https://forum.systemcrafters.net/u/bos)\
**Post date:** [January 13, 2026, 3:22pm UTC](https://forum.systemcrafters.net/t/soft-wrapping-with-hanging-indent/1877/4 "2026-01-13T15:22:39Z")

</div>

Thank you! This seems to be what I’m after.

I would additionally like to add `visual-fill-column-mode` ([joostkremers/visual-fill-column: Emacs mode for wrapping visual-line-mode buffers at fill-column. - Codeberg.org](https://codeberg.org/joostkremers/visual-fill-column)) but I am confused a little with the instructions:

> `visual-fill-column-mode` wraps long lines at `fill-column` without adding newlines to the buffer. Its primary (though not exclusive) purpose is to soft-wrap text in buffers that use `visual-line-mode`. The most straightforward way to achieve this is to add the function `visual-fill-column-for-vline` to `visual-line-mode-hook`:
> 
> ```auto
> (add-hook 'visual-line-mode-hook #'visual-fill-column-for-vline)
> 
> ```
> 
> This function ensures that `visual-fill-column-mode` is enabled and disabled in conjunction with `visual-line-mode`. Note that you should _not_ add `visual-fill-column-mode` to `visual-line-mode-hook`, because then `visual-fill-column-mode` is not disabled when you disable `visual-line-mode`. This also means that if you use `use-package`, you should not use the `:hook` keyword, because it will add `-hook` to the name of the function. Instead, put the `add-hook` invocation under `:config`.

I wasn’t sure how or where I should add this `add-hook` This Is what I’ve attempted so far, but `visual-fill-column-mode` isn’t called when i load a tex file:

```auto
(use-package visual-fill-column
:ensure t
:defer t
:config
((add-hook 'visual-line-mode-hook #'visual-fill-column-for-vline)
(setq visual-fill-column-width 120))
)

(defun enable-line-prefix-wrap (&optional indent)
"Enable visual-line-mode' and visual-wrap-prefix-mode’ in the current buffer.

The optional setting INDENT is the amount of indentation."
(interactive “P”)
(visual-line-mode 1)
(setq-local visual-wrap-extra-indent (or indent 4))
(visual-wrap-prefix-mode 1))

(use-package tex
:ensure auctex
:mode (“\.tex\'” . LaTeX-mode)
:hook
((LaTeX-mode . visual-line-mode))
(LaTeX-mode . enable-line-prefix-wrap))

```

---

<div class="post-metadata">

**Author:** ![ashraz](https://yyz1.discourse-cdn.com/flex029/user_avatar/forum.systemcrafters.net/ashraz/32/509_2.png) [@ashraz](https://forum.systemcrafters.net/u/ashraz)\
**Post date:** [January 14, 2026, 7:26pm UTC](https://forum.systemcrafters.net/t/soft-wrapping-with-hanging-indent/1877/5 "2026-01-14T19:26:14Z")

</div>

You’re mixing a bit of syntax there. Given that you _always_ want to run `visual-fill-column` when you run `visual-line-mode`, I’d recommend to use the following `use-package`:

```lisp
(use-package visual-fill-column
  :ensure t
  :hook 
  (visual-line-mode . visual-fill-column-for-vline)
  :config
  (setopt visual-fill-column-width 120))

```

Note that there is no `:defer` necessary if you use `:hook`.\[1\] **But:** `:hook` should only be used if the function that is called is defined by the package.\[2\]

So, next up, let’s customize `visual-wrap-prefix-mode`:

```lisp
(use-package visual-wrap
  :ensure nil
  :config
  (setopt visual-wrap-extra-indent 4))

```

And last but not least, let’s customize `tex`:

```lisp
(use-package tex
  :ensure auctex
  :mode (“\.tex\'” . LaTeX-mode)
  :config
  (add-hook 'LaTeX-mode-hook #'visual-line-mode)
  (add-hook 'LaTeX-mode-hook #'visual-wrap-prefix-mode))

```

Here, we have to use `add-hook`, because the called function is _not_ provided by `auctex`. Now, if you always want to use `visual-wrap-prefix-mode` whenever you use `visual-line-mode`, then it gets a bit easier:

```lisp
;; visual-fill-column's package definition stays as-is
(use-package visual-wrap
  :ensure nil
  :hook
  (visual-line-mode . visual-wrap-prefix-mode) ; always use wrap-prefix
  :config
  (setopt visual-wrap-extra-indent 4))

(use-package tex
  :ensure auctex
  :mode (“\.tex\'” . LaTeX-mode)
  :config
  (add-hook 'LaTeX-mode-hook #'visual-line-mode)) ; second hook removed

```

* * *

Now, with all that said, I think that this is not quite correct. While `visual-line-mode` can work together with `visual-wrap-prefix-mode`, you can use the latter without the former and then get hints in the fringes about the continuation, which you may prefer. However, the authors of `visual-fill-column` have bound `visual-fill-column-for-vline` to `visual-line-mode`’s variable value, so you would have to do that yourself\[3\].

* * *

1. That’s also the reason why I don’t like the maintainers comment about `:hook`: _“This also means that if you use use-package, you should not use the :hook keyword, because it will add -hook to the name of the function. Instead, put the add-hook invocation under :config.”_ That is not necessary and will instead work against use-package’s autoloading features. 

2. Again, use-package does some magic and defers loading your package if you specify :hook. It does so by providing autoloads; setting them on unrelated functions would be bad, hmkay? 

3. see `visual-fill-column-for-vline`’s definition
