hasky-mode / ideas

An alternative Emacs mode for Haskell (so far, I collect here ideas and links)
4 stars 0 forks source link

+TITLE: Hasky Mode

+AUTHOR: Mark Karpov

+DATE: Tuesday, 19 January 2016

+STARTUP: showeverything

** Syntax highlighting =easy=

Two things here: Cabal files and Haskell sources. In Haskell sources we need to highlight Haddock markup in doc comments. See how it's currently done in Org sources, =markdown-mode= sources, and what is in =haskell-mode= so far.

** Indentation =needs experiments, moderate=

It's too hard and error-prone to parse Haskell in Emacs Lisp. There is [[https://github.com/chrisdone/structured-haskell-mode][Structured Haskell Mode]], but it's too slow (microseconds matter when you type and get visual response, there are studies about this stuff), it's too flashy. It does not work with my [[https://github.com/mrkkrp/modalka][Modalka]]. I guess Chris managed to make it work with his God Mode, but I don't like it either, Modalka is way superior, IMO (nothing personal, I like his other projects). However, the idea with using Haskell to extract vector of source spans is good. Perhaps, we could use the principle in not-so-flashy way and on limited fragments when re-indenting is necessary.

What about Cabal files? Well, it would be better if we could use similar approach as for Haskell sources — seems more robust.

Other thoughts: implement as minor mode, but turn on by default — user should be able to use it out-of-box. Support for different styles and indentation steps. The thing should be really flexible and well-designed.

This is really a thing that I would be glad to have in a bug-free, lightweight, flexible, and fast form. Should be doable.

** Complete interface to Stack à la Magit =moderate=

Cabal sucks, let's omit support for that thing. The hard thing here is those pretty pop-ups. But there is [[https://github.com/abo-abo/hydra][Hydra]] and [[http://magit.vc/manual/magit-popup/][Magit popup]] itself as a separate library. If we leverage one of these, it's not that hard. Use what is worth re-using from [[https://github.com/mrkkrp/ebal][Ebal]] and then abandon it (this name translates from Russian as “fucked”, and it supported only Cabal originally and I looove Cabal, you know).

Also, commands like =stack haddock= and =stack test --coverage= should open HTML reports in browser on success by default.

** Normal navigation, jumping to functions

TAGS file should be generated automatically with =hasktags= when it's missing or out-of-date. Of course it should work instantly and always, without the need to start some sort of session.

** REPL =easy=

Make REPL as one of these Stack commands with the ability to select build target, that's all. Steal some code from =haskell-mode=, maybe.

** Creation of a new project

Handle generation of Cabal file here and other boilerplate as well. I already have something like that in [[https://github.com/mrkkrp/ebal][Ebal]], but that can be greatly improved.

** Minor primitives for editing

Here are some things that are useful.

*** Language pragmas management

There should be a command to add pragmas to current file. The command
should be able to find where to put those pragmas, how to keep them
sorted and beautiful. There should be various options. I have working
prototype in my configuration [[https://github.com/mrkkrp/dot-emacs/blob/master/mk/mk-haskell.el][here]].

*** Imports management

This one should be really smart too. Automatically form list of imports
with configurable style. It should be able to add to list of exported
symbols and in general allow to work with all import syntax. I have
working prototype in my configuration [[https://github.com/mrkkrp/dot-emacs/blob/master/mk/mk-haskell.el][here]].

** The system should be able to diagnose what's wrong with it

It should give clear and understandable recommendations how to resolve many common problems.

** Flycheck

I really care only for Flycheck, the rest I can handle. =flycheck-haskell= depends on =haskell-mode= — too bad, but I can add built-in support into my package or even make Flycheck a dependency and tune it more tightly (with good results I guess). I can probably provide =husky-mode= with more powerful interface to Haskell internals than in =haskell-mode= and make it even better than =flycheck-haskell=. For a start, all the code is available for hacking anyway.

Also, there is that problem with Cabal-generated macros (min-versions for example). We should handle that decently while we're at it. Flycheck's author doesn't care, so we have to do it ourselves. There is a hackish solution in my config — a place to start our digging.