Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for RefactoringTools/HaRe to the Haskell layer #8664

Closed
mrkgnao opened this issue Apr 8, 2017 · 4 comments
Closed

Add support for RefactoringTools/HaRe to the Haskell layer #8664

mrkgnao opened this issue Apr 8, 2017 · 4 comments
Labels
- Mailling list - Feature request Haskell stale marked as a stale issue/pr (usually by a bot)

Comments

@mrkgnao
Copy link

mrkgnao commented Apr 8, 2017

HaRe is an amazing refactoring tool that I just learned about. It does renaming, promoting and demoting of definitions, etc.

I actually learned about it from an announcement for haskell-tools, which is seeing more activity but only has Atom integration now. On the other hand, a HaRe installation generates some Emacs Lisp (it's not on MELPA yet, which is a problem) which you can autoload in user-config.

I think many people would like Spacemacs support for it: see RefactoringTools/HaRe#7. I've written some bindings for my own use, which are given below. Here's an example: suppose we have this silly code:

original :: IO ()
original = print val
  where
    val =
      if val' == 3
        then 4
        else 5
    val' = 3

With my cursor on the definition of val, on pressing SPC m e k or , e k (hare-refactor-lift-one), val is extracted as follows:

original :: IO ()
original = print (val val')
  where
    val' = 3

val val' =
  if val' == 3
    then 4
    else 5

Here is what I have currently in init.el, in user-config. (I don't know if it's good to load packages there, I'm a noob, haha.) The first few lines are from the HaRe readme.

(add-to-load-path 
  "/home/mrkgnao/.stack/snapshots/x86_64-linux/lts-8.8/8.0.2/share/x86_64-linux-ghc-8.0.2/HaRe-0.8.4.0/elisp/")
(require 'hare)
(autoload 'hare-init "hare" nil t)

(spacemacs/declare-prefix-for-mode 'haskell-mode "me" "haskell/hare-refactor")
(spacemacs/set-leader-keys-for-major-mode 'haskell-mode
  "ej" 'hare-refactor-demote
  "ek" 'hare-refactor-lift-one
  "eK" 'hare-refactor-lifttotop
  "ei" 'hare-refactor-iftocase
  "ey" 'hare-refactor-dupdef
  "ec" 'hare-refactor-rename
  )

(defun haskell-mode-custom-hook ()
  (message "Running haskell-mode-hook")
  (intero-mode)
  (push '(company-ghci :with company-yasnippet
                       :with company-dabbrev)
        company-backends-haskell-mode)
  (interactive-haskell-mode)
  (turn-on-haskell-indentation)
  (hlint-refactor-mode +1)
  (hindent-mode)

  ;; This is new
  (ghc-init)
  (hare-init)

  (setq haskell-stylish-on-save t)
  (message "Completed haskell-mode-hook"))

(add-hook 'haskell-mode-hook 'haskell-mode-custom-hook)

Other concerns:

  • how well will it play with Intero? Not seeing any trouble so far, but it relies on ghc-mod internally, which I've heard isn't very compatible with Stack.
@alanz
Copy link
Contributor

alanz commented Apr 8, 2017

In terms of other concerns, ghc-mod does work with stack. But also with plain cabal projects. Which is one of the main reasons we use it.

If you want to make a PR on haskell mode, or the spacemacs layer, that would be awesome.

@mrkgnao
Copy link
Author

mrkgnao commented Apr 8, 2017

I'm not sure how to go about "guessing" the path to the elisp/ directory as I don't have any experience with writing cross-platform-y things like that, especially since there will be people who don't use Stack.

If that could be put into a defvar (I think that's the correct term?) then I could just make a PR by copying my bindings into the existing Haskell layer. I'm not sure what the official Spacemacs stance on non-MELPA stuff is, though. Maybe it could be similar to an optional Flycheck checker in that it'd only be enabled if present?

@alanz
Copy link
Contributor

alanz commented Apr 8, 2017

Sounds good to me. Then experts who are irked by the defvar can fix it up, which is the joy of community driven software dev. Make a positive change, even if it is not perfect.

@github-actions
Copy link

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Please let us know if this issue is still valid!

@github-actions github-actions bot added the stale marked as a stale issue/pr (usually by a bot) label Feb 28, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
- Mailling list - Feature request Haskell stale marked as a stale issue/pr (usually by a bot)
Projects
None yet
Development

No branches or pull requests

3 participants