Skip to content

Commit

Permalink
Extract hoogle/hayoo code into haskell-hoogle.el, and tidy up
Browse files Browse the repository at this point in the history
- Moved existing code to fresh module
- Fixed checkdoc warnings
- Renamed hoogle-* to use consistent haskell-hoogle-* prefix
  • Loading branch information
purcell committed Nov 1, 2015
1 parent 5d5a9a0 commit 44b5420
Show file tree
Hide file tree
Showing 4 changed files with 151 additions and 113 deletions.
1 change: 1 addition & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ ELFILES = \
haskell-doc.el \
haskell.el \
haskell-font-lock.el \
haskell-hoogle.el \
haskell-indentation.el \
haskell-indent.el \
haskell-interactive-mode.el \
Expand Down
149 changes: 149 additions & 0 deletions haskell-hoogle.el
Original file line number Diff line number Diff line change
@@ -0,0 +1,149 @@
;;; haskell-hoogle.el --- Look up Haskell documentation via hoogle or hayoo -*- lexical-binding: t; -*-

;; Copyright (C) 2015 Steve Purcell

;; Author: Steve Purcell <steve@sanityinc.com>
;; Keywords: docs

;; This program is free software; you can redistribute it and/or modify
;; it under the terms of the GNU General Public License as published by
;; the Free Software Foundation, either version 3 of the License, or
;; (at your option) any later version.

;; This program is distributed in the hope that it will be useful,
;; but WITHOUT ANY WARRANTY; without even the implied warranty of
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
;; GNU General Public License for more details.

;; You should have received a copy of the GNU General Public License
;; along with this program. If not, see <http://www.gnu.org/licenses/>.

;;; Commentary:

;; Functions for looking up documentation with hayoo or hoogle, via
;; either local or remote servers.

;;; Code:

(require 'ansi-color)
(require 'haskell-mode)


;;;###autoload
(defcustom haskell-hoogle-command
(if (executable-find "hoogle") "hoogle")
"Name of the command to use to query Hoogle.
If nil, use the Hoogle web-site."
:group 'haskell
:type '(choice (const :tag "Use Web-site" nil)
string))

;;;###autoload
(defcustom haskell-hoogle-url "http://haskell.org/hoogle/?q=%s"
"Default value for hoogle web site."
:group 'haskell
:type '(choice
(const :tag "haskell-org" "http://haskell.org/hoogle/?q=%s")
(const :tag "fp-complete" "https://www.stackage.org/lts/hoogle?q=%s")
string))

;;;###autoload
(defun haskell-hoogle (query &optional info)
"Do a Hoogle search for QUERY.
When `haskell-hoogle-command' is non-nil, this command runs
that. Otherwise, it opens a hoogle search result in the browser.
If prefix argument INFO is given, then `haskell-hoogle-command'
is asked to show extra info for the items matching QUERY.."
(interactive
(let ((def (haskell-ident-at-point)))
(if (and def (symbolp def)) (setq def (symbol-name def)))
(list (read-string (if def
(format "Hoogle query (default %s): " def)
"Hoogle query: ")
nil nil def)
current-prefix-arg)))
(if (null haskell-hoogle-command)
(browse-url (format haskell-hoogle-url (url-hexify-string query)))
(with-help-window "*hoogle*"
(with-current-buffer standard-output
(insert (shell-command-to-string
(concat haskell-hoogle-command
(if info " -i " "")
" --color " (shell-quote-argument query))))
(ansi-color-apply-on-region (point-min) (point-max))))))

;;;###autoload
(defalias 'hoogle 'haskell-hoogle)

(defvar haskell-hoogle-server-process-name "emacs-local-hoogle")
(defvar haskell-hoogle-server-buffer-name (format "*%s*" haskell-hoogle-server-process-name))
(defvar haskell-hoogle-port-number 49513 "Port number.")
(defvar haskell-hoogle-server-process nil "The process handle of the local hoogle server.")

(defun haskell-hoogle-start-server ()
"Start hoogle local server."
(interactive)
(if (executable-find "hoogle")
(unless (haskell-hoogle-server-live-p)
(set 'haskell-hoogle-server-process
(start-process
haskell-hoogle-server-process-name
(get-buffer-create haskell-hoogle-server-buffer-name)
"hoogle" "server" "-p" (number-to-string haskell-hoogle-port-number))))
(error "\"hoogle\" executable not found")))

(defun haskell-hoogle-server-live-p ()
"Whether the hoogle server process is live."
(condition-case _err
(process-live-p haskell-hoogle-server-process)
(error nil)))

(defun haskell-hoogle-kill-server ()
"Kill the hoogle server if it is live."
(interactive)
(when (haskell-hoogle-server-live-p)
(kill-process (get-buffer-create haskell-hoogle-server-buffer-name))
(set 'haskell-hoogle-server-process nil)))

;;;###autoload
(defun haskell-hoogle-lookup-from-local ()
"Lookup by local hoogle."
(interactive)
(if (haskell-hoogle-server-live-p)
(browse-url (format "http://localhost:%i/?hoogle=%s"
haskell-hoogle-port-number
(read-string "hoogle: " (haskell-ident-at-point))))
(when (y-or-n-p "Hoogle server not running, start hoogle server? ")
(haskell-hoogle-start-server))))



;;;###autoload
(defcustom haskell-hayoo-url "http://hayoo.fh-wedel.de/?query=%s"
"Default value for hayoo web site."
:group 'haskell
:type '(choice
(const :tag "fh-wedel.de" "http://hayoo.fh-wedel.de/?query=%s")
string))

;;;###autoload
(defun haskell-hayoo (query)
"Do a Hayoo search for QUERY."
(interactive
(let ((def (haskell-ident-at-point)))
(if (and def (symbolp def)) (setq def (symbol-name def)))
(list (read-string (if def
(format "Hayoo query (default %s): " def)
"Hayoo query: ")
nil nil def))))
(browse-url (format haskell-hayoo-url (url-hexify-string query))))

;;;###autoload
(defalias 'hayoo 'haskell-hayoo)




(provide 'haskell-hoogle)
;;; haskell-hoogle.el ends here
113 changes: 0 additions & 113 deletions haskell-mode.el
Original file line number Diff line number Diff line change
Expand Up @@ -810,119 +810,6 @@ Note that negative arguments do not work so well."
;;;###autoload
(add-to-list 'completion-ignored-extensions ".hi")

;;;###autoload
(defcustom haskell-hoogle-command
(if (executable-find "hoogle") "hoogle")
"Name of the command to use to query Hoogle.
If nil, use the Hoogle web-site."
:group 'haskell
:type '(choice (const :tag "Use Web-site" nil)
string))

;;;###autoload
(defcustom haskell-hoogle-url "http://haskell.org/hoogle/?q=%s"
"Default value for hoogle web site.
"
:group 'haskell
:type '(choice
(const :tag "haskell-org" "http://haskell.org/hoogle/?q=%s")
(const :tag "fp-complete" "https://www.stackage.org/lts/hoogle?q=%s")
string))

;;;###autoload
(defun haskell-hoogle (query &optional info)
"Do a Hoogle search for QUERY.
When `haskell-hoogle-command' is non-nil, this command runs
that. Otherwise, it opens a hoogle search result in the browser.
If prefix argument INFO is given, then `haskell-hoogle-command'
is asked to show extra info for the items matching QUERY.."
(interactive
(let ((def (haskell-ident-at-point)))
(if (and def (symbolp def)) (setq def (symbol-name def)))
(list (read-string (if def
(format "Hoogle query (default %s): " def)
"Hoogle query: ")
nil nil def)
current-prefix-arg)))
(if (null haskell-hoogle-command)
(browse-url (format haskell-hoogle-url (url-hexify-string query)))
(with-help-window "*hoogle*"
(with-current-buffer standard-output
(insert (shell-command-to-string
(concat haskell-hoogle-command
(if info " -i " "")
" --color " (shell-quote-argument query))))
(ansi-color-apply-on-region (point-min) (point-max))))))

;;;###autoload
(defalias 'hoogle 'haskell-hoogle)

(defvar hoogle-server-process-name "emacs-local-hoogle")
(defvar hoogle-server-buffer-name (format "*%s*" hoogle-server-process-name))
(defvar hoogle-port-number 49513 "Port number.")
(defvar hoogle-server-process nil "The process handle of the local hoogle server.")

(defun hoogle-start-server ()
"Start hoogle local server."
(interactive)
(if (executable-find "hoogle")
(unless (hoogle-server-live-p)
(set 'hoogle-server-process
(start-process
hoogle-server-process-name
(get-buffer-create hoogle-server-buffer-name)
"hoogle" "server" "-p" (number-to-string hoogle-port-number))))
(error "hoogle executable not found")))

(defun hoogle-server-live-p ()
"Whether the hoogle server process is live."
(condition-case _err
(process-live-p hoogle-server-process)
(error nil)))

(defun hoogle-kill-server ()
"Kill the hoogle server if it is live."
(interactive)
(when (hoogle-server-live-p)
(kill-process (get-buffer-create hoogle-server-buffer-name))
(set 'hoogle-server-process nil)))

;;;###autoload
(defun hoogle-lookup-from-local ()
"Lookup by local hoogle."
(interactive)
(if (hoogle-server-live-p)
(browse-url (format "http://localhost:%i/?hoogle=%s"
hoogle-port-number
(read-string "hoogle: " (haskell-ident-at-point))))
(when (y-or-n-p
"hoogle server not running, start hoogle server?")
(hoogle-start-server))))

;;;###autoload
(defcustom haskell-hayoo-url "http://hayoo.fh-wedel.de/?query=%s"
"Default value for hayoo web site.
"
:group 'haskell
:type '(choice
(const :tag "fh-wedel.de" "http://hayoo.fh-wedel.de/?query=%s")
string))

;;;###autoload
(defun haskell-hayoo (query)
"Do a Hayoo search for QUERY."
(interactive
(let ((def (haskell-ident-at-point)))
(if (and def (symbolp def)) (setq def (symbol-name def)))
(list (read-string (if def
(format "Hayoo query (default %s): " def)
"Hayoo query: ")
nil nil def))))
(browse-url (format haskell-hayoo-url (url-hexify-string query))))

;;;###autoload
(defalias 'hayoo 'haskell-hayoo)

;;;###autoload
(defcustom haskell-check-command "hlint"
Expand Down
1 change: 1 addition & 0 deletions haskell.el
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@

(require 'cl-lib)
(require 'haskell-mode)
(require 'haskell-hoogle)
(require 'haskell-process)
(require 'haskell-debug)
(require 'haskell-interactive-mode)
Expand Down

0 comments on commit 44b5420

Please sign in to comment.