Skip to content

New indentation — using backspace to move to the previous indentation position #500

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

Closed
EDmitry opened this issue Mar 10, 2015 · 11 comments

Comments

@EDmitry
Copy link

EDmitry commented Mar 10, 2015

I have noticed one difference between original haskell-indentation and the new one. If I have (the cursor position is indicated with ^):

some :: Int -> Int
        ^

Hitting <Backspace> would move the cursor to the beginning of the line (the previous valid indentation position), but in the new indentation mode it just deletes one space.

I haven't looked more closely why this happens, but I have verified the difference exists when just switching branches, so all other settings are completely identical in my set up.

@EDmitry
Copy link
Author

EDmitry commented Mar 10, 2015

I visited the hi2 repo and found out that this is expected (<Del> is not binded anymore). <S-Tab> works well. The main reason I was using Backspace is because of this bug: #276 otherwise I could just hit <Tab> all the time

@gracjan
Copy link
Contributor

gracjan commented Mar 10, 2015

In hi2 TAB cycles forward till the last position and the backward. S-TAB cycles backward. DEL is not bound and does it own usual thing.

#276 should affect only haskell-indent which is different than haskell-indentation(hi2).

So this is not a bug.

@gracjan gracjan closed this as completed Mar 10, 2015
@EDmitry
Copy link
Author

EDmitry commented Mar 12, 2015

Is there a possibility to add an option to bind it back? I realized I kind of got used to it and don't mind any possible problems with it (I didn't experience any to be honest). It's hard to do anything with muscle memory once it has been acquired.

@gracjan
Copy link
Contributor

gracjan commented Mar 12, 2015

Can you bind to unindent for you locally, use it a little and see how it feels?

In theory binding is a good idea, in practice there were problems with exact mechanics how it should work. has already many options associated with it in Emacs.

Can you find out how other modes for indentation-based languages bind edit keys? Python mode usually is a good reference point.

@EDmitry
Copy link
Author

EDmitry commented Mar 12, 2015

I have tried Python and it seems like <Backspace> moves to the previous indentation place:

arr = [100] * 10000000

for x in range (0, 10000000 - 1):
    arr[x] = arr[x] - 1
    if arr[x] == 0:
        print x
        ^`<Backspace>`
    ^`<Backspace>`
^

@gergoerdi
Copy link

I've just updated my haskell-mode from an ancient version and immediately noticed the lack of this feature. My problem is not that unindent-or-delete-backwards is not bound to backspace by default; the problem is that I don't see where the functionality is implemented! (in v13.14.2)

Does that mean I need to revert to my old version from 2012 to get this functionality back?

@gergoerdi
Copy link

Would something like this work?

(defun haskell-indentation-at-beginning-of-line ()
  (and
   (not (= (current-column) 0))
   (= (haskell-indentation-current-indentation) (current-column))))

(defun haskell-indentation-unindent-or-delete-backwards ()
  (interactive)
  (if (haskell-indentation-at-beginning-of-line)
      (haskell-indentation-indent-backwards)
    (backward-delete-char 1)))

@gracjan
Copy link
Contributor

gracjan commented Sep 8, 2015

Authors of haskell-indentation provided two ways to control indentation:

  • TAB cycle that goes over all possible indentations for a line
  • SHIFT-TAB to unindent

@gergoerdi
Copy link

Yes, and neither of them is what I and the OP want. With the haskell-indentation-unindent-or-delete-backwards function mapped to [backspace], you can use backspace to delete one indentation level if you press it at the start of a line, or one character otherwise. This is exactly the functionality that OP was missing in the newer versions.

I'll prepare a proper pull request that adds these functions and maps [backspace] in turn-on-haskell-indentation, so that it matches its own documentation which states

turn-on-haskell-indentation

Improved variation of turn-on-haskell-indent indentation mode.
Rebinds <RET> and <DEL>, so that indentations can be set and
deleted as if they were real tabs.

@gracjan
Copy link
Contributor

gracjan commented Sep 8, 2015 via email

gergoerdi added a commit to gergoerdi/haskell-mode that referenced this issue Sep 12, 2015
unindent instead of deleting a single character. This restores the old
behaviour mentioned in `haskell-indentation-mode`'s docstring. See
haskell#500
@gergoerdi
Copy link

@EDmitry can you try my pull request and see if it works for you?

gergoerdi added a commit to gergoerdi/haskell-mode that referenced this issue Feb 16, 2016
…nindent

instead of deleting a single character. This restores the old behaviour
mentioned in `haskell-indentation-mode`'s docstring.

See haskell#500
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants