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
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:
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
0 commit comments