Inserting templates and sorting imports.

This commit is contained in:
Kazu Yamamoto 2010-04-13 23:29:48 +09:00
parent 5e5f995661
commit 51a533202a
2 changed files with 55 additions and 2 deletions

50
elisp/ghc-command.el Normal file
View File

@ -0,0 +1,50 @@
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;
;;; ghc-command.el
;;;
;; Author: Kazu Yamamoto <Kazu@Mew.org>
;; Created: Apr 13, 2010
;;; Code:
(provide 'ghc-flymake)
(defun ghc-insert-template ()
(interactive)
(cond
((bobp)
(ghc-insert-module-template))
((save-excursion
(beginning-of-line)
(looking-at "^[^ ]+ *::"))
(ghc-insert-function-template))
(t
(ghc-flymake-insert-type))))
(defun ghc-insert-module-template ()
;; xxx mod from filename...
(let ((mod (file-name-sans-extension (buffer-name))))
(insert "module " mod " where\n")))
(defun ghc-insert-function-template ()
(save-excursion
(beginning-of-line)
(when (looking-at "^\\([^ ]+\\) *::")
(forward-line)
(insert (match-string 1) " = undefined\n"))))
(defun ghc-sort-lines (beg end)
(interactive "r")
(save-excursion
(save-restriction
(narrow-to-region beg end)
(goto-char (point-min))
(let ((inhibit-field-text-motion t))
(sort-subr nil 'forward-line 'end-of-line
(lambda ()
(re-search-forward "^import\\( *qualified\\)? *" nil t)
nil)
'end-of-line)))))
(provide 'ghc-command)

View File

@ -24,6 +24,7 @@
(require 'ghc-comp) (require 'ghc-comp)
(require 'ghc-doc) (require 'ghc-doc)
(require 'ghc-flymake) (require 'ghc-flymake)
(require 'ghc-command)
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;; ;;;
@ -36,7 +37,8 @@
(defvar ghc-previous-key "\ep") (defvar ghc-previous-key "\ep")
(defvar ghc-next-key "\en") (defvar ghc-next-key "\en")
(defvar ghc-help-key "\e?") (defvar ghc-help-key "\e?")
(defvar ghc-insert-type-key "\et") (defvar ghc-insert-key "\et")
(defvar ghc-sort-key "\es")
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;; ;;;
@ -53,7 +55,8 @@
(define-key haskell-mode-map ghc-previous-key 'flymake-goto-prev-error) (define-key haskell-mode-map ghc-previous-key 'flymake-goto-prev-error)
(define-key haskell-mode-map ghc-next-key 'flymake-goto-next-error) (define-key haskell-mode-map ghc-next-key 'flymake-goto-next-error)
(define-key haskell-mode-map ghc-help-key 'ghc-display-errors) (define-key haskell-mode-map ghc-help-key 'ghc-display-errors)
(define-key haskell-mode-map ghc-insert-type-key 'ghc-flymake-insert-type) (define-key haskell-mode-map ghc-insert-key 'ghc-insert-template)
(define-key haskell-mode-map ghc-sort-key 'ghc-sort-lines)
(ghc-comp-init) (ghc-comp-init)
(setq ghc-initialized t))) (setq ghc-initialized t)))