lhs2tex
lhs2tex copied to clipboard
Add option to remove the -ignore-dot-ghci flag
I am writing a document in a folder other than the one with the code. I have a .ghci file that includes the required directories. When I load the file using haskell-mode in emacs all the modules are correctly loaded.
However when using \perform or \eval I can't evaluate the expressiones that depend on those external modules. It seems the -ignore-dot-ghci is hardcoded at the end of the invocation to ghci, hence I cannot override it using the -read-dot-ghci nor -ghci-script flags.
What is the rationale for ignoring the .ghci files? is it possible to configure the document to accept such files?
Thanks
I agree that adding the options in the end is a bad idea. I think that the main reason I added ignore-dot-ghci
is (relative) safety. A .ghci
file might contain code that's executed or might affect what happens in a document, so I'd rather want someone to make an explicit decision here. I think I'll add the option to the beginning of the command line though, so that it can be overridden explicitly.
Ah, I now see why I added them to the end :) The %options
flag contains the entire command line including the binary name, so inserting options at the beginning requires being more clever about plugging things together. I'll think a bit more about it.
Thanks for the quick replies!
Maybe it is easier to add a directive like:
%options ghci-load-dot-ghci yes
%options ghci ...
Which will just remove the -ignore-dot-ghci flag from the process invocation. Then you can keep the default as it is now without major modifications.
It seems to be a minor change, without knowing the code base it seems the src/Main.lhs file needs to be modified. But I don't know where to add "ghci-load-dot-ghci" as a new value for the opts operation. Maybe you can point me to where I need to tinker, and I can send you a patch.
Thanks
Wow, 2 years later and I came back to the same issue! This time I explicitly added the directories into the %options directory:
%options ghci -i/path/to/mycode
Still, for consistency and to avoid spurious errors it would be nice to have a @use-dot-ghci
directive. I looked into the implementation, and I think the following modification in Main.lhs
would be enough:
> external :: String -> XIO Exc State String
> external expr = do st <- get
> let os = opts st
> f = file st
> ex = externals st
> ghcimode = "ghci" `isPrefixOf` os
> ghcidotmode = "ghci-dot" `isPrefixOf` os && (not ghcidotmode) -- as ghci is prefix of ghci-dot
> cmd
> | ghcidotmode = (replace "ghci" "ghci-dot" os) ++ " -v0 " ++ f
> | ghcimode = os ++ " -v0 -ignore-dot-ghci " ++ f
> | otherwise = (if null os then "hugs " else os ++ " ") ++ f
Here I add the ghcidotmode
which simply removes the flag. The replace
function should replace all instances of ghci-dot
for ghci
in the options string. It can be done using Data.List.Utils.replace
.
I'm sorry I don't send a proper pull request, but I guess it will be easier for you to add such a small fix.
Cheers!