Closed ashlineldridge closed 5 months ago
FYI, I have made the following changes to my config to modify the HCL indentation behavior to only modify the buffer if it needs to. This seems to have addressed the issue. Happy to raise a PR if you like.
(use-package terraform-mode
:hook
(terraform-mode . (lambda () (setq-local indent-line-function 'my/hcl-indent-line))))
(defun my/hcl--maybe-indent-line (column)
"Indent current line to COLUMN if required."
(let ((curcol (- (point) (line-beginning-position))))
(unless (= curcol column)
(delete-region (line-beginning-position) (point))
(indent-to column))))
(defun my/hcl-indent-line ()
"Indent current line as HCL configuration."
(interactive)
(let* ((curpoint (point))
(pos (- (point-max) curpoint)))
(back-to-indentation)
(if (hcl--in-string-or-comment-p)
(goto-char curpoint)
(let ((block-indentation (hcl--block-indentation)))
(if block-indentation
(if (looking-at "[]}]")
(my/hcl--maybe-indent-line block-indentation)
(my/hcl--maybe-indent-line (+ block-indentation hcl-indent-level)))
(my/hcl--maybe-indent-line (hcl--previous-indentation)))
(when (> (- (point-max) pos) (point))
(goto-char (- (point-max) pos)))))))
@ashlineldridge I presume this can be closed. Should've been fixed by https://github.com/hcl-emacs/hcl-mode/commit/3afcc1ac02ba5d84b21b1806a841d89698eb2b35
@Hi-Angel Yes, I assume it can be based on the described change. Thanks for fixing 👍🏽
The function
hcl-indent-line
is called when TAB is pressed via Emacs'indent-for-tab-command
. Even when no indentation changes are required,hcl-indent-line
modifies the buffer by callingdelete-region
(here) and then re-adding the indentation. This has the side-effect of modifying the buffer's tick count whichindent-for-tab-command
inspects (here) to determine whether or not to callcompletion-at-point
. Becauseindent-for-tab-command
thinks that the buffer has changed every time TAB is pressed it never callscompletion-at-point
which has the effect of breaking the completion system.