From 51a533202a7066001bf19f158ad05694fc8837b0 Mon Sep 17 00:00:00 2001 From: Kazu Yamamoto Date: Tue, 13 Apr 2010 23:29:48 +0900 Subject: [PATCH] Inserting templates and sorting imports. --- elisp/ghc-command.el | 50 ++++++++++++++++++++++++++++++++++++++++++++ elisp/ghc.el | 7 +++++-- 2 files changed, 55 insertions(+), 2 deletions(-) create mode 100644 elisp/ghc-command.el diff --git a/elisp/ghc-command.el b/elisp/ghc-command.el new file mode 100644 index 0000000..233342c --- /dev/null +++ b/elisp/ghc-command.el @@ -0,0 +1,50 @@ +;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; +;;; +;;; ghc-command.el +;;; + +;; Author: Kazu Yamamoto +;; 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) diff --git a/elisp/ghc.el b/elisp/ghc.el index f256728..abfd0cc 100644 --- a/elisp/ghc.el +++ b/elisp/ghc.el @@ -24,6 +24,7 @@ (require 'ghc-comp) (require 'ghc-doc) (require 'ghc-flymake) +(require 'ghc-command) ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;; @@ -36,7 +37,8 @@ (defvar ghc-previous-key "\ep") (defvar ghc-next-key "\en") (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-next-key 'flymake-goto-next-error) (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) (setq ghc-initialized t)))