+++ /dev/null
-;;; hcl-mode-autoloads.el --- automatically extracted autoloads
-;;
-;;; Code:
-
-(add-to-list 'load-path (directory-file-name
- (or (file-name-directory #$) (car load-path))))
-
-\f
-;;;### (autoloads nil "hcl-mode" "hcl-mode.el" (0 0 0 0))
-;;; Generated autoloads from hcl-mode.el
-
-(autoload 'hcl-mode "hcl-mode" "\
-Major mode for editing hcl configuration file
-
-\(fn)" t nil)
-
-(add-to-list 'auto-mode-alist '("\\.hcl\\'" . hcl-mode))
-
-(add-to-list 'auto-mode-alist '("\\.nomad\\'" . hcl-mode))
-
-(if (fboundp 'register-definition-prefixes) (register-definition-prefixes "hcl-mode" '("hcl-")))
-
-;;;***
-\f
-;; Local Variables:
-;; version-control: never
-;; no-byte-compile: t
-;; no-update-autoloads: t
-;; coding: utf-8
-;; End:
-;;; hcl-mode-autoloads.el ends here
+++ /dev/null
-;;; -*- no-byte-compile: t -*-
-(define-package "hcl-mode" "20170107.827" "Major mode for Hashicorp" '((emacs "24.3")) :commit "0f2c5ec7e7bcf77c8548e8cac8721ea935ca1b5e" :authors '(("Syohei YOSHIDA" . "syohexNOSPAMgmail.com")) :maintainer '("Syohei YOSHIDA" . "syohexNOSPAMgmail.com") :url "https://github.com/syohex/emacs-hcl-mode")
+++ /dev/null
-;;; hcl-mode.el --- Major mode for Hashicorp -*- lexical-binding: t -*-
-
-;; Copyright (C) 2017 by Syohei YOSHIDA
-
-;; Author: Syohei YOSHIDA <syohexNOSPAMgmail.com>
-;; URL: https://github.com/syohex/emacs-hcl-mode
-;; Package-Version: 20170107.827
-;; Version: 0.03
-;; Package-Requires: ((emacs "24.3"))
-
-;; This program is free software; you can redistribute it and/or modify
-;; it under the terms of the GNU General Public License as published by
-;; the Free Software Foundation, either version 3 of the License, or
-;; (at your option) any later version.
-
-;; This program is distributed in the hope that it will be useful,
-;; but WITHOUT ANY WARRANTY; without even the implied warranty of
-;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-;; GNU General Public License for more details.
-
-;; You should have received a copy of the GNU General Public License
-;; along with this program. If not, see <http://www.gnu.org/licenses/>.
-
-;;; Commentary:
-
-;; hcl-mode provides a major-mode of hcl file.
-
-;;; Code:
-
-(require 'cl-lib)
-(require 'rx)
-
-(defgroup hcl nil
- "Major mode of Hashicorp Configuration Language."
- :group 'languages)
-
-(defcustom hcl-indent-level 2
- "The tab width to use when indenting."
- :type 'integer)
-
-(defconst hcl--block-regexp
- "^\\s-*[^{]+{")
-
-;; String Interpolation(This regexp is taken from ruby-mode)
-(defconst hcl--string-interpolation-regexp
- "\\${[^}\n\\\\]*\\(?:\\\\.[^}\n\\\\]*\\)*}")
-
-(defconst hcl--assignment-regexp
- "\\s-*\\([[:word:]]+\\)\\s-*=\\(?:[^>=]\\)")
-
-(defconst hcl--map-regexp
- "\\s-*\\([[:word:]]+\\)\\s-*{")
-
-(defconst hcl--boolean-regexp
- (concat "\\(?:^\\|[^.]\\)"
- (regexp-opt '("true" "false" "on" "off" "yes" "no")
- 'words)))
-
-(defvar hcl-font-lock-keywords
- `((,hcl--assignment-regexp 1 font-lock-variable-name-face)
- (,hcl--boolean-regexp . font-lock-constant-face)
- (,hcl--map-regexp 1 font-lock-type-face)
- (,hcl--string-interpolation-regexp 0 font-lock-variable-name-face t)))
-
-(defsubst hcl--paren-level ()
- (car (syntax-ppss)))
-
-(defsubst hcl--in-string-or-comment-p ()
- (nth 8 (syntax-ppss)))
-
-(defun hcl--block-indentation ()
- (let ((curline (line-number-at-pos)))
- (save-excursion
- (condition-case nil
- (progn
- (backward-up-list)
- (unless (= curline (line-number-at-pos))
- (current-indentation)))
- (scan-error nil)))))
-
-(defun hcl--previous-indentation ()
- (save-excursion
- (forward-line -1)
- (let (finish)
- (while (not finish)
- (cond ((bobp) (setq finish t))
- ((hcl--in-string-or-comment-p) (forward-line -1))
- (t
- (let ((line (buffer-substring-no-properties
- (line-beginning-position) (line-end-position))))
- (if (not (string-match-p "\\`\\s-*\\'" line))
- (setq finish t)
- (forward-line -1))))))
- (current-indentation))))
-
-(defun 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)))
- (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)))))))
-
-(defun hcl-beginning-of-defun (&optional count)
- (interactive "p")
- (setq count (or count 1))
- (let ((match 0)
- finish)
- (while (and (not finish)
- (re-search-backward hcl--block-regexp nil t))
- (unless (hcl--in-string-or-comment-p)
- (cl-incf match)
- (when (= match count)
- (setq finish t))))))
-
-(defun hcl-end-of-defun (&optional count)
- (interactive "p")
- (let ((paren-level (hcl--paren-level)))
- (when (or (and (looking-at-p "}") (= paren-level 1))
- (= paren-level 0))
- (re-search-forward hcl--block-regexp nil t)))
- (dotimes (_i count)
- (when (looking-at-p hcl--block-regexp)
- (goto-char (line-end-position)))
- (hcl-beginning-of-defun 1)
- (skip-chars-forward "^{")
- (forward-char 1)
- (let ((orig-level (hcl--paren-level)))
- (while (>= (hcl--paren-level) orig-level)
- (skip-chars-forward "^}")
- (forward-line +1)))))
-
-(eval-and-compile
- (defconst hcl--here-doc-beg-re
- "[^<]<<-?\\s-*\\\\?\\(\\(?:['\"][^'\"]+['\"]\\|\\sw\\|[-/~._]\\)+\\)\\(\n\\)"))
-
-(defun hcl--syntax-propertize-heredoc (end)
- (let ((ppss (syntax-ppss)))
- (when (eq t (nth 3 ppss))
- (let ((key (get-text-property (nth 8 ppss) 'hcl-here-doc-marker))
- (case-fold-search nil))
- (when (re-search-forward
- (concat "^\\(?:[ \t]*\\)" (regexp-quote key) "\\(\n\\)")
- end 'move)
- (let ((eol (match-beginning 1)))
- (put-text-property eol (1+ eol)
- 'syntax-table (string-to-syntax "|"))))))))
-
-(defun hcl--font-lock-open-heredoc (start string eol)
- (unless (or (memq (char-before start) '(?< ?>))
- (save-excursion
- (goto-char start)
- (hcl--in-string-or-comment-p)))
- (let ((str (replace-regexp-in-string "['\"]" "" string))
- (ppss (save-excursion (syntax-ppss eol))))
- (put-text-property eol (1+ eol) 'hcl-here-doc-marker str)
- (prog1 (string-to-syntax "|")
- (goto-char (+ 2 start))))))
-
-(defun hcl--syntax-propertize-function (start end)
- (goto-char start)
- (hcl--syntax-propertize-heredoc end)
- (funcall
- (syntax-propertize-rules
- (hcl--here-doc-beg-re
- (2 (hcl--font-lock-open-heredoc
- (match-beginning 0) (match-string 1) (match-beginning 2))))
- ("\\s|" (0 (prog1 nil (hcl--syntax-propertize-heredoc end)))))
- (point) end))
-
-(defvar hcl-mode-map
- (let ((map (make-sparse-keymap)))
- (define-key map (kbd "C-M-a") 'hcl-beginning-of-defun)
- (define-key map (kbd "C-M-e") 'hcl-end-of-defun)
- map)
- "Keymap for Hcl major mode.")
-
-;;;###autoload
-(define-derived-mode hcl-mode prog-mode "HCL"
- "Major mode for editing hcl configuration file"
-
- (setq font-lock-defaults '((hcl-font-lock-keywords)))
-
- (modify-syntax-entry ?_ "w" hcl-mode-syntax-table)
-
- ;;; Comments
- ;; Single line comment
- (modify-syntax-entry ?# "< b" hcl-mode-syntax-table)
- (modify-syntax-entry ?\n "> b" hcl-mode-syntax-table)
-
- ;; multiple line comment(/* ... */) taken from `go-mode'
- (modify-syntax-entry ?/ ". 124b" hcl-mode-syntax-table)
- (modify-syntax-entry ?* ". 23" hcl-mode-syntax-table)
-
- (setq-local comment-start "#")
- (setq-local comment-use-syntax t)
- (setq-local comment-start-skip "\\(//+\\|/\\*+\\)\\s *")
-
- ;; indentation
- (make-local-variable 'hcl-indent-level)
- (setq-local indent-line-function 'hcl-indent-line)
-
- (setq-local beginning-of-defun-function #'hcl-beginning-of-defun)
- (setq-local end-of-defun-function #'hcl-end-of-defun)
-
- (setq-local syntax-propertize-function #'hcl--syntax-propertize-function)
-
- ;; electric-mode
- (setq-local electric-indent-chars (append "{}[]" electric-indent-chars)))
-
-;;;###autoload
-(progn
- (add-to-list 'auto-mode-alist '("\\.hcl\\'" . hcl-mode))
- (add-to-list 'auto-mode-alist '("\\.nomad\\'" . hcl-mode)))
-
-(provide 'hcl-mode)
-
-;;; hcl-mode.el ends here
--- /dev/null
+;;; hcl-mode-autoloads.el --- automatically extracted autoloads -*- lexical-binding: t -*-
+;;
+;;; Code:
+
+(add-to-list 'load-path (directory-file-name
+ (or (file-name-directory #$) (car load-path))))
+
+\f
+;;;### (autoloads nil "hcl-mode" "hcl-mode.el" (0 0 0 0))
+;;; Generated autoloads from hcl-mode.el
+
+(autoload 'hcl-mode "hcl-mode" "\
+Major mode for editing hcl configuration file
+
+\(fn)" t nil)
+
+(add-to-list 'auto-mode-alist '("\\.hcl\\'" . hcl-mode))
+
+(add-to-list 'auto-mode-alist '("\\.nomad\\'" . hcl-mode))
+
+(register-definition-prefixes "hcl-mode" '("hcl-"))
+
+;;;***
+\f
+;; Local Variables:
+;; version-control: never
+;; no-byte-compile: t
+;; no-update-autoloads: t
+;; coding: utf-8
+;; End:
+;;; hcl-mode-autoloads.el ends here
--- /dev/null
+;;; Generated package description from hcl-mode.el -*- no-byte-compile: t -*-
+(define-package "hcl-mode" "20230302.1029" "Major mode for Hashicorp" '((emacs "24.3")) :commit "35784854efd29fa8c9fe827654d747a2ace5cb19" :authors '(("Syohei YOSHIDA" . "syohexNOSPAMgmail.com")) :maintainers '(("Steve Purcell" . "steveNOSPAMsanityinc.com")) :maintainer '("Steve Purcell" . "steveNOSPAMsanityinc.com") :url "https://github.com/purcell/emacs-hcl-mode")
--- /dev/null
+;;; hcl-mode.el --- Major mode for Hashicorp -*- lexical-binding: t -*-
+
+;; Copyright (C) 2017 by Syohei YOSHIDA
+;; Copyright (C) 2020 by Steve Purcell
+
+;; Author: Syohei YOSHIDA <syohexNOSPAMgmail.com>
+;; Maintainer: Steve Purcell <steveNOSPAMsanityinc.com>
+;; URL: https://github.com/purcell/emacs-hcl-mode
+;; Package-Version: 20230302.1029
+;; Package-Commit: 35784854efd29fa8c9fe827654d747a2ace5cb19
+;; Version: 0.03
+;; Package-Requires: ((emacs "24.3"))
+
+;; This program is free software; you can redistribute it and/or modify
+;; it under the terms of the GNU General Public License as published by
+;; the Free Software Foundation, either version 3 of the License, or
+;; (at your option) any later version.
+
+;; This program is distributed in the hope that it will be useful,
+;; but WITHOUT ANY WARRANTY; without even the implied warranty of
+;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+;; GNU General Public License for more details.
+
+;; You should have received a copy of the GNU General Public License
+;; along with this program. If not, see <http://www.gnu.org/licenses/>.
+
+;;; Commentary:
+
+;; hcl-mode provides a major-mode of hcl file.
+
+;;; Code:
+
+(require 'cl-lib)
+(require 'rx)
+
+(defgroup hcl nil
+ "Major mode for Hashicorp Configuration Language."
+ :group 'languages)
+
+(defcustom hcl-indent-level 2
+ "The tab width to use when indenting."
+ :type 'integer)
+
+(defconst hcl--block-regexp
+ "^\\s-*[^{]+{")
+
+;; String Interpolation(This regexp is taken from ruby-mode)
+(defconst hcl--string-interpolation-regexp
+ "\\${[^}\n\\\\]*\\(?:\\\\.[^}\n\\\\]*\\)*}")
+
+(defconst hcl--identifier-regexp
+ "\\_<\\(\\sw+\\(?:\\s_+\\sw+\\)*\\)\\_>")
+
+(defconst hcl--assignment-regexp
+ (concat hcl--identifier-regexp "\\s-*=\\(?:[^>=]\\)"))
+
+(defconst hcl--map-regexp
+ (concat hcl--identifier-regexp "\\s-*{"))
+
+(defconst hcl--boolean-regexp
+ (concat "\\(?:^\\|[^.]\\)"
+ (regexp-opt '("true" "false" "on" "off" "yes" "no")
+ 'words)))
+
+(defconst hcl-font-lock-keywords
+ `((,hcl--assignment-regexp 1 font-lock-variable-name-face)
+ (,hcl--boolean-regexp . font-lock-constant-face)
+ (,hcl--map-regexp 1 font-lock-type-face)
+ (hcl--string-interpolation-matcher 0 font-lock-variable-name-face t)))
+
+(defsubst hcl--paren-level ()
+ (car (syntax-ppss)))
+
+(defsubst hcl--in-string-or-comment-p ()
+ (nth 8 (syntax-ppss)))
+
+(cl-defun hcl--string-interpolation-matcher (lim)
+ (while (re-search-forward hcl--string-interpolation-regexp lim t)
+ (when (nth 3 (syntax-ppss))
+ (cl-return-from hcl--string-interpolation-matcher (point)))))
+
+(defun hcl--block-indentation ()
+ (let ((curline (line-number-at-pos)))
+ (save-excursion
+ (condition-case nil
+ (progn
+ (backward-up-list)
+ (unless (= curline (line-number-at-pos))
+ (current-indentation)))
+ (scan-error nil)))))
+
+(defun hcl--previous-indentation ()
+ (save-excursion
+ (forward-line -1)
+ (let (finish)
+ (while (not finish)
+ (cond ((bobp) (setq finish t))
+ ((hcl--in-string-or-comment-p) (forward-line -1))
+ (t
+ (let ((line (buffer-substring-no-properties
+ (line-beginning-position) (line-end-position))))
+ (if (not (string-match-p "\\`\\s-*\\'" line))
+ (setq finish t)
+ (forward-line -1))))))
+ (current-indentation))))
+
+(defun 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)))
+ (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)))))))
+
+(defun hcl-beginning-of-defun (&optional count)
+ (interactive "p")
+ (setq count (or count 1))
+ (let ((match 0)
+ finish)
+ (while (and (not finish)
+ (re-search-backward hcl--block-regexp nil t))
+ (unless (hcl--in-string-or-comment-p)
+ (cl-incf match)
+ (when (= match count)
+ (setq finish t))))))
+
+(defun hcl-end-of-defun (&optional count)
+ (interactive "p")
+ (setq count (or count 1))
+ (let ((paren-level (hcl--paren-level)))
+ (when (or (and (looking-at-p "}") (= paren-level 1))
+ (= paren-level 0))
+ (re-search-forward hcl--block-regexp nil t)))
+ (dotimes (_i count)
+ (when (looking-at-p hcl--block-regexp)
+ (goto-char (line-end-position)))
+ (hcl-beginning-of-defun 1)
+ (skip-chars-forward "^{")
+ (forward-char 1)
+ (let ((orig-level (hcl--paren-level)))
+ (while (and (>= (hcl--paren-level) orig-level)
+ (< (point) (point-max)))
+ (skip-chars-forward "^}")
+ (forward-line +1)))))
+
+(eval-and-compile
+ (defconst hcl--here-doc-beg-re
+ "[^<]<<-?\\s-*\\\\?\\(\\(?:['\"][^'\"]+['\"]\\|\\sw\\|[-/~._]\\)+\\)\\(\n\\)"))
+
+(defun hcl--syntax-propertize-heredoc (end)
+ (let ((ppss (syntax-ppss)))
+ (when (eq t (nth 3 ppss))
+ (let ((key (get-text-property (nth 8 ppss) 'hcl-here-doc-marker))
+ (case-fold-search nil))
+ (when (re-search-forward
+ (concat "^\\(?:[ \t]*\\)" (regexp-quote key) "\\(\n\\)")
+ end 'move)
+ (let ((eol (match-beginning 1)))
+ (put-text-property eol (1+ eol)
+ 'syntax-table (string-to-syntax "|"))))))))
+
+(defun hcl--font-lock-open-heredoc (start string eol)
+ (unless (or (memq (char-before start) '(?< ?>))
+ (save-excursion
+ (goto-char start)
+ (hcl--in-string-or-comment-p)))
+ (let ((str (replace-regexp-in-string "['\"]" "" string)))
+ (put-text-property eol (1+ eol) 'hcl-here-doc-marker str)
+ (prog1 (string-to-syntax "|")
+ (goto-char (+ 2 start))))))
+
+(defun hcl--syntax-propertize-function (start end)
+ (goto-char start)
+ (hcl--syntax-propertize-heredoc end)
+ (funcall
+ (syntax-propertize-rules
+ (hcl--here-doc-beg-re
+ (2 (hcl--font-lock-open-heredoc
+ (match-beginning 0) (match-string 1) (match-beginning 2))))
+ ("\\s|" (0 (prog1 nil (hcl--syntax-propertize-heredoc end)))))
+ (point) end))
+
+(defvar hcl-mode-map
+ (let ((map (make-sparse-keymap)))
+ (define-key map (kbd "C-M-a") 'hcl-beginning-of-defun)
+ (define-key map (kbd "C-M-e") 'hcl-end-of-defun)
+ map)
+ "Keymap for Hcl major mode.")
+
+(defconst hcl-mode-syntax-table
+ (let ((table (make-syntax-table)))
+ (prog1
+ table
+ (modify-syntax-entry ?_ "_" table)
+ (modify-syntax-entry ?- "_" table)
+ (modify-syntax-entry ?= "." table)
+
+ ;; Comments
+ ;; Single line comment
+ (modify-syntax-entry ?# "< b" table)
+ (modify-syntax-entry ?\n "> b" table)
+
+ ;; multiple line comment(/* ... */) taken from `go-mode'
+ (modify-syntax-entry ?/ ". 124b" table)
+ (modify-syntax-entry ?* ". 23" table)))
+ "Syntax table for `hcl-mode'.")
+
+;;;###autoload
+(define-derived-mode hcl-mode prog-mode "HCL"
+ "Major mode for editing hcl configuration file"
+
+ (setq font-lock-defaults '((hcl-font-lock-keywords)))
+
+ (setq-local comment-start "#")
+ (setq-local comment-use-syntax t)
+ (setq-local comment-start-skip "\\(//+\\|/\\*+\\)\\s *")
+
+ ;; indentation
+ (make-local-variable 'hcl-indent-level)
+ (setq-local indent-line-function 'hcl-indent-line)
+
+ (setq-local beginning-of-defun-function #'hcl-beginning-of-defun)
+ (setq-local end-of-defun-function #'hcl-end-of-defun)
+
+ (setq-local syntax-propertize-function #'hcl--syntax-propertize-function)
+
+ ;; electric-mode
+ (setq-local electric-indent-chars (append "{}[]" electric-indent-chars)))
+
+;;;###autoload
+(progn
+ (add-to-list 'auto-mode-alist '("\\.hcl\\'" . hcl-mode))
+ (add-to-list 'auto-mode-alist '("\\.nomad\\'" . hcl-mode)))
+
+(provide 'hcl-mode)
+
+;;; hcl-mode.el ends here
--- /dev/null
+;;; terraform-doc-autoloads.el --- automatically extracted autoloads -*- lexical-binding: t -*-
+;;
+;;; Code:
+
+(add-to-list 'load-path (directory-file-name
+ (or (file-name-directory #$) (car load-path))))
+
+\f
+;;;### (autoloads nil "terraform-doc" "terraform-doc.el" (0 0 0 0))
+;;; Generated autoloads from terraform-doc.el
+
+(autoload 'terraform-doc "terraform-doc" "\
+Look up PROVIDER.
+
+\(fn &optional PROVIDER)" t nil)
+
+(register-definition-prefixes "terraform-doc" '("terraform-doc-"))
+
+;;;***
+\f
+;; Local Variables:
+;; version-control: never
+;; no-byte-compile: t
+;; no-update-autoloads: t
+;; coding: utf-8
+;; End:
+;;; terraform-doc-autoloads.el ends here
--- /dev/null
+;;; Generated package description from terraform-doc.el -*- no-byte-compile: t -*-
+(define-package "terraform-doc" "20230521.849" "Look up terraform documentation on the fly" '((emacs "24.4")) :commit "8a6ffd5ac133ced5afd07b9d963272e4208f8b1e" :authors '(("Giap Tran" . "txgvnnNOSPAMgmail.com")) :maintainers '(("Giap Tran" . "txgvnnNOSPAMgmail.com")) :maintainer '("Giap Tran" . "txgvnnNOSPAMgmail.com") :keywords '("comm") :url "https://github.com/TxGVNN/terraform-doc")
--- /dev/null
+;;; terraform-doc.el --- Look up terraform documentation on the fly -*- lexical-binding: t -*-
+
+;; Copyright (C) 2019 Giap Tran <txgvnnNOSPAMgmail.com>
+
+;; Author: Giap Tran <txgvnnNOSPAMgmail.com>
+;; URL: https://github.com/TxGVNN/terraform-doc
+;; Package-Version: 20230521.849
+;; Package-Commit: 8a6ffd5ac133ced5afd07b9d963272e4208f8b1e
+;; Version: 1.2.0
+;; Package-Requires: ((emacs "24.4"))
+;; Keywords: comm
+
+;; This file is NOT part of GNU Emacs.
+
+;; This file is free software; you can redistribute it and/or modify
+;; it under the terms of the GNU General Public License as published by
+;; the Free Software Foundation; either version 3, or (at your option)
+;; any later version.
+
+;; This program is distributed in the hope that it will be useful,
+;; but WITHOUT ANY WARRANTY; without even the implied warranty of
+;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+;; GNU General Public License for more details.
+
+;; For a full copy of the GNU General Public License
+;; see <https://www.gnu.org/licenses/>.
+
+;;; Commentary:
+;; M-x terraform-doc
+
+;;; Code:
+
+(require 'shr)
+
+(defgroup terraform nil
+ "Major mode of `terraform-doc' file."
+ :group 'languages
+ :prefix "terraform-doc-")
+
+(defcustom terraform-doc-hook nil
+ "*Hook run by `terraform-doc'."
+ :type 'hook
+ :group 'terraform)
+
+(defcustom terraform-doc-name "Terraform-Doc"
+ "*Modeline of `terraform-doc'."
+ :type 'string
+ :group 'terraform)
+
+(defcustom terraform-doc-markdown-mode-function 'markdown-mode
+ "*Function to use for markdown rendering in `terraform-doc', e.g. `markdown-mode' or `gfm-view-mode'."
+ :type 'function
+ :group 'terraform)
+
+(defvar terraform-doc-mode-map
+ (let ((keymap (make-sparse-keymap)))
+ (define-key keymap (kbd "o") 'terraform-doc-at-point)
+ (define-key keymap (kbd "RET") 'terraform-doc-at-point)
+ (define-key keymap (kbd "<tab>") 'shr-next-link)
+ (define-key keymap (kbd "TAB") 'shr-next-link)
+ (define-key keymap (kbd "n") 'next-line)
+ (define-key keymap (kbd "p") 'previous-line)
+ keymap)
+ "Keymap for Terraform-Doc major mode.")
+
+
+(defvar terraform-doc-providers
+ '(("ACME" . "acme") ("Akamai" . "akamai") ("Alibaba Cloud" . "alicloud") ("Archive" . "archive") ("Arukas" . "arukas") ("Auth0" . "auth0") ("Avi Vantage" . "avi") ("Aviatrix"("Cisco ACI" . "aci") ("Cisco MSO" . "mso") ("CloudAMQP" . "cloudamqp") ("Cloudflare" . "cloudflare") ("Cloud-init" . "cloudinit") ("CloudScalech" . "cloudscale") ("CloudStack" . "cloudstack") ("Cobbler" . "cobbler") ("Cohesity" . "cohesity") ("Constellix" . "constellix") ("Consul" . "consul")
+ ("Datadog" . "datadog") ("DigitalOcean" . "do") ("DNS" . "dns") ("DNSimple" . "dnsimple") ("DNSMadeEasy" . "dme")&nb;hedvig") ("Helm" . "helm") ("Heroku" . "heroku") ("Hetzner Cloud" . "hcloud") ("HTTP" . "http") ("HuaweiCloud" . "huaweicloud") ("HuaweiCloudStack" . "huaweicloudstack") ("Icinga2" . "icinga2")
+ ("Ignition" . "ignition") ("Incapsula" . "incapsula") ("InfluxDB" . "influxdb") ("Infoblox" . "infoblox") ("JDCloud" . "jdcloud") ("KingsoftCloud" . "ksyun") ("Kubernetes" . "kubernetes") ("Lacework" . "lacework") ("LaunchDarkly"&n;Okta Advanced Server Access" . "oktaasa") ("OpenNebula" . "opennebula") ("OpenStack" . "openstack") ("OpenTelekomCloud" . "opentelekomcloud") ("OpsGenie" . "opsgenie")
+ ("Oracle Cloud Infrastructure" . "oci") ("Oracle Cloud Platform" . "oraclepaas") ("Oracle Public Cloud" . "opc") ("OVH" . "ovh") ("Packet" . "packet") ("PagerDuty" . "pagerduty") ("Palo Alto Networks PANOS" . "panos") ("Palo Alto Networks PrismaCloud" . "prismacloud") ("PostgreSQL" . "postgresql") ("PowerDNS" . "powerdns") ("ProfitBricks" . "profitbricks") ("Pureport" . "pureport") ("RabbitMQ" . "rabbitmq") ("Rancher" . "rancher") ("Rancher2" . "rancher2") ("RightScale" . "rightscale") ("Rubrik" . "rubrik") ("Rundeck" . "rundeck") ("RunScope" . "runscope") ("Scaleway" . "scaleway") ("Selectel" . "selectel") ("SignalFx" . "signalfx") ("Skytap" . "skytap")
+ ("SoftLayer" . "softlayer") ("venafi") ("VMware Cloud" . "vmc") ("VMware NSX-T" . "nsxt") ("VMware vCloud Director" . "vcd") ("VMware vRA7" . "vra7") ("VMware vSphere" . "vsphere") ("Vultr" . "vultr") ("Wavefront" . "wavefront") ("Yandex" . "yandex")))
+
+;;;###autoload
+(defun terraform-doc (&optional provider)
+ "Look up PROVIDER."
+ (interactive (list
+ (assoc (completing-read
+ "Provider: "
+ (mapcar (lambda (x) (car x)) terraform-doc-providers))
+ terraform-doc-providers)))
+ (if (member provider terraform-doc-providers)
+ (terraform-doc--render-tree (cdr provider) (format "*Terraform:%s*" (cdr provider)))
+ (message "%s" (propertize "Provider is not valid"))))
+
+(defun terraform-doc-at-point()
+ "Render url by 'terraform-doc--render-object."
+ (interactive)
+ (if (get-text-property (point) 'shr-url)
+ (let* ((url (get-text-property (point) 'shr-url))
+ (buffer-name (string-join (last (split-string url "/") 2) "/"))
+ (provider (replace-regexp-in-string ".*terraform-provider-\\(.+?\\)/.*" "\\1" url)))
+ (terraform-doc--render-object url (format "*Terraform:%s:%s*" provider buffer-name)))))
+
+(defun terraform-doc--render-tree (provider buffer-name)
+ "Render the PROVIDER and rename to BUFFER-NAME."
+ (if (get-buffer buffer-name)
+ (switch-to-buffer buffer-name)
+ (with-current-buffer (get-buffer-create buffer-name)
+ (insert (format "<a href=\"/terraform-providers/terraform-provider-%s/HEAD/website/docs/index.html.markdown\">Provider</a><br/>" provider))
+ (let ((content))
+ (dolist (url '("d" "r"))
+ (with-current-buffer
+ (url-retrieve-synchronously
+ (format "https://github.com/terraform-providers/terraform-provider-%s/file-list/HEAD/website/docs/%s" provider url))
+ (goto-char (point-min))
+ (search-forward-regexp "\n\n" )
+ (delete-region (point) (point-min))
+ (let* ((html-dom-tree (libxml-parse-html-region (point-min) (point-max)))
+ (dives (dom-elements html-dom-tree 'role "rowheader"))
+ (j 0) (div nil) (file nil) (url_type nil) (formatted_str nil))
+ (erase-buffer)
+ (while (< j (length dives))
+ (setq div (elt dives j))
+ (setq file (dom-by-class div "Link--primary"))
+ (unless (not file)
+ (setq url_type (if (string= "d" url) "data" "resource"))
+ (setq formatted_str (car (split-string (dom-text file) "\\.")))
+ (setcdr (cdr (car file)) (list (format "%s/%s" url_type formatted_str)))
+ (xml-print file)
+ (insert "<br/>"))
+ (setq j (+ j 1))))
+ (setq content (buffer-string)))
+ (insert content))
+ (goto-char (point-min))
+ (while (re-search-forward "href=\"" nil t)
+ (replace-match "href=\"https://raw.githubusercontent.com" nil nil))
+ (goto-char (point-min))
+ (while (re-search-forward "/blob" nil t)
+ (replace-match "" nil nil))
+ (shr-render-region (point-min) (point-max))
+ (terraform-doc-mode-on)
+ (switch-to-buffer (current-buffer))))))
+
+(defun terraform-doc--render-object (url buffer-name)
+ "Render the URL and rename to BUFFER-NAME."
+ (if (get-buffer buffer-name)
+ (switch-to-buffer buffer-name)
+ (url-retrieve
+ url
+ (lambda (arg)
+ (cond
+ ((equal :error (car arg))
+ (message arg))
+ (t
+ (goto-char (point-min))
+ (search-forward-regexp "\n\n" )
+ (delete-region (point) (point-min))
+ (rename-buffer buffer-name)
+ (if (fboundp terraform-doc-markdown-mode-function)
+ (funcall terraform-doc-markdown-mode-function))
+ (setq buffer-read-only t)
+ (switch-to-buffer (current-buffer))))))))
+
+(defun terraform-doc-mode-on ()
+ "Render and switch to ‘terraform-doc’ mode."
+ (goto-char (point-min))
+ (terraform-doc-mode))
+
+(define-derived-mode terraform-doc-mode special-mode terraform-doc-name
+ "Major mode for looking up terraform documentation on the fly."
+ (local-set-key [remap shr-browse-url] 'terraform-doc-at-point)
+ (setq buffer-auto-save-file-name nil
+ buffer-read-only t))
+
+(provide 'terraform-doc)
+;;; terraform-doc.el ends here
+++ /dev/null
-;;; terraform-mode-autoloads.el --- automatically extracted autoloads
-;;
-;;; Code:
-
-(add-to-list 'load-path (directory-file-name
- (or (file-name-directory #$) (car load-path))))
-
-\f
-;;;### (autoloads nil "terraform-mode" "terraform-mode.el" (0 0 0
-;;;;;; 0))
-;;; Generated autoloads from terraform-mode.el
-
-(autoload 'terraform-mode "terraform-mode" "\
-Major mode for editing terraform configuration file
-
-\(fn)" t nil)
-
-(add-to-list 'auto-mode-alist '("\\.tf\\(vars\\)?\\'" . terraform-mode))
-
-(if (fboundp 'register-definition-prefixes) (register-definition-prefixes "terraform-mode" '("terraform-")))
-
-;;;***
-\f
-;; Local Variables:
-;; version-control: never
-;; no-byte-compile: t
-;; no-update-autoloads: t
-;; coding: utf-8
-;; End:
-;;; terraform-mode-autoloads.el ends here
+++ /dev/null
-;;; -*- no-byte-compile: t -*-
-(define-package "terraform-mode" "20170112.517" "Major mode for terraform configuration file" '((emacs "24.3") (hcl-mode "0.3")) :commit "6973d1acaba2835dfdf174f5a5e27de6366002e1" :authors '(("Syohei YOSHIDA" . "syohexNOSPAMgmail.com")) :maintainer '("Syohei YOSHIDA" . "syohexNOSPAMgmail.com") :url "https://github.com/syohex/emacs-terraform-mode")
+++ /dev/null
-;;; terraform-mode.el --- Major mode for terraform configuration file -*- lexical-binding: t -*-
-
-;; Copyright (C) 2017 by Syohei YOSHIDA
-
-;; Author: Syohei YOSHIDA <syohexNOSPAMgmail.com>
-;; URL: https://github.com/syohex/emacs-terraform-mode
-;; Package-Version: 20170112.517
-;; Version: 0.06
-;; Package-Requires: ((emacs "24.3") (hcl-mode "0.03"))
-
-;; This program is free software; you can redistribute it and/or modify
-;; it under the terms of the GNU General Public License as published by
-;; the Free Software Foundation, either version 3 of the License, or
-;; (at your option) any later version.
-
-;; This program is distributed in the hope that it will be useful,
-;; but WITHOUT ANY WARRANTY; without even the implied warranty of
-;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-;; GNU General Public License for more details.
-
-;; You should have received a copy of the GNU General Public License
-;; along with this program. If not, see <http://www.gnu.org/licenses/>.
-
-;;; Commentary:
-
-;; Major mode of terraform configuration file. terraform-mode provides
-;; syntax highlighting, indentation function and formatting.
-
-;; Format the current buffer with terraform-format-buffer. To always
-;; format terraform buffers when saving, use:
-;; (add-hook 'terraform-mode-hook #'terraform-format-on-save-mode)
-
-;;; Code:
-
-(require 'cl-lib)
-(require 'rx)
-(require 'hcl-mode)
-
-(defgroup terraform nil
- "Major mode of Terraform configuration file."
- :group 'languages)
-
-(defcustom terraform-indent-level 2
- "The tab width to use when indenting."
- :type 'integer)
-
-(defconst terraform--block-regexp
- "^\\s-*\\(provider\\|resource\\|data\\|module\\|variable\\|output\\)\\s-+\"")
-
-(defconst terraform--atlas-regexp
- "^\\s-*\\(atlas\\)\\s-*")
-
-(defconst terraform--provisioner-regexp
- "^\\s-+\\(provisioner\\)\\s-+\"")
-
-(defconst terraform--inner-block-regexp
- "^\\s-+\\(connection\\)\\s-+{"
- "Inner special block.")
-
-(defvar terraform-font-lock-keywords
- `((,terraform--block-regexp 1 font-lock-function-name-face)
- (,terraform--atlas-regexp 1 font-lock-function-name-face)
- (,terraform--provisioner-regexp 1 font-lock-function-name-face)
- (,terraform--inner-block-regexp 1 font-lock-keyword-face)
- ,@hcl-font-lock-keywords))
-
-(defun terraform-format-buffer ()
- "Rewrite current buffer in a canonical format using terraform fmt."
- (interactive)
- (let ((buf (get-buffer-create "*terraform-fmt*")))
- (if (zerop (call-process-region (point-min) (point-max)
- "terraform" nil buf nil "fmt" "-"))
- (let ((point (point))
- (window-start (window-start)))
- (erase-buffer)
- (insert-buffer-substring buf)
- (goto-char point)
- (set-window-start nil window-start))
- (message "terraform fmt: %s" (with-current-buffer buf (buffer-string))))
- (kill-buffer buf)))
-
-(define-minor-mode terraform-format-on-save-mode
- "Run terraform-format-buffer before saving current buffer."
- :lighter ""
- (if terraform-format-on-save-mode
- (add-hook 'before-save-hook #'terraform-format-buffer nil t)
- (remove-hook 'before-save-hook #'terraform-format-buffer t)))
-
-;;;###autoload
-(define-derived-mode terraform-mode hcl-mode "Terraform"
- "Major mode for editing terraform configuration file"
-
- (setq font-lock-defaults '((terraform-font-lock-keywords)))
-
- ;; indentation
- (make-local-variable 'terraform-indent-level)
- (setq hcl-indent-level terraform-indent-level)
-
- ;; imenu
- (setq imenu-generic-expression
- '(("resource" "^resource\\s-+\"[^\"]+\"\\s-+\"\\([^\"]+\\)\"" 1)
- ("data" "^data\\s-+\"[^\"]+\"\\s-+\"\\([^\"]+\\)\"" 1)
- ("provider" "^provider\\s-+\"\\([^\"]+\\)\"" 1)
- ("module" "^module\\s-+\"\\([^\"]+\\)\"" 1)
- ("variable" "^variable\\s-+\"\\([^\"]+\\)\"" 1)
- ("output" "^output\\s-+\"\\([^\"]+\\)\"" 1)))
- (imenu-add-to-menubar "Index"))
-
-;;;###autoload
-(add-to-list 'auto-mode-alist '("\\.tf\\(vars\\)?\\'" . terraform-mode))
-
-(provide 'terraform-mode)
-
-;;; terraform-mode.el ends here
--- /dev/null
+;;; terraform-mode-autoloads.el --- automatically extracted autoloads -*- lexical-binding: t -*-
+;;
+;;; Code:
+
+(add-to-list 'load-path (directory-file-name
+ (or (file-name-directory #$) (car load-path))))
+
+\f
+;;;### (autoloads nil "terraform-mode" "terraform-mode.el" (0 0 0
+;;;;;; 0))
+;;; Generated autoloads from terraform-mode.el
+
+(autoload 'terraform-mode "terraform-mode" "\
+Major mode for editing terraform configuration file
+
+\(fn)" t nil)
+
+(add-to-list 'auto-mode-alist '("\\.tf\\(vars\\)?\\'" . terraform-mode))
+
+(register-definition-prefixes "terraform-mode" '("terraform-"))
+
+;;;***
+\f
+;; Local Variables:
+;; version-control: never
+;; no-byte-compile: t
+;; no-update-autoloads: t
+;; coding: utf-8
+;; End:
+;;; terraform-mode-autoloads.el ends here
--- /dev/null
+;;; Generated package description from terraform-mode.el -*- no-byte-compile: t -*-
+(define-package "terraform-mode" "20230502.2213" "Major mode for terraform configuration file" '((emacs "24.3") (hcl-mode "0.3") (dash "2.17.0")) :commit "56f19abae95afb7e13e48ec3e6aeba3820d31307" :authors '(("Syohei YOSHIDA" . "syohexNOSPAMgmail.com")) :maintainers '(("Syohei YOSHIDA" . "syohexNOSPAMgmail.com")) :maintainer '("Syohei YOSHIDA" . "syohexNOSPAMgmail.com") :url "https://github.com/syohex/emacs-terraform-mode")
--- /dev/null
+;;; terraform-mode.el --- Major mode for terraform configuration file -*- lexical-binding: t -*-
+
+;; Copyright (C) 2017 by Syohei YOSHIDA
+
+;; Author: Syohei YOSHIDA <syohexNOSPAMgmail.com>
+;; URL: https://github.com/syohex/emacs-terraform-mode
+;; Package-Version: 20230502.2213
+;; Package-Commit: 56f19abae95afb7e13e48ec3e6aeba3820d31307
+;; Version: 0.06
+;; Package-Requires: ((emacs "24.3") (hcl-mode "0.03") (dash "2.17.0"))
+
+;; This program is free software; you can redistribute it and/or modify
+;; it under the terms of the GNU General Public License as published by
+;; the Free Software Foundation, either version 3 of the License, or
+;; (at your option) any later version.
+
+;; This program is distributed in the hope that it will be useful,
+;; but WITHOUT ANY WARRANTY; without even the implied warranty of
+;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+;; GNU General Public License for more details.
+
+;; You should have received a copy of the GNU General Public License
+;; along with this program. If not, see <http://www.gnu.org/licenses/>.
+
+;;; Commentary:
+
+;; Major mode of terraform configuration file. terraform-mode provides
+;; syntax highlighting, indentation function and formatting.
+
+;; Format the current buffer with terraform-format-buffer. To always
+;; format terraform buffers when saving, use:
+;; (setq terraform-format-on-save t)
+
+;;; Code:
+
+(require 'cl-lib)
+(require 'rx)
+(require 'hcl-mode)
+(require 'dash)
+(require 'thingatpt)
+(require 'outline)
+
+(defgroup terraform nil
+ "Major mode of Terraform configuration file."
+ :group 'languages)
+
+(defcustom terraform-indent-level 2
+ "The tab width to use when indenting."
+ :type 'integer)
+
+(defcustom terraform-format-on-save nil
+ "Format buffer on save"
+ :type 'boolean
+ :group 'terraform-mode)
+
+(defface terraform-resource-type-face
+ '((t :inherit font-lock-type-face))
+ "Face for resource names."
+ :group 'terraform-mode)
+
+(define-obsolete-face-alias 'terraform--resource-type-face 'terraform-resource-type-face "1.0.0")
+
+(defface terraform-resource-name-face
+ '((t :inherit font-lock-function-name-face))
+ "Face for resource names."
+ :group 'terraform-mode)
+
+(define-obsolete-face-alias 'terraform--resource-name-face 'terraform-resource-name-face "1.0.0")
+
+(defface terraform-builtin-face
+ '((t :inherit font-lock-builtin-face))
+ "Face for builtins."
+ :group 'terraform-mode)
+
+(define-obsolete-face-alias 'terraform--builtin-face 'terraform-builtin-face "1.0.0")
+
+(defface terraform-variable-name-face
+ '((t :inherit font-lock-variable-name-face))
+ "Face for varriables."
+ :group 'terraform-mode)
+
+(defconst terraform--block-builtins-without-name-or-type-regexp
+ (rx line-start
+ (zero-or-more space)
+ (group-n 1 (or "terraform" "locals" "required_providers" "atlas" "connection"))
+ (or (one-or-more space) "{")))
+
+(defconst terraform--block-builtins-with-type-only
+ (rx (or "backend" "provider" "provisioner")))
+
+(defconst terraform--block-builtins-with-type-only--builtin-highlight-regexp
+ (eval `(rx line-start
+ (zero-or-more space)
+ (group-n 1 (regexp ,(eval terraform--block-builtins-with-type-only)))
+ (one-or-more space))))
+
+(defconst terraform--block-builtins-with-type-only--resource-type-highlight-regexp
+ (eval `(rx (regexp ,(eval terraform--block-builtins-with-type-only--builtin-highlight-regexp))
+ (group-n 2 (and (not (any "=")) (+? (not space))))
+ (or (one-or-more space) "{"))))
+
+(defconst terraform--block-builtins-with-name-only
+ (rx (or "variable" "module" "output")))
+
+(defconst terraform--block-builtins-with-name-only--builtin-highlight-regexp
+ (eval `(rx line-start
+ (zero-or-more space)
+ (group-n 1 (regexp ,(eval terraform--block-builtins-with-name-only)))
+ (one-or-more space))))
+
+(defconst terraform--block-builtins-with-name-only--name-highlight-regexp
+ (eval `(rx (regexp ,(eval terraform--block-builtins-with-name-only--builtin-highlight-regexp))
+ (group-n 2 (+? (not space)))
+ (or (one-or-more space) "{"))))
+
+(defconst terraform--block-builtins-with-type-and-name
+ (rx (or "data" "resource")))
+
+(defconst terraform--block-builtins-with-type-and-name--builtin-highlight-regexp
+ (eval `(rx line-start
+ (zero-or-more space)
+ (group-n 1 (regexp ,(eval terraform--block-builtins-with-type-and-name)))
+ (one-or-more space))))
+
+(defconst terraform--block-builtins-with-type-and-name--type-highlight-regexp
+ (eval `(rx (regexp ,(eval terraform--block-builtins-with-type-and-name--builtin-highlight-regexp))
+ (group-n 2 "\"" (+? (not space)) "\"")
+ (one-or-more space))))
+
+(defconst terraform--block-builtins-with-type-and-name--name-highlight-regexp
+ (eval `(rx (regexp ,(eval terraform--block-builtins-with-type-and-name--type-highlight-regexp))
+ (group-n 3 (+? (not space)))
+ (or (one-or-more space) "{"))))
+
+(defconst terraform--assignment-statement
+ (rx line-start
+ (zero-or-more space)
+ (group-n 1 (minimal-match (one-or-more any)))
+ (zero-or-more space)
+ "="))
+
+(defvar terraform-font-lock-keywords
+ `((,terraform--assignment-statement 1 'terraform-variable-name-face)
+ (,terraform--block-builtins-without-name-or-type-regexp 1 'terraform-builtin-face)
+ (,terraform--block-builtins-with-type-only--builtin-highlight-regexp 1 'terraform-builtin-face)
+ (,terraform--block-builtins-with-type-only--resource-type-highlight-regexp
+ (1 'terraform-builtin-face)
+ (2 'terraform-resource-type-face t))
+ (,terraform--block-builtins-with-name-only--builtin-highlight-regexp 1 'terraform-builtin-face)
+ (,terraform--block-builtins-with-name-only--name-highlight-regexp
+ (1 'terraform-builtin-face)
+ (2 'terraform-resource-name-face t))
+ (,terraform--block-builtins-with-type-and-name--builtin-highlight-regexp 1 'terraform-builtin-face)
+ (,terraform--block-builtins-with-type-and-name--type-highlight-regexp 2 'terraform-resource-type-face t)
+ (,terraform--block-builtins-with-type-and-name--name-highlight-regexp
+ (1 'terraform-builtin-face)
+ (2 'terraform-resource-type-face t)
+ (3 'terraform-resource-name-face t))
+ ,@hcl-font-lock-keywords))
+
+(defun terraform-format-buffer ()
+ "Rewrite current buffer in a canonical format using terraform fmt."
+ (interactive)
+ (let ((buf (get-buffer-create "*terraform-fmt*")))
+ (if (zerop (call-process-region (point-min) (point-max)
+ "terraform" nil buf nil "fmt" "-no-color" "-"))
+ (let ((point (point))
+ (window-start (window-start)))
+ (erase-buffer)
+ (insert-buffer-substring buf)
+ (when (/= terraform-indent-level 2)
+ (indent-region (point-min) (point-max)))
+ (goto-char point)
+ (set-window-start nil window-start))
+ (message "terraform fmt: %s" (with-current-buffer buf (buffer-string))))
+ (kill-buffer buf)))
+
+(defun terraform-format-region ()
+ "Rewrite current region in a canonical format using terraform fmt."
+ (interactive)
+ (let ((buf (get-buffer-create "*terraform-fmt*")))
+ (when (use-region-p)
+ (if (zerop (call-process-region (region-beginning) (region-end)
+ "terraform" nil buf nil "fmt" "-"))
+ (let ((point (region-end))
+ (window-start (region-beginning)))
+ (delete-region window-start point)
+ (insert-buffer-substring buf)
+ (goto-char point)
+ (set-window-start nil window-start))
+ (message "terraform fmt: %s" (with-current-buffer buf (buffer-string))))
+ (kill-buffer buf))))
+
+(define-minor-mode terraform-format-on-save-mode
+ "Run terraform-format-buffer before saving current buffer."
+ :lighter ""
+ (if terraform-format-on-save-mode
+ (add-hook 'before-save-hook #'terraform-format-buffer nil t)
+ (remove-hook 'before-save-hook #'terraform-format-buffer t)))
+
+(defun terraform--generate-imenu ()
+ (let ((search-results (make-hash-table :test #'equal))
+ (menu-list '()))
+ (save-match-data
+ (goto-char (point-min))
+ (while (re-search-forward terraform--block-builtins-with-type-only--resource-type-highlight-regexp nil t)
+ (let ((key (match-string 1))
+ (location (match-beginning 2))
+ (resource-type (replace-regexp-in-string "\"" "" (match-string 2))))
+ (-if-let (matches (gethash key search-results))
+ (puthash key (push `(,resource-type . ,location) matches) search-results)
+ (puthash key `((,resource-type . ,location)) search-results))))
+
+
+ (goto-char (point-min))
+ (while (re-search-forward terraform--block-builtins-with-name-only--name-highlight-regexp nil t)
+ (let ((key (match-string 1))
+ (location (match-beginning 2))
+ (resource-name (replace-regexp-in-string "\"" "" (match-string 2))))
+ (-if-let (matches (gethash key search-results))
+ (puthash key (push `(,resource-name . ,location) matches) search-results)
+ (puthash key `((,resource-name . ,location)) search-results))))
+
+ (goto-char (point-min))
+ (while (re-search-forward terraform--block-builtins-with-type-and-name--name-highlight-regexp nil t)
+ (let* ((key (match-string 1))
+ (location (match-beginning 2))
+ (type (match-string 2))
+ (name (match-string 3))
+ (resource-name (concat (replace-regexp-in-string "\"" "" type)
+ "/"
+ (replace-regexp-in-string "\"" "" name))))
+ (-if-let (matches (gethash key search-results))
+ (puthash key (push `(,resource-name . ,location) matches) search-results)
+ (puthash key `((,resource-name . ,location)) search-results))))
+
+ (maphash (lambda (k v) (push `(,k ,@v) menu-list)) search-results)
+ menu-list)))
+
+(defun terraform--extract-provider (resource-name)
+ "Return the provider associated with a RESOURCE-NAME."
+ (car (split-string resource-name "_")))
+
+(defun terraform--extract-resource (resource-name)
+ "Return the resource associated with a RESOURCE-NAME."
+ (mapconcat #'identity (cdr (split-string resource-name "_")) "_"))
+
+(defun terraform--get-resource-provider-namespace (provider)
+ "Return provider namespace for PROVIDER."
+ (let ((provider-info (shell-command-to-string "terraform providers")))
+ (with-temp-buffer
+ (insert provider-info)
+ (goto-char (point-min))
+ (when (re-search-forward (concat "/\\(.*?\\)/" provider "\\]") nil t)
+ (match-string 1)))))
+
+(defun terraform--resource-url (resource)
+ "Return the url containing the documentation for RESOURCE."
+ (let* ((provider (terraform--extract-provider resource))
+ (provider-ns (terraform--get-resource-provider-namespace provider))
+ (resource-name (terraform--extract-resource resource)))
+ (if provider-ns
+ (format "https://registry.terraform.io/providers/%s/%s/latest/docs/resources/%s"
+ provider-ns
+ provider
+ resource-name)
+ (user-error "Can not determine the provider namespace for %s" provider))))
+
+(defun terraform--resource-url-at-point ()
+ (save-excursion
+ (goto-char (line-beginning-position))
+ (unless (looking-at-p "^resource")
+ (re-search-backward "^resource" nil t))
+ (forward-symbol 2)
+ (terraform--resource-url (thing-at-point 'symbol))))
+
+(defun terraform-open-doc ()
+ "Open a browser at the URL documenting the resource at point."
+ (interactive)
+ (browse-url (terraform--resource-url-at-point)))
+
+(defun terraform--outline-level ()
+ "Return the depth to which a statement is nested in the outline.
+
+See also `outline-level'."
+ (or (cdr (assoc (match-string 1) outline-heading-alist))
+ (- (match-end 1) (match-beginning 1))))
+
+(defun terraform--setup-outline-mode ()
+ (set (make-local-variable 'outline-level) #'terraform--outline-level)
+
+ (let ((terraform-keywords
+ (list "terraform" "locals" "required_providers" "atlas" "connection"
+ "backend" "provider" "provisioner"
+ "variable" "module" "output"
+ "data" "resource")))
+ (set (make-local-variable 'outline-regexp)
+ (concat
+ "^"
+ (regexp-opt terraform-keywords 'symbols)
+ "[[:blank:]].*{[[:blank:]]*$"))
+ (set (make-local-variable 'outline-heading-alist)
+ (mapcar
+ (lambda (item) (cons item 2))
+ terraform-keywords))))
+
+(defun terraform-toggle-or-indent (&optional arg)
+ "Toggle visibility of block under point or indent.
+
+If the point is not at the heading, call
+`indent-for-tab-command'."
+ (interactive)
+ (if (and outline-minor-mode (outline-on-heading-p))
+ (outline-toggle-children)
+ (indent-for-tab-command arg)))
+
+(defvar terraform-mode-map
+ (let ((map (make-sparse-keymap)))
+ (define-key map (kbd "C-c C-h") #'terraform-open-doc)
+ (define-key map (kbd "C-c C-f") #'outline-toggle-children)
+ map))
+
+;;;###autoload
+(define-derived-mode terraform-mode hcl-mode "Terraform"
+ "Major mode for editing terraform configuration file"
+
+ (setq font-lock-defaults '((terraform-font-lock-keywords)))
+ (when terraform-format-on-save
+ (terraform-format-on-save-mode 1))
+
+ ;; indentation
+ (make-local-variable 'terraform-indent-level)
+ (setq hcl-indent-level terraform-indent-level)
+
+ ;; outline
+ (terraform--setup-outline-mode)
+
+ ;; imenu
+ (setq imenu-sort-function 'imenu--sort-by-name)
+ (setq imenu-create-index-function 'terraform--generate-imenu)
+ (imenu-add-to-menubar "Terraform"))
+
+;;;###autoload
+(add-to-list 'auto-mode-alist '("\\.tf\\(vars\\)?\\'" . terraform-mode))
+
+(provide 'terraform-mode)
+
+;;; terraform-mode.el ends here