Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Structured Haskell Mode [SHM]: How to delete single bracket or string quote by <backspace> or <del>?

Suppose I want to remove parentheses around some expression, e.g. I want to unwrap (not True).

  • Pressing <backspace> with the cursor standing right after closing parenthesis does not delete it, but the cursor jumps inside the parentheses (runs shm/del).
  • Pressing <delete> when the cursor is placed over opening parenthesis deletes everything inside, including the parentheses themselves (runs delete-char).

The same goes with string double quote delimiters, curly brackets, square brackets, and I believe something else.

Is there some predefined function to unwrap expression in SHM? Or should I override this behaviour with some manual key bindings/actions?

like image 513
Geradlus_RU Avatar asked Dec 02 '25 08:12

Geradlus_RU


1 Answers

structured-haskell-mode is very heavily influenced by paredit, which is where it gets the basic movement and editing bindings from. You can see what commands paredit provides either by looking it up in the Emacs help system (easiest way: open up a lisp buffer, enable paredit, C-h m) or using this handy cheatsheet (which looks reasonable but I haven't read).

Also, this video introduction to paredit for Lisp is probably worth watching.

For your specific question: M-s deletes the current level of nesting. In paredit this works for parentheses, brackets or quotes, but it looks like shm only supports parentheses at the moment. You can invoke it anywhere inside an expression:

((a |b c) d e f)
M-s
(a b c d e f)

EDIT: As @ReinHenrichs pointed out, you have to expand the selection to the whole node using M-a before using M-s to delete the surrounding parentheses, which is why it wasn't working for me earlier.

In the meantime, a decent workaround would be to rebind DEL to something like haskell-indentation-delete-backward-char (or whatever is appropriate for your setup) so that you can delete structural characters as before. From a bit of experimenation, shm seems to gracefully degrade for code that doesn't parse properly, so this isn't too inconvenient.

like image 138
Tikhon Jelvis Avatar answered Dec 04 '25 00:12

Tikhon Jelvis



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!