[add :grep command to jhci
John Meacham <john@repetae.net>**20051202034821] hunk ./Interactive.hs 4
+import IO(stdout)
+import List(sort)
+import Maybe
+import qualified Data.Map as Map
hunk ./Interactive.hs 9
+import Text.Regex
+import Text.Regex.Posix(regcomp,regExtended)
hunk ./Interactive.hs 12
-import Util.Interact
+
+import Doc.DocLike
+import Doc.Pretty
+import GenUtil
hunk ./Interactive.hs 17
-import Version
+import HsSyn
+import Name.Name
hunk ./Interactive.hs 20
+import Util.Interact
+import Version
+
+printDoc doc = do
+    displayIO stdout (renderPretty 0.9 80 doc)
+    putStrLn ""
+
+{-
+ 'f' - normal value
+ 'C' - data constructor
+ 'T' - type constructor
+ 'L' - class
+ '?' - odd
+-}
+
+nameTag :: NameType -> Char
+nameTag TypeConstructor = 'T'
+nameTag DataConstructor = 'C'
+nameTag ClassName = 'L'
+nameTag Val = 'f'
+nameTag _ = '?'
hunk ./Interactive.hs 43
-interact _ho = beginInteraction emptyInteract { interactSettables = ["prog", "args"], interactVersion = versionString }
+interact ho = beginInteraction emptyInteract { interactSettables = ["prog", "args"], interactVersion = versionString, interactCommands = commands } where
+    commands = [cmd_mods,cmd_grep]
+    cmd_mods = InteractCommand { commandName = ":mods", commandHelp = "mods currently loaded modules", commandAction = do_mods }
+    do_mods act _ _ = do
+        printDoc $ fillSep (map tshow $ Map.keys $  hoExports ho)
+        return act
+    cmd_grep = InteractCommand { commandName = ":grep", commandHelp = "show names matching a regex", commandAction = do_grep }
+    do_grep act _ "" = do
+        putStrLn ":grep <regex>"
+        return act
+    do_grep act _ arg = do
+        rx <- catch ( Just `fmap` regcomp arg regExtended) (\_ -> return Nothing)
+        case rx of
+            Nothing -> putStrLn $ "Invalid regex: " ++ arg
+            Just rx -> mapM_ putStrLn $ sort [ nameTag (nameType v):' ':show v | v <- Map.keys (hoDefs ho), isJust (matchRegex rx (show v)) ]
+        return act
hunk ./Main.hs 136
-    putStrLn $ "Initial annotate: " ++ show (Map.keys $ hoModules ho)
+    --putStrLn $ "Initial annotate: " ++ show (Map.keys $ hoModules ho)
hunk ./Main.hs 587
+
hunk ./Util/Interact.hs 114
+            [m] -> let [a] =  [ a | InteractCommand { commandName = n, commandAction = a } <-  interactCommands act, n == m] in do
+                act' <- a act m arg
+                beginInteraction act'