emacs-elpa-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[elpa] externals/devicetree-ts-mode fecea965dc 03/11: Add indent rules.


From: ELPA Syncer
Subject: [elpa] externals/devicetree-ts-mode fecea965dc 03/11: Add indent rules.
Date: Tue, 16 Jan 2024 03:58:28 -0500 (EST)

branch: externals/devicetree-ts-mode
commit fecea965dc00e30284cfaecfe9a2e740898a0922
Author: Aleksandr Vityazev <avityazew@gmail.com>
Commit: Aleksandr Vityazev <avityazew@gmail.com>

    Add indent rules.
---
 devicetree-ts-mode.el | 33 +++++++++++++++++++++++++++++----
 1 file changed, 29 insertions(+), 4 deletions(-)

diff --git a/devicetree-ts-mode.el b/devicetree-ts-mode.el
index db053323ba..2e1544934b 100644
--- a/devicetree-ts-mode.el
+++ b/devicetree-ts-mode.el
@@ -1,9 +1,12 @@
-;;; devicetree-ts-mode.el --- tree-sitter support for DTS   -*- 
lexical-binding: t; -*-
+;;; devicetree-ts-mode.el --- Tree-sitter support for DTS   -*- 
lexical-binding: t; -*-
 
 ;; Copyright (C) 2023  Aleksandr Vityazev
 
 ;; Author: Aleksandr Vityazev <avityazew@gmail.com>
-;; Keywords: devicetree tree-sitter
+;; Keywords: languages devicetree tree-sitter
+;; Version: 0.1
+;; Homepage: https://sr.ht/~akagi/devicetree-ts-mode
+;; Package-Requires: ((emacs "29.1"))
 
 ;; This program is free software; you can redistribute it and/or modify
 ;; it under the terms of the GNU General Public License as published by
@@ -35,6 +38,13 @@
 ;; (declare-function treesit-node-start "treesit.c")
 ;; (declare-function treesit-node-type "treesit.c")
 
+(defcustom devicetree-ts-mode-indent-offset 4
+  "Number of spaces for each indentation step in `devicetree-ts-mode'."
+  :version "29.1"
+  :type 'natnum
+  :safe 'natnump
+  :group 'devicetree)
+
 ;; Taken from the dts-mode
 (defvar devicetree-ts-mode--syntax-table
   (let ((table (make-syntax-table)))
@@ -63,6 +73,21 @@
     table)
   "Syntax table for `devicetree-ts-mode'.")
 
+(defvar devicetree-ts-mode--indent-rules
+  (let ((offset devicetree-ts-mode-indent-offset))
+    `((devicetree
+       ((node-is ">") parent-bol 0)
+       ((node-is "]") parent-bol 0)
+       ((node-is "}") standalone-parent 0)
+       ((node-is "]") parent-bol 0)
+       ((and (parent-is "comment") c-ts-common-looking-at-star)
+        c-ts-common-comment-start-after-first-star -1)
+       ((parent-is "node") parent-bol ,offset)
+       ((parent-is "property") parent-bol ,offset)
+       ((parent-is "integer_cells") parent-bol ,offset)
+       (no-node parent-bol 0))))
+  "Tree-sitter indent rules for `devicetree-ts-mode'.")
+
 (defvar devicetree-ts-mode--treesit-keywords
   '("/delete-node/" "/delete-property/" "#define" "#include"
     "/omit-if-no-ref/" "/dts-v1/"))
@@ -158,8 +183,8 @@
     (setq-local which-func-functions nil)
 
     ;; Indent.
-    ;; (setq-local treesit-simple-indent-rules
-    ;;             devicetree-ts-mode--indent-rules)
+    (setq-local treesit-simple-indent-rules
+                devicetree-ts-mode--indent-rules)
     ;; (setq-local indent-tabs-mode t)
 
     ;; Electric



reply via email to

[Prev in Thread] Current Thread [Next in Thread]