[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[elpa] master 41ed3b6 14/21: add indentation support
From: |
Stefan Monnier |
Subject: |
[elpa] master 41ed3b6 14/21: add indentation support |
Date: |
Tue, 18 Aug 2015 14:59:06 +0000 |
branch: master
commit 41ed3b6ccd4c5161fe0a79428da94dc05d740eec
Author: Mitchel Humpherys <address@hidden>
Commit: Mitchel Humpherys <address@hidden>
add indentation support
Add a simple indentation function that looks at nothing but opening and
closes braces.
Ideally we should use `smie' to do indentation, but this works for now.
Given the following file:
/ {
cpus {
cpu-map {
cluster1 {
core0 {
cpu = <&CPU0>;
};
core1 {
cpu = <&CPU1>;
};
};
};
};
widget: pizza,address@hidden {
compatible = "pizza,feast-v1";
things = <1 2 3>;
};
};
With this change we get the following indentation:
/ {
cpus {
cpu-map {
cluster1 {
core0 {
cpu = <&CPU0>;
};
core1 {
cpu = <&CPU1>;
};
};
};
};
widget: pizza,address@hidden {
compatible = "pizza,feast-v1";
things = <1 2 3>;
};
};
---
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))
- [elpa] master updated (8acc296 -> 72e1086), Stefan Monnier, 2015/08/18
- [elpa] master ab852b2 02/21: Add README, Stefan Monnier, 2015/08/18
- [elpa] master c31adb4 01/21: Initial commit, Stefan Monnier, 2015/08/18
- [elpa] master 4f50e89 04/21: Proper em-dash, Stefan Monnier, 2015/08/18
- [elpa] master 872d58f 05/21: Addresses are hex digits, not decimal, Stefan Monnier, 2015/08/18
- [elpa] master a303f72 07/21: Update README.mkd, Stefan Monnier, 2015/08/18
- [elpa] master 28154cf 08/21: Update README.mkd, Stefan Monnier, 2015/08/18
- [elpa] master 20043ee 09/21: Add ends here, Stefan Monnier, 2015/08/18
- [elpa] master 41ed3b6 14/21: add indentation support,
Stefan Monnier <=
- [elpa] master c3624e9 06/21: Update README.mkd, Stefan Monnier, 2015/08/18
- [elpa] master 90c6ac3 03/21: More readme, Stefan Monnier, 2015/08/18
- [elpa] master 72e1086 21/21: packages/dts-mode: New major mode, Stefan Monnier, 2015/08/18
- [elpa] master 42ed276 18/21: Spell Device Tree with a space, Stefan Monnier, 2015/08/18
- [elpa] master daab780 20/21: Add 'packages/dts-mode/' from commit '6ec1443ead16105234765f9b48df9b4aca562e61', Stefan Monnier, 2015/08/18
- [elpa] master 4fd4484 10/21: A few fixes, Stefan Monnier, 2015/08/18
- [elpa] master 87eefb3 13/21: Merge pull request #2 from jamienicol/master, Stefan Monnier, 2015/08/18
- [elpa] master 565565e 11/21: Merge pull request #1 from purcell/patch-1, Stefan Monnier, 2015/08/18
- [elpa] master b66e6f9 12/21: Add autoload statements, Stefan Monnier, 2015/08/18
- [elpa] master 7f10920 16/21: respect the user's indent-tabs-mode, Stefan Monnier, 2015/08/18