inserting module.
This commit is contained in:
parent
fdc66396d4
commit
94be5c3760
@ -1,5 +1,5 @@
|
|||||||
SRCS = ghc.el ghc-func.el ghc-doc.el ghc-comp.el ghc-flymake.el \
|
SRCS = ghc.el ghc-func.el ghc-doc.el ghc-comp.el ghc-flymake.el \
|
||||||
ghc-command.el ghc-info.el
|
ghc-command.el ghc-info.el ghc-ins-mod.el
|
||||||
EMACS = emacs
|
EMACS = emacs
|
||||||
|
|
||||||
TEMPFILE = temp.el
|
TEMPFILE = temp.el
|
||||||
|
48
elisp/ghc-ins-mod.el
Normal file
48
elisp/ghc-ins-mod.el
Normal file
@ -0,0 +1,48 @@
|
|||||||
|
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
||||||
|
;;;
|
||||||
|
;;; ghc-ins-mod.el
|
||||||
|
;;;
|
||||||
|
|
||||||
|
;; Author: Kazu Yamamoto <Kazu@Mew.org>
|
||||||
|
;; Created: Dec 27, 2011
|
||||||
|
|
||||||
|
;;; Code:
|
||||||
|
|
||||||
|
(defvar ghc-hoogle-command "hoogle")
|
||||||
|
|
||||||
|
(defun ghc-insert-module ()
|
||||||
|
(interactive)
|
||||||
|
(if (not (ghc-which ghc-hoogle-command))
|
||||||
|
(message "%s not found" ghc-hoogle-command)
|
||||||
|
(let* ((expr0 (thing-at-point 'symbol))
|
||||||
|
(expr (ghc-read-expression expr0))
|
||||||
|
(mods (ghc-function-to-modules expr))
|
||||||
|
(first (car mods))
|
||||||
|
(ini (cons first 0))
|
||||||
|
(mod (if (= (length mods) 1)
|
||||||
|
first
|
||||||
|
(completing-read "Module name: " mods nil t ini))))
|
||||||
|
(save-excursion
|
||||||
|
(ghc-goto-module-position)
|
||||||
|
(insert "import " mod "\n")
|
||||||
|
(message "%s was inserted" mod)))))
|
||||||
|
|
||||||
|
(defun ghc-goto-module-position ()
|
||||||
|
(goto-char (point-max))
|
||||||
|
(if (re-search-backward "^import" nil t)
|
||||||
|
(forward-line)
|
||||||
|
(if (re-search-backward "^module" nil t)
|
||||||
|
(forward-line)
|
||||||
|
(goto-char (point-min)))))
|
||||||
|
|
||||||
|
(defun ghc-function-to-modules (fn)
|
||||||
|
(with-temp-buffer
|
||||||
|
(call-process ghc-hoogle-command nil t nil fn)
|
||||||
|
(goto-char (point-min))
|
||||||
|
(let ((regex (concat "^\\([a-zA-Z0-9.]+\\) " fn " "))
|
||||||
|
ret)
|
||||||
|
(while (re-search-forward regex nil t)
|
||||||
|
(setq ret (cons (match-string 1) ret)))
|
||||||
|
(nreverse ret))))
|
||||||
|
|
||||||
|
(provide 'ghc-ins-mod)
|
@ -26,6 +26,7 @@
|
|||||||
(require 'ghc-info)
|
(require 'ghc-info)
|
||||||
(require 'ghc-flymake)
|
(require 'ghc-flymake)
|
||||||
(require 'ghc-command)
|
(require 'ghc-command)
|
||||||
|
(require 'ghc-ins-mod)
|
||||||
(require 'dabbrev)
|
(require 'dabbrev)
|
||||||
|
|
||||||
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
||||||
@ -50,6 +51,7 @@
|
|||||||
(defvar ghc-info-key "\C-c\C-i")
|
(defvar ghc-info-key "\C-c\C-i")
|
||||||
(defvar ghc-check-key "\C-x\C-s")
|
(defvar ghc-check-key "\C-x\C-s")
|
||||||
(defvar ghc-toggle-key "\C-c\C-c")
|
(defvar ghc-toggle-key "\C-c\C-c")
|
||||||
|
(defvar ghc-module-key "\C-c\C-m")
|
||||||
(defvar ghc-hoogle-key (format "\C-c%c" (ghc-find-C-h)))
|
(defvar ghc-hoogle-key (format "\C-c%c" (ghc-find-C-h)))
|
||||||
|
|
||||||
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
||||||
@ -74,6 +76,7 @@
|
|||||||
(define-key haskell-mode-map ghc-sort-key 'ghc-sort-lines)
|
(define-key haskell-mode-map ghc-sort-key 'ghc-sort-lines)
|
||||||
(define-key haskell-mode-map ghc-check-key 'ghc-save-buffer)
|
(define-key haskell-mode-map ghc-check-key 'ghc-save-buffer)
|
||||||
(define-key haskell-mode-map ghc-toggle-key 'ghc-flymake-toggle-command)
|
(define-key haskell-mode-map ghc-toggle-key 'ghc-flymake-toggle-command)
|
||||||
|
(define-key haskell-mode-map ghc-module-key 'ghc-insert-module)
|
||||||
(define-key haskell-mode-map ghc-hoogle-key 'haskell-hoogle)
|
(define-key haskell-mode-map ghc-hoogle-key 'haskell-hoogle)
|
||||||
(ghc-comp-init)
|
(ghc-comp-init)
|
||||||
(setq ghc-initialized t)))
|
(setq ghc-initialized t)))
|
||||||
|
@ -20,7 +20,7 @@ Cabal-Version: >= 1.6
|
|||||||
Build-Type: Simple
|
Build-Type: Simple
|
||||||
Data-Dir: elisp
|
Data-Dir: elisp
|
||||||
Data-Files: Makefile ghc.el ghc-func.el ghc-doc.el ghc-comp.el
|
Data-Files: Makefile ghc.el ghc-func.el ghc-doc.el ghc-comp.el
|
||||||
ghc-flymake.el ghc-command.el ghc-info.el
|
ghc-flymake.el ghc-command.el ghc-info.el ghc-ins-mod.el
|
||||||
Executable ghc-mod
|
Executable ghc-mod
|
||||||
Main-Is: GHCMod.hs
|
Main-Is: GHCMod.hs
|
||||||
Other-Modules: List Browse Cabal CabalDev Check Info Lang Lint Types ErrMsg Paths_ghc_mod
|
Other-Modules: List Browse Cabal CabalDev Check Info Lang Lint Types ErrMsg Paths_ghc_mod
|
||||||
|
Loading…
Reference in New Issue
Block a user