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

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

[elpa] master bd9038d 15/21: Merge pull request #3 from mgalgs/indentati


From: Stefan Monnier
Subject: [elpa] master bd9038d 15/21: Merge pull request #3 from mgalgs/indentation
Date: Tue, 18 Aug 2015 14:59:06 +0000

branch: master
commit bd9038dd601f285b8d0f451cf92d7b43efec7edb
Merge: 87eefb3 41ed3b6
Author: Ben Gamari <address@hidden>
Commit: Ben Gamari <address@hidden>

    Merge pull request #3 from mgalgs/indentation
    
    add indentation support
---
 dts-mode.el |   27 ++++++++++++++++++++++++++-
 1 files changed, 26 insertions(+), 1 deletions(-)

diff --git a/dts-mode.el b/dts-mode.el
index 3f2e1ae..883a8d8 100644
--- a/dts-mode.el
+++ b/dts-mode.el
@@ -67,6 +67,30 @@
 
     table))
 
+(defun dts--calculate-indentation ()
+  (interactive)
+  (save-excursion
+    (let ((end (point-at-eol))
+          (cnt 0)
+          (initial-point (point)))
+      (goto-char 0)
+      (while (re-search-forward "\\([{}]\\)" end t)
+        (if (string= (match-string-no-properties 0) "{")
+            (setq cnt (1+ cnt))
+          (setq cnt (1- cnt))))
+      ;; subtract one if the current line has an opening brace since we
+      ;; shouldn't add the indentation level until the following line
+      (goto-char initial-point)
+      (beginning-of-line)
+      (when (re-search-forward "{" (point-at-eol) t)
+        (setq cnt (1- cnt)))
+      cnt)))
+
+(defun dts-indent-line ()
+  (interactive)
+  (let ((indent (dts--calculate-indentation)))
+    (indent-line-to (* indent tab-width))))
+
 (defalias 'dts-parent-mode
   (if (fboundp 'prog-mode) 'prog-mode 'fundamental-mode))
 
@@ -82,7 +106,8 @@
   (set (make-local-variable 'comment-start) "/* ")
   (set (make-local-variable 'comment-end)   " */")
   (set (make-local-variable 'indent-tabs-mode) nil)
-  (set (make-local-variable 'comment-multi-line) t))
+  (set (make-local-variable 'comment-multi-line) t)
+  (set (make-local-variable 'indent-line-function) 'dts-indent-line))
 
 ;;;###autoload
 (add-to-list 'auto-mode-alist '("\\.dts\\'" . dts-mode))



reply via email to

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