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

Am I doing it wrong? #120

Open
paldepind opened this issue Dec 18, 2015 · 6 comments
Open

Am I doing it wrong? #120

paldepind opened this issue Dec 18, 2015 · 6 comments

Comments

@paldepind
Copy link

Hello @chrisdone

First of all thanks for the great work you have done for both the Haskell and the Emacs communities.

I'm finding that shm is working against me more often than it is helping me. I'm wondering if it's because I'm doing it wrong.

Just now I was trying to edit this simple piece of code:

plural :: (Ord a, Show a, Num a) => a -> String
plural s = if length s > 1 then "s" else ""

I had just changed the definition of the function and wanted to update the signature accordingly. I did something like this:

  • Moved the cursor inside the parentheses in the type class constraint.
  • Then I pressed ')' (shm/close-paren) until the entire type class constraint was selected.
  • I deleted the constraint with shm/delete. This left me with this (my cursor being right before the a)
plural :: |a -> String
plural s = if length s > 1 then "s" else ""
  • To wrap the a in brackets I typed [. This gave me both and opening and a closing bracket. So I deleted the closing bracket with delete-char and moved over the a.
plural :: [a| -> String
plural s = if length s > 1 then "s" else ""
  • From this position I typed ] to insert a closing bracket. But instead the cursor moved one character backwards (due to the end of of node behaviour of ]).
  • Unable to insert a closing bracket I decided to delete the [a and type it again. I deleted the a just fine, but the [ could not be deleted.
  • I slammed backspace a couple of time.

At this point shm had prevented me both from inserting the closing bracket and from deleting the opening bracket. I often end up in such situations unable to do what I want.

In the end I managed to get rid of the opening bracket with some other editing commands.

@chrisdone
Copy link
Member

To wrap something in brackets you can select it with C-M-<space> and then hit [. That'll give you [a].

In general SHM works on a complete tree. If you're trying to type one opening delimiter then the closing one you're going to have a bad time.

@paldepind
Copy link
Author

To wrap something in brackets you can select it with C-M- and then hit [. That'll give you [a].

At some point when writing the above post trying that actually occurred to me. It does work but doesn't seem very intuitive to me.

It still seems to me like some parts of shm is making my existing typing habits useless without any gains. It tries to guess what I'm doing and unfortunately it's sometimes wrong.

In the above case it decided that I actually didn't meant to delete anything even though I pressed backspace. Assuming that a user pressed the wrong key and simply ignoring it is not good UI IMO.

Here is another example: At one point I accidentally typed a = instead of a +. When trying to delete the = shm decided that it knew better and converted my editing command into a movement command (the gliding feature). Why would it do that? If I wanted to move backwards I would have typed backward-char or backward-word. How should I correct add n m = n = m with the cursor right after the last =.

I love the parts of shm that makes typing Haskell easier! I don't understand the parts where it wants to protect me from myself.

Another question. It is correct that when typing something like (foo bar) you have to press ) twice at the end to move the cursor to after the ). Is that intentional?

@paldepind
Copy link
Author

Today I accidentally wrote this:

eqToBool :: Eq a => a -> ->

That is, I mistakenly typed two ->s in a row. Gliding prevented me from deleting the last -> with backspace. Again the gliding behaviour seems to break my editing habits with no benefit.

@maerten
Copy link

maerten commented Mar 11, 2016

Found this issue while trying to understand why insertion of brackets/braces was suddenly broken!
I actually just installed spacemacs/emacs/shm at this point, just followed this example: https://www.reddit.com/r/haskell/comments/3kr6m3/update_i_got_spacemacs_working_using_stack_with/
At some point I'll probably be able to appreciate this feature, but for now I find this feature of this otherwise great plugin too distracting while trying to write some code :)

@paldepind : I have managed to disable this by adding the following to my .spacemacs [WARNING: it works for me after a quick test, but it could also break other things!]

(defun insert-closing-parenthesis ()
  "Insert closing parenthesis."
  (interactive)
  (shm-insert-string ")"))

(defun insert-closing-bracket ()
  "Insert closing bracket."
  (interactive)
  (shm-insert-string "]"))

(defun insert-closing-braces ()
  "Insert closing braces."
  (interactive)
  (shm-insert-string "}"))

(with-eval-after-load 'shm
  (define-key shm-map (kbd ")") 'insert-closing-parenthesis)
  (define-key shm-map (kbd "]") 'insert-closing-bracket)
  (define-key shm-map (kbd "}") 'insert-closing-braces))

@dramforever
Copy link

I occasionally have the same problem to. My workaround is to use delete-char until the syntax tree is valid again, then get back to normal.

It seems that delete-char is not touched by shm, so by using it you either confuse or un-confuse shm.

@emmanueldenloye
Copy link
Contributor

@maerten You can just press C-q then the character you actually want. So to insert a closing parenthesis, bracket or brace, just type C-q ) or C-q ] or C-q }.

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

5 participants