branch: elpa/haskell-tng-mode commit f7f0e0fa98088a434f09564ee9fd2cc98e1f312d Author: Tseen She <ts33n....@gmail.com> Commit: Tseen She <ts33n....@gmail.com>
moar extras --- README.md | 2 ++ haskell-tng-extra-cabal-mode.el | 21 +++++++++++++++ haskell-tng-extra-hideshow.el | 39 +++++++++++++++++++++++++++ haskell-tng-extra.el | 59 ++++++++++++++++++++++------------------- haskell-tng-hsinspect.el | 2 +- haskell-tng-mode.el | 20 -------------- 6 files changed, 95 insertions(+), 48 deletions(-) diff --git a/README.md b/README.md index 0acc1c7..acec808 100644 --- a/README.md +++ b/README.md @@ -48,10 +48,12 @@ A full installation may look like the following (require 'haskell-tng-hsinspect) (require 'haskell-tng-extra) (require 'haskell-tng-extra-abbrev) + (require 'haskell-tng-extra-hideshow) (require 'haskell-tng-extra-company) (require 'haskell-tng-extra-projectile) (require 'haskell-tng-extra-smartparens) (require 'haskell-tng-extra-yasnippet) + ;; (require 'haskell-tng-extra-cabal-mode) ;; (require 'haskell-tng-extra-stack) :bind diff --git a/haskell-tng-extra-cabal-mode.el b/haskell-tng-extra-cabal-mode.el new file mode 100644 index 0000000..c0724ab --- /dev/null +++ b/haskell-tng-extra-cabal-mode.el @@ -0,0 +1,21 @@ +;;; haskell-tng-extra-cabal-mode.el --- a basic cabal-mode -*- lexical-binding: t -*- + +;; Copyright (C) 2020 Tseen She +;; License: GPL 3 or any later version + +;;; Commentary: +;; +;; A basic cabal-mode +;; +;;; Code: + +(define-derived-mode cabal-tng-mode fundamental-mode "Cabal" + "Major mode for editing Cabal configuration." + (setq-local compile-command (format "cabal-fmt -i %s" buffer-file-name))) + +(progn + (add-to-list 'auto-mode-alist `(,(rx ".cabal" eos) . cabal-tng-mode)) + (modify-coding-system-alist 'file (rx ".cabal" eos) 'utf-8)) + +(provide 'haskell-tng-extra-cabal-mode) +;;; haskell-tng-extra-cabal-mode.el ends here diff --git a/haskell-tng-extra-hideshow.el b/haskell-tng-extra-hideshow.el new file mode 100644 index 0000000..a9615d0 --- /dev/null +++ b/haskell-tng-extra-hideshow.el @@ -0,0 +1,39 @@ +;;; haskell-tng-extra-hideshow.el --- hideshow-mode integration -*- lexical-binding: t -*- + +;; Copyright (C) 2020 Tseen She +;; License: GPL 3 or any later version + +;;; Commentary: +;; +;; Hide and show BOILERPLATE blocks. +;; +;;; Code: + +(require 'hideshow) +(require 'haskell-tng-mode) + +(add-hook + 'haskell-tng-mode-hook + (lambda () + (hs-minor-mode 1) + (setq-local hs-hide-comments-when-hiding-all nil) + (let ((inhibit-message t)) + (hs-hide-all)))) + +(add-to-list + 'hs-special-modes-alist + '(haskell-tng-mode + "{- BOILERPLATE START -}" + "{- BOILERPLATE END -}" + "-- " + haskell-tng--extra-hideshow-forward)) + +(defun haskell-tng--extra-hideshow-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-extra-hideshow) +;;; haskell-tng-extra-hideshow.el ends here diff --git a/haskell-tng-extra.el b/haskell-tng-extra.el index baa28bc..d648846 100644 --- a/haskell-tng-extra.el +++ b/haskell-tng-extra.el @@ -75,11 +75,12 @@ When in a comment and called with a prefix, the comment will be completed." (interactive) (when (buffer-modified-p) (save-buffer)) - (when (= 0 (call-process - (haskell-tng--util-cached-variable - (lambda () (haskell-tng--util-which "stylish-haskell")) - 'haskell-tng-stylish-haskell) - nil "*stylish-haskell*" nil "-i" buffer-file-name)) + (if (/= 0 (call-process + (haskell-tng--util-cached-variable + (lambda () (haskell-tng--util-which "stylish-haskell")) + 'haskell-tng-stylish-haskell) + nil "*stylish-haskell*" nil "-i" buffer-file-name)) + (user-error "stylish-haskell formatting failed") (revert-buffer t t t))) ;;;###autoload @@ -91,17 +92,18 @@ When in a comment and called with a prefix, the comment will be completed." (interactive) (when (buffer-modified-p) (save-buffer)) - (when (= 0 (call-process - (haskell-tng--util-cached-variable - (lambda () (haskell-tng--util-which "ormolu")) - 'haskell-tng-ormolu) - nil "*ormolu*" nil - ;; "-p" - "-o" "-XTypeApplications" - "-o" "-XBangPatterns" - "-o" "-XPatternSynonyms" - "-m" "inplace" - buffer-file-name)) + (if (/= 0 (call-process + (haskell-tng--util-cached-variable + (lambda () (haskell-tng--util-which "ormolu")) + 'haskell-tng-ormolu) + nil "*ormolu*" nil + ;; "-p" + "-o" "-XTypeApplications" + "-o" "-XBangPatterns" + "-o" "-XPatternSynonyms" + "-m" "inplace" + buffer-file-name)) + (user-error "ormolu formatting failed") (revert-buffer t t t))) ;;;###autoload @@ -112,10 +114,11 @@ When in a comment and called with a prefix, the comment will be completed." (interactive) (when-let (default-directory (locate-dominating-file default-directory "stack.yaml")) - (call-process - (haskell-tng--util-cached-variable - (lambda () (haskell-tng--util-which "stack2cabal")) - 'haskell-tng-stack2cabal)))) + (when (/= 0 (call-process + (haskell-tng--util-cached-variable + (lambda () (haskell-tng--util-which "stack2cabal")) + 'haskell-tng-stack2cabal))) + (user-error "stack2cabal failed")))) ;;;###autoload (defvar-local haskell-tng-boilerplate nil @@ -125,13 +128,15 @@ When in a comment and called with a prefix, the comment will be completed." (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)) + (if (/= 0 (call-process + (haskell-tng--util-cached-variable + (lambda () (haskell-tng--util-which "boilerplate")) + 'haskell-tng-boilerplate) + nil "*boilerplate*" nil "-i" buffer-file-name)) + (user-error "boilerplate generation failed") (revert-buffer t t t) - (hs-hide-all))) + (when hs-minor-mode + (hs-hide-all)))) ;;;###autoload (defun haskell-tng-goto-imports () @@ -169,7 +174,7 @@ When in a comment and called with a prefix, the comment will be completed." (reverse (seq-take-while (lambda (e) (let (case-fold-search) - (string-match-p (rx bos upper) e))) + (string-match-p (rx bos upper) e))) (reverse (split-string (file-name-sans-extension buffer-file-name) diff --git a/haskell-tng-hsinspect.el b/haskell-tng-hsinspect.el index ac9f645..6f888e6 100644 --- a/haskell-tng-hsinspect.el +++ b/haskell-tng-hsinspect.el @@ -503,7 +503,7 @@ Does not persist the cache changes to disk." "Finds and checks the hsinspect binary for the current buffer. This is uncached, prefer `haskell-tng--hsinspect-exe'." - (let ((supported '("0.0.7" "0.0.8" "0.0.9" "0.0.10" "0.0.11" "0.0.12" "0.0.13" "0.0.14")) + (let ((supported '("0.0.7" "0.0.8" "0.0.9" "0.0.10" "0.0.11" "0.0.12" "0.0.13" "0.0.14" "0.0.15")) (bin (haskell-tng--util-ghcpath-which "hsinspect"))) (if bin (let ((version diff --git a/haskell-tng-mode.el b/haskell-tng-mode.el index 60a584c..d53abfc 100644 --- a/haskell-tng-mode.el +++ b/haskell-tng-mode.el @@ -15,7 +15,6 @@ ;;; Code: (require 'dabbrev) -(require 'hideshow) (require 'imenu) (require 'rx) @@ -91,31 +90,12 @@ 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