2012-06-13 04:56:39 +00:00
|
|
|
;;; ghc.el --- ghc-mod front-end for haskell-mode
|
2010-01-06 05:38:06 +00:00
|
|
|
|
|
|
|
;; Author: Kazu Yamamoto <Kazu@Mew.org>
|
|
|
|
;; Created: Sep 25, 2009
|
2010-02-19 14:43:03 +00:00
|
|
|
;; Revised:
|
2010-01-06 05:38:06 +00:00
|
|
|
|
|
|
|
;; Put the following code to your "~/.emacs".
|
|
|
|
;;
|
|
|
|
;; (autoload 'ghc-init "ghc" nil t)
|
2014-04-25 05:31:09 +00:00
|
|
|
;; (autoload 'ghc-debug "ghc" nil t)
|
2010-01-06 05:38:06 +00:00
|
|
|
;; (add-hook 'haskell-mode-hook (lambda () (ghc-init)))
|
2014-04-04 14:52:09 +00:00
|
|
|
;;
|
2014-04-05 00:53:28 +00:00
|
|
|
;; Or if you wish to display error each goto next/prev error,
|
|
|
|
;; set ghc-display-error valiable.
|
2014-04-04 14:52:09 +00:00
|
|
|
;;
|
2014-04-05 00:53:28 +00:00
|
|
|
;; (setq ghc-display-error 'minibuffer) ; to minibuffer
|
|
|
|
;; ; (setq ghc-display-error 'other-buffer) ; to other-buffer
|
2014-04-04 14:52:09 +00:00
|
|
|
|
|
|
|
;;
|
2010-01-06 05:38:06 +00:00
|
|
|
|
|
|
|
;;; Code:
|
|
|
|
|
2014-04-30 23:19:23 +00:00
|
|
|
;; defvar-local was introduced in 24.3
|
|
|
|
(let* ((major 24)
|
|
|
|
(minor 3))
|
|
|
|
(if (or (< emacs-major-version major)
|
|
|
|
(and (= emacs-major-version major)
|
|
|
|
(< emacs-minor-version minor)))
|
|
|
|
(error "ghc-mod requires at least Emacs %d.%d" major minor)))
|
|
|
|
|
2014-07-15 02:54:39 +00:00
|
|
|
(defconst ghc-version "5.0.0")
|
2010-03-11 10:03:17 +00:00
|
|
|
|
|
|
|
;; (eval-when-compile
|
|
|
|
;; (require 'haskell-mode))
|
2010-01-06 05:38:06 +00:00
|
|
|
|
|
|
|
(require 'ghc-comp)
|
|
|
|
(require 'ghc-doc)
|
2010-11-15 03:46:55 +00:00
|
|
|
(require 'ghc-info)
|
2014-03-19 06:03:03 +00:00
|
|
|
(require 'ghc-check)
|
2010-04-13 14:29:48 +00:00
|
|
|
(require 'ghc-command)
|
2011-12-27 07:28:02 +00:00
|
|
|
(require 'ghc-ins-mod)
|
2012-02-28 11:38:50 +00:00
|
|
|
(require 'ghc-indent)
|
2014-06-17 16:15:36 +00:00
|
|
|
(require 'ghc-rewrite)
|
2010-04-23 09:37:48 +00:00
|
|
|
(require 'dabbrev)
|
2010-01-06 05:38:06 +00:00
|
|
|
|
|
|
|
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
|
|
|
;;;
|
|
|
|
;;; Customize Variables
|
|
|
|
;;;
|
|
|
|
|
2011-10-05 01:40:31 +00:00
|
|
|
(defun ghc-find-C-h ()
|
2013-10-12 17:49:18 +00:00
|
|
|
(or
|
|
|
|
(when keyboard-translate-table
|
|
|
|
(aref keyboard-translate-table ?\C-h))
|
|
|
|
?\C-h))
|
2011-10-05 01:40:31 +00:00
|
|
|
|
2010-03-14 13:39:45 +00:00
|
|
|
(defvar ghc-completion-key "\e\t")
|
|
|
|
(defvar ghc-document-key "\e\C-d")
|
|
|
|
(defvar ghc-import-key "\e\C-m")
|
|
|
|
(defvar ghc-previous-key "\ep")
|
|
|
|
(defvar ghc-next-key "\en")
|
|
|
|
(defvar ghc-help-key "\e?")
|
2010-04-13 14:29:48 +00:00
|
|
|
(defvar ghc-insert-key "\et")
|
|
|
|
(defvar ghc-sort-key "\es")
|
2010-11-18 07:42:19 +00:00
|
|
|
(defvar ghc-type-key "\C-c\C-t")
|
|
|
|
(defvar ghc-info-key "\C-c\C-i")
|
2010-05-06 06:29:55 +00:00
|
|
|
(defvar ghc-toggle-key "\C-c\C-c")
|
2014-03-31 05:58:41 +00:00
|
|
|
(defvar ghc-jump-key "\C-c\C-j")
|
2011-12-27 07:28:02 +00:00
|
|
|
(defvar ghc-module-key "\C-c\C-m")
|
2012-02-27 03:53:33 +00:00
|
|
|
(defvar ghc-expand-key "\C-c\C-e")
|
2014-03-30 02:54:17 +00:00
|
|
|
(defvar ghc-kill-key "\C-c\C-k")
|
2011-10-05 01:40:31 +00:00
|
|
|
(defvar ghc-hoogle-key (format "\C-c%c" (ghc-find-C-h)))
|
2012-02-28 11:38:50 +00:00
|
|
|
(defvar ghc-shallower-key "\C-c<")
|
|
|
|
(defvar ghc-deeper-key "\C-c>")
|
2014-08-12 20:44:11 +00:00
|
|
|
;(defvar ghc-case-split-key "\C-c\C-s")
|
2014-08-05 07:05:19 +00:00
|
|
|
(defvar ghc-refine-key "\C-c\C-f")
|
2014-08-02 07:52:36 +00:00
|
|
|
(defvar ghc-auto-key "\C-c\C-a")
|
2014-07-27 09:10:37 +00:00
|
|
|
(defvar ghc-prev-hole-key "\C-c\ep")
|
|
|
|
(defvar ghc-next-hole-key "\C-c\en")
|
2010-01-06 05:38:06 +00:00
|
|
|
|
|
|
|
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
|
|
|
;;;
|
|
|
|
;;; Initializer
|
|
|
|
;;;
|
|
|
|
|
|
|
|
(defvar ghc-initialized nil)
|
|
|
|
|
2012-02-18 17:23:41 +00:00
|
|
|
;;;###autoload
|
2010-01-06 05:38:06 +00:00
|
|
|
(defun ghc-init ()
|
2010-04-23 09:21:22 +00:00
|
|
|
(ghc-abbrev-init)
|
2012-02-13 04:23:04 +00:00
|
|
|
(ghc-type-init)
|
2010-01-06 05:38:06 +00:00
|
|
|
(unless ghc-initialized
|
2010-03-14 13:39:45 +00:00
|
|
|
(define-key haskell-mode-map ghc-completion-key 'ghc-complete)
|
|
|
|
(define-key haskell-mode-map ghc-document-key 'ghc-browse-document)
|
2010-11-15 03:46:55 +00:00
|
|
|
(define-key haskell-mode-map ghc-type-key 'ghc-show-type)
|
2010-11-15 05:46:59 +00:00
|
|
|
(define-key haskell-mode-map ghc-info-key 'ghc-show-info)
|
2012-02-27 03:53:33 +00:00
|
|
|
(define-key haskell-mode-map ghc-expand-key 'ghc-expand-th)
|
2010-05-04 08:52:16 +00:00
|
|
|
(define-key haskell-mode-map ghc-import-key 'ghc-import-module)
|
2014-04-05 00:53:28 +00:00
|
|
|
(define-key haskell-mode-map ghc-previous-key 'ghc-goto-prev-error)
|
|
|
|
(define-key haskell-mode-map ghc-next-key 'ghc-goto-next-error)
|
2014-03-20 06:32:54 +00:00
|
|
|
(define-key haskell-mode-map ghc-help-key 'ghc-display-errors)
|
2014-08-26 00:19:17 +00:00
|
|
|
(define-key haskell-mode-map ghc-insert-key 'ghc-insert-template-or-signature)
|
2010-04-13 14:29:48 +00:00
|
|
|
(define-key haskell-mode-map ghc-sort-key 'ghc-sort-lines)
|
2014-03-27 01:35:09 +00:00
|
|
|
(define-key haskell-mode-map ghc-toggle-key 'ghc-toggle-check-command)
|
2014-03-31 05:58:41 +00:00
|
|
|
(define-key haskell-mode-map ghc-jump-key 'ghc-jump-file)
|
2011-12-27 07:28:02 +00:00
|
|
|
(define-key haskell-mode-map ghc-module-key 'ghc-insert-module)
|
2014-03-30 02:54:17 +00:00
|
|
|
(define-key haskell-mode-map ghc-kill-key 'ghc-kill-process)
|
2011-10-05 01:40:31 +00:00
|
|
|
(define-key haskell-mode-map ghc-hoogle-key 'haskell-hoogle)
|
2012-02-28 11:38:50 +00:00
|
|
|
(define-key haskell-mode-map ghc-shallower-key 'ghc-make-indent-shallower)
|
|
|
|
(define-key haskell-mode-map ghc-deeper-key 'ghc-make-indent-deeper)
|
2014-08-12 20:44:11 +00:00
|
|
|
;(define-key haskell-mode-map ghc-case-split-key 'ghc-case-split)
|
2014-07-20 08:45:01 +00:00
|
|
|
(define-key haskell-mode-map ghc-refine-key 'ghc-refine)
|
2014-08-02 07:52:36 +00:00
|
|
|
(define-key haskell-mode-map ghc-auto-key 'ghc-auto)
|
2014-07-27 09:10:37 +00:00
|
|
|
(define-key haskell-mode-map ghc-prev-hole-key 'ghc-goto-prev-hole)
|
|
|
|
(define-key haskell-mode-map ghc-next-hole-key 'ghc-goto-next-hole)
|
2010-01-06 05:38:06 +00:00
|
|
|
(ghc-comp-init)
|
2014-08-24 01:47:15 +00:00
|
|
|
(setq ghc-initialized t)
|
|
|
|
(defadvice save-buffer (after ghc-check-syntax-on-save activate)
|
|
|
|
"Check syntax with GHC when a haskell-mode buffer is saved."
|
|
|
|
(when (eq 'haskell-mode major-mode) (ghc-check-syntax))))
|
2014-04-21 08:35:32 +00:00
|
|
|
(ghc-import-module)
|
2014-03-20 08:55:20 +00:00
|
|
|
(ghc-check-syntax))
|
2010-03-11 10:03:17 +00:00
|
|
|
|
2010-04-23 09:21:22 +00:00
|
|
|
(defun ghc-abbrev-init ()
|
2010-10-28 06:57:39 +00:00
|
|
|
(set (make-local-variable 'dabbrev-case-fold-search) nil))
|
2010-04-23 09:21:22 +00:00
|
|
|
|
2014-04-25 05:31:09 +00:00
|
|
|
;;;###autoload
|
|
|
|
(defun ghc-debug ()
|
|
|
|
(interactive)
|
|
|
|
(let ((el-path (locate-file "ghc.el" load-path))
|
2014-06-25 06:05:23 +00:00
|
|
|
(ghc-path (executable-find "ghc")) ;; FIXME
|
2014-04-25 05:31:09 +00:00
|
|
|
(ghc-mod-path (executable-find ghc-module-command))
|
|
|
|
(ghc-modi-path (executable-find ghc-interactive-command))
|
|
|
|
(el-ver ghc-version)
|
2014-04-25 13:03:09 +00:00
|
|
|
(ghc-ver (ghc-run-ghc-mod '("--version") "ghc"))
|
2014-04-25 05:31:09 +00:00
|
|
|
(ghc-mod-ver (ghc-run-ghc-mod '("version")))
|
2014-06-25 06:05:23 +00:00
|
|
|
(ghc-modi-ver (ghc-run-ghc-mod '("version") ghc-interactive-command))
|
|
|
|
(path (getenv "PATH")))
|
2014-04-25 05:31:09 +00:00
|
|
|
(switch-to-buffer (get-buffer-create "**GHC Debug**"))
|
|
|
|
(erase-buffer)
|
|
|
|
(insert "Path: check if you are using intended programs.\n")
|
2014-04-25 13:03:09 +00:00
|
|
|
(insert (format "\t ghc.el path: %s\n" el-path))
|
|
|
|
(insert (format "\t ghc-mod path: %s\n" ghc-mod-path))
|
|
|
|
(insert (format "\tghc-modi path: %s\n" ghc-modi-path))
|
|
|
|
(insert (format "\t ghc path: %s\n" ghc-path))
|
2014-04-25 05:31:09 +00:00
|
|
|
(insert "\nVersion: all versions must be the same.\n")
|
|
|
|
(insert (format "\t ghc.el version %s\n" el-ver))
|
|
|
|
(insert (format "\t %s\n" ghc-mod-ver))
|
2014-04-25 13:03:09 +00:00
|
|
|
(insert (format "\t%s\n" ghc-modi-ver))
|
2014-06-25 06:05:23 +00:00
|
|
|
(insert (format "\t%s\n" ghc-ver))
|
|
|
|
(insert "\nEnvironment variables:\n")
|
|
|
|
(insert (format "\tPATH=%s\n" path))))
|
2014-04-25 05:31:09 +00:00
|
|
|
|
2014-08-26 00:19:17 +00:00
|
|
|
(defun ghc-insert-template-or-signature (&optional flag)
|
|
|
|
(interactive "P")
|
|
|
|
(if flag
|
|
|
|
(ghc-initial-code-from-signature)
|
|
|
|
(ghc-insert-template)))
|
|
|
|
|
2010-10-28 07:19:19 +00:00
|
|
|
(provide 'ghc)
|