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

Stepped indentation with haskell-indentation-mode and yasnippets #719

Closed
eigengrau opened this issue Jun 11, 2015 · 23 comments
Closed

Stepped indentation with haskell-indentation-mode and yasnippets #719

eigengrau opened this issue Jun 11, 2015 · 23 comments

Comments

@eigengrau
Copy link
Contributor

When haskell-indent-mode is active, using ghc-insert-template-or-signature to expand a class instance stub, or expanding from a yasnippet keyword, produces odd indentation. It looks as if the layout rule is applied after every line.

instance Num Token where
    x + y = _body
            x - y = _body
                    x * y = _body
                            …
@eigengrau
Copy link
Contributor Author

I have noticed that when using haskell-indentation-mode instead, ghc-insert-template-or-signature yields the correct results, while yasnippet expansion (courtesy of haskell-snippets) still yields the stepping.

@gracjan
Copy link
Contributor

gracjan commented Jun 11, 2015 via email

@eigengrau eigengrau changed the title Stepped indentation with haskell-indent-mode and yasnippets/ghc-mod Stepped indentation with haskell-indentation-mode and yasnippets Jun 11, 2015
@eigengrau
Copy link
Contributor Author

Ah, okay, thanks. So this is for haskell-indentation-mode (no electric indent mode active). Yasnippets issue?

x = case var of
  cond -> value

          otherwise -> other

@gracjan
Copy link
Contributor

gracjan commented Jun 12, 2015

yassnippets have their own github issues page, I guess it is better to report there.

@lukehoersten
Copy link
Member

I'm seeing the same problem as you with haskell-indentation-mode and haskell-snippets.

Yasnippets really has no control over how the buffer treats indentation as the snippet goes in. All the haskell-snippets go in with spaces for indentation as well so I don't think tab characters are causing indentation to run or anything. You can see how straightforward the snippet is here:
https://github.com/haskell/haskell-snippets/blob/master/snippets/haskell-mode/case

My feeling at this point is that it's something to do with haskell-indentation-mode or yasnippet itself outside of the control of the snippet. In fact this used to work fine so my suspicion is that it's a regression.

@npostavs
Copy link

npostavs commented Dec 3, 2015

Hi, yasnippet dev here. It looks like there exists a case snippet in yasnippet-snippets which is where the snippet collection comes from in a typical install (MELPA). The yasnippet-snippets one lacks the # expand-env: ((yas-indent-line 'fixed)) which haskell-mode's has. Perhaps this is the reason for the problem?

Regardless, I suggest you ask @AndreaCrotti to update the haskell snippets in his repository, or else remove them entirely.

@AndreaCrotti
Copy link

Hi @npostavs yes well I can definitively update them, but just to be clear only the snippets in haskell mode that would have indentation need that right?
I think it's only class and case from what I can see so far, is that right?

@AndreaCrotti
Copy link

I tried and this works

AndreaCrotti/yasnippet-snippets#107

if that's all we need I'll merge that @npostavs @eigengrau
If anyone else could confirm that snippet works fine it would be great

@xuzhao9
Copy link

xuzhao9 commented Jan 29, 2016

Still have this problem on haskell-mode-20160128.621 and yasnippet-20160122.1056.
My snippet that triggers this problem see here:
https://pastebin.com/DQLzy2rg

@gracjan
Copy link
Contributor

gracjan commented Jan 29, 2016

@xuzhao9: Can you help us finding the root cause of this? Please do:

  • restart Emacs
  • try yassnippet with haskell-indent instead of haskell-indentation
  • disable electric-indent-mode

Please report back what you found, thanks.

@xuzhao9
Copy link

xuzhao9 commented Feb 1, 2016

Hello, I have restarted emacs.

  1. The result of using haskell-indent instead of haskell-indentation is slightly different but still problematic.
    See: http://pastebin.com/pAZnPiw7.
  2. Disabling electrc-indent-mode does not help either.

My emacs version is 24.5.1.

@jarmitage
Copy link

Hi,

I am also having this problem:

  1. Type snippet shortcut
  2. Use TAB or RET to expand
  3. Haskell code indents

Any ideas of even a quick workaround?

Thanks

@npostavs
Copy link

npostavs commented Jul 8, 2016

Is this still with the case snippet or other snippets? Perhaps it's best to disable yasnippet auto indenting for haskell mode:

(defun set-yasnippet-fixed-indent ()
  (setq-local yas-indent-line 'fixed))
(add-hook 'haskell-mode-hook #'set-yasnippet-fixed-indent) ; EDIT: had the wrong hook name

@jarmitage
Copy link

This is with other snippets. That doesn't seem to work either I'm afraid. Currently I am just disabling haskell-indentation-mode (manually, see: #90)

@npostavs
Copy link

npostavs commented Jul 8, 2016

This is with other snippets.

Please show a concrete example so that others might have a chance of replicating your problem.

@jarmitage
Copy link

jarmitage commented Jul 8, 2016

It's slightly complex, as I'm using Tidal which is built on Haskell and uses the same indentation mode.

An example snippet for Tidal would be:

# -*- mode: snippet -*-
# name: sustain 
# key: #s
# --
# sustain "$0"

And an example of using this in Tidal would be:

d1 $ sound "bd" # sustain "0.5"

or

d1 $ sound "bd"
    # sustain "0.5"

In either case, currently using the #s snippet causes indentation after triggering.

If you want I can try to see if the problem is exactly the same in plain haskell-mode, but you'll have to provide an example as I'm not a Haskell programmer.

@npostavs
Copy link

npostavs commented Jul 8, 2016

I'm neither a Haskell nor Tidal programmer :)

I had the wrong hook variable name in my suggestion above, edited now. After fixing that problem, it seems to work.

Started emacs with emacs -Q -L haskell-mode -L Tidal -L yasnippet -l haskell -l tidal.el -l yasnippet.el -f yas-global-mode

Evaluate

(progn (defun set-yasnippet-fixed-indent ()
         (setq-local yas-indent-line 'fixed))
       (add-hook 'haskell-mode-hook #'set-yasnippet-fixed-indent))

M-x tidal-mode
C-u M-x yas-new-snippet
Put

# -*- mode: snippet -*-
# name: sustain 
# key: #s
# --
# sustain "$0"

C-c C-l RET to load snippet
C-x b RET switch back to *scratch*
M-< C-w delete original text
Put

d1 $ sound "bd"
#s

Hit <tab>, now I have

d1 $ sound "bd"
# sustain ""

@jarmitage
Copy link

Wow amazing, can't wait to try this later! Thank you

@jarmitage
Copy link

That works for the case where the snippet is on a new line, but not when the snippet is in an existing line, which is much more common in Tidal. Any ideas for extending your function to include snippets in existing lines?

@npostavs
Copy link

npostavs commented Jul 9, 2016

I tried d1 $ sound "bd" #s and pressing <tab> gave me d1 $ sound "bd" # sustain "" with no change to indentation. Can you give an example where it doesn't work?

@jarmitage
Copy link

That's strange. Are you working with haskell-indentation-mode enabled too? I will have another go and check back here...

@npostavs
Copy link

npostavs commented Jul 9, 2016

Are you working with haskell-indentation-mode enabled too?

Yes, according to <f1> v haskell-indentation-mode RET (this is all using same emacs -Q -L haskell-mode -L Tidal ... setup detailed above).

@gracjan
Copy link
Contributor

gracjan commented Jul 19, 2016

Looks to me that this issue is more about yasnippets than haskell-indentation. Therefore closing.

Thanks for participation!

@gracjan gracjan closed this as completed Jul 19, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

7 participants