ghc-import-module uses ghc-modi browse.

This commit is contained in:
Kazu Yamamoto 2014-04-21 17:35:32 +09:00
parent 3dc8e345b2
commit 36e32ab1b2
4 changed files with 31 additions and 23 deletions

View File

@ -69,7 +69,6 @@ unloaded modules are loaded")
(defvar ghc-loaded-module nil)
(defun ghc-comp-init ()
(add-hook 'find-file-hook 'ghc-import-module)
(let* ((syms '(ghc-module-names
ghc-language-extensions
ghc-option-flags
@ -110,27 +109,19 @@ unloaded modules are loaded")
;;;
(defun ghc-boot (n)
(ghc-executable-find ghc-module-command
(ghc-read-lisp-list
(lambda ()
(message "Initializing...")
(ghc-call-process ghc-module-command nil t nil "-l" "boot")
(message "Initializing...done"))
n)))
(prog2
(message "Initializing...")
(ghc-sync-process "boot\n" n)
(message "Initializing...done")))
(defun ghc-load-modules (mods)
(if (null mods)
(progn
(message "No new modules")
nil)
(ghc-executable-find ghc-module-command
(ghc-read-lisp-list
(lambda ()
(message "Loading names...")
(apply 'ghc-call-process ghc-module-command nil '(t nil) nil
`(,@(ghc-make-ghc-options) "-l" "browse" ,@mods))
(message "Loading names...done"))
(length mods)))))
(if mods
(mapcar 'ghc-load-module mods)
(message "No new modules")
nil))
(defun ghc-load-module (mod)
(ghc-sync-process (format "browse %s\n" mod)))
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;

View File

@ -84,6 +84,16 @@
(ghc-add ret (read m))))
(error ()))))
(defun ghc-read-lisp-list-this-buffer (n)
(save-excursion
(goto-char (point-min))
(condition-case nil
(let ((m (set-marker (make-marker) 1 (current-buffer)))
ret)
(dotimes (i n (nreverse ret))
(ghc-add ret (read m))))
(error ()))))
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(defun ghc-mapconcat (func list)

View File

@ -81,19 +81,25 @@
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(defvar ghc-process-rendezvous nil)
(defvar ghc-process-num-of-results nil)
(defvar ghc-process-results nil)
(defun ghc-sync-process (cmd)
(defun ghc-sync-process (cmd &optional n)
(setq ghc-process-rendezvous nil)
(setq ghc-process-results nil)
(setq ghc-process-num-of-results (or n 1))
(ghc-with-process cmd 'ghc-process-callback)
(while (null ghc-process-rendezvous)
(sit-for 0.01))
ghc-process-results)
(defun ghc-process-callback ()
(let ((mods (ghc-read-lisp-this-buffer)))
(setq ghc-process-results mods)
(let* ((n ghc-process-num-of-results)
(ret (if (= n 1)
(ghc-read-lisp-this-buffer)
(ghc-read-lisp-list-this-buffer n))))
(setq ghc-process-results ret)
(setq ghc-process-num-of-results nil)
(setq ghc-process-rendezvous t)))
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

View File

@ -97,6 +97,7 @@
(define-key haskell-mode-map ghc-deeper-key 'ghc-make-indent-deeper)
(ghc-comp-init)
(setq ghc-initialized t))
(ghc-import-module)
(ghc-check-syntax))
(defun ghc-abbrev-init ()