Skip to content

Commit

Permalink
Merge pull request #10 from Hi-Angel/fix-indent
Browse files Browse the repository at this point in the history
Do not change the buffer if indentation is correct
  • Loading branch information
purcell authored Feb 20, 2024
2 parents 751b792 + 8acf964 commit b2a03a4
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 10 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -33,4 +33,4 @@ test:
clean-elc:
rm -f f.elc

.PHONY: all compile clean-elc package-lint
.PHONY: all compile clean-elc package-lint test
20 changes: 11 additions & 9 deletions hcl-mode.el
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,14 @@
(forward-line -1))))))
(current-indentation))))

(defun hcl-calculate-indentation ()
(let ((block-indentation (hcl--block-indentation)))
(if block-indentation
(if (looking-at "[]}]")
block-indentation
(+ block-indentation hcl-indent-level))
(hcl--previous-indentation))))

(defun hcl-indent-line ()
"Indent current line as Hcl configuration."
(interactive)
Expand All @@ -110,15 +118,9 @@
(back-to-indentation)
(if (hcl--in-string-or-comment-p)
(goto-char curpoint)
(let ((block-indentation (hcl--block-indentation)))
(delete-region (line-beginning-position) (point))
(if block-indentation
(if (looking-at "[]}]")
(indent-to block-indentation)
(indent-to (+ block-indentation hcl-indent-level)))
(indent-to (hcl--previous-indentation)))
(when (> (- (point-max) pos) (point))
(goto-char (- (point-max) pos)))))))
(indent-line-to (hcl-calculate-indentation))
(when (> (- (point-max) pos) (point))
(goto-char (- (point-max) pos))))))

(defun hcl-beginning-of-defun (&optional count)
(interactive "p")
Expand Down

0 comments on commit b2a03a4

Please sign in to comment.