branch: elpa/haskell-mode commit 4f8cea6e937d5c4846c46361884e57b2e3d5ae14 Author: jao <j...@gnu.org> Commit: jao <j...@gnu.org>
hoogle: colorize hoogle cli output using haskell-mode font-lock It's been a long time since hoogle command line interface lost the ability to output ANSI colors (see https://github.com/ndmitchell/hoogle/issues/133). This patch makes haskell-hoogle to use emacs font lock to fontify its output, with a custom flag to opt out. --- haskell-hoogle.el | 25 +++++++++++++++++++++---- 1 file changed, 21 insertions(+), 4 deletions(-) diff --git a/haskell-hoogle.el b/haskell-hoogle.el index 86835b7f7e..42476501d1 100644 --- a/haskell-hoogle.el +++ b/haskell-hoogle.el @@ -27,6 +27,7 @@ ;;; Code: (require 'ansi-color) +(require 'view) (require 'haskell-mode) (require 'haskell-utils) @@ -58,6 +59,11 @@ If nil, use the Hoogle web-site." (const :tag "fp-complete" "https://www.stackage.org/lts/hoogle?q=%s") string)) +(defcustom haskell-hoogle-colorize-with-haskell-mode t + "Whether to use haskell-mode to colorize hoogles's CLI output." + :group 'haskell + :type 'boolean) + ;;;###autoload (defun haskell-hoogle (query &optional info) "Do a Hoogle search for QUERY. @@ -73,10 +79,21 @@ is asked to show extra info for the items matching QUERY.." (if info " -i " "") " --color " (shell-quote-argument query))) (output (shell-command-to-string command))) - (with-help-window "*hoogle*" - (with-current-buffer standard-output - (insert output) - (ansi-color-apply-on-region (point-min) (point-max))))))) + (with-help-window "*hoogle*" + (with-current-buffer standard-output + (if haskell-hoogle-colorize-with-haskell-mode + (let ((outs (ansi-color-filter-apply output))) + (delay-mode-hooks (haskell-mode)) + (if info + (let ((lns (split-string output "\n" t " "))) + (insert (car lns) "\n\n") + (dolist (ln (cdr lns)) (insert "-- " ln "\n"))) + (insert outs) + (forward-line -1) + (when (looking-at-p "^plus more results") (insert "\n-- "))) + (view-mode)) + (insert output) + (ansi-color-apply-on-region (point-min) (point-max)))))))) ;;;###autoload (defalias 'hoogle 'haskell-hoogle)