projectional-haskell / structured-haskell-mode

Structured editing minor mode for Haskell in Emacs
BSD 3-Clause "New" or "Revised" License
540 stars 38 forks source link

Am I doing it wrong? #120

Open paldepind opened 8 years ago

paldepind commented 8 years ago

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:

plural :: |a -> String
plural s = if length s > 1 then "s" else ""
plural :: [a| -> String
plural s = if length s > 1 then "s" else ""

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 commented 8 years ago

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 commented 8 years ago

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 commented 8 years ago

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 commented 8 years ago

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 commented 8 years ago

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 commented 7 years ago

@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 }.