From a3a71977ad55c31867b9256c3da4bad39c67e830 Mon Sep 17 00:00:00 2001 From: Andreas Gerler Date: Mon, 5 Jun 2023 12:16:57 +0200 Subject: [PATCH] update terraform and hcl. add terraform-doc Signed-off-by: Andreas Gerler --- elpa/hcl-mode-20170107.827/hcl-mode-pkg.el | 2 - .../hcl-mode-autoloads.el | 4 +- elpa/hcl-mode-20230302.1029/hcl-mode-pkg.el | 2 + .../hcl-mode.el | 61 +-- .../terraform-doc-autoloads.el | 27 ++ .../terraform-doc-pkg.el | 2 + .../terraform-doc.el | 167 +++++++++ .../terraform-mode-pkg.el | 2 - .../terraform-mode.el | 114 ------ .../terraform-mode-autoloads.el | 4 +- .../terraform-mode-pkg.el | 2 + .../terraform-mode.el | 348 ++++++++++++++++++ 12 files changed, 592 insertions(+), 143 deletions(-) delete mode 100644 elpa/hcl-mode-20170107.827/hcl-mode-pkg.el rename elpa/{hcl-mode-20170107.827 => hcl-mode-20230302.1029}/hcl-mode-autoloads.el (79%) create mode 100644 elpa/hcl-mode-20230302.1029/hcl-mode-pkg.el rename elpa/{hcl-mode-20170107.827 => hcl-mode-20230302.1029}/hcl-mode.el (81%) create mode 100644 elpa/terraform-doc-20230521.849/terraform-doc-autoloads.el create mode 100644 elpa/terraform-doc-20230521.849/terraform-doc-pkg.el create mode 100644 elpa/terraform-doc-20230521.849/terraform-doc.el delete mode 100644 elpa/terraform-mode-20170112.517/terraform-mode-pkg.el delete mode 100644 elpa/terraform-mode-20170112.517/terraform-mode.el rename elpa/{terraform-mode-20170112.517 => terraform-mode-20230502.2213}/terraform-mode-autoloads.el (85%) create mode 100644 elpa/terraform-mode-20230502.2213/terraform-mode-pkg.el create mode 100644 elpa/terraform-mode-20230502.2213/terraform-mode.el diff --git a/elpa/hcl-mode-20170107.827/hcl-mode-pkg.el b/elpa/hcl-mode-20170107.827/hcl-mode-pkg.el deleted file mode 100644 index a9e446b3..00000000 --- a/elpa/hcl-mode-20170107.827/hcl-mode-pkg.el +++ /dev/null @@ -1,2 +0,0 @@ -;;; -*- no-byte-compile: t -*- -(define-package "hcl-mode" "20170107.827" "Major mode for Hashicorp" '((emacs "24.3")) :commit "0f2c5ec7e7bcf77c8548e8cac8721ea935ca1b5e" :authors '(("Syohei YOSHIDA" . "syohex@gmail.com")) :maintainer '("Syohei YOSHIDA" . "syohex@gmail.com") :url "https://github.com/syohex/emacs-hcl-mode") diff --git a/elpa/hcl-mode-20170107.827/hcl-mode-autoloads.el b/elpa/hcl-mode-20230302.1029/hcl-mode-autoloads.el similarity index 79% rename from elpa/hcl-mode-20170107.827/hcl-mode-autoloads.el rename to elpa/hcl-mode-20230302.1029/hcl-mode-autoloads.el index fc19b9e3..53a39f56 100644 --- a/elpa/hcl-mode-20170107.827/hcl-mode-autoloads.el +++ b/elpa/hcl-mode-20230302.1029/hcl-mode-autoloads.el @@ -1,4 +1,4 @@ -;;; hcl-mode-autoloads.el --- automatically extracted autoloads +;;; hcl-mode-autoloads.el --- automatically extracted autoloads -*- lexical-binding: t -*- ;; ;;; Code: @@ -18,7 +18,7 @@ Major mode for editing hcl configuration file (add-to-list 'auto-mode-alist '("\\.nomad\\'" . hcl-mode)) -(if (fboundp 'register-definition-prefixes) (register-definition-prefixes "hcl-mode" '("hcl-"))) +(register-definition-prefixes "hcl-mode" '("hcl-")) ;;;*** diff --git a/elpa/hcl-mode-20230302.1029/hcl-mode-pkg.el b/elpa/hcl-mode-20230302.1029/hcl-mode-pkg.el new file mode 100644 index 00000000..7a97bfd5 --- /dev/null +++ b/elpa/hcl-mode-20230302.1029/hcl-mode-pkg.el @@ -0,0 +1,2 @@ +;;; 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" . "syohex@gmail.com")) :maintainers '(("Steve Purcell" . "steve@sanityinc.com")) :maintainer '("Steve Purcell" . "steve@sanityinc.com") :url "https://github.com/purcell/emacs-hcl-mode") diff --git a/elpa/hcl-mode-20170107.827/hcl-mode.el b/elpa/hcl-mode-20230302.1029/hcl-mode.el similarity index 81% rename from elpa/hcl-mode-20170107.827/hcl-mode.el rename to elpa/hcl-mode-20230302.1029/hcl-mode.el index f6fc4918..31942dd2 100644 --- a/elpa/hcl-mode-20170107.827/hcl-mode.el +++ b/elpa/hcl-mode-20230302.1029/hcl-mode.el @@ -1,10 +1,13 @@ ;;; 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 -;; URL: https://github.com/syohex/emacs-hcl-mode -;; Package-Version: 20170107.827 +;; Maintainer: Steve Purcell +;; URL: https://github.com/purcell/emacs-hcl-mode +;; Package-Version: 20230302.1029 +;; Package-Commit: 35784854efd29fa8c9fe827654d747a2ace5cb19 ;; Version: 0.03 ;; Package-Requires: ((emacs "24.3")) @@ -31,7 +34,7 @@ (require 'rx) (defgroup hcl nil - "Major mode of Hashicorp Configuration Language." + "Major mode for Hashicorp Configuration Language." :group 'languages) (defcustom hcl-indent-level 2 @@ -45,22 +48,25 @@ (defconst hcl--string-interpolation-regexp "\\${[^}\n\\\\]*\\(?:\\\\.[^}\n\\\\]*\\)*}") +(defconst hcl--identifier-regexp + "\\_<\\(\\sw+\\(?:\\s_+\\sw+\\)*\\)\\_>") + (defconst hcl--assignment-regexp - "\\s-*\\([[:word:]]+\\)\\s-*=\\(?:[^>=]\\)") + (concat hcl--identifier-regexp "\\s-*=\\(?:[^>=]\\)")) (defconst hcl--map-regexp - "\\s-*\\([[:word:]]+\\)\\s-*{") + (concat hcl--identifier-regexp "\\s-*{")) (defconst hcl--boolean-regexp (concat "\\(?:^\\|[^.]\\)" (regexp-opt '("true" "false" "on" "off" "yes" "no") 'words))) -(defvar hcl-font-lock-keywords +(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-regexp 0 font-lock-variable-name-face t))) + (hcl--string-interpolation-matcher 0 font-lock-variable-name-face t))) (defsubst hcl--paren-level () (car (syntax-ppss))) @@ -68,6 +74,11 @@ (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 @@ -125,6 +136,7 @@ (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)) @@ -136,7 +148,8 @@ (skip-chars-forward "^{") (forward-char 1) (let ((orig-level (hcl--paren-level))) - (while (>= (hcl--paren-level) orig-level) + (while (and (>= (hcl--paren-level) orig-level) + (< (point) (point-max))) (skip-chars-forward "^}") (forward-line +1))))) @@ -161,8 +174,7 @@ (save-excursion (goto-char start) (hcl--in-string-or-comment-p))) - (let ((str (replace-regexp-in-string "['\"]" "" string)) - (ppss (save-excursion (syntax-ppss eol)))) + (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)))))) @@ -185,23 +197,30 @@ 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))) - (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 *") diff --git a/elpa/terraform-doc-20230521.849/terraform-doc-autoloads.el b/elpa/terraform-doc-20230521.849/terraform-doc-autoloads.el new file mode 100644 index 00000000..d0567054 --- /dev/null +++ b/elpa/terraform-doc-20230521.849/terraform-doc-autoloads.el @@ -0,0 +1,27 @@ +;;; 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)))) + + +;;;### (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-")) + +;;;*** + +;; Local Variables: +;; version-control: never +;; no-byte-compile: t +;; no-update-autoloads: t +;; coding: utf-8 +;; End: +;;; terraform-doc-autoloads.el ends here diff --git a/elpa/terraform-doc-20230521.849/terraform-doc-pkg.el b/elpa/terraform-doc-20230521.849/terraform-doc-pkg.el new file mode 100644 index 00000000..fa05dc69 --- /dev/null +++ b/elpa/terraform-doc-20230521.849/terraform-doc-pkg.el @@ -0,0 +1,2 @@ +;;; 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" . "txgvnn@gmail.com")) :maintainers '(("Giap Tran" . "txgvnn@gmail.com")) :maintainer '("Giap Tran" . "txgvnn@gmail.com") :keywords '("comm") :url "https://github.com/TxGVNN/terraform-doc") diff --git a/elpa/terraform-doc-20230521.849/terraform-doc.el b/elpa/terraform-doc-20230521.849/terraform-doc.el new file mode 100644 index 00000000..f0b505c0 --- /dev/null +++ b/elpa/terraform-doc-20230521.849/terraform-doc.el @@ -0,0 +1,167 @@ +;;; terraform-doc.el --- Look up terraform documentation on the fly -*- lexical-binding: t -*- + +;; Copyright (C) 2019 Giap Tran + +;; Author: Giap Tran +;; 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 . + +;;; 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 "") '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" . "aviatrix") ("AWS" . "aws") ("Azure" . "azurerm") ("Azure Active Directory" . "azuread") ("Azure DevOps" . "azuredevops") ("Azure Stack" . "azurestack") ("A10 Networks" . "vthunder") ("BaiduCloud" . "baiducloud") ("Bitbucket" . "bitbucket") ("Brightbox" . "brightbox") ("CenturyLinkCloud" . "clc") ("Check Point" . "checkpoint") ("Chef" . "chef") ("CherryServers" . "cherryservers") ("Circonus" . "circonus") ("Cisco ASA" . "ciscoasa") ("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") ("Docker" . "docker") ("Dome9" . "dome9") ("Dyn" . "dyn") ("EnterpriseCloud" . "ecl") ("Exoscale" . "exoscale") ("External" . "external") ("F5 BIG-IP" . "bigip") ("Fastly" . "fastly") ("FlexibleEngine" . "flexibleengine") ("FortiOS" . "fortios") ("Genymotion" . "genymotion") ("GitHub" . "github") ("GitLab" . "gitlab") ("Google Cloud Platform" . "google") ("Grafana" . "grafana") ("Gridscale" . "gridscale") ("Hedvig" . "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" . "launchdarkly") ("Librato" . "librato") ("Linode" . "linode") ("Local" . "local") ("Logentries" . "logentries") ("LogicMonitor" . "logicmonitor") ("Mailgun" . "mailgun") ("MetalCloud" . "metalcloud") ("MongoDB Atlas" . "mongodbatlas") ("MySQL" . "mysql") ("Naver Cloud" . "ncloud") ("Netlify" . "netlify") ("Nomad" . "nomad") ("NS1" . "ns1") ("Nutanix" . "nutanix") ("1 & 1" . "oneandone") ("Okta" . "okta") ("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") ("Spotinst" . "spotinst") ("StackPath" . "stackpath") ("StatusCake" . "statuscake") ("Sumo Logic" . "sumologic") ("TelefonicaOpenCloud" . "telefonicaopencloud") ("Template" . "template") ("TencentCloud" . "tencentcloud") ("Terraform" . "terraform") ("Terraform Cloud" . "tfe") ("Time" . "time") ("TLS" . "tls") ("Triton" . "triton") ("Turbot" . "turbot") ("UCloud" . "ucloud") ("UltraDNS" . "ultradns") ("Vault" . "vault") ("Venafi" . "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 "Provider
" 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 "
")) + (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 diff --git a/elpa/terraform-mode-20170112.517/terraform-mode-pkg.el b/elpa/terraform-mode-20170112.517/terraform-mode-pkg.el deleted file mode 100644 index 05899c2a..00000000 --- a/elpa/terraform-mode-20170112.517/terraform-mode-pkg.el +++ /dev/null @@ -1,2 +0,0 @@ -;;; -*- 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" . "syohex@gmail.com")) :maintainer '("Syohei YOSHIDA" . "syohex@gmail.com") :url "https://github.com/syohex/emacs-terraform-mode") diff --git a/elpa/terraform-mode-20170112.517/terraform-mode.el b/elpa/terraform-mode-20170112.517/terraform-mode.el deleted file mode 100644 index eedb596e..00000000 --- a/elpa/terraform-mode-20170112.517/terraform-mode.el +++ /dev/null @@ -1,114 +0,0 @@ -;;; terraform-mode.el --- Major mode for terraform configuration file -*- lexical-binding: t -*- - -;; Copyright (C) 2017 by Syohei YOSHIDA - -;; Author: Syohei YOSHIDA -;; 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 . - -;;; 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 diff --git a/elpa/terraform-mode-20170112.517/terraform-mode-autoloads.el b/elpa/terraform-mode-20230502.2213/terraform-mode-autoloads.el similarity index 85% rename from elpa/terraform-mode-20170112.517/terraform-mode-autoloads.el rename to elpa/terraform-mode-20230502.2213/terraform-mode-autoloads.el index 13c82755..419183f1 100644 --- a/elpa/terraform-mode-20170112.517/terraform-mode-autoloads.el +++ b/elpa/terraform-mode-20230502.2213/terraform-mode-autoloads.el @@ -1,4 +1,4 @@ -;;; terraform-mode-autoloads.el --- automatically extracted autoloads +;;; terraform-mode-autoloads.el --- automatically extracted autoloads -*- lexical-binding: t -*- ;; ;;; Code: @@ -17,7 +17,7 @@ Major mode for editing terraform configuration file (add-to-list 'auto-mode-alist '("\\.tf\\(vars\\)?\\'" . terraform-mode)) -(if (fboundp 'register-definition-prefixes) (register-definition-prefixes "terraform-mode" '("terraform-"))) +(register-definition-prefixes "terraform-mode" '("terraform-")) ;;;*** diff --git a/elpa/terraform-mode-20230502.2213/terraform-mode-pkg.el b/elpa/terraform-mode-20230502.2213/terraform-mode-pkg.el new file mode 100644 index 00000000..cc3d516c --- /dev/null +++ b/elpa/terraform-mode-20230502.2213/terraform-mode-pkg.el @@ -0,0 +1,2 @@ +;;; 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" . "syohex@gmail.com")) :maintainers '(("Syohei YOSHIDA" . "syohex@gmail.com")) :maintainer '("Syohei YOSHIDA" . "syohex@gmail.com") :url "https://github.com/syohex/emacs-terraform-mode") diff --git a/elpa/terraform-mode-20230502.2213/terraform-mode.el b/elpa/terraform-mode-20230502.2213/terraform-mode.el new file mode 100644 index 00000000..24ef8b8b --- /dev/null +++ b/elpa/terraform-mode-20230502.2213/terraform-mode.el @@ -0,0 +1,348 @@ +;;; terraform-mode.el --- Major mode for terraform configuration file -*- lexical-binding: t -*- + +;; Copyright (C) 2017 by Syohei YOSHIDA + +;; Author: Syohei YOSHIDA +;; 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 . + +;;; 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 -- 2.47.3