Skip to content

Commit

Permalink
use 'stack hoogle' by default if stack available; add 'hoogleCommand'…
Browse files Browse the repository at this point in the history
… setting to override
  • Loading branch information
RichardWarfield committed Apr 30, 2019
1 parent 61d6cc5 commit 50577f2
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 7 deletions.
14 changes: 14 additions & 0 deletions ptghci.yaml.default
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,31 @@
## ghciCommand defaults to "stack ghci" if stack is on PATH, otherwise just "ghci".
## "cabal new-repl" is another popular choice.
#ghciCommand: stack ghci

## hoogleCommand defaults to "stack hoogle" if stack is on PATH, otherwise just "hoogle".
#hoogleCommand: stack hoogle

inputPrompt: "\x1b[32;1m\u03BB [{lineno}]\x1b[0m: "

historyPath: "~/.ptghci_history"

style: "default"

outPrompt: "\x1b[31;1mOut [{lineno}]\x1b[0m: "

typeBarEnabled: true

typeBarStyle: 'noreverse bg:#222222'

typeBarTextStyle: ''

## By default, uses the open-browser package to determine the user's preferred
## browser
#webBrowser: firefox

## By default, no logging
#logFile: "ptghci_log.txt"

verbosity: Info # One of Trace, Debug, Info, Warn, Error, Critical

viMode: false
16 changes: 15 additions & 1 deletion pybits/ptghci/magic/magic.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
import re
import subprocess
import shlex
import shutil
import webbrowser
from . import run
from ..highlight import hl
Expand Down Expand Up @@ -55,8 +56,21 @@ def handle_magic(entry: str, session, config, dispatcher) -> Response:

def handle_hoogle(command, args, session, config, dispatcher):
try:
hoogle_output = subprocess.check_output(['hoogle']+shlex.split(args))
base_cmd = shlex.split(config.hoogle_command)
except AttributeError:
have_stack = shutil.which('stack')
if have_stack:
base_cmd = ['stack', 'hoogle']
else:
base_cmd = ['hoogle']
cmd = base_cmd + shlex.split(args)
try:
hoogle_output = subprocess.check_output(cmd)
resp = Response.from_value(hl(hoogle_output.decode(), config))
except FileNotFoundError:
resp = Response.from_error_message("Couldn't find hoogle executable."
"Shell command was '%s'"
% (' '.join(cmd)))
except subprocess.CalledProcessError as det:
resp = Response.from_error_message("Hoogle call returned error %d: %s"
% (det.returncode, det.output))
Expand Down
2 changes: 1 addition & 1 deletion pybits/ptghci/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
'typeBarStyle': 'noreverse bg:#222222',
'typeBarTextStyle': '',
'magicPrefix': '%',
'viMode': False
'viMode': False,
}

class Settings():
Expand Down
10 changes: 5 additions & 5 deletions src/Language/Haskell/PtGhci/Ghci.hs
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,6 @@ module Language.Haskell.PtGhci.Ghci (
Stream(..)
) where

-- | This module consists of logic that relates to communicating with the GHCi
-- process. Portions of the code in this module are taken verbatim from Neil
-- Mitchell's fabulous ghcid project. The parts that are messy and/or buggy
-- are mine.

import Language.Haskell.PtGhci.Prelude hiding (traceIO, appendFile)
import Debug.Trace (traceIO)
import System.Process
Expand All @@ -30,6 +25,11 @@ import Language.Haskell.Ghcid.Parser
import Language.Haskell.Ghcid.Types
import Language.Haskell.Ghcid.Util

-- | This module consists of logic that relates to communicating with the GHCi
-- process. Portions of the code in this module are taken verbatim from Neil
-- Mitchell's fabulous ghcid project. The parts that are messy and/or buggy
-- are mine.

streamLogFile = "streams.log"

appendLine :: Handle -> String -> IO ()
Expand Down

0 comments on commit 50577f2

Please sign in to comment.