* bug#61131: [PATCH] Fix dockerfile-ts-mode line continuation indentation
@ 2023-01-29 2:43 Randy Taylor
2023-01-29 8:30 ` Yuan Fu
0 siblings, 1 reply; 3+ messages in thread
From: Randy Taylor @ 2023-01-29 2:43 UTC (permalink / raw)
To: 61131; +Cc: casouri
[-- Attachment #1.1: Type: text/plain, Size: 52 bytes --]
X-Debbugs-CC: casouri@gmail.com
See attached patch.
[-- Attachment #1.2: Type: text/html, Size: 632 bytes --]
[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: 0001-Fix-dockerfile-ts-mode-line-continuation-indentation.patch --]
[-- Type: text/x-patch; name=0001-Fix-dockerfile-ts-mode-line-continuation-indentation.patch, Size: 2383 bytes --]
From 8e2cde800da8d6a694a3626d255fd0d9952e1e8f Mon Sep 17 00:00:00 2001
From: Randy Taylor <dev@rjt.dev>
Date: Sat, 28 Jan 2023 21:21:29 -0500
Subject: [PATCH] Fix dockerfile-ts-mode line continuation indentation
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 @@ dockerfile-ts-mode--indent-rules
((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"
--
2.39.1
^ permalink raw reply related [flat|nested] 3+ messages in thread
* bug#61131: [PATCH] Fix dockerfile-ts-mode line continuation indentation
2023-01-29 2:43 bug#61131: [PATCH] Fix dockerfile-ts-mode line continuation indentation Randy Taylor
@ 2023-01-29 8:30 ` Yuan Fu
2023-01-29 19:16 ` Randy Taylor
0 siblings, 1 reply; 3+ messages in thread
From: Yuan Fu @ 2023-01-29 8:30 UTC (permalink / raw)
To: Randy Taylor; +Cc: 61131
Randy Taylor <dev@rjt.dev> writes:
> X-Debbugs-CC: casouri@gmail.com
>
> See attached patch.
Thanks! Pushed.
Yuan
^ permalink raw reply [flat|nested] 3+ messages in thread
* bug#61131: [PATCH] Fix dockerfile-ts-mode line continuation indentation
2023-01-29 8:30 ` Yuan Fu
@ 2023-01-29 19:16 ` Randy Taylor
0 siblings, 0 replies; 3+ messages in thread
From: Randy Taylor @ 2023-01-29 19:16 UTC (permalink / raw)
To: Yuan Fu; +Cc: 61131-done@debbugs.gnu.org
On Sunday, January 29th, 2023 at 03:30, Yuan Fu <casouri@gmail.com> wrote:
>
> Randy Taylor dev@rjt.dev writes:
>
> > X-Debbugs-CC: casouri@gmail.com
> >
> > See attached patch.
>
>
> Thanks! Pushed.
>
> Yuan
Thanks! Closing.
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2023-01-29 19:16 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-01-29 2:43 bug#61131: [PATCH] Fix dockerfile-ts-mode line continuation indentation Randy Taylor
2023-01-29 8:30 ` Yuan Fu
2023-01-29 19:16 ` Randy Taylor
Code repositories for project(s) associated with this public inbox
https://git.savannah.gnu.org/cgit/emacs.git
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).