Closed Matsa59 closed 1 year ago
Just try 2/3 things and following code could be a beginning
(defun web-mode-elixir-indentation (pos line initial-column language-offset limit)
(unless limit (setq limit nil))
(let (h offset prev-line prev-indentation open-ctx)
(setq open-ctx (web-mode-bracket-up pos "elixir" limit))
;;(message "%S" open-ctx)
(if (plist-get open-ctx :pos)
(cond
((web-mode-looking-at-p ".[ \t\n]+" (plist-get open-ctx :pos))
(setq offset (+ (plist-get open-ctx :indentation) language-offset)))
(t
(setq offset (1+ (plist-get open-ctx :column))))
)
(setq h (web-mode-previous-line pos limit))
(setq offset initial-column)
(when h
(setq prev-line (car h))
(setq prev-indentation (cdr h))
(cond
((string-match-p ",$" prev-line)
(save-excursion
(goto-char limit)
(looking-at "<%=? [a-z]+ ")
;; (setq offset (+ initial-column (length (match-string-no-properties 0))))
(setq offset (+ initial-column 4))
) ;save-excursion
)
((string-match-p "\\(do\\)" prev-line)
(setq offset (+ prev-indentation language-offset))
)
(t
(setq offset prev-indentation)
)
)
) ;when
) ;if
offset))
Don't know why
(setq offset (+ initial-column (length (match-string-no-properties 0))))
return me an error
@Matsa59 thank you ... I'll look at this very soon
Also please add the following piece of code:
((string= web-mode-engine "elixir")
(cond
((web-mode-block-starts-with "</form>" reg-beg)
(setq controls (append controls (list (cons 'close "form-ctrl")))))
((web-mode-block-starts-with "f =" reg-beg)
(setq controls (append controls (list (cons 'open "ctrl")))))
...
It fix the "simple" eex pattern
<%= f = form_for ... %>
<%= text_input f, :some_field %>
</form>
Currently it's transformed to
<%= f = form_for ... %>
<%= text_input f, :some_field %>
</form>
Edit : Finally, I made a PR, I used it form weeks and everything works great so far.
Multi line inside a
<% ... %>
block should be aligned as HTML doesEdit : Finally, I made a PR, I used it form weeks and everything works great so far.
Expected
OR
Obtains
(same as https://github.com/fxbois/web-mode/issues/1047 for ruby)