ghc-command.el 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  2. ;;;
  3. ;;; ghc-command.el
  4. ;;;
  5. ;; Author: Kazu Yamamoto <Kazu@Mew.org>
  6. ;; Created: Apr 13, 2010
  7. ;;; Code:
  8. (require 'ghc-flymake)
  9. (defun ghc-insert-template ()
  10. (interactive)
  11. (cond
  12. ((bobp)
  13. (ghc-insert-module-template))
  14. ((ghc-flymake-have-errs-p)
  15. (ghc-flymake-insert-from-warning))
  16. (t
  17. (message "Nothing to be done"))))
  18. (defun ghc-insert-module-template ()
  19. (let ((mod (file-name-sans-extension (buffer-name))))
  20. (aset mod 0 (upcase (aref mod 0)))
  21. (insert "module " mod " where\n")))
  22. (defun ghc-sort-lines (beg end)
  23. (interactive "r")
  24. (save-excursion
  25. (save-restriction
  26. (narrow-to-region beg end)
  27. (goto-char (point-min))
  28. (let ((inhibit-field-text-motion t))
  29. (sort-subr nil 'forward-line 'end-of-line
  30. (lambda ()
  31. (re-search-forward "^import\\( *qualified\\)? *" nil t)
  32. nil)
  33. 'end-of-line)))))
  34. (defun ghc-save-buffer ()
  35. (interactive)
  36. (if (buffer-modified-p)
  37. (call-interactively 'save-buffer)
  38. (flymake-start-syntax-check)))
  39. (provide 'ghc-command)