Skip to content

Commit 4c54ce6

Browse files
committed
Merge pull request #973 from purcell/haskell-hoogle-el
Extract hoogle/hayoo code into haskell-hoogle.el and tidy up
2 parents 5d5a9a0 + 44b5420 commit 4c54ce6

File tree

4 files changed

+151
-113
lines changed

4 files changed

+151
-113
lines changed

Makefile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@ ELFILES = \
6262
haskell-doc.el \
6363
haskell.el \
6464
haskell-font-lock.el \
65+
haskell-hoogle.el \
6566
haskell-indentation.el \
6667
haskell-indent.el \
6768
haskell-interactive-mode.el \

haskell-hoogle.el

Lines changed: 149 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,149 @@
1+
;;; haskell-hoogle.el --- Look up Haskell documentation via hoogle or hayoo -*- lexical-binding: t; -*-
2+
3+
;; Copyright (C) 2015 Steve Purcell
4+
5+
;; Author: Steve Purcell <[email protected]>
6+
;; Keywords: docs
7+
8+
;; This program is free software; you can redistribute it and/or modify
9+
;; it under the terms of the GNU General Public License as published by
10+
;; the Free Software Foundation, either version 3 of the License, or
11+
;; (at your option) any later version.
12+
13+
;; This program is distributed in the hope that it will be useful,
14+
;; but WITHOUT ANY WARRANTY; without even the implied warranty of
15+
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16+
;; GNU General Public License for more details.
17+
18+
;; You should have received a copy of the GNU General Public License
19+
;; along with this program. If not, see <http://www.gnu.org/licenses/>.
20+
21+
;;; Commentary:
22+
23+
;; Functions for looking up documentation with hayoo or hoogle, via
24+
;; either local or remote servers.
25+
26+
;;; Code:
27+
28+
(require 'ansi-color)
29+
(require 'haskell-mode)
30+
31+
32+
;;;###autoload
33+
(defcustom haskell-hoogle-command
34+
(if (executable-find "hoogle") "hoogle")
35+
"Name of the command to use to query Hoogle.
36+
If nil, use the Hoogle web-site."
37+
:group 'haskell
38+
:type '(choice (const :tag "Use Web-site" nil)
39+
string))
40+
41+
;;;###autoload
42+
(defcustom haskell-hoogle-url "http://haskell.org/hoogle/?q=%s"
43+
"Default value for hoogle web site."
44+
:group 'haskell
45+
:type '(choice
46+
(const :tag "haskell-org" "http://haskell.org/hoogle/?q=%s")
47+
(const :tag "fp-complete" "https://www.stackage.org/lts/hoogle?q=%s")
48+
string))
49+
50+
;;;###autoload
51+
(defun haskell-hoogle (query &optional info)
52+
"Do a Hoogle search for QUERY.
53+
When `haskell-hoogle-command' is non-nil, this command runs
54+
that. Otherwise, it opens a hoogle search result in the browser.
55+
56+
If prefix argument INFO is given, then `haskell-hoogle-command'
57+
is asked to show extra info for the items matching QUERY.."
58+
(interactive
59+
(let ((def (haskell-ident-at-point)))
60+
(if (and def (symbolp def)) (setq def (symbol-name def)))
61+
(list (read-string (if def
62+
(format "Hoogle query (default %s): " def)
63+
"Hoogle query: ")
64+
nil nil def)
65+
current-prefix-arg)))
66+
(if (null haskell-hoogle-command)
67+
(browse-url (format haskell-hoogle-url (url-hexify-string query)))
68+
(with-help-window "*hoogle*"
69+
(with-current-buffer standard-output
70+
(insert (shell-command-to-string
71+
(concat haskell-hoogle-command
72+
(if info " -i " "")
73+
" --color " (shell-quote-argument query))))
74+
(ansi-color-apply-on-region (point-min) (point-max))))))
75+
76+
;;;###autoload
77+
(defalias 'hoogle 'haskell-hoogle)
78+
79+
(defvar haskell-hoogle-server-process-name "emacs-local-hoogle")
80+
(defvar haskell-hoogle-server-buffer-name (format "*%s*" haskell-hoogle-server-process-name))
81+
(defvar haskell-hoogle-port-number 49513 "Port number.")
82+
(defvar haskell-hoogle-server-process nil "The process handle of the local hoogle server.")
83+
84+
(defun haskell-hoogle-start-server ()
85+
"Start hoogle local server."
86+
(interactive)
87+
(if (executable-find "hoogle")
88+
(unless (haskell-hoogle-server-live-p)
89+
(set 'haskell-hoogle-server-process
90+
(start-process
91+
haskell-hoogle-server-process-name
92+
(get-buffer-create haskell-hoogle-server-buffer-name)
93+
"hoogle" "server" "-p" (number-to-string haskell-hoogle-port-number))))
94+
(error "\"hoogle\" executable not found")))
95+
96+
(defun haskell-hoogle-server-live-p ()
97+
"Whether the hoogle server process is live."
98+
(condition-case _err
99+
(process-live-p haskell-hoogle-server-process)
100+
(error nil)))
101+
102+
(defun haskell-hoogle-kill-server ()
103+
"Kill the hoogle server if it is live."
104+
(interactive)
105+
(when (haskell-hoogle-server-live-p)
106+
(kill-process (get-buffer-create haskell-hoogle-server-buffer-name))
107+
(set 'haskell-hoogle-server-process nil)))
108+
109+
;;;###autoload
110+
(defun haskell-hoogle-lookup-from-local ()
111+
"Lookup by local hoogle."
112+
(interactive)
113+
(if (haskell-hoogle-server-live-p)
114+
(browse-url (format "http://localhost:%i/?hoogle=%s"
115+
haskell-hoogle-port-number
116+
(read-string "hoogle: " (haskell-ident-at-point))))
117+
(when (y-or-n-p "Hoogle server not running, start hoogle server? ")
118+
(haskell-hoogle-start-server))))
119+
120+
121+
122+
;;;###autoload
123+
(defcustom haskell-hayoo-url "http://hayoo.fh-wedel.de/?query=%s"
124+
"Default value for hayoo web site."
125+
:group 'haskell
126+
:type '(choice
127+
(const :tag "fh-wedel.de" "http://hayoo.fh-wedel.de/?query=%s")
128+
string))
129+
130+
;;;###autoload
131+
(defun haskell-hayoo (query)
132+
"Do a Hayoo search for QUERY."
133+
(interactive
134+
(let ((def (haskell-ident-at-point)))
135+
(if (and def (symbolp def)) (setq def (symbol-name def)))
136+
(list (read-string (if def
137+
(format "Hayoo query (default %s): " def)
138+
"Hayoo query: ")
139+
nil nil def))))
140+
(browse-url (format haskell-hayoo-url (url-hexify-string query))))
141+
142+
;;;###autoload
143+
(defalias 'hayoo 'haskell-hayoo)
144+
145+
146+
147+
148+
(provide 'haskell-hoogle)
149+
;;; haskell-hoogle.el ends here

haskell-mode.el

Lines changed: 0 additions & 113 deletions
Original file line numberDiff line numberDiff line change
@@ -810,119 +810,6 @@ Note that negative arguments do not work so well."
810810
;;;###autoload
811811
(add-to-list 'completion-ignored-extensions ".hi")
812812

813-
;;;###autoload
814-
(defcustom haskell-hoogle-command
815-
(if (executable-find "hoogle") "hoogle")
816-
"Name of the command to use to query Hoogle.
817-
If nil, use the Hoogle web-site."
818-
:group 'haskell
819-
:type '(choice (const :tag "Use Web-site" nil)
820-
string))
821-
822-
;;;###autoload
823-
(defcustom haskell-hoogle-url "http://haskell.org/hoogle/?q=%s"
824-
"Default value for hoogle web site.
825-
"
826-
:group 'haskell
827-
:type '(choice
828-
(const :tag "haskell-org" "http://haskell.org/hoogle/?q=%s")
829-
(const :tag "fp-complete" "https://www.stackage.org/lts/hoogle?q=%s")
830-
string))
831-
832-
;;;###autoload
833-
(defun haskell-hoogle (query &optional info)
834-
"Do a Hoogle search for QUERY.
835-
When `haskell-hoogle-command' is non-nil, this command runs
836-
that. Otherwise, it opens a hoogle search result in the browser.
837-
838-
If prefix argument INFO is given, then `haskell-hoogle-command'
839-
is asked to show extra info for the items matching QUERY.."
840-
(interactive
841-
(let ((def (haskell-ident-at-point)))
842-
(if (and def (symbolp def)) (setq def (symbol-name def)))
843-
(list (read-string (if def
844-
(format "Hoogle query (default %s): " def)
845-
"Hoogle query: ")
846-
nil nil def)
847-
current-prefix-arg)))
848-
(if (null haskell-hoogle-command)
849-
(browse-url (format haskell-hoogle-url (url-hexify-string query)))
850-
(with-help-window "*hoogle*"
851-
(with-current-buffer standard-output
852-
(insert (shell-command-to-string
853-
(concat haskell-hoogle-command
854-
(if info " -i " "")
855-
" --color " (shell-quote-argument query))))
856-
(ansi-color-apply-on-region (point-min) (point-max))))))
857-
858-
;;;###autoload
859-
(defalias 'hoogle 'haskell-hoogle)
860-
861-
(defvar hoogle-server-process-name "emacs-local-hoogle")
862-
(defvar hoogle-server-buffer-name (format "*%s*" hoogle-server-process-name))
863-
(defvar hoogle-port-number 49513 "Port number.")
864-
(defvar hoogle-server-process nil "The process handle of the local hoogle server.")
865-
866-
(defun hoogle-start-server ()
867-
"Start hoogle local server."
868-
(interactive)
869-
(if (executable-find "hoogle")
870-
(unless (hoogle-server-live-p)
871-
(set 'hoogle-server-process
872-
(start-process
873-
hoogle-server-process-name
874-
(get-buffer-create hoogle-server-buffer-name)
875-
"hoogle" "server" "-p" (number-to-string hoogle-port-number))))
876-
(error "hoogle executable not found")))
877-
878-
(defun hoogle-server-live-p ()
879-
"Whether the hoogle server process is live."
880-
(condition-case _err
881-
(process-live-p hoogle-server-process)
882-
(error nil)))
883-
884-
(defun hoogle-kill-server ()
885-
"Kill the hoogle server if it is live."
886-
(interactive)
887-
(when (hoogle-server-live-p)
888-
(kill-process (get-buffer-create hoogle-server-buffer-name))
889-
(set 'hoogle-server-process nil)))
890-
891-
;;;###autoload
892-
(defun hoogle-lookup-from-local ()
893-
"Lookup by local hoogle."
894-
(interactive)
895-
(if (hoogle-server-live-p)
896-
(browse-url (format "http://localhost:%i/?hoogle=%s"
897-
hoogle-port-number
898-
(read-string "hoogle: " (haskell-ident-at-point))))
899-
(when (y-or-n-p
900-
"hoogle server not running, start hoogle server?")
901-
(hoogle-start-server))))
902-
903-
;;;###autoload
904-
(defcustom haskell-hayoo-url "http://hayoo.fh-wedel.de/?query=%s"
905-
"Default value for hayoo web site.
906-
"
907-
:group 'haskell
908-
:type '(choice
909-
(const :tag "fh-wedel.de" "http://hayoo.fh-wedel.de/?query=%s")
910-
string))
911-
912-
;;;###autoload
913-
(defun haskell-hayoo (query)
914-
"Do a Hayoo search for QUERY."
915-
(interactive
916-
(let ((def (haskell-ident-at-point)))
917-
(if (and def (symbolp def)) (setq def (symbol-name def)))
918-
(list (read-string (if def
919-
(format "Hayoo query (default %s): " def)
920-
"Hayoo query: ")
921-
nil nil def))))
922-
(browse-url (format haskell-hayoo-url (url-hexify-string query))))
923-
924-
;;;###autoload
925-
(defalias 'hayoo 'haskell-hayoo)
926813

927814
;;;###autoload
928815
(defcustom haskell-check-command "hlint"

haskell.el

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919

2020
(require 'cl-lib)
2121
(require 'haskell-mode)
22+
(require 'haskell-hoogle)
2223
(require 'haskell-process)
2324
(require 'haskell-debug)
2425
(require 'haskell-interactive-mode)

0 commit comments

Comments
 (0)