Skip to content

Commit 20d4e23

Browse files
authored
Merge pull request #1786 from jaor/master
Hoogle: colorize hoogle cli output using haskell-mode font-lock
2 parents 810b08e + 4206520 commit 20d4e23

File tree

1 file changed

+19
-10
lines changed

1 file changed

+19
-10
lines changed

haskell-hoogle.el

+19-10
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
;;; Code:
2828

2929
(require 'ansi-color)
30+
(require 'view)
3031
(require 'haskell-mode)
3132
(require 'haskell-utils)
3233

@@ -70,13 +71,21 @@ is asked to show extra info for the items matching QUERY.."
7071
(let* ((command (concat (if (functionp haskell-hoogle-command)
7172
(funcall haskell-hoogle-command)
7273
haskell-hoogle-command)
73-
(if info " -i " "")
74-
" --color " (shell-quote-argument query)))
75-
(output (shell-command-to-string command)))
76-
(with-help-window "*hoogle*"
77-
(with-current-buffer standard-output
78-
(insert output)
79-
(ansi-color-apply-on-region (point-min) (point-max)))))))
74+
(if info " -i " "")
75+
" --color " (shell-quote-argument query)))
76+
(output (shell-command-to-string command)))
77+
(with-help-window "*hoogle*"
78+
(with-current-buffer standard-output
79+
(let ((outs (ansi-color-filter-apply output)))
80+
(delay-mode-hooks (haskell-mode))
81+
(if info
82+
(let ((lns (split-string output "\n" t " ")))
83+
(insert (car lns) "\n\n")
84+
(dolist (ln (cdr lns)) (insert "-- " ln "\n")))
85+
(insert outs)
86+
(forward-line -1)
87+
(when (looking-at-p "^plus more results") (insert "\n-- ")))
88+
(view-mode)))))))
8089

8190
;;;###autoload
8291
(defalias 'hoogle 'haskell-hoogle)
@@ -89,9 +98,9 @@ is asked to show extra info for the items matching QUERY.."
8998

9099
(defcustom haskell-hoogle-server-command (lambda (port)
91100
(list "hoogle" "server"
92-
"--local"
93-
"-p"
94-
(number-to-string port)))
101+
"--local"
102+
"-p"
103+
(number-to-string port)))
95104
"Command used to start the local hoogle server."
96105
:group 'haskell
97106
:type 'function

0 commit comments

Comments
 (0)