2010-04-13 14:29:48 +00:00
|
|
|
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
|
|
|
;;;
|
|
|
|
;;; ghc-command.el
|
|
|
|
;;;
|
|
|
|
|
|
|
|
;; Author: Kazu Yamamoto <Kazu@Mew.org>
|
|
|
|
;; Created: Apr 13, 2010
|
|
|
|
|
|
|
|
;;; Code:
|
|
|
|
|
2014-03-25 06:23:08 +00:00
|
|
|
(require 'ghc-process)
|
2014-03-19 06:03:03 +00:00
|
|
|
(require 'ghc-check)
|
2010-04-13 14:29:48 +00:00
|
|
|
|
|
|
|
(defun ghc-insert-template ()
|
|
|
|
(interactive)
|
|
|
|
(cond
|
|
|
|
((bobp)
|
|
|
|
(ghc-insert-module-template))
|
2014-03-20 09:06:04 +00:00
|
|
|
((ghc-check-overlay-at (point))
|
|
|
|
(ghc-check-insert-from-warning))
|
2010-04-13 14:29:48 +00:00
|
|
|
(t
|
2010-05-04 03:14:33 +00:00
|
|
|
(message "Nothing to be done"))))
|
2010-04-13 14:29:48 +00:00
|
|
|
|
|
|
|
(defun ghc-insert-module-template ()
|
2014-03-25 06:23:08 +00:00
|
|
|
(let* ((fullname (file-name-sans-extension (buffer-file-name)))
|
|
|
|
(rootdir (ghc-get-project-root))
|
|
|
|
(len (length rootdir))
|
|
|
|
(name (substring fullname (1+ len)))
|
|
|
|
(file (file-name-sans-extension (buffer-name)))
|
|
|
|
(case-fold-search nil)
|
|
|
|
(mod (if (string-match "^[A-Z]" name)
|
|
|
|
(ghc-replace-character name ?/ ?.)
|
|
|
|
(if (string-match "^[a-z]" file)
|
|
|
|
"Main"
|
|
|
|
file))))
|
2010-04-13 14:29:48 +00:00
|
|
|
(insert "module " mod " where\n")))
|
|
|
|
|
2014-03-25 06:23:08 +00:00
|
|
|
;; (defun ghc-capitalize (str)
|
|
|
|
;; (let ((ret (copy-sequence str)))
|
|
|
|
;; (aset ret 0 (upcase (aref ret 0)))
|
|
|
|
;; ret))
|
|
|
|
|
2010-04-13 14:29:48 +00:00
|
|
|
(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)))))
|
|
|
|
|
2010-04-23 09:38:11 +00:00
|
|
|
(defun ghc-save-buffer ()
|
|
|
|
(interactive)
|
2014-03-20 07:21:48 +00:00
|
|
|
;; fixme: better way then saving?
|
|
|
|
(set-buffer-modified-p t)
|
|
|
|
(call-interactively 'save-buffer)
|
2014-03-19 06:03:03 +00:00
|
|
|
(ghc-check-syntax))
|
2010-04-23 09:38:11 +00:00
|
|
|
|
2010-04-13 14:29:48 +00:00
|
|
|
(provide 'ghc-command)
|