branch: elpa/haskell-tng-mode commit e2e3490a0bc4d14c96b3bac4cea35a37e774065a Author: Tseen She <ts33n....@gmail.com> Commit: Tseen She <ts33n....@gmail.com>
hide-show supports BOILERPLATE START ... BOILERPLATE END --- haskell-tng-extra.el | 17 +++++++++++++++++ haskell-tng-mode.el | 20 ++++++++++++++++++++ 2 files changed, 37 insertions(+) diff --git a/haskell-tng-extra.el b/haskell-tng-extra.el index 4789b04..baa28bc 100644 --- a/haskell-tng-extra.el +++ b/haskell-tng-extra.el @@ -19,6 +19,7 @@ ;; hook in both `before-save-hook' (detecting that the file is new) and ;; `after-save-hook' (running the command and resetting the newfile var). +(require 'hideshow) (require 'subr-x) (require 'haskell-tng-util) @@ -117,6 +118,22 @@ When in a comment and called with a prefix, the comment will be completed." 'haskell-tng-stack2cabal)))) ;;;###autoload +(defvar-local haskell-tng-boilerplate nil + "A cache of the `boilerplate' binary as seen from this buffer.") +(defun haskell-tng-boilerplate () + "Apply `boilerplate' expansion rules." + (interactive) + (when (buffer-modified-p) + (save-buffer)) + (when (= 0 (call-process + (haskell-tng--util-cached-variable + (lambda () (haskell-tng--util-which "boilerplate")) + 'haskell-tng-boilerplate) + nil "*boilerplate*" nil "-i" buffer-file-name)) + (revert-buffer t t t) + (hs-hide-all))) + +;;;###autoload (defun haskell-tng-goto-imports () "Hack to jump to imports" ;; TODO is this useful? diff --git a/haskell-tng-mode.el b/haskell-tng-mode.el index d53abfc..60a584c 100644 --- a/haskell-tng-mode.el +++ b/haskell-tng-mode.el @@ -15,6 +15,7 @@ ;;; Code: (require 'dabbrev) +(require 'hideshow) (require 'imenu) (require 'rx) @@ -90,12 +91,31 @@ Load `prettify-symbols-mode' in `haskell-tng-mode-hook'." (haskell-tng--smie-setup) (prettify-symbols-mode 1) + (hs-minor-mode 1) + + (setq-local hs-hide-comments-when-hiding-all nil) + (unless noninteractive + (let ((inhibit-message t)) + (hs-hide-all))) ) ;;;###autoload (progn (add-to-list 'auto-mode-alist `(,(rx ".hs" eos) . haskell-tng-mode)) + (add-to-list 'hs-special-modes-alist + '(haskell-tng-mode + "{- BOILERPLATE START -}" + "{- BOILERPLATE END -}" + "-- " + haskell-tng--hs-forward)) (modify-coding-system-alist 'file (rx ".hs" eos) 'utf-8)) +(defun haskell-tng--hs-forward (&optional _arg _interactive) + "hide-show forward function that does what you'd expect" + (goto-char + (save-excursion + (re-search-forward hs-block-end-regexp nil t) + (point)))) + (provide 'haskell-tng-mode) ;;; haskell-tng-mode.el ends here