Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p><em>Caveat:</em> I'm not a Haskell user, so take this with a grain of salt.</p> <p>When you press <kbd>RET</kbd> after the <code>Hello</code>, Emacs doesn't know you're going to add a <code>|</code> (<a href="http://en.wikibooks.org/wiki/Haskell/Type_declarations" rel="nofollow">quick search</a> shows you can have other symbols). The Haskell folks have deemed the proper indentation to be lined up directly below the <code>H</code> in <code>Hello</code>. If the indentation were to automatically line up with the <code>|</code> on the line above, then all the cases where you <em>don't</em> type a <code>|</code> will result in improper indentation. Damned if you do, damned if you don't...</p> <p>Other programming modes (C/C++, Lisp, Tcl, ...) have the same problem - they cannot know ahead of time what you're going to put on the next line, so the indentation my not be what you'd hoped for.</p> <p>One solution is to use <a href="http://www.gnu.org/software/emacs/manual/html_node/emacs/Electric-C.html" rel="nofollow">"electric"</a> keys, which is to say that they insert characters and also force re-indentation. You could easily define <kbd>|</kbd> to be electric with the following code:</p> <pre><code>(defun haskell-electric-| () "it's electric! (insert | and indent as long as the | follows whitespace)" (interactive) (insert "|") (if (string-match-p "^\\s-*|" (buffer-substring (line-beginning-position) (point))) (haskell-indentation-indent-line))) (define-key haskell-mode-map "|" 'haskell-electric-|) </code></pre> <p>I added a check to ensure that the <code>|</code> inserted is preceded by only whitespace, you can customize that however you want or remove the check altogether.</p> <p>I presume there might also be other symbols in Haskell that would be worth making electric.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload