[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
emacs-29 64fee21d5f8 1/2: Fix dockerfile-ts-mode line continuation inden
From: |
Yuan Fu |
Subject: |
emacs-29 64fee21d5f8 1/2: Fix dockerfile-ts-mode line continuation indentation (bug#61131) |
Date: |
Sun, 29 Jan 2023 03:32:22 -0500 (EST) |
branch: emacs-29
commit 64fee21d5f85db465198970a4d636cb17d500f26
Author: Randy Taylor <dev@rjt.dev>
Commit: Yuan Fu <casouri@gmail.com>
Fix dockerfile-ts-mode line continuation indentation (bug#61131)
Without this rule, line continuations are only indented after entering
the contents for the line and hitting TAB or RET.
For example:
```
EXPOSE 1 \
```
After hitting RET to go to the next line, point would end up at BOL
instead of lining up with the previous entry, like so:
```
EXPOSE 1 \
2
```
The new rule will indent it as so:
```
EXPOSE 1 \
2
```
* lisp/progmodes/dockerfile-ts-mode.el:
(dockerfile-ts-mode--indent-rules): New rule.
(dockerfile-ts-mode--line-continuation-p)
(dockerfile-ts-mode--line-continuation-anchor): New functions.
---
lisp/progmodes/dockerfile-ts-mode.el | 20 +++++++++++++++++++-
1 file changed, 19 insertions(+), 1 deletion(-)
diff --git a/lisp/progmodes/dockerfile-ts-mode.el
b/lisp/progmodes/dockerfile-ts-mode.el
index 2a295e885b0..f2f30cf2617 100644
--- a/lisp/progmodes/dockerfile-ts-mode.el
+++ b/lisp/progmodes/dockerfile-ts-mode.el
@@ -51,9 +51,27 @@
((parent-is "expose_instruction") (nth-sibling 1) 0)
((parent-is "label_instruction") (nth-sibling 1) 0)
((parent-is "shell_command") first-sibling 0)
- ((parent-is "string_array") first-sibling 1)))
+ ((parent-is "string_array") first-sibling 1)
+ ((dockerfile-ts-mode--line-continuation-p)
dockerfile-ts-mode--line-continuation-anchor 0)))
"Tree-sitter indent rules.")
+(defun dockerfile-ts-mode--line-continuation-p ()
+ "Return t if the current node is a line continuation node."
+ (lambda (node _ _ &rest _)
+ (string= (treesit-node-type node) "\n")))
+
+(defun dockerfile-ts-mode--line-continuation-anchor (_ _ &rest _)
+ "This anchor is used to align any nodes that are part of a line
+continuation to the previous entry."
+ (save-excursion
+ (forward-line -1)
+ (let ((prev-node (treesit-node-at (point))))
+ (if (string= (treesit-node-type prev-node) "\\\n")
+ (back-to-indentation)
+ (forward-word)
+ (forward-char))
+ (+ 1 (- (point) (pos-bol))))))
+
(defvar dockerfile-ts-mode--keywords
'("ADD" "ARG" "AS" "CMD" "COPY" "CROSS_BUILD" "ENTRYPOINT" "ENV"
"EXPOSE" "FROM" "HEALTHCHECK" "LABEL" "MAINTAINER" "ONBUILD" "RUN"