aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorWilhelm H Kirschbaum2023-04-02 11:26:02 +0200
committerYuan Fu2023-04-04 23:01:21 -0700
commiteb0a9e463347b0191a07befcc3138db37f77b402 (patch)
tree145868d3df59cf67169d04766eb3564d56643c57
parent830bf66dadbb4b9b9393ade53b890b5497bdf479 (diff)
downloademacs-eb0a9e463347b0191a07befcc3138db37f77b402.tar.gz
emacs-eb0a9e463347b0191a07befcc3138db37f77b402.zip
Improve list indentation for elixir-ts-mode
* lisp/progmodes/elixir-ts-mode.el: (elixir-ts--argument-indent-offset): Add empty line check. (elixir-ts--argument-indent-anchor): Change ERROR offset. * test/lisp/progmodes/elixir-ts-mode-resources/indent.erts: Add test.
-rw-r--r--lisp/progmodes/elixir-ts-mode.el10
-rw-r--r--test/lisp/progmodes/elixir-ts-mode-resources/indent.erts20
2 files changed, 27 insertions, 3 deletions
diff --git a/lisp/progmodes/elixir-ts-mode.el b/lisp/progmodes/elixir-ts-mode.el
index 286f3e39f43..e0335fe15ed 100644
--- a/lisp/progmodes/elixir-ts-mode.el
+++ b/lisp/progmodes/elixir-ts-mode.el
@@ -169,7 +169,13 @@
169 169
170(defun elixir-ts--argument-indent-offset (node _parent &rest _) 170(defun elixir-ts--argument-indent-offset (node _parent &rest _)
171 "Return the argument offset position for NODE." 171 "Return the argument offset position for NODE."
172 (if (treesit-node-prev-sibling node t) 0 elixir-ts-indent-offset)) 172 (if (or (treesit-node-prev-sibling node t)
173 ;; Don't indent if this is the first node or
174 ;; if the line is empty.
175 (save-excursion
176 (beginning-of-line)
177 (looking-at-p "[[:blank:]]*$")))
178 0 elixir-ts-indent-offset))
173 179
174(defun elixir-ts--argument-indent-anchor (node parent &rest _) 180(defun elixir-ts--argument-indent-anchor (node parent &rest _)
175 "Return the argument anchor position for NODE and PARENT." 181 "Return the argument anchor position for NODE and PARENT."
@@ -264,7 +270,7 @@
264 ;; Handle incomplete maps when parent is ERROR. 270 ;; Handle incomplete maps when parent is ERROR.
265 ((n-p-gp "^binary_operator$" "ERROR" nil) parent-bol 0) 271 ((n-p-gp "^binary_operator$" "ERROR" nil) parent-bol 0)
266 ;; When there is an ERROR, just indent to prev-line. 272 ;; When there is an ERROR, just indent to prev-line.
267 ((parent-is "ERROR") prev-line 0) 273 ((parent-is "ERROR") prev-line ,offset)
268 ((node-is "^binary_operator$") 274 ((node-is "^binary_operator$")
269 (lambda (node parent &rest _) 275 (lambda (node parent &rest _)
270 (let ((top-level 276 (let ((top-level
diff --git a/test/lisp/progmodes/elixir-ts-mode-resources/indent.erts b/test/lisp/progmodes/elixir-ts-mode-resources/indent.erts
index ea5d9e62240..9ad604e5198 100644
--- a/test/lisp/progmodes/elixir-ts-mode-resources/indent.erts
+++ b/test/lisp/progmodes/elixir-ts-mode-resources/indent.erts
@@ -1,6 +1,5 @@
1Code: 1Code:
2 (lambda () 2 (lambda ()
3 (setq indent-tabs-mode nil)
4 (elixir-ts-mode) 3 (elixir-ts-mode)
5 (indent-region (point-min) (point-max))) 4 (indent-region (point-min) (point-max)))
6 5
@@ -330,3 +329,22 @@ defmodule Foo do
330 end 329 end
331end 330end
332=-=-= 331=-=-=
332
333Code:
334 (lambda ()
335 (elixir-ts-mode)
336 (newline)
337 (indent-for-tab-command))
338
339Name: New list item
340
341=-=
342[
343 :foo,$
344]
345=-=
346[
347 :foo,
348 $
349]
350=-=-=