Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Provide folding of blocks #20

Closed
chrislong opened this issue Jun 21, 2018 · 2 comments
Closed

Provide folding of blocks #20

chrislong opened this issue Jun 21, 2018 · 2 comments

Comments

@chrislong
Copy link

It would be great to hide/show blocks of a terraform file with something like folding mode or outline mode. I put together some code to make it work with outline-minor-mode. Feel free to adapt it, etc.

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; Allow simple visibility toggling in outline mode with TAB
;;

(defun my-outline-toggle-or-indent (&optional ARG)
  (interactive)
  (if (outline-on-heading-p)
	  (outline-toggle-children)
	(indent-for-tab-command ARG)
	)
  )

(define-key outline-minor-mode-map "\C-i" 'my-outline-toggle-or-indent)

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; set outline headings for terraform mode
;;

(defun my-terraform-mode-hook ()
  (make-local-variable 'outline-regexp)
  (setq outline-regexp
		(concat
		 (mapconcat (lambda (item)
					  (and (car item) (format "\\(%s\\)" (regexp-quote (car item))))
					  )
					imenu-generic-expression
					"\\|")
		 "[[:blank:]].*{[[:blank:]]*$")
		)
  (setq outline-heading-alist
		(mapcar (lambda (item)
				  (cons (car item) 2)
				  )
				imenu-generic-expression)
		)
  (outline-minor-mode 1)
  )

	   
(add-hook 'terraform-mode-hook 'my-terraform-mode-hook)
@jtoss
Copy link

jtoss commented Oct 7, 2022

Another option is to use yafolding mode from https://github.com/zenozeng/yafolding.el, I found it works pretty well with indented files.

@Fuco1 Fuco1 closed this as completed in 7b1e482 Mar 1, 2023
@Fuco1
Copy link
Collaborator

Fuco1 commented Mar 1, 2023

I took the code from OP and cleaned it up a bit and included automatic setup for outline mode.

You still have to manually enable outline-minor-mode somewhere in your config in terraform-mode. Then you can use C-c C-f to fold blocks.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants