|
| 1 | +<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> |
| 2 | +<html> |
| 3 | +<!-- This manual is for Haskell mode, version 16.1-git |
| 4 | + |
| 5 | +Copyright (C) 2013-2016 Haskell Mode contributors. |
| 6 | + |
| 7 | +Permission is granted to copy, distribute and/or modify this document |
| 8 | +under the terms of the http://www.gnu.org/licenses/fdl.html (GNU |
| 9 | +Free Documentation License), Version 1.3 or any later version published |
| 10 | +by the Free Software Foundation; with no Invariant Sections, no |
| 11 | +Front-Cover Texts and no Back-Cover Texts. --> |
| 12 | +<!-- Created by GNU Texinfo 5.2, http://www.gnu.org/software/texinfo/ --> |
| 13 | +<head> |
| 14 | +<title>Haskell Mode 16.1-git: Editing Haskell Code</title> |
| 15 | + |
| 16 | +<meta name="description" content="Haskell Mode 16.1-git: Editing Haskell Code"> |
| 17 | +<meta name="keywords" content="Haskell Mode 16.1-git: Editing Haskell Code"> |
| 18 | +<meta name="resource-type" content="document"> |
| 19 | +<meta name="distribution" content="global"> |
| 20 | +<meta name="Generator" content="makeinfo"> |
| 21 | +<meta http-equiv="Content-Type" content="text/html; charset=utf-8"> |
| 22 | +<link href="index.html#Top" rel="start" title="Top"> |
| 23 | +<link href="Concept-index.html#Concept-index" rel="index" title="Concept index"> |
| 24 | +<link href="index.html#Top" rel="up" title="Top"> |
| 25 | +<link href="Unicode-support.html#Unicode-support" rel="next" title="Unicode support"> |
| 26 | +<link href="Getting-Started.html#Getting-Started" rel="prev" title="Getting Started"> |
| 27 | +<style type="text/css"> |
| 28 | +<!-- |
| 29 | +a.summary-letter {text-decoration: none} |
| 30 | +blockquote.smallquotation {font-size: smaller} |
| 31 | +div.display {margin-left: 3.2em} |
| 32 | +div.example {margin-left: 3.2em} |
| 33 | +div.indentedblock {margin-left: 3.2em} |
| 34 | +div.lisp {margin-left: 3.2em} |
| 35 | +div.smalldisplay {margin-left: 3.2em} |
| 36 | +div.smallexample {margin-left: 3.2em} |
| 37 | +div.smallindentedblock {margin-left: 3.2em; font-size: smaller} |
| 38 | +div.smalllisp {margin-left: 3.2em} |
| 39 | +kbd {font-style:oblique} |
| 40 | +pre.display {font-family: inherit} |
| 41 | +pre.format {font-family: inherit} |
| 42 | +pre.menu-comment {font-family: serif} |
| 43 | +pre.menu-preformatted {font-family: serif} |
| 44 | +pre.smalldisplay {font-family: inherit; font-size: smaller} |
| 45 | +pre.smallexample {font-size: smaller} |
| 46 | +pre.smallformat {font-family: inherit; font-size: smaller} |
| 47 | +pre.smalllisp {font-size: smaller} |
| 48 | +span.nocodebreak {white-space:nowrap} |
| 49 | +span.nolinebreak {white-space:nowrap} |
| 50 | +span.roman {font-family:serif; font-weight:normal} |
| 51 | +span.sansserif {font-family:sans-serif; font-weight:normal} |
| 52 | +ul.no-bullet {list-style: none} |
| 53 | +--> |
| 54 | +</style> |
| 55 | +<link rel="stylesheet" type="text/css" href="haskell-mode.css"> |
| 56 | + |
| 57 | +<link rel="shortcut icon" href="haskell-mode-32x32.png"> |
| 58 | +</head> |
| 59 | + |
| 60 | +<body lang="en" bgcolor="#FFFFFF" text="#000000" link="#0000FF" vlink="#800080" alink="#FF0000"> |
| 61 | +<div class="background"> </div><a name="Editing-Haskell-Code"></a> |
| 62 | +<div class="header"> |
| 63 | +<p> |
| 64 | +Next: <a href="Unicode-support.html#Unicode-support" accesskey="n" rel="next">Unicode support</a>, Previous: <a href="Getting-Started.html#Getting-Started" accesskey="p" rel="prev">Getting Started</a>, Up: <a href="index.html#Top" accesskey="u" rel="up">Top</a> [<a href="Concept-index.html#Concept-index" title="Index" rel="index">Index</a>]</p> |
| 65 | +</div> |
| 66 | +<hr> |
| 67 | +<a name="Editing-Haskell-Code-1"></a> |
| 68 | +<h2 class="chapter">4 Editing Haskell Code</h2> |
| 69 | + |
| 70 | +<a name="index-haskell_002dmode-1"></a> |
| 71 | +<a name="index-haskell_002dmode"></a> |
| 72 | + |
| 73 | +<p><em>Haskell Mode</em> is actually a collection of so-called major |
| 74 | +modes<a name="DOCF1" href="#FOOT1"><sup>1</sup></a> one of which is called |
| 75 | +<code>haskell-mode</code>. To avoid confusion, when referring to this package |
| 76 | +the name “Haskell mode” is written in a normal font, whereas when |
| 77 | +referring the major mode of the same name <code>haskell-mode</code> written |
| 78 | +with a dash in-between in a typewriter font is used. |
| 79 | +</p> |
| 80 | +<p>As one might guess, <code>haskell-mode</code> is the (programming |
| 81 | +language<a name="DOCF2" href="#FOOT2"><sup>2</sup></a>) |
| 82 | +major mode for editing (non-literate) Haskell source |
| 83 | +code. <code>haskell-mode</code> is associated with the file extensions listed |
| 84 | +below by default<a name="DOCF3" href="#FOOT3"><sup>3</sup></a>. |
| 85 | +</p> |
| 86 | +<dl compact="compact"> |
| 87 | +<dt><samp>.hs</samp></dt> |
| 88 | +<dd><p>official file extension for (non-literate) Haskell 98/2010 files |
| 89 | +</p></dd> |
| 90 | +<dt><samp>.hsc</samp></dt> |
| 91 | +<dd><p>“almost-Haskell” input file for the |
| 92 | +<a href="http://www.haskell.org/ghc/docs/latest/html/users_guide/hsc2hs.html">hsc2hs</a> |
| 93 | +pre-processor |
| 94 | +</p></dd> |
| 95 | +<dt><samp>.cpphs</samp></dt> |
| 96 | +<dd><p>input file for the <a href="http://projects.haskell.org/cpphs/">cpphs</a> |
| 97 | +pre-processor |
| 98 | +</p></dd> |
| 99 | +</dl> |
| 100 | + |
| 101 | +<a name="index-literate-programming"></a> |
| 102 | +<a name="index-literate_002dhaskell_002dmode"></a> |
| 103 | + |
| 104 | +<p>The major mode <code>literate-haskell-mode</code> (which is derived from |
| 105 | +<code>haskell-mode</code> and thus transitively from <code>prog-mode</code>) |
| 106 | +provides support for |
| 107 | +<a href="http://www.haskell.org/haskellwiki/Literate_programming">literate |
| 108 | +Haskell programs</a> and is associated with the <samp>.lhs</samp> file extension |
| 109 | +by default. |
| 110 | +</p> |
| 111 | +<p><code>literate-haskell-mode</code> supports Bird-style as well as TeX-style |
| 112 | +literate Haskell files. The currently detected literate Haskell variant |
| 113 | +is shown in the mode line (see <a href="http://www.gnu.org/software/emacs/manual/html_node/emacs/Mode-Line.html#Mode-Line">(emacs)Mode Line</a>) as either |
| 114 | +‘<samp>LitHaskell/bird</samp>’ or ‘<samp>LitHaskell/tex</samp>’. |
| 115 | +</p> |
| 116 | +<a name="Font-Lock-Support"></a> |
| 117 | +<h3 class="section">4.1 Font Lock Support</h3> |
| 118 | + |
| 119 | +<p><code>haskell-mode</code> supports <em>syntax highlighting</em> via Emacs’ Font |
| 120 | +Lock minor mode which should be enabled by default in current |
| 121 | +Emacsen. See <a href="http://www.gnu.org/software/emacs/manual/html_node/emacs/Font-Lock.html#Font-Lock">(emacs)Font Lock</a>, for more information on how to |
| 122 | +control <code>font-lock-mode</code>. |
| 123 | +</p> |
| 124 | +<img src="anim/font-lock.gif" alt="anim/font-lock"> |
| 125 | + |
| 126 | +<p>Syntax highlighting facilities parse strings and string escape sequences |
| 127 | +and are able to highlight unrecognized constructs. |
| 128 | +</p> |
| 129 | +<img src="anim/string-escape-highlight.gif" alt="anim/string-escape-highlight"> |
| 130 | + |
| 131 | + |
| 132 | +<a name="Managing-imports"></a> |
| 133 | +<h3 class="section">4.2 Managing imports</h3> |
| 134 | + |
| 135 | +<p>There are a few functions for managing imports. |
| 136 | +</p> |
| 137 | +<a name="Jump-to-imports"></a> |
| 138 | +<h4 class="subsection">4.2.1 Jump to imports</h4> |
| 139 | + |
| 140 | +<p>To jump to your import list, run |
| 141 | +</p> |
| 142 | +<p><code>M-x haskell-navigate-imports</code> |
| 143 | +</p> |
| 144 | +<p>It’s nicer to have a keybinding to do this, for example: |
| 145 | +</p> |
| 146 | +<div class="lisp"> |
| 147 | +<pre class="lisp">(define-key haskell-mode-map (kbd "<f8>") 'haskell-navigate-imports) |
| 148 | +</pre></div> |
| 149 | + |
| 150 | +<p>You can hit it repeatedly to jump between groups of imports. It will |
| 151 | +cycle. |
| 152 | +</p> |
| 153 | +<a name="Format-imports"></a> |
| 154 | +<h4 class="subsection">4.2.2 Format imports</h4> |
| 155 | + |
| 156 | +<p>To generally format (sort, align) your imports, you can run |
| 157 | +</p> |
| 158 | +<p><code>M-x haskell-mode-format-imports</code> |
| 159 | +</p> |
| 160 | +<p>Or <kbd>C-c C-.</kbd>. |
| 161 | +</p> |
| 162 | +<a name="Sort-imports"></a> |
| 163 | +<h4 class="subsection">4.2.3 Sort imports</h4> |
| 164 | + |
| 165 | +<p>To just sort imports, jump to an import section and run |
| 166 | +</p> |
| 167 | +<p><code>M-x haskell-sort-imports</code> |
| 168 | +</p> |
| 169 | +<a name="Align-imports"></a> |
| 170 | +<h4 class="subsection">4.2.4 Align imports</h4> |
| 171 | + |
| 172 | +<p>To just align imports, jump to an import section and run |
| 173 | +</p> |
| 174 | +<p><code>M-x haskell-align-imports</code> |
| 175 | +</p> |
| 176 | +<a name="Entering-imports"></a> |
| 177 | +<h4 class="subsection">4.2.5 Entering imports</h4> |
| 178 | + |
| 179 | +<p>If you have Haskell Interactive Mode enabled and a session open, |
| 180 | +you can write |
| 181 | +</p> |
| 182 | +<p><code>import</code> |
| 183 | +</p> |
| 184 | +<p>And then hit <kbd>SPC</kbd> (running <code>M-x haskell-mode-contextual-space</code>) |
| 185 | +which will prompt a list of all modules, either installed modules or |
| 186 | +local project directory files. Then it’ll insert it and then format that |
| 187 | +module section. |
| 188 | +</p> |
| 189 | +<a name="stylish_002dhaskell"></a> |
| 190 | +<h4 class="subsection">4.2.6 stylish-haskell</h4> |
| 191 | + |
| 192 | +<p>As an alternative to the elisp functions described above, haskell-mode |
| 193 | +can use the program <a href="http://hackage.haskell.org/package/stylish-haskell">stylish-haskell</a> |
| 194 | +to format imports. You can set this behavior by typing: <kbd>M-x |
| 195 | +customize-variable <span class="key">RET</span> haskell-stylish-on-save</kbd>. You can |
| 196 | +install <code>stylish-haskell</code> by running <code>stack install |
| 197 | +stylish-haskell</code>, or if you have not installed <code>stack</code>, |
| 198 | +<code>cabal install stylish-haskell</code>. |
| 199 | +</p> |
| 200 | +<a name="Completion-support"></a> |
| 201 | +<h3 class="section">4.3 Completion support</h3> |
| 202 | + |
| 203 | +<p><code>haskell-mode</code> can complete symbols, pragma directives and language |
| 204 | +extensions. This is part of <code>haskell-interactive-mode</code>. |
| 205 | +</p> |
| 206 | +<img src="anim/company-mode-language-pragma.gif" alt="anim/company-mode-language-pragma"> |
| 207 | + |
| 208 | +<p>If haskell-interactive-mode is enabled and working haskell mode provides |
| 209 | +completions for import statements taking into account currently loaded |
| 210 | +and available packages. |
| 211 | +</p> |
| 212 | +<img src="anim/company-mode-import-statement.gif" alt="anim/company-mode-import-statement"> |
| 213 | + |
| 214 | +<a name="Profiling-and-Debugging-support"></a> |
| 215 | +<h3 class="section">4.4 Profiling and Debugging support</h3> |
| 216 | + |
| 217 | +<p>When profiling code with GHC, it is often useful to add |
| 218 | +<a href="https://downloads.haskell.org/~ghc/latest/docs/html/users_guide/profiling.html#cost-centres">cost centres</a> by hand. These allow finer-grained information about |
| 219 | +program behavior. <code>haskell-mode</code> provides the function |
| 220 | +<code>haskell-mode-toggle-scc-at-point</code> to make this more convenient. |
| 221 | +It will remove an SCC annotation at point if one is present, or add |
| 222 | +one if point is over whitespace. By default it is bound to <kbd>C-c C-s</kbd>. |
| 223 | +</p> |
| 224 | +<div class="footnote"> |
| 225 | +<hr> |
| 226 | +<h4 class="footnotes-heading">Footnotes</h4> |
| 227 | + |
| 228 | +<h3><a name="FOOT1" href="#DOCF1">(1)</a></h3> |
| 229 | +<p>for more information about the concept of <em>major |
| 230 | +modes</em> see <a href="http://www.gnu.org/software/emacs/manual/html_node/emacs/Major-Modes.html#Major-Modes">(emacs)Major Modes</a></p> |
| 231 | +<h3><a name="FOOT2" href="#DOCF2">(2)</a></h3> |
| 232 | +<p><code>haskell-mode</code> is derived from <code>prog-mode</code></p> |
| 233 | +<h3><a name="FOOT3" href="#DOCF3">(3)</a></h3> |
| 234 | +<p>for more information about file associations, |
| 235 | +see <a href="http://www.gnu.org/software/emacs/manual/html_node/emacs/Choosing-Modes.html#Choosing-Modes">(emacs)Choosing Modes</a></p> |
| 236 | +</div> |
| 237 | +<hr> |
| 238 | +<div class="header"> |
| 239 | +<p> |
| 240 | +Next: <a href="Unicode-support.html#Unicode-support" accesskey="n" rel="next">Unicode support</a>, Previous: <a href="Getting-Started.html#Getting-Started" accesskey="p" rel="prev">Getting Started</a>, Up: <a href="index.html#Top" accesskey="u" rel="up">Top</a> [<a href="Concept-index.html#Concept-index" title="Index" rel="index">Index</a>]</p> |
| 241 | +</div> |
| 242 | + |
| 243 | + |
| 244 | + |
| 245 | +</body> |
| 246 | +</html> |
0 commit comments