haskell-mode
haskell-mode copied to clipboard
Ask for session target
It seems now that with the work towards not asking the user questions at the start of each session, you are no longer asked for which target you want to use.
This means that if I'm starting to hack on a project with multiple targets, I'm suddenly dropped into an Interactive Haskell buffer telling me that it can't find modules from packages that aren't listed in the default target.
How can I change this behaviour?
There is haskell-session-change-target. But then you are right that the first load tries with default target first and the is not optimal.
What do you propose?
If there are multiple targets in the .cabal file, then ask (especially with the new ido-based listing); otherwise, just use the default.
Will you implement this?
I can have a look, but no promises.
@gracjan, @ivan-m, the sister-project, https://github.com/jyp/dante, implements this using directory-local variables, in an exceptionally clever way -- all that is needed is a single defcustom: https://github.com/jyp/dante/blob/master/dante.el#L99
Then, we only need to supply .dir-locals.el inside the project directory:
((nil
.((dante-target . "lib:foo"))))
..and it automagically picks it up.
This is based on the somewhat rarely-mentioned Emacs feature, called "directory variables": https://www.gnu.org/software/emacs/manual/html_node/emacs/Directory-Variables.html
Well, .dir-locals.el is not my favorite mechanism for, well, anything.
Why? This is essentially project configuration, as far as I can see.
Since the picking of the default cabal target is not really deducible in the general case [1], I would say at least its default value belong to project configuration.
--
- consider multi-executable projects also defining libraries -- working with a couple of such beasts now : -)
I agree that there should be a way to specify default target for cabal invocations and that this default should be permanently stored somewhere. Just .dir-locals.el irks me wrong way.
But I'd love to see functionality that:
- lists potential targets from a cabal/stack file
- saves selection somewhere for later
And then C-c C-l will use the saved target selection and C-u C-c C-l would show the potential targets again.
And I think that 'saving for later' should be done automatically for the user, so that nobody has to edit .dir-locals.el by hand.
FYI you can force emacs to run haskell-session-choose-target with .dir-locals.el and recover this exact behavior. For example, for my test suite I have
;; In /root-project/TestSuite/.dir-locals.el
((nil . ((dante-target . "test:VSMTTest") ;; unnecessary dante specifics
(dante-project-root . "~/Research/VSmt/haskell/vsmt") ;; unnecessary dante specifics
(eval . (haskell-session-choose-target)) ;; this line will run the function when a buffer opens in any file this .dir-locals.el file is in scope
)))
Now anytime you enter a buffer in TestSuite emacs will run the function haskell-session-choose-target and you can pick from whichever target it picks up. I'm not sure how to default it to test:foo yet though.
In any case, it is not necessary to code this into haskell-mode especially if .dir-locals.el use is discouraged