fxbois / web-mode

web template editing mode for emacs
https://web-mode.org
GNU General Public License v3.0
1.63k stars 262 forks source link

HTML attributes misaligned on different lines #1288

Closed sphakka closed 7 months ago

sphakka commented 8 months ago

Maybe I'm missing something about lineup args, etc. I have these in my .emacs:

(add-to-list 'web-mode-indentation-params '("lineup-args" . nil))
(add-to-list 'web-mode-indentation-params '("lineup-calls" . nil))
(add-to-list 'web-mode-indentation-params '("lineup-concats" . nil))
(add-to-list 'web-mode-indentation-params '("lineup-ternary" . nil))

Still, with plain HTML, I can't manage to stop attrs to (mis)align on different lines. This is what happens:

  1. Write a first line, then (| is the cursor) hit enter: the cursor is correctly indented by one tab:
    <div class="foobar" 
        |
  2. Keep writing on the next line:
    <div class="foobar" 
        id="quux"|
  3. As soon as enter is hit, the second line gets misaligned like this:
    <div class="foobar" 
               id="quux"

    That's, ahem... ugly! How to prevent it?

BTW, even when lineup alignment is desired, IMO, it would be nicer to have attributes on multiple lines to get aligned (whenever possible -- I guess it might be really complicated!) at the = sign:

<div class="foobar" 
        id="quux"
fxbois commented 8 months ago

try with an empty .emacs

sphakka commented 8 months ago

After much head scratching, here comes the bug. It has nothing to do with lineup settings and it happens with minimal .emacs:

(require 'web-mode)

(setq-default tab-width 4)

(add-hook
 'web-mode-hook
 (lambda ()
   (setq indent-tabs-mode t)
   (web-mode-use-tabs)
   ))

The culprit is (web-mode-use-tabs) -- removing it, brings back the expected behavior.

fxbois commented 8 months ago

There is issues with tab alignment. Would be happy to review a patch.