Skip to content

Commit 150fc35

Browse files
authored
Merge pull request #1719 from galagora/hoogle-improvements
Make Hoogle work in Nix shell
2 parents 4cc375d + a8d2f1a commit 150fc35

File tree

4 files changed

+37
-105
lines changed

4 files changed

+37
-105
lines changed

haskell-commands.el

Lines changed: 0 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -192,29 +192,6 @@ MODULE-BUFFER is the actual Emacs buffer of the module being loaded."
192192
(defvar haskell-cabal-targets-history nil
193193
"History list for session targets.")
194194

195-
(defun haskell-process-hayoo-ident (ident)
196-
"Hayoo for IDENT, return a list of modules"
197-
;; We need a real/simulated closure, because otherwise these
198-
;; variables will be unbound when the url-retrieve callback is
199-
;; called.
200-
;; TODO: Remove when this code is converted to lexical bindings by
201-
;; default (Emacs 24.1+)
202-
(let ((url (format haskell-process-hayoo-query-url (url-hexify-string ident))))
203-
(with-current-buffer (url-retrieve-synchronously url)
204-
(if (= 200 url-http-response-status)
205-
(progn
206-
(goto-char url-http-end-of-headers)
207-
(let* ((res (json-read))
208-
(results (assoc-default 'result res)))
209-
;; TODO: gather packages as well, and when we choose a
210-
;; given import, check that we have the package in the
211-
;; cabal file as well.
212-
(cl-mapcan (lambda (r)
213-
;; append converts from vector -> list
214-
(append (assoc-default 'resultModules r) nil))
215-
results)))
216-
(warn "HTTP error %s fetching %s" url-http-response-status url)))))
217-
218195
(defun haskell-process-hoogle-ident (ident)
219196
"Hoogle for IDENT, return a list of modules."
220197
(with-temp-buffer

haskell-customize.el

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -214,18 +214,6 @@ Flycheck users might like to disable this."
214214
:type 'boolean
215215
:group 'haskell-interactive)
216216

217-
(defcustom haskell-process-suggest-hayoo-imports
218-
nil
219-
"Suggest to add import statements using Hayoo as a backend."
220-
:type 'boolean
221-
:group 'haskell-interactive)
222-
223-
(defcustom haskell-process-hayoo-query-url
224-
"http://hayoo.fh-wedel.de/json/?query=%s"
225-
"Query url for json hayoo results."
226-
:type 'string
227-
:group 'haskell-interactive)
228-
229217
(defcustom haskell-process-suggest-haskell-docs-imports
230218
nil
231219
"Suggest to add import statements using haskell-docs as a backend."

haskell-hoogle.el

Lines changed: 37 additions & 67 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
;;; haskell-hoogle.el --- Look up Haskell documentation via hoogle or hayoo -*- lexical-binding: t; -*-
1+
;;; haskell-hoogle.el --- Look up Haskell documentation via hoogle -*- lexical-binding: t; -*-
22

33
;; Copyright © 2015 Steve Purcell
44
;; 2016 Arthur Fayzrakhmanov
@@ -21,7 +21,7 @@
2121

2222
;;; Commentary:
2323

24-
;; Functions for looking up documentation with hayoo or hoogle, via
24+
;; Functions for looking up documentation with hoogle, via
2525
;; either local or remote servers.
2626

2727
;;; Code:
@@ -30,24 +30,49 @@
3030
(require 'haskell-mode)
3131
(require 'haskell-utils)
3232

33+
(defun hoogle-prompt ()
34+
"Prompt for Hoogle query."
35+
(let ((def (haskell-ident-at-point)))
36+
(if (and def (symbolp def)) (setq def (symbol-name def)))
37+
(list (read-string (if def
38+
(format "Hoogle query (default %s): " def)
39+
"Hoogle query: ")
40+
nil nil def)
41+
)))
3342

34-
(defcustom haskell-hoogle-command
35-
(if (executable-find "hoogle") "hoogle")
36-
"Name of the command to use to query Hoogle.
37-
If nil, use the Hoogle web-site."
38-
:group 'haskell
39-
:type '(choice (const :tag "Use Web-site" nil)
40-
string))
43+
;;;###autoload
44+
(defun haskell-hoogle (query &optional info)
45+
"Do a Hoogle search for QUERY.
46+
47+
If prefix argument INFO is given, then `haskell-hoogle-command'
48+
is asked to show extra info for the items matching QUERY.."
49+
(interactive (append (hoogle-prompt) current-prefix-arg))
50+
(let* ((command (concat (executable-find "hoogle")
51+
(if info " -i " "")
52+
" --color " (shell-quote-argument query)))
53+
(output (shell-command-to-string command)))
54+
(with-help-window "*hoogle*"
55+
(with-current-buffer standard-output
56+
(insert output)
57+
(ansi-color-apply-on-region (point-min) (point-max))))))
58+
59+
;;;###autoload
60+
(defalias 'hoogle 'haskell-hoogle)
4161

4262
(defcustom haskell-hoogle-url "https://hoogle.haskell.org/?hoogle=%s"
4363
"Default value for hoogle web site."
4464
:group 'haskell
4565
:type '(choice
4666
(const :tag "haskell-org" "https://hoogle.haskell.org/?hoogle=%s")
4767
(const :tag "fp-complete" "https://www.stackage.org/lts/hoogle?q=%s")
48-
(const :tag "hayoo" "http://hayoo.fh-wedel.de/?query=%s")
4968
string))
5069

70+
;;;###autoload
71+
(defun haskell-hoogle-lookup-from-website (query)
72+
"Lookup QUERY at `haskell-hoogle-url'."
73+
(interactive (hoogle-prompt))
74+
(browse-url (format haskell-hoogle-url (url-hexify-string query))))
75+
5176
(defcustom haskell-hoogle-server-command (lambda (port)
5277
(list "hoogle" "server"
5378
"--local"
@@ -58,35 +83,6 @@ If nil, use the Hoogle web-site."
5883
:type 'function
5984
)
6085

61-
;;;###autoload
62-
(defun haskell-hoogle (query &optional info)
63-
"Do a Hoogle search for QUERY.
64-
When `haskell-hoogle-command' is non-nil, this command runs
65-
that. Otherwise, it opens a hoogle search result in the browser.
66-
67-
If prefix argument INFO is given, then `haskell-hoogle-command'
68-
is asked to show extra info for the items matching QUERY.."
69-
(interactive
70-
(let ((def (haskell-ident-at-point)))
71-
(if (and def (symbolp def)) (setq def (symbol-name def)))
72-
(list (read-string (if def
73-
(format "Hoogle query (default %s): " def)
74-
"Hoogle query: ")
75-
nil nil def)
76-
current-prefix-arg)))
77-
(if (null haskell-hoogle-command)
78-
(browse-url (format haskell-hoogle-url (url-hexify-string query)))
79-
(let ((command (concat haskell-hoogle-command
80-
(if info " -i " "")
81-
" --color " (shell-quote-argument query))))
82-
(with-help-window "*hoogle*"
83-
(with-current-buffer standard-output
84-
(insert (shell-command-to-string command))
85-
(ansi-color-apply-on-region (point-min) (point-max)))))))
86-
87-
;;;###autoload
88-
(defalias 'hoogle 'haskell-hoogle)
89-
9086
(defvar haskell-hoogle-server-process-name "emacs-local-hoogle")
9187
(defvar haskell-hoogle-server-buffer-name (format "*%s*" haskell-hoogle-server-process-name))
9288
(defvar haskell-hoogle-port-number 49513 "Port number.")
@@ -119,43 +115,17 @@ is asked to show extra info for the items matching QUERY.."
119115

120116
;;;###autoload
121117
(defun haskell-hoogle-lookup-from-local ()
122-
"Lookup by local hoogle."
118+
"Lookup QUERY on local hoogle server."
123119
(interactive)
124120
(if (haskell-hoogle-server-live-p)
125121
(browse-url (format "http://localhost:%i/?hoogle=%s"
126122
haskell-hoogle-port-number
127-
(read-string "hoogle: " (haskell-ident-at-point))))
123+
(car (hoogle-prompt))))
128124
(haskell-mode-toggle-interactive-prompt-state)
129125
(unwind-protect
130126
(when (y-or-n-p "Hoogle server not running, start hoogle server? ")
131127
(haskell-hoogle-start-server))
132128
(haskell-mode-toggle-interactive-prompt-state t))))
133129

134-
135-
(defcustom haskell-hayoo-url "http://hayoo.fh-wedel.de/?query=%s"
136-
"Default value for hayoo web site."
137-
:group 'haskell
138-
:type '(choice
139-
(const :tag "fh-wedel.de" "http://hayoo.fh-wedel.de/?query=%s")
140-
string))
141-
142-
;;;###autoload
143-
(defun haskell-hayoo (query)
144-
"Do a Hayoo search for QUERY."
145-
(interactive
146-
(let ((def (haskell-ident-at-point)))
147-
(if (and def (symbolp def)) (setq def (symbol-name def)))
148-
(list (read-string (if def
149-
(format "Hayoo query (default %s): " def)
150-
"Hayoo query: ")
151-
nil nil def))))
152-
(browse-url (format haskell-hayoo-url (url-hexify-string query))))
153-
154-
;;;###autoload
155-
(defalias 'hayoo 'haskell-hayoo)
156-
157-
158-
159-
160130
(provide 'haskell-hoogle)
161131
;;; haskell-hoogle.el ends here

haskell-load.el

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -246,9 +246,6 @@ list of modules where missed IDENT was found."
246246
(haskell-process-suggest-imports session file modules ident)))
247247
(when haskell-process-suggest-haskell-docs-imports
248248
(let ((modules (haskell-process-haskell-docs-ident ident)))
249-
(haskell-process-suggest-imports session file modules ident)))
250-
(when haskell-process-suggest-hayoo-imports
251-
(let ((modules (haskell-process-hayoo-ident ident)))
252249
(haskell-process-suggest-imports session file modules ident)))))
253250
((string-match "^[ ]+It is a member of the hidden package [‘`‛]\\([^@\r\n]+\\).*['’].$" msg)
254251
(when haskell-process-suggest-add-package

0 commit comments

Comments
 (0)