[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
master eb0a9e46334 1/2: Improve list indentation for elixir-ts-mode
From: |
Yuan Fu |
Subject: |
master eb0a9e46334 1/2: Improve list indentation for elixir-ts-mode |
Date: |
Wed, 5 Apr 2023 02:01:32 -0400 (EDT) |
branch: master
commit eb0a9e463347b0191a07befcc3138db37f77b402
Author: Wilhelm H Kirschbaum <wkirschbaum@gmail.com>
Commit: Yuan Fu <casouri@gmail.com>
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.
---
lisp/progmodes/elixir-ts-mode.el | 10 ++++++++--
.../progmodes/elixir-ts-mode-resources/indent.erts | 20 +++++++++++++++++++-
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 @@
(defun elixir-ts--argument-indent-offset (node _parent &rest _)
"Return the argument offset position for NODE."
- (if (treesit-node-prev-sibling node t) 0 elixir-ts-indent-offset))
+ (if (or (treesit-node-prev-sibling node t)
+ ;; Don't indent if this is the first node or
+ ;; if the line is empty.
+ (save-excursion
+ (beginning-of-line)
+ (looking-at-p "[[:blank:]]*$")))
+ 0 elixir-ts-indent-offset))
(defun elixir-ts--argument-indent-anchor (node parent &rest _)
"Return the argument anchor position for NODE and PARENT."
@@ -264,7 +270,7 @@
;; Handle incomplete maps when parent is ERROR.
((n-p-gp "^binary_operator$" "ERROR" nil) parent-bol 0)
;; When there is an ERROR, just indent to prev-line.
- ((parent-is "ERROR") prev-line 0)
+ ((parent-is "ERROR") prev-line ,offset)
((node-is "^binary_operator$")
(lambda (node parent &rest _)
(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 @@
Code:
(lambda ()
- (setq indent-tabs-mode nil)
(elixir-ts-mode)
(indent-region (point-min) (point-max)))
@@ -330,3 +329,22 @@ defmodule Foo do
end
end
=-=-=
+
+Code:
+ (lambda ()
+ (elixir-ts-mode)
+ (newline)
+ (indent-for-tab-command))
+
+Name: New list item
+
+=-=
+[
+ :foo,$
+]
+=-=
+[
+ :foo,
+ $
+]
+=-=-=