Using "hoogle search".
This commit is contained in:
parent
94efd2f250
commit
432de2e4f9
@ -10,27 +10,22 @@
|
|||||||
|
|
||||||
(defvar ghc-hoogle-command "hoogle")
|
(defvar ghc-hoogle-command "hoogle")
|
||||||
|
|
||||||
(defvar ghc-hoogle-keywords '("data" "server" "combine" "convert" "test" "dump" "rank" "log"))
|
|
||||||
|
|
||||||
(defun ghc-insert-module ()
|
(defun ghc-insert-module ()
|
||||||
(interactive)
|
(interactive)
|
||||||
(if (not (ghc-which ghc-hoogle-command))
|
(if (not (ghc-which ghc-hoogle-command))
|
||||||
(message "\"%s\" not found" ghc-hoogle-command)
|
(message "\"%s\" not found" ghc-hoogle-command)
|
||||||
(let* ((expr0 (thing-at-point 'symbol))
|
(let* ((expr0 (thing-at-point 'symbol))
|
||||||
(expr (ghc-read-expression expr0)))
|
(expr (ghc-read-expression expr0)))
|
||||||
(if (member expr ghc-hoogle-keywords)
|
(let ((mods (ghc-function-to-modules expr)))
|
||||||
(message "\"%s\" not allowed" expr)
|
(if (null mods)
|
||||||
(let ((mods (ghc-function-to-modules expr)))
|
(message "No module guessed")
|
||||||
(if (null mods)
|
(let* ((first (car mods))
|
||||||
(message "No module guessed")
|
(mod (if (= (length mods) 1)
|
||||||
(let* ((first (car mods))
|
first
|
||||||
(ini (cons first 0))
|
(completing-read "Module name: " mods nil t first))))
|
||||||
(mod (if (= (length mods) 1)
|
(save-excursion
|
||||||
first
|
(ghc-goto-module-position)
|
||||||
(completing-read "Module name: " mods nil t ini))))
|
(insert "import " mod "\n"))))))))
|
||||||
(save-excursion
|
|
||||||
(ghc-goto-module-position)
|
|
||||||
(insert "import " mod "\n")))))))))
|
|
||||||
|
|
||||||
(defun ghc-goto-module-position ()
|
(defun ghc-goto-module-position ()
|
||||||
(goto-char (point-max))
|
(goto-char (point-max))
|
||||||
@ -42,7 +37,7 @@
|
|||||||
|
|
||||||
(defun ghc-function-to-modules (fn)
|
(defun ghc-function-to-modules (fn)
|
||||||
(with-temp-buffer
|
(with-temp-buffer
|
||||||
(call-process ghc-hoogle-command nil t nil fn)
|
(call-process ghc-hoogle-command nil t nil "search" fn)
|
||||||
(goto-char (point-min))
|
(goto-char (point-min))
|
||||||
(let ((regex (concat "^\\([a-zA-Z0-9.]+\\) " fn " "))
|
(let ((regex (concat "^\\([a-zA-Z0-9.]+\\) " fn " "))
|
||||||
ret)
|
ret)
|
||||||
|
Loading…
Reference in New Issue
Block a user