Skip to content

Commit b2a03a4

Browse files
authored
Merge pull request #10 from Hi-Angel/fix-indent
Do not change the buffer if indentation is correct
2 parents 751b792 + 8acf964 commit b2a03a4

File tree

2 files changed

+12
-10
lines changed

2 files changed

+12
-10
lines changed

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,4 +33,4 @@ test:
3333
clean-elc:
3434
rm -f f.elc
3535

36-
.PHONY: all compile clean-elc package-lint
36+
.PHONY: all compile clean-elc package-lint test

hcl-mode.el

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,14 @@
102102
(forward-line -1))))))
103103
(current-indentation))))
104104

105+
(defun hcl-calculate-indentation ()
106+
(let ((block-indentation (hcl--block-indentation)))
107+
(if block-indentation
108+
(if (looking-at "[]}]")
109+
block-indentation
110+
(+ block-indentation hcl-indent-level))
111+
(hcl--previous-indentation))))
112+
105113
(defun hcl-indent-line ()
106114
"Indent current line as Hcl configuration."
107115
(interactive)
@@ -110,15 +118,9 @@
110118
(back-to-indentation)
111119
(if (hcl--in-string-or-comment-p)
112120
(goto-char curpoint)
113-
(let ((block-indentation (hcl--block-indentation)))
114-
(delete-region (line-beginning-position) (point))
115-
(if block-indentation
116-
(if (looking-at "[]}]")
117-
(indent-to block-indentation)
118-
(indent-to (+ block-indentation hcl-indent-level)))
119-
(indent-to (hcl--previous-indentation)))
120-
(when (> (- (point-max) pos) (point))
121-
(goto-char (- (point-max) pos)))))))
121+
(indent-line-to (hcl-calculate-indentation))
122+
(when (> (- (point-max) pos) (point))
123+
(goto-char (- (point-max) pos))))))
122124

123125
(defun hcl-beginning-of-defun (&optional count)
124126
(interactive "p")

0 commit comments

Comments
 (0)