Klimi's new dotfiles with stow.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

2457 lines
83 KiB

4 years ago
  1. This is haskell-mode.info, produced by makeinfo version 6.5 from
  2. haskell-mode.texi.
  3. This manual is for Haskell mode, version 16.1-git
  4. Copyright © 2013-2017 Haskell Mode contributors.
  5. Permission is granted to copy, distribute and/or modify this
  6. document under the terms of the GNU Free Documentation License
  7. (http://www.gnu.org/licenses/fdl.html), Version 1.3 or any later
  8. version published by the Free Software Foundation; with no
  9. Invariant Sections, no Front-Cover Texts and no Back-Cover Texts.
  10. INFO-DIR-SECTION Emacs
  11. START-INFO-DIR-ENTRY
  12. * Haskell Mode: (haskell-mode). Haskell Development Environment for Emacs(en)
  13. END-INFO-DIR-ENTRY
  14. 
  15. File: haskell-mode.info, Node: Top, Next: Introduction, Up: (dir)
  16. Haskell Mode
  17. ************
  18. Haskell Mode is an Haskell development Environment for GNU Emacs version
  19. 24.3 or later. It provides syntax-based indentation, font locking,
  20. editing cabal files, and supports running an inferior Haskell
  21. interpreter (e.g. GHCi).
  22. * Menu:
  23. * Introduction:: An introduction to Haskell Mode
  24. * Installation:: How to get started
  25. * Editing Haskell Code:: How to edit code
  26. * Syntax highlighting:: Haskell Mode has colors
  27. * Completion support:: Autocomplete
  28. * Unicode support:: How to use Unicode
  29. * Indentation:: Notes about indentation
  30. * External indentation:: Other ways to indent code
  31. * Autoformating:: Using external formatters
  32. * Module templates:: Module templates
  33. * Declaration scanning:: How to navigate in a source file
  34. * Compilation:: How to compile
  35. * Interactive Haskell:: How to interact with GHCi
  36. * Editing Cabal files:: Cabal support
  37. * Browsing Haddocks:: Using ‘w3m’ to browse documentation
  38. * Spell checking strings and comments:: Using ‘flyspell-prog-mode’
  39. * Aligning code:: Aligning code using ‘align-regexp’
  40. * Rectangular commands:: Manage indentation manually
  41. * REPL:: GHCi REPL
  42. * Collapsing Haskell code:: View more code on screen
  43. * Getting Help and Reporting Bugs:: How to improve Haskell Mode
  44. * Concept index:: Index of Haskell Mode concepts
  45. * Function index:: Index of commands
  46. * Variable index:: Index of options and types
  47. 
  48. File: haskell-mode.info, Node: Introduction, Next: Installation, Prev: Top, Up: Top
  49. 1 Introduction
  50. **************
  51. “Haskell Mode” is a major mode providing a convenient environment for
  52. editing Haskell (http://www.haskell.org) programs.
  53. Some of its major features are:
  54. • Syntax highlighting (font lock),
  55. • automatic semi-intelligent indentation,
  56. • on-the-fly documentation,
  57. • interaction with inferior GHCi/Hugs instance,
  58. • project building with cabal and stack
  59. • scanning declarations and placing them in a menu.
  60. The name Haskell Mode refers to the whole collection of modules in
  61. this package. There is specifically a file ‘haskell-mode.el’ which
  62. defines a major mode called ‘haskell-mode’. Generally, in this
  63. documentation they will be distinguished by normal font and title case
  64. (Haskell Mode) and code font (‘haskell-mode’).
  65. 1.1 History
  66. ===========
  67. ‘haskell-mode’ has a long history. It goes all the way back to 1992.
  68. Since then, it has received many contributions in many forms. Some
  69. design choices that remain in haskell-mode today are historical. Some
  70. modules are outdated or no longer used, or are used by a few people.
  71. Historically there hasn’t been a single individual or set of
  72. individuals directing the package’s architecture for a long period of
  73. time, rather, patches and new modules were accepted in liberally and we
  74. are left with a box full of interesting toys that may or may not work.
  75. As of 2016 Haskell Mode is coordinated using Github at
  76. <https://github.com/haskell/haskell-mode>.
  77. 
  78. File: haskell-mode.info, Node: Installation, Next: Editing Haskell Code, Prev: Introduction, Up: Top
  79. 2 Installation
  80. **************
  81. Haskell Mode is distributed as a package in MELPA repository
  82. (https://melpa.org). To use MELPA as Emacs package archive do the
  83. following:
  84. 1. Customize ‘package-archives’ using
  85. M-x customize-option RET package-archives
  86. 2. Use ‘INS’ to add new archive, use:
  87. Archive name: melpa-stable
  88. URL or directory name: http://stable.melpa.org/packages/
  89. 3. Fetch new packages using:
  90. M-x package-refresh-contents
  91. 4. Install Haskell Mode using:
  92. M-x package-install RET haskell-mode RET
  93. Voila! ‘haskell-mode’ is installed! You should be able to edit
  94. Haskell source code in color now.
  95. The above steps should result in the following snippet in your
  96. ‘.emacs’:
  97. (require 'package)
  98. (custom-set-variables
  99. ;; custom-set-variables was added by Custom.
  100. ;; If you edit it by hand, you could mess it up, so be careful.
  101. ;; Your init file should contain only one such instance.
  102. ;; If there is more than one, they won't work right.
  103. '(package-archives
  104. (quote
  105. (("gnu" . "http://elpa.gnu.org/packages/")
  106. ("melpa-stable" . "http://stable.melpa.org/packages/")))))
  107. Haskell Mode supports GNU Emacs versions 24.3+, including 25
  108. (snapshot).
  109. Haskell Mode is available from melpa-stable (releases)
  110. (http://stable.melpa.org) and melpa (git snapshots) (http://melpa.org).
  111. Other means of obtaining ‘haskell-mode’ include el-get
  112. (https://github.com/dimitri/el-get), Emacs Prelude
  113. (https://github.com/bbatsov/prelude) and Debian package
  114. (https://packages.debian.org/search?keywords=haskell-mode).
  115. Last version of ‘haskell-mode’ that supported Emacs 23, 24.1, and
  116. 24.2 is ‘haskell-mode’ 13.16 available at
  117. <https://github.com/haskell/haskell-mode/releases/tag/v13.16>.
  118. 2.1 Customizing
  119. ===============
  120. Most of Haskell Mode’s settings are configurable via customizable
  121. variables (*note (emacs)Easy Customization::, for details). You can use
  122. ‘M-x customize-group <RET> haskell’ to browse the ‘haskell’
  123. customization sub-tree.
  124. One of the important setting you should customize is the
  125. ‘haskell-mode-hook’ variable (*note (emacs)Hooks::) which gets run right
  126. after the ‘haskell-mode’ major mode is initialized for a buffer. You
  127. can customize ‘haskell-mode-hook’ by
  128. M-x customize-variable RET haskell-mode-hook
  129. There you can enable or disable a couple of predefined options or add
  130. any function to the list.
  131. 
  132. File: haskell-mode.info, Node: Editing Haskell Code, Next: Syntax highlighting, Prev: Installation, Up: Top
  133. 3 Editing Haskell Code
  134. **********************
  135. Haskell Mode as one of its components provides a major mode for editing
  136. Haskell source code called ‘haskell-mode’, which gave the name to the
  137. whole project. There is a derived mode provided called
  138. ‘literate-haskell-mode’ that support Literate Haskell source code both
  139. in Bird and in Latex forms.
  140. Haskell Mode supports files with the following extensions:
  141. ‘.hs’
  142. official file extension for Haskell files. Haskell Mode out of the
  143. box supports most of GHC extensions.
  144. ‘.lhs’
  145. official file extension for Literate Haskell files. Both Bird and
  146. Latex styles are supported.
  147. ‘.hsc’
  148. Haskell interfaces to C code used by hsc2hs
  149. (http://www.haskell.org/ghc/docs/latest/html/users_guide/hsc2hs.html)
  150. pre-processor.
  151. ‘.cpphs’
  152. Haskell source with CPP pragmas used with cpphs
  153. (http://projects.haskell.org/cpphs) pre-processor.
  154. ‘.c2hs’
  155. Haskell FFI bindings to C libraries used with c2hs
  156. (https://github.com/haskell/c2hs) pre-processor.
  157. Haskell Mode offers many productivity tools described in following
  158. chapters in this manual.
  159. 3.1 Managing imports
  160. ====================
  161. There are a few functions for managing imports.
  162. 3.1.1 Jump to imports
  163. ---------------------
  164. To jump to your import list, run
  165. ‘M-x’ ‘haskell-navigate-imports’
  166. It’s nicer to have a keybinding to do this, for example:
  167. (define-key haskell-mode-map (kbd "<f8>") 'haskell-navigate-imports)
  168. You can hit it repeatedly to jump between groups of imports. It will
  169. cycle.
  170. 3.1.2 Format imports
  171. --------------------
  172. To generally format (sort, align) your imports, you can run
  173. ‘M-x’ ‘haskell-mode-format-imports’
  174. Or ‘C-c C-,’.
  175. 3.1.3 Sort imports
  176. ------------------
  177. To just sort imports, jump to an import section and run
  178. ‘M-x’ ‘haskell-sort-imports’
  179. 3.1.4 Align imports
  180. -------------------
  181. To just align imports, jump to an import section and run
  182. ‘M-x’ ‘haskell-align-imports’
  183. 3.1.5 stylish-haskell
  184. ---------------------
  185. As an alternative to the elisp functions described above, haskell-mode
  186. can use the program stylish-haskell
  187. (http://hackage.haskell.org/package/stylish-haskell) to format imports.
  188. You can set this behavior by typing: ‘M-x’ ‘customize-variable’ ‘RET’
  189. ‘haskell-stylish-on-save’. You can install ‘stylish-haskell’ by running
  190. ‘stack install stylish-haskell’, or if you have not installed ‘stack’,
  191. ‘cabal install stylish-haskell’.
  192. 3.2 Haskell Tags
  193. ================
  194. ‘haskell-mode’ can generate tags when saving source files. To generate
  195. tags ‘haskell-mode’ uses external program — Hasktags
  196. (https://github.com/MarcWeber/hasktags) (wiki-article
  197. (https://wiki.haskell.org/Tags)). To turn on tags generatation
  198. customize or set to ‘t’ ‘haskell-tags-on-save’ variable. Also, you may
  199. find useful to revert tags tables automatically, this can be done by
  200. customizing ‘tags-revert-without-query’ variable (either globally or for
  201. Haskell buffers only).
  202. 3.3 Profiling and Debugging support
  203. ===================================
  204. When profiling code with GHC, it is often useful to add cost centres
  205. (https://downloads.haskell.org/~ghc/latest/docs/html/users_guide/profiling.html#cost-centres)
  206. by hand. These allow finer-grained information about program behavior.
  207. ‘haskell-mode’ provides the function ‘haskell-mode-toggle-scc-at-point’
  208. to make this more convenient. It will remove an SCC annotation at point
  209. if one is present, or add one if point is over whitespace. By default
  210. it is bound to ‘C-c C-s’.
  211. 
  212. File: haskell-mode.info, Node: Syntax highlighting, Next: Completion support, Prev: Editing Haskell Code, Up: Top
  213. 4 Syntax highlighting
  214. *********************
  215. ‘haskell-mode’ supports “syntax highlighting” via Emacs’ Font Lock minor
  216. mode which should be enabled by default in current Emacsen. *Note
  217. (emacs)Font Lock::, for more information on how to control
  218. ‘font-lock-mode’.
  219. Syntax highlighting facilities parse strings and string escape
  220. sequences and are able to highlight unrecognized constructs.
  221. Haskell Mode shows keywords, identifiers, operators, constructors and
  222. types in different colors.
  223. There is also support to use mode-specific syntax highlighing for
  224. quasiquotes.
  225. At this point quasi quotes for HTML, XML, shell scripts, Hamlet
  226. templates and SQL are supported out of the box. Customize
  227. ‘haskell-font-lock-quasi-quote-modes’ to make sure your quoters are
  228. supported.
  229. The following customization variables are responsible for faces
  230. applied:
  231. ‘’ ‘haskell-keyword-face’: for keywords
  232. ‘’ ‘haskell-type-face’: for type names and type class names
  233. ‘’ ‘haskell-constructor-face’: for constructors
  234. ‘’ ‘haskell-definition-face’: function and operator name at the
  235. definition place
  236. ‘’ ‘haskell-operator-face’: operators
  237. ‘’ ‘haskell-pragma-face’: GHC pragmas
  238. ‘’ ‘haskell-literate-comment-face’: literate comments
  239. ‘’ ‘haskell-quasi-quote-face’: quasi quotes unless using mode
  240. specific highlighting
  241. ‘’ ‘haskell-c2hs-hook-pair-face’: c2hs hooks
  242. ‘’ ‘haskell-c2hs-hook-name-face’: c2hs hook names
  243. All the above are available for customization.
  244. GHC quasi quote syntax is ambiguous with list comprehension therefore
  245. syntax highlighting might get confused with situations like these:
  246. result = [html| html <- htmlList]
  247. result = [html| <html><body>...</body></html> |]
  248. Please use spaces around a list comprehension variable to make this
  249. unambiguous. Any of the following will work:
  250. result = [ html| html <- htmlList]
  251. result = [html | html <- htmlList]
  252. GHC’s ambiguity is an accident of the past but it is unlikely to be
  253. fixed due to backward compatibility baggage.
  254. 
  255. File: haskell-mode.info, Node: Completion support, Next: Unicode support, Prev: Syntax highlighting, Up: Top
  256. 5 Completion support
  257. ********************
  258. ‘haskell-mode’ can complete symbols, pragma directives, language
  259. extensions, and language keywords out-of-box. ‘haskell-mode’ completes
  260. identifiers (symbols) using tags (see “Tags”), however you can get more
  261. precise completions with ‘haskell-interactive-mode’. In interactive
  262. mode completion candidates are produced by querying GHCi REPL.
  263. If ‘haskell-interactive-mode’ is enabled and working Haskell mode
  264. provides completions for import statements taking into account currently
  265. loaded and available packages. Also it completes symbols querying REPL
  266. with ‘:complete’ command, hence completion candidate list also includes
  267. symbols from imported modules.
  268. Unfortunately, it is not possible to provide candidates for
  269. identifiers defined locally in ‘let’ and ‘where’ blocks even in
  270. interactive mode. But if you’re using company-mode
  271. (http://company-mode.github.io/) you can override ‘company-backends’
  272. variable for Haskell buffers to combine completion candidates from
  273. completion-at-point function (‘company-capf’ backend) and dynamic
  274. abbrevs. ‘company-mode’ provides special backend for dabbrev code
  275. completions, namely ‘company-dabbrev-code’. To combine completions from
  276. diffrent backends you can create grouped backends, it is very easy — a
  277. grouped backend is just a list of backends, for example:
  278. (add-hook 'haskell-mode-hook
  279. (lambda ()
  280. (set (make-local-variable 'company-backends)
  281. (append '((company-capf company-dabbrev-code))
  282. company-backends))))
  283. If you use a GHCi version prior to 8.0.1 you might want to set
  284. ‘haskell-completions-complete-operators’ to ‘nil’, if you experience
  285. major slowdown while trying to complete after an Haskell operator (See
  286. GHC-Bug 10576 (https://ghc.haskell.org/trac/ghc/ticket/10576)).
  287. 
  288. File: haskell-mode.info, Node: Unicode support, Next: Indentation, Prev: Completion support, Up: Top
  289. 6 Unicode support
  290. *****************
  291. See the Haskell Wiki’s entry on Unicode Symbols
  292. (http://www.haskell.org/haskellwiki/Unicode-symbols) for general
  293. information about Unicode support in Haskell.
  294. As Emacs supports editing files containing Unicode out of the box, so
  295. does Haskell Mode. As an add-on, Haskell Mode includes the
  296. ‘haskell-unicode’ input method which allows you to easily type a number
  297. of Unicode symbols that are useful when writing Haskell code; *Note
  298. (emacs)Input Methods::, for more details.
  299. To automatically enable the ‘haskell-unicode’ input method in
  300. haskell-mode buffers use ‘M-x customize-variable <RET>
  301. haskell-mode-hook’ or put the following code in your ‘.emacs’ file:
  302. (add-hook 'haskell-mode-hook 'turn-on-haskell-unicode-input-method)
  303. To temporarily enable this input method for a single buffer you can use
  304. ‘M-x turn-on-haskell-unicode-input-method’.
  305. When the ‘haskell-unicode’ input method is active, you can simply
  306. type ‘->’ and it is immediately replaced with ‘→’. Use ‘C-\’ to toggle
  307. the input method. To see a table of all key sequences use ‘M-x
  308. describe-input-method <RET> haskell-unicode’. A sequence like ‘<=’ is
  309. ambiguous and can mean either ‘⇐’ or ‘≤’. Typing it presents you with a
  310. choice. Type ‘1’ or ‘2’ to select an option or keep typing to use the
  311. default option.
  312. Currently defined sequences are listed in the following table:
  313. SequenceUnicode SequenceUnicode SequenceUnicode SequenceUnicode
  314. ----------------------------------------------------------------------------
  315. alpha α Alpha Α beta β Beta Β
  316. gamma γ Gamma Γ delta δ Delta Δ
  317. epsilonε EpsilonΕ zeta ζ Zeta Ζ
  318. eta η Eta Η theta θ Theta Θ
  319. iota ι Iota Ι kappa κ Kappa Κ
  320. lambda λ Lambda Λ lamda λ Lamda Λ
  321. mu μ Mu Μ nu ν Nu Ν
  322. xi ξ Xi Ξ omicronο OmicronΟ
  323. pi π Pi Π rho ρ Rho Ρ
  324. sigma σ Sigma Σ tau τ Tau Τ
  325. upsilonυ UpsilonΥ phi φ Phi Φ
  326. chi χ Chi Χ psi ψ Psi Ψ
  327. omega ω Omega Ω digammaϝ DigammaϜ
  328. san ϻ San Ϻ qoppa ϙ Qoppa Ϙ
  329. sampi ϡ Sampi Ϡ stigma ϛ Stigma Ϛ
  330. heta ͱ Heta Ͱ sho ϸ Sho Ϸ
  331. |A| 𝔸 |B| 𝔹 |C| ℂ |D| 𝔻
  332. |E| 𝔼 |F| 𝔽 |G| 𝔾 |H| ℍ
  333. |I| 𝕀 |J| 𝕁 |K| 𝕂 |L| 𝕃
  334. |M| 𝕄 |N| ℕ |O| 𝕆 |P| ℙ
  335. |Q| ℚ |R| ℝ |S| 𝕊 |T| 𝕋
  336. |U| 𝕌 |V| 𝕍 |W| 𝕎 |X| 𝕏
  337. |Y| 𝕐 |Z| ℤ |gamma|ℽ |Gamma|ℾ
  338. |pi| ℼ |Pi| ℿ :: ∷ forall ∀
  339. exists ∃ -> → <- ← => ⇒
  340. ~> ⇝ <~ ⇜ && ∧ || ∨
  341. == ≡ /= ≢, ≠ <= ≤ >= ≥
  342. /< ≮ /> ≯ * ⋅ elem ∈
  343. notElem∉ member ∈ notMember∉ union ∪
  344. intersection∩ isSubsetOf⊆ isProperSubsetOf⊂ <<< ⋘
  345. >>> ⋙ <| ⊲ |> ⊳ >< ⋈
  346. mappend⊕ . ∘ undefined⊥ := ≔
  347. =: ≕ =def ≝ =? ≟ ... …
  348. _0 ₀ _1 ₁ _2 ₂ _3 ₃
  349. _4 ₄ _5 ₅ _6 ₆ _7 ₇
  350. _8 ₈ _9 ₉ ^0 ⁰ ^1 ¹
  351. ^2 ² ^3 ³ ^4 ⁴ ^5 ⁵
  352. ^6 ⁶ ^7 ⁷ ^8 ⁸ ^9 ⁹
  353. If you don’t like the highlighting of partially matching tokens you
  354. can turn it off by setting ‘input-method-highlight-flag’ to ‘nil’ via
  355. ‘M-x customize-variable’.
  356. 
  357. File: haskell-mode.info, Node: Indentation, Next: External indentation, Prev: Unicode support, Up: Top
  358. 7 Indentation
  359. *************
  360. In Haskell, code indentation has semantic meaning as it defines the
  361. block structure. Haskell also supports braces and semicolons notation
  362. for conveying the block structure. However, most Haskell programs
  363. written by humans use indentation for block structuring.
  364. Haskell Mode ships with two indentation modes:
  365. • ‘haskell-indentation-mode’ (default).
  366. This is a semi-intelligent indentation mode doing a decent job at
  367. recognizing Haskell syntactical constructs. It is based on a
  368. recursive descent Haskell parser. ‘TAB’ selects the next potential
  369. indentation position, ‘S-TAB’ selects the previous one. If a block
  370. is selected you can use ‘TAB’ to indent the block more and ‘S-TAB’
  371. to indent the block less.
  372. When ‘electric-indent-mode’ is enabled or the variable
  373. ‘haskell-indentation-electric-flag’ is non-nil, the insertion of
  374. some characters (by default ‘,’ ‘;’ ‘)’ ‘}’ ‘]’) may trigger auto
  375. reindentation under appropriate conditions. See the documentation
  376. of ‘haskell-indentation-common-electric-command’ for more details.
  377. • ‘haskell-indent-mode’ (optional).
  378. This is a semi-intelligent indentation mode doing a decent job at
  379. recognizing Haskell syntactical constructs. It is based on a
  380. decision table. Sadly it is no longer developed and does not
  381. recognize newer Haskell syntax. ‘TAB’ cycles through all available
  382. indentation positions.
  383. To use ‘haskell-indent-mode’, add this to your ‘~/.emacs’ file:
  384. (add-hook 'haskell-mode-hook 'turn-on-haskell-indent)
  385. Note that ‘turn-on-haskell-indent’ will disable
  386. ‘haskell-indentation-mode’.
  387. For general information about indentation support in GNU Emacs, *note
  388. (emacs)Indentation::.
  389. 7.1 Rectangle Commands
  390. ======================
  391. GNU Emacs provides so-called “rectangle commands” which operate on
  392. rectangular areas of text, which are particularly useful for languages
  393. with a layout rule such as Haskell. *Note (emacs)Rectangles::, to learn
  394. more about rectangle commands.
  395. Moreover, CUA mode (*note (emacs)CUA Bindings::) provides enhanced
  396. rectangle support with visible rectangle highlighting. When CUA mode is
  397. active, you can initiate a rectangle selection by ‘C-RET’ and extend it
  398. simply by movement commands. You don’t have to enable full CUA mode to
  399. benefit from these enhanced rectangle commands; you can activate CUA
  400. selection mode (without redefining ‘C-x’,‘C-c’,‘C-v’, and ‘C-z’) by
  401. calling ‘M-x cua-selection-mode’ (or adding ‘(cua-selection-mode nil)’
  402. to your ‘haskell-mode-hook’).
  403. 7.2 Region indent is a no-op
  404. ============================
  405. There is a ‘indent-region’ function that supposedly could be used to
  406. indent code region without changing its semantics. Sadly it does not
  407. work that way because usual use case for ‘indent-region’ is:
  408. 1. Alter first line of code in region.
  409. 2. Call ‘indent-region’ to fix indentation for remaining lines.
  410. Note that between 1 and 2 program is already semantically broken and
  411. knowing how to indent it preserving semantic from before step 1 would
  412. require time travel.
  413. To stay on the safe side ‘indent-region-function’ is bound to a no-op
  414. in ‘haskell-mode’.
  415. 
  416. File: haskell-mode.info, Node: External indentation, Next: Autoformating, Prev: Indentation, Up: Top
  417. 8 Other ways to indent code
  418. ***************************
  419. 8.1 Indentation with tabs, not spaces
  420. =====================================
  421. Some projects require indenting code with tabs and forbid indenting it
  422. with spaces. For hacking on such projects, check out
  423. haskell-tab-indent-mode
  424. (https://spwhitton.name/tech/code/haskell-tab-indent).
  425. 8.2 Structured indentation
  426. ==========================
  427. Another alternative is to install structured-haskell-mode
  428. (https://github.com/chrisdone/structured-haskell-mode). which indents
  429. code by parsing the code with a full Haskell parser and deciding where
  430. to indent based on that.
  431. 
  432. File: haskell-mode.info, Node: Autoformating, Next: Module templates, Prev: External indentation, Up: Top
  433. 9 Using external formatters
  434. ***************************
  435. You can enable stylish-haskell
  436. (https://github.com/jaspervdj/stylish-haskell) by installing it:
  437. $ cabal install stylish-haskell
  438. And by enabling it with a customization
  439. (custom-set-variables
  440. '(haskell-stylish-on-save t))
  441. Now when you run ‘save-buffer’ (or ‘C-x C-s’) the module will be
  442. automatically formatted.
  443. Alternatively, you can run the function directly on demand with ‘M-x’
  444. ‘haskell-mode-stylish-buffer’.
  445. 
  446. File: haskell-mode.info, Node: Module templates, Next: Declaration scanning, Prev: Autoformating, Up: Top
  447. 10 Module templates
  448. *******************
  449. To enable auto-insertion of module templates, enable:
  450. (add-hook 'haskell-mode-hook 'haskell-auto-insert-module-template)
  451. When you open a file called ‘Foo.hs’, it will auto-insert
  452. -- |
  453. module Foo where
  454. And put your cursor in the comment section.
  455. 
  456. File: haskell-mode.info, Node: Declaration scanning, Next: Compilation, Prev: Module templates, Up: Top
  457. 11 Declaration scannning
  458. ************************
  459. ‘haskell-decl-scan-mode’ is a minor mode which performs declaration
  460. scanning and provides ‘M-x imenu’ support (*note (emacs)Imenu:: for more
  461. information).
  462. For non-literate and TeX-style literate scripts, the common
  463. convention that top-level declarations start at the first column is
  464. assumed. For Bird-style literate scripts, the common convention that
  465. top-level declarations start at the third column, ie. after ‘> ’, is
  466. assumed.
  467. When ‘haskell-decl-scan-mode’ is active, the standard Emacs top-level
  468. definition movement commands (*note (emacs)Moving by Defuns::) are
  469. enabled to operate on Haskell declarations:
  470. ‘C-M-a’
  471. Move to beginning of current or preceding declaration
  472. (‘beginning-of-defun’).
  473. ‘C-M-e’
  474. Move to end of current or following declaration (‘end-of-defun’).
  475. ‘C-M-h’
  476. Select whole current or following declaration (‘mark-defun’).
  477. Moreover, if enabled via the option
  478. ‘haskell-decl-scan-add-to-menubar’, a menu item “Declarations” is added
  479. to the menu bar listing the scanned declarations and allowing to jump to
  480. declarations in the source buffer.
  481. It’s recommended to have font lock mode enabled (*note (emacs)Font
  482. Lock::) as ‘haskell-decl-scan-mode’ ignores text highlighted with
  483. ‘font-lock-comment-face’.
  484. As usual, in order to activate ‘haskell-decl-scan-mode’ automatically
  485. for Haskell buffers, add ‘haskell-decl-scan-mode’ to
  486. ‘haskell-mode-hook’:
  487. (add-hook 'haskell-mode-hook 'haskell-decl-scan-mode)
  488. ‘haskell-decl-scan-mode’ enables the use of features that build upon
  489. ‘imenu’ support such as Speedbar Frames (*note (emacs)Speedbar::) or the
  490. global “Which Function” minor mode (*note (emacs)Which Function::).
  491. In order to enable ‘which-function-mode’ for Haskell buffers you need
  492. to add the following to your Emacs initialization:
  493. (eval-after-load "which-func"
  494. '(add-to-list 'which-func-modes 'haskell-mode))
  495. 11.1 Speedbar
  496. =============
  497. Haskell-mode comes with declaration scanning support. This means that
  498. if you enable Haskell support for speedbar:
  499. (speedbar-add-supported-extension ".hs")
  500. And open speedbar with
  501. ‘M-x speedbar’
  502. It gives a listing of each module and under each module:
  503. Imports
  504. Instances
  505. Data types
  506. Classes
  507. Bindings
  508. You will get a bar that looks like this:
  509. ~/Projects/ace/src/ACE/
  510. 0:<+> Types
  511. 0:[+] Combinators.hs
  512. 0:[-] Datalog.hs
  513. 1: {-} Classes
  514. 2: > ToTerm
  515. 1: {-} Imports
  516. 2: > ACE.Types.Syntax
  517. 2: > Database.Datalog
  518. 1: {-} Instances
  519. 2: {+} ToTerm A
  520. 2: {+} ToTerm Co to ToTerm Gen
  521. 2: {+} ToTerm Intransitive to ToTerm N
  522. 2: {+} ToTerm P
  523. 2: {+} ToTerm Quotation to ToTerm Un
  524. 2: {+} ToTerm V
  525. 0:[-] Html.hs
  526. 1: {+} Imports
  527. 1: {+} Instances
  528. 1: > mtoMarkup
  529. 1: > toMarkupm
  530. 1: > wrap
  531. 0:[-] Parsers.hs
  532. 1: {+} Imports
  533. 1: {-} Datatypes
  534. 2: > ACEParser
  535. 0:[+] Pretty.hs
  536. 0:[+] Tokenizer.hs
  537. The hierarchy is expandable/collapsible and each entry will jump to
  538. the line in the right file when clicked/selected.
  539. 
  540. File: haskell-mode.info, Node: Compilation, Next: Interactive Haskell, Prev: Declaration scanning, Up: Top
  541. 12 Compilation
  542. **************
  543. Haskell mode comes equipped with a specialized “Compilation mode”
  544. tailored to GHC’s compiler messages with optional support for Cabal
  545. projects. *Note (emacs)Compilation Mode::, for more information about
  546. the basic commands provided by the Compilation mode which are available
  547. in the Haskell compilation sub-mode as well. The additional features
  548. provided compared to Emacs’ basic Compilation mode are:
  549. • DWIM-style auto-detection of compile command (including support for
  550. CABAL projects)
  551. • Support for GHC’s compile messages and recognizing error, warning
  552. and info source locations (including ‘-ferror-spans’ syntax)
  553. • Support for filtering out GHC’s uninteresting ‘Loading package...’
  554. linker messages
  555. In order to use it, invoke the ‘haskell-compile’ command instead of
  556. ‘compile’ as you would for the ordinary Compilation mode. It’s
  557. recommended to bind ‘haskell-compile’ to a convenient key binding. For
  558. instance, you can add the following to your Emacs initialization to bind
  559. ‘haskell-compile’ to ‘C-c C-c’.
  560. (eval-after-load "haskell-mode"
  561. '(define-key haskell-mode-map (kbd "C-c C-c") 'haskell-compile))
  562. (eval-after-load "haskell-cabal"
  563. '(define-key haskell-cabal-mode-map (kbd "C-c C-c") 'haskell-compile))
  564. The following description assumes that ‘haskell-compile’ has been bound
  565. to ‘C-c C-c’.
  566. When invoked, ‘haskell-compile’ tries to guess how to compile the
  567. Haskell program your currently visited buffer belongs to, by searching
  568. for a ‘.cabal’ file in the current of enclosing parent folders. If a
  569. ‘.cabal’ file was found, the command defined in the
  570. ‘haskell-compile-cabal-build-command’ option is used. Note that to
  571. compile a ‘stack’ based project you will need to set this variable to
  572. ‘stack build’. As usual you can do it using ‘M-x customize-variable’ or
  573. with:
  574. (setq haskell-compile-cabal-build-command "stack build")
  575. Moreover, when requesting to compile a ‘.cabal’-file is detected and
  576. a negative prefix argument (e.g. ‘C-- C-c C-c’) was given, the
  577. alternative ‘haskell-compile-cabal-build-command-alt’ is invoked. By
  578. default, ‘haskell-compile-cabal-build-command-alt’ contains a ‘cabal
  579. clean -s’ command in order to force a full rebuild.
  580. Otherwise if no ‘.cabal’ could be found, a single-module compilation
  581. is assumed and ‘haskell-compile-command’ is used (_if_ the currently
  582. visited buffer contains Haskell source code).
  583. You can also inspect and modify the compile command to be invoked
  584. temporarily by invoking ‘haskell-compile’ with a prefix argument (e.g.
  585. ‘C-u C-c C-c’). If later-on you want to recompile using the same
  586. customized compile command, invoke ‘recompile’ (bound to ‘g’) inside the
  587. ‘*haskell-compilation*’ buffer.
  588. 12.1 Keybindings
  589. ================
  590. Key Function
  591. binding
  592. ------------
  593. TAB compilation-next-error
  594. RET compile-goto-error
  595. C-o compilation-display-error
  596. SPC scroll-up-command
  597. - negative-argument
  598. 0 digit-argument
  599. ..
  600. 9
  601. < beginning-of-buffer
  602. > end-of-buffer
  603. ? describe-mode
  604. g recompile
  605. h describe-mode
  606. q quit-window
  607. DEL scroll-down-command
  608. S-SPC scroll-down-command
  609. <backtab>compilation-previous-error
  610. <follow-link>mouse-face
  611. <mouse-2>compile-goto-error
  612. <remap>Prefix
  613. Command
  614. M-n compilation-next-error
  615. M-p compilation-previous-error
  616. M-{ compilation-previous-file
  617. M-} compilation-next-file
  618. C-c compile-goto-error
  619. C-c
  620. C-c next-error-follow-minor-mode
  621. C-f
  622. C-c kill-compilation
  623. C-k
  624. 
  625. File: haskell-mode.info, Node: Interactive Haskell, Next: Editing Cabal files, Prev: Compilation, Up: Top
  626. 13 Interactive Haskell
  627. **********************
  628. REPL (read–eval–print loop) is provided both via Comint
  629. (‘inferior-haskell-mode’) and an adhoc way called
  630. ‘haskell-interactive-mode’. The Comint based ‘inferior-haskell-mode’ is
  631. just the REPL, it comes with the standard key bindings(like ‘ielm’ or
  632. ‘eshell’).
  633. ‘haskell-interactive-mode’ comes with a different set of features:
  634. • Separate sessions per Cabal project ‘haskell-session.el’.
  635. • A new inferior Haskell process handling code ‘haskell-process.el’.
  636. • New REPL implementation similiar to SLIME/IELM
  637. • Navigatable error overlays ‘haskell-interactive-mode.el’.
  638. With ‘haskell-interactive-mode’, each Haskell source buffer is
  639. associated with at most one GHCi session, so when you call
  640. ‘haskell-process-load-file’ for a Haskell source buffer which has no
  641. session associated yet, you’re asked which GHCi session to create or
  642. associate with.
  643. 13.1 Goto Error
  644. ===============
  645. In a Haskell source buffer associated with a GHCi session, errors that
  646. prevent the file from loading are highlighted with ‘haskell-error-face’.
  647. You can move between these error lines with
  648. ‘M-n’
  649. is bound to ‘haskell-goto-next-error’
  650. ‘M-p’
  651. is bound to ‘haskell-goto-prev-error’
  652. ‘C-c M-p’
  653. is bound to ‘haskell-goto-first-error’
  654. 13.2 Using GHCi 8+ or GHCi-ng
  655. =============================
  656. If you use either of the above, then you can use these functions:
  657. (define-key interactive-haskell-mode-map (kbd "M-.") 'haskell-mode-goto-loc)
  658. (define-key interactive-haskell-mode-map (kbd "C-c C-t") 'haskell-mode-show-type-at)
  659. You have to load the module before it works, after that it will
  660. remember for the current GHCi session.
  661. 13.3 Customizing
  662. ================
  663. What kind of Haskell REPL ‘haskell-interactive-mode’ will start up
  664. depends on the value of ‘haskell-process-type’. This can be one of the
  665. symbols ‘auto’, ‘ghci’, ‘cabal-repl’, ‘cabal-new-repl’, or ‘stack-ghci’.
  666. If it’s ‘auto’, the directory contents and available programs will be
  667. used to make a best guess at the process type. The actual process type
  668. will then determine which variables ‘haskell-interactive-mode’ will
  669. access to determine the program to start and its arguments:
  670. • If it’s ‘ghci’, ‘haskell-process-path-ghci’ and
  671. ‘haskell-process-args-ghci’ will be used.
  672. • If it’s ‘cabal-repl’, ‘haskell-process-path-cabal’ and
  673. ‘haskell-process-args-cabal-repl’.
  674. • If it’s ‘cabal-new-repl’, ‘haskell-process-path-cabal’ and
  675. ‘haskell-process-args-cabal-new-repl’.
  676. • If it’s ‘stack-ghci’, ‘haskell-process-path-stack’ and
  677. ‘haskell-process-args-stack-ghci’ will be used.
  678. With each of these pairs, the the ‘haskell-process-path-...’ variable
  679. needs to be a string specifying the program path, or a list of strings
  680. where the first element is the program path and the rest are initial
  681. arguments. The ‘haskell-process-args-...’ is a list of strings
  682. specifying (further) command-line arguments.
  683. 13.4 Haskell Interactive Mode Setup
  684. ===================================
  685. The most straight-forward way to get setup with Interactive Mode is to
  686. bind the right keybindings and set some customizations. This page
  687. contains a good base setup.
  688. To enable the minor mode which activates keybindings associated with
  689. interactive mode, use:
  690. (require 'haskell-interactive-mode)
  691. (require 'haskell-process)
  692. (add-hook 'haskell-mode-hook 'interactive-haskell-mode)
  693. 13.4.1 Customizations
  694. ---------------------
  695. This enables some handy and benign features.
  696. (custom-set-variables
  697. '(haskell-process-suggest-remove-import-lines t)
  698. '(haskell-process-auto-import-loaded-modules t)
  699. '(haskell-process-log t))
  700. 13.4.2 Haskell-mode bindings
  701. ----------------------------
  702. This gives the basic ways to start a session. In a Haskell buffer:
  703. • Run ‘C-`’ to make a REPL open, this will create a session, start
  704. GHCi, and open the REPL.
  705. • Or: run ‘C-c C-l’ to load the file. This will first try to start a
  706. session as the previous command does.
  707. • Or: run any command which requires a running session. It will
  708. always prompt to create one if there isn’t one already for the
  709. current project.
  710. (define-key haskell-mode-map (kbd "C-c C-l") 'haskell-process-load-or-reload)
  711. (define-key haskell-mode-map (kbd "C-`") 'haskell-interactive-bring)
  712. (define-key haskell-mode-map (kbd "C-c C-t") 'haskell-process-do-type)
  713. (define-key haskell-mode-map (kbd "C-c C-i") 'haskell-process-do-info)
  714. (define-key haskell-mode-map (kbd "C-c C-c") 'haskell-process-cabal-build)
  715. (define-key haskell-mode-map (kbd "C-c C-k") 'haskell-interactive-mode-clear)
  716. (define-key haskell-mode-map (kbd "C-c c") 'haskell-process-cabal)
  717. 13.4.3 Cabal-mode bindings
  718. --------------------------
  719. The below commands pretty much match the ones above, but are handy to
  720. have in cabal-mode, too:
  721. (define-key haskell-cabal-mode-map (kbd "C-`") 'haskell-interactive-bring)
  722. (define-key haskell-cabal-mode-map (kbd "C-c C-k") 'haskell-interactive-mode-clear)
  723. (define-key haskell-cabal-mode-map (kbd "C-c C-c") 'haskell-process-cabal-build)
  724. (define-key haskell-cabal-mode-map (kbd "C-c c") 'haskell-process-cabal)
  725. 13.4.4 GHCi process type
  726. ------------------------
  727. By default ‘haskell-process-type’ is set to ‘auto’. It is smart enough
  728. to pick the right type based on your project structure and installed
  729. tools, but in case something goes funky or you want to explicitly set
  730. the process type and ignore the inferred type, you can customize this
  731. setting by running ‘M-x’ ‘customize-variable’ ‘RET’
  732. ‘haskell-process-type’ ‘RET’, or by setting the code:
  733. (custom-set-variables
  734. '(haskell-process-type 'cabal-repl))
  735. Here is a list of available process types:
  736. • ghci
  737. • cabal-repl
  738. • cabal-new-repl
  739. • cabal-dev
  740. • cabal-ghci
  741. • stack-ghci
  742. Please, check the documentation for ‘haskell-process-type’ to see how
  743. the real type is guessed, when it’s set to ‘auto’.
  744. 13.4.5 Troubleshooting
  745. ----------------------
  746. Launching your GHCi process can fail when you’re first getting setup,
  747. depending on the type you choose. If it does fail to launch, switch to
  748. the buffer ‘*haskell-process-log*’ and see what’s up. The buffer
  749. contains a log of incoming/outgoing messages to the GHCi process.
  750. 13.5 Haskell Interactive Mode Tags Using GHCi
  751. =============================================
  752. You can bind the following to use GHCi to find definitions of things:
  753. (define-key haskell-mode-map (kbd "M-.") 'haskell-mode-jump-to-def)
  754. The one problem with this approach is that if your code doesn’t
  755. compile, GHCi doesn’t give any location info. So you need to make sure
  756. your code compiles and the modules you want to jump to are loaded
  757. byte-compiled.
  758. Note: I think that when you restart GHCi you lose location
  759. information, even if you have the ‘.o’ and ‘.hi’ files lying around.
  760. I’m not sure. But sometimes ‘:i foo’ will give ‘foo is defined in Bar’
  761. rather than ‘foo is defined in /foo/Bar.hs:123:23’.
  762. Alternatively, you can use tags generation, which doesn’t require a
  763. valid compile.
  764. 13.5.1 Tags Setup
  765. -----------------
  766. Make sure to install ‘hasktags’.
  767. $ cabal install hasktags
  768. Then add the customization variable to enable tags generation on
  769. save:
  770. (custom-set-variables
  771. '(haskell-tags-on-save t))
  772. And make sure ‘hasktags’ is in your ‘$PATH’ which Emacs can see.
  773. 13.5.2 Generating tags
  774. ----------------------
  775. Now, every time you run ‘save-buffer’ (‘C-x C-s’), there is a hook that
  776. will run and generate Emacs *Note (emacs)Tags::, for the whole project
  777. directory. The resulting file will be called ‘TAGS’.
  778. WARNING: You should be careful that your project root isn’t your home
  779. directory or something, otherwise it will traverse all the way down and
  780. take an impossibly long time.
  781. 13.5.3 Jumping to tags
  782. ----------------------
  783. Bind the following keybinding:
  784. (define-key haskell-mode-map (kbd "M-.") 'haskell-mode-tag-find)
  785. To jump to the location of the top-level identifier at point, run
  786. ‘M-x’ ‘haskell-mode-tag-find’ or ‘M-.’.
  787. 13.5.4 Hybrid: GHCi and fallback to tags
  788. ----------------------------------------
  789. To use GHCi first and then if that fails to fallback to tags for
  790. jumping, use:
  791. (define-key haskell-mode-map (kbd "M-.") 'haskell-mode-jump-to-def-or-tag)
  792. 13.5.5 Troubleshooting tags
  793. ---------------------------
  794. Sometimes a ‘TAGS’ file is deleted (by you or some other process).
  795. Emacs will complain that it doesn’t exist anymore. To resolve this
  796. simply do ‘M-x’ ‘tags-reset-tags-tables’.
  797. 13.6 Sessions
  798. =============
  799. All commands in Haskell Interactive Mode work within a session.
  800. Consider it like a “project” or a “solution” in popular IDEs. It tracks
  801. the root of your project and an associated process and REPL.
  802. 13.6.1 Start a session
  803. ----------------------
  804. To start a session run the following steps:
  805. • Open some Cabal or Haskell file.
  806. • Run ‘C-`’ to make a REPL open, this will create a session, start
  807. GHCi, and open the REPL.
  808. • Or: run ‘C-c C-l’ to load the file. This will first try to start a
  809. session as the previous command does.
  810. • Or: run any command which requires a running session. It will
  811. always prompt to create one if there isn’t one already for the
  812. current project.
  813. It will prompt for a Cabal directory and a current directory. It
  814. figures out where the cabal directory is and defaults for the current
  815. directory, so you should be able to just hit RET twice.
  816. 13.6.2 Switch a session
  817. -----------------------
  818. Sometimes a particular file is used in two different sessions/projects.
  819. You can run
  820. M-x haskell-session-change
  821. If it prompts you to make a new session, tell it no (that’s a bug).
  822. It will ask you to choose from a list of sessions.
  823. 13.6.3 Killing a session
  824. ------------------------
  825. To kill a session you can run
  826. M-x haskell-session-kill
  827. Which will prompt to kill all associated buffers, too. Hit ‘n‘ to
  828. retain them.
  829. Alternatively, you can switch to the REPL and just kill the buffer
  830. normally with ‘C-x k RET’. It will prompt
  831. Kill the whole session (y or n)?
  832. You can choose ‘y’ to kill the session itself, or ‘n’ to just kill
  833. the REPL buffer. You can bring it back with ‘M-x’
  834. ‘haskell-interactive-bring’.
  835. 13.6.4 Menu
  836. -----------
  837. To see a list of all sessions you have open with some simple statistics
  838. about memory usage, etc. run
  839. M-x haskell-menu
  840. For example:
  841. foo 14648 08:21:42 214MB /path/to/fpco/foo/ /path/to/fpco/foo/ ghci
  842. bar 29119 00:22:03 130MB /path/to/bar/ /path/to/bar/ ghci
  843. mu 22575 08:48:20 73MB /path/to/fpco/mu/ /path/to/fpco/mu/ ghci
  844. 13.7 Compiling
  845. ==============
  846. There are a bunch of ways to compile Haskell modules. This page covers
  847. a few of them.
  848. 13.7.1 Load into GHCi
  849. ---------------------
  850. To compile and load a Haskell module into GHCi, run the following
  851. M-x haskell-process-load
  852. Or ‘C-c C-l’. You’ll see any compile errors in the REPL window.
  853. 13.7.2 Build the Cabal project
  854. ------------------------------
  855. To compile the whole Cabal project, run the following
  856. M-x haskell-process-cabal-build
  857. Or ‘C-c C-c’. You’ll see any compile errors in the REPL window.
  858. 13.7.3 Reloading modules
  859. ------------------------
  860. To reload the current module, even when you’re in other modules, you can
  861. run ‘C-u M-x’ ‘haskell-process-load-or-reload’ or ‘C-u C-c C-l’. It
  862. will now reload that module whenever you run ‘C-c C-l’ in the future
  863. from whatever module you’re in. To disable this mode, just run ‘C-u C-c
  864. C-l’ again.
  865. 13.7.4 Jumping to compile errors
  866. --------------------------------
  867. You can use the standard compile error navigation function ‘C-x `’ —
  868. jump to the next error.
  869. Or you can move your cursor to an error in the REPL and hit ‘RET’ to
  870. jump to it.
  871. 13.7.5 Auto-removing imports
  872. ----------------------------
  873. If the customization variable
  874. ‘haskell-process-suggest-remove-import-lines’ is enabled.
  875. (custom-set-variables
  876. '(haskell-process-suggest-remove-import-lines t))
  877. Building and loading modules which output warnings like,
  878. Warning: The import of `Control.Monad' is redundant
  879. except perhaps to import instances from `Control.Monad'
  880. To import instances alone, use: import Control.Monad()
  881. will prompt the user with
  882. > The import line `Control.Monad' is redundant. Remove? (y, n, c: comment out)
  883. If you answer
  884. • ‘y’: it will delete the import, but leave the empty line remaining
  885. (this avoids messing with line positions in subsequent error
  886. messages).
  887. • ‘n’: it will leave the import.
  888. • ‘c’: it will comment out the import (this is handy for when you
  889. just want to temporarily hide an import).
  890. 13.7.6 Auto-adding of modules to import
  891. ---------------------------------------
  892. Enable the customization variable
  893. ‘haskell-process-suggest-hoogle-imports’.
  894. (custom-set-variables
  895. '(haskell-process-suggest-hoogle-imports t))
  896. Whenever GHC says something is not in scope, it will hoogle that
  897. symbol. If there are results, it will prompt to add one of the modules
  898. from Hoogle’s results.
  899. You need to make sure you’ve generated your Hoogle database properly.
  900. 13.7.7 Auto-adding of extensions
  901. --------------------------------
  902. It you use an extension which is not enabled, GHC will often inform you.
  903. For example, if you write:
  904. newtype X a = X (IO a)
  905. deriving (Monad)
  906. Then you’ll see a message like:
  907. x.hs:13:13: Can't make a derived instance of `Monad X': …
  908. `Monad' is not a derivable class
  909. Try -XGeneralizedNewtypeDeriving for GHC's newtype-deriving extension
  910. In the newtype declaration for `X'
  911. This ‘-XFoo’ pattern will be picked up and you will be prompted:
  912. > Add `{-# LANGUAGE GeneralizedNewtypeDeriving #-}` to the top of the
  913. > file? (y or n)
  914. If you answer ‘y‘, it will temporarily jump to the buffer and it to
  915. the top of the file.
  916. 13.7.8 Orphan instances
  917. -----------------------
  918. If GHC complains about orphan instances, you usually are doing it
  919. intentionally, so it prompts to add ‘-fno-warn-orphans’ to the top of
  920. the file with an ‘OPTIONS’ pragma.
  921. 13.7.9 Auto-adding of dependencies
  922. ----------------------------------
  923. When doing a build, you will sometimes get a message from GHC like:
  924. src/ACE/Tokenizer.hs:11:18: Could not find module `Data.Attoparsec.Text' …
  925. It is a member of the hidden package `attoparsec-0.11.1.0'.
  926. This message contains all the necessary information to add this to
  927. your .cabal file, so you will be prompted to add it to your .cabal file:
  928. Add `attoparsec' to ace.cabal? (y or n) y
  929. If you hit ‘y’, it will prompt with this:
  930. attoparsec >= 0.11.1.0
  931. Which you can edit (e.g. do some PVP decision or remove constraints
  932. entirely), and then it will open up your ‘.cabal’ file and go through
  933. each section:
  934. Add to library? (y or n) y
  935. This will add it to the top of the ‘build-depends’ field in your
  936. library section. If you have any executables, it will go through each
  937. of those, prompting, too.
  938. Now you can rebuild with ‘C-c C-c’ again.
  939. 13.8 Haskell Interactive Mode REPL
  940. ==================================
  941. When GHCi has been launched, it works on a read-eval-print basis. So
  942. you will be presented with the prompt:
  943. The lambdas must flow.
  944. Changed directory: /path/to/your/project/
  945. λ>
  946. 13.8.1 Changing REPL target
  947. ---------------------------
  948. With ‘haskell-session-change-target’ you can change the target for REPL
  949. session.
  950. After REPL session started, in ‘haskell-interactive-mode’ buffer
  951. invoke the ‘haskell-session-change-target’ and select from available
  952. targets for
  953. - Testing
  954. - Benchmark
  955. - Executable
  956. - Library
  957. Answer “yes” to restart the session and run your tests, benchmarks,
  958. executables.
  959. TODO/WRITEME
  960. 13.8.2 Bringing the REPL
  961. ------------------------
  962. If you don’t know where the REPL buffer is, you can always bring it
  963. with:
  964. M-x haskell-interactive-bring
  965. Or ‘C-`’.
  966. 13.8.3 Evaluating expressions
  967. -----------------------------
  968. To evaluate expressions, simply type one out and hit ‘RET‘.
  969. λ> 123
  970. 123
  971. 13.8.4 Evaluating multiline expressions
  972. ---------------------------------------
  973. GHCi features two ways to evaluate multiline expressions. You can use
  974. ‘:set +m’ to enable multiline input
  975. (https://www.haskell.org/ghc/docs/latest/html/users_guide/ghci.html#multiline-input)
  976. for all expressions, or you can wrap your expression in ‘:{’ and ‘:}’
  977. (they have to be on their own lines).
  978. The prompt will change to indicate that you’re inputting a multiline
  979. expression:
  980. λ> :{
  981. λ| let a = 10
  982. λ| b = 20
  983. λ| c = 30
  984. λ| :}
  985. You can also simulate multiline mode by having your input contain
  986. newline characters. You can input a literal newline character with ‘C-q
  987. C-j’, or you can use:
  988. M-x haskell-interactive-mode-newline-indent
  989. which is bound to ‘C-j’. This command indents after the newline.
  990. You can simulate the above example like so:
  991. λ> let a = 10
  992. b = 20
  993. c = 30
  994. 13.8.5 Type of expressions
  995. --------------------------
  996. You can use normal ‘:type’ which is part of GHCi to get the type of
  997. something:
  998. λ> :t id
  999. id :: a -> a
  1000. But you can also just write out the value directly,
  1001. λ> id
  1002. id :: a -> a
  1003. and because there’s no ‘Show’ instance for ‘(a -> a)’. This would
  1004. normally yield a compile error:
  1005. No instance for (Show (a0 -> a0))
  1006. arising from a use of `print'
  1007. Possible fix: add an instance declaration for (Show (a0 -> a0))
  1008. In a stmt of an interactive GHCi command: print it
  1009. It will run ‘:type id’ in the background and print out the result.
  1010. The same is true for ambiguous things:
  1011. λ> :t read "a"
  1012. read "a" :: Read a => a
  1013. Because this would normally be an ambiguous constraint:
  1014. Ambiguous type variable `a0' in the constraint:
  1015. (Read a0) arising from a use of `read'
  1016. Probable fix: add a type signature that fixes these type variable(s)
  1017. In the expression: read \"a\"
  1018. In an equation for `it': it = read \"a\"
  1019. Which is less useful than just printing the type out.
  1020. You can disable this behaviour by disabling the customization option:
  1021. (custom-set-variables
  1022. '(haskell-interactive-types-for-show-ambiguous nil))
  1023. 13.8.6 Printing mode
  1024. --------------------
  1025. You can choose between printing modes used for the results of evaluating
  1026. expressions. To do that, configure the variable
  1027. ‘haskell-interactive-mode-eval-mode’. Example:
  1028. (setq haskell-interactive-mode-eval-mode 'haskell-mode)
  1029. A handy function you can use is:
  1030. (defun haskell-interactive-toggle-print-mode ()
  1031. (interactive)
  1032. (setq haskell-interactive-mode-eval-mode
  1033. (intern
  1034. (ido-completing-read "Eval result mode: "
  1035. '("fundamental-mode"
  1036. "haskell-mode"
  1037. "espresso-mode"
  1038. "ghc-core-mode"
  1039. "org-mode")))))
  1040. (Add whichever modes you want to use.)
  1041. And then run
  1042. M-x haskell-interactive-toggle-print-mode
  1043. Or ‘C-c C-v’:
  1044. (define-key haskell-interactive-mode-map (kbd "C-c C-v")
  1045. 'haskell-interactive-toggle-print-mode)
  1046. There you can choose ‘haskell-mode‘, for example, to pretty print the
  1047. output as Haskell.
  1048. 13.8.7 SVG images rendering
  1049. ---------------------------
  1050. If you are working on SVG images, you can instruct Emacs to render the
  1051. image as the output of an image producing command at the REPL.
  1052. The following example uses the ‘diamgrams’ library with the default
  1053. SVG backend to produce a circle:
  1054. {-# LANGUAGE OverloadedStrings #-}
  1055. import Diagrams.Prelude
  1056. import Diagrams.Backend.SVG
  1057. myCircle :: Diagram B
  1058. myCircle = circle 1 # lc purple # fc yellow
  1059. circle = renderDia SVG (SVGOptions (mkWidth 250) Nothing "" [] True) myCircle
  1060. After enabling SVG rendering with ‘M-x
  1061. haskell-svg-toggle-render-images’, if you load the above code and type
  1062. ‘circle’ at the REPL, you will see the rendered circle instead of the
  1063. XML representation of the image.
  1064. This feature can be enabled by default by setting the customization
  1065. variable ‘haskell-svg-render-images’ to a non-nil value.
  1066. 13.8.8 Presentations
  1067. --------------------
  1068. If you have the ‘present’ package installed, you can use the following
  1069. syntax to print anything which is an instance of ‘Data’:
  1070. λ> :present 123
  1071. 123
  1072. It will print data structures lazily:
  1073. λ> :present [1..]
  1074. [1
  1075. ,[Integer]]
  1076. It shows types when there is an unevaluated field in a constructor.
  1077. You can click the ‘[Integer]’ or press ‘RET’ on it to expand further:
  1078. λ> :present [1..]
  1079. [1
  1080. ,2
  1081. ,[Integer]]
  1082. Etc. Remember: this only works for instances of ‘Data.Data.Data’.
  1083. 13.8.9 History
  1084. --------------
  1085. A history is maintained for the duration of the REPL buffer. To go up
  1086. and down in the history, run ‘M-p’ for previous and ‘M-n’ for next.
  1087. 13.8.10 Cancelling commands
  1088. ---------------------------
  1089. To cancel a running REPL command, run ‘C-c C-c’.
  1090. 13.8.11 Clear the REPL
  1091. ----------------------
  1092. Run ‘C-c C-k’ to clear the REPL.
  1093. 13.8.12 Trick: Put Interactive REPL in Separate Frame
  1094. -----------------------------------------------------
  1095. The following ‘create-haskell-interactive-frame’ is a quick hack to move
  1096. the repl to a separate frame, for those that want a more predictable
  1097. layout of windows in Emacs.
  1098. (defun create-unfocused-frame ()
  1099. (let*
  1100. ((prv (window-frame))
  1101. (created (make-frame)))
  1102. (select-frame-set-input-focus prv) created))
  1103. (defun create-haskell-interactive-frame ()
  1104. (interactive)
  1105. (haskell-interactive-bring)
  1106. (create-unfocused-frame)
  1107. (delete-window))
  1108. 13.8.13 Troubleshooting
  1109. -----------------------
  1110. If the REPL ever goes funny, you can clear the command queue via:
  1111. M-x haskell-process-clear
  1112. Alternatively, you can just restart the process:
  1113. M-x haskell-process-restart
  1114. You can also switch to the buffer ‘*haskell-process-log*’, which can
  1115. be enabled and disabled with the customization variable
  1116. ‘haskell-process-log‘, to see what the cause of your troubles are.
  1117. If the process fails and nothing unusual is in the process log, the
  1118. following command can dump the ‘haskell-process’ state:
  1119. M-: (haskell-process)
  1120. The output can be copied from the ‘*Messages*’ buffer.
  1121. 13.9 Haskell Interactive Mode Querying
  1122. ======================================
  1123. There a few ways GHCi lets you query information about your code.
  1124. 13.9.1 Get identifier type
  1125. --------------------------
  1126. To print the type of the top-level identifier at point in the REPL and
  1127. in the message buffer, run the following command:
  1128. M-x haskell-process-do-type
  1129. or ‘C-c C-t’.
  1130. 13.9.2 Insert identifier’s type as type signature
  1131. -------------------------------------------------
  1132. To print the type of the top-level identifier at point, run the
  1133. following command:
  1134. C-u M-x haskell-process-do-type
  1135. or ‘C-u C-c C-t’.
  1136. 13.9.3 Get identifier info
  1137. --------------------------
  1138. To print the info of the identifier at point, run the following command:
  1139. M-x haskell-process-do-info
  1140. or ‘C-c C-i’.
  1141. 13.9.4 Presentation mode
  1142. ------------------------
  1143. When using ‘C-c C-i’ or ‘C-c C-t’ it will open a buffer in
  1144. haskell-presentation-mode. You can hit ‘q’ to close the buffer.
  1145. But you can also continue to use ‘C-c C-i’ inside the buffer to drill
  1146. further down data types and classes.
  1147. E.g. if you go to ‘Ord’ in your code buffer and ‘C-c C-i’, it will
  1148. popup a buffer containing
  1149. class Eq a => Ord a where
  1150. compare :: a -> a -> Ordering
  1151. (<) :: a -> a -> Bool
  1152. (>=) :: a -> a -> Bool
  1153. (>) :: a -> a -> Bool
  1154. (<=) :: a -> a -> Bool
  1155. max :: a -> a -> a
  1156. min :: a -> a -> a
  1157. -- Defined in `GHC.Classes'
  1158. And all the instances of that class. But then you can also move your
  1159. cursor to ‘Ordering’ and hit ‘C-c C-i’ again to get another popup:
  1160. data Ordering = LT | EQ | GT -- Defined in `GHC.Types'
  1161. instance Bounded Ordering -- Defined in `GHC.Enum'
  1162. instance Enum Ordering -- Defined in `GHC.Enum'
  1163. instance Eq Ordering -- Defined in `GHC.Classes'
  1164. instance Ord Ordering -- Defined in `GHC.Classes'
  1165. instance Read Ordering -- Defined in `GHC.Read'
  1166. instance Show Ordering -- Defined in `GHC.Show'
  1167. And so on. It’s a very good way of exploring a new codebase.
  1168. 13.9.5 Browse import’s module
  1169. -----------------------------
  1170. To print all exported identifiers of the module imported by the import
  1171. line at point, run the following command:
  1172. M-x haskell-process-do-info
  1173. or ‘C-c C-i’. It will print all exports by running ‘:browse
  1174. The.Module’ in the GHCi process.
  1175. 13.10 Haskell Interactive Mode Cabal integration
  1176. ================================================
  1177. There’s some integration with Cabal in Haskell Interactive Mode. Once
  1178. you’ve started a session, the features below are available.
  1179. 13.10.1 Cabal building
  1180. ----------------------
  1181. The most common Cabal action is building, so that has a specific
  1182. command:
  1183. M-x haskell-process-cabal-build
  1184. Or ‘C-c C-c’. When building, it will hide unneccessary output.
  1185. For example, to build the ‘ace‘ package, the output is simply:
  1186. Compiling: ACE.Types.Tokens
  1187. Compiling: ACE.Combinators
  1188. Compiling: ACE.Tokenizer
  1189. Compiling: ACE.Parsers
  1190. Compiling: ACE.Pretty
  1191. Compiling: ACE
  1192. Complete: cabal build (0 compiler messages)
  1193. Whereas the complete output is normally:
  1194. Building ace-0.5...
  1195. Preprocessing library ace-0.5...
  1196. [4 of 9] Compiling ACE.Types.Tokens ( src/ACE/Types/Tokens.hs, dist/build/ACE/Types/Tokens.o )
  1197. [5 of 9] Compiling ACE.Combinators ( src/ACE/Combinators.hs, dist/build/ACE/Combinators.o ) [ACE.Types.Tokens changed]
  1198. [6 of 9] Compiling ACE.Tokenizer ( src/ACE/Tokenizer.hs, dist/build/ACE/Tokenizer.o ) [ACE.Types.Tokens changed]
  1199. [7 of 9] Compiling ACE.Parsers ( src/ACE/Parsers.hs, dist/build/ACE/Parsers.o )
  1200. [8 of 9] Compiling ACE.Pretty ( src/ACE/Pretty.hs, dist/build/ACE/Pretty.o )
  1201. [9 of 9] Compiling ACE ( src/ACE.hs, dist/build/ACE.o ) [ACE.Tokenizer changed]
  1202. In-place registering ace-0.5...
  1203. Which is considerably more verbose but rarely useful or interesting.
  1204. 13.10.2 Arbitrary cabal commands
  1205. --------------------------------
  1206. To run an arbitrary Cabal command:
  1207. C-u M-x haskell-process-cabal
  1208. Or run ‘C-u C-c c’.
  1209. It will prompt for an input, so you can write ‘configure -fdev’, for
  1210. example.
  1211. 13.10.3 Completing cabal commands
  1212. ---------------------------------
  1213. To run some common Cabal commands, just run:
  1214. M-x haskell-process-cabal
  1215. Or ‘C-c c’. This is commonly used to do ‘install’, ‘haddock’,
  1216. ‘configure’, etc.
  1217. 13.11 Haskell Interactive Mode Debugger
  1218. =======================================
  1219. There is limited support for debugging in GHCi. Haskell Interactive
  1220. Mode provides an interface for interacting with this.
  1221. 13.11.1 Opening the debug buffer
  1222. --------------------------------
  1223. To open the debug buffer run the following command from any buffer
  1224. associated with a session:
  1225. M-x haskell-debug
  1226. It will open a buffer that looks like this:
  1227. Debugging haskell
  1228. You have to load a module to start debugging.
  1229. g - refresh
  1230. Modules
  1231. No loaded modules.
  1232. 13.11.2 Loading modules
  1233. -----------------------
  1234. To debug anything you need to load something into GHCi. Switch to a
  1235. normal file, for example:
  1236. main = do putStrLn "Hello!"
  1237. putStrLn "World"
  1238. and load it into GHCi (‘C-c C-l’). Now when you hit ‘g’ (to refresh)
  1239. in the debugging buffer, you’ll see something like:
  1240. Debugging haskell
  1241. b - breakpoint, g - refresh
  1242. Context
  1243. Not debugging right now.
  1244. Breakpoints
  1245. No active breakpoints.
  1246. Modules
  1247. Main - hello.hs
  1248. 13.11.3 Setting a breakpoint
  1249. ----------------------------
  1250. To set a breakpoint hit ‘b’ in the debugger buffer. It will prompt for
  1251. a name. Enter ‘main’ and hit ‘RET’.
  1252. Now the buffer will look like this:
  1253. Debugging haskell
  1254. s - step into an expression, b - breakpoint
  1255. d - delete breakpoint, g - refresh
  1256. Context
  1257. Not debugging right now.
  1258. Breakpoints
  1259. 0 - Main (1:8)
  1260. Modules
  1261. Main - hello.hs
  1262. 13.11.4 Start stepping
  1263. ----------------------
  1264. Hit ‘s’ to step through an expression: it will prompt for an expression
  1265. to evaluate and step through. Enter ‘main’ and hit ‘RET’. Now the
  1266. buffer will look like this:
  1267. Debugging haskell
  1268. s - step into an expression, b - breakpoint
  1269. d - delete breakpoint, a - abandon context, c - continue
  1270. p - previous step, n - next step
  1271. g - refresh
  1272. Context
  1273. main - hello.hs (stopped)
  1274. do putStrLn "Hello!"
  1275. putStrLn "World"
  1276. _result :: IO () = _
  1277. 1 do putStrLn "Hello!" putStrLn "World"
  1278. Breakpoints
  1279. 0 - Main (1:8)
  1280. Modules
  1281. Main - hello.hs
  1282. What we see here is the current expression being evaluated:
  1283. do putStrLn "Hello!"
  1284. putStrLn "World"
  1285. And we see the type of it:
  1286. _result :: IO () = _
  1287. And we see a backtrace of steps so far:
  1288. 1 do putStrLn "Hello!" putStrLn "World"
  1289. 13.11.5 Continue stepping
  1290. -------------------------
  1291. To continue stepping, just hit ‘s’ again. Now the context will change
  1292. to:
  1293. main - hello.hs (stopped)
  1294. putStrLn "Hello!"
  1295. _result :: IO () = _
  1296. 1 do putStrLn "Hello!" putStrLn "World"
  1297. Hitting ‘s’ once more, we see the context change to:
  1298. putStrLn "World"
  1299. _result :: IO () = _
  1300. 2 putStrLn "Hello!"
  1301. 1 do putStrLn "Hello!" putStrLn "World"
  1302. Finally hitting ‘s’ again will say "Computation finished". Hitting
  1303. ‘s’ a final time will change the display back to:
  1304. Debugging haskell
  1305. s - step into an expression, b - breakpoint
  1306. d - delete breakpoint, g - refresh
  1307. Context
  1308. Finished debugging.
  1309. 2 putStrLn "Hello!"
  1310. 1 do putStrLn "Hello!" putStrLn "World"
  1311. Breakpoints
  1312. 1 - Main (1:8)
  1313. Modules
  1314. Main - hello.hs
  1315. And you’re done debugging.
  1316. 
  1317. File: haskell-mode.info, Node: Editing Cabal files, Next: Browsing Haddocks, Prev: Interactive Haskell, Up: Top
  1318. 14 Editing Cabal files
  1319. **********************
  1320. ‘haskell-cabal-mode’ is a major mode for editing Cabal package
  1321. description files
  1322. (http://www.haskell.org/cabal/users-guide/developing-packages.html) and
  1323. is automatically associated with files having a ‘.cabal’ extension.
  1324. For quickly locating and jumping to the nearest ‘.cabal’ file from a
  1325. Haskell source buffer, you can use ‘M-x haskell-cabal-visit-file’; with
  1326. a prefix argument (i.e. ‘C-u’) ‘find-file-other-window’ is used to
  1327. visit the ‘.cabal’ file. ‘haskell-cabal-visit-file’ is bound to the key
  1328. sequence ‘C-c v c’.
  1329. TODO/WRITEME
  1330. 
  1331. File: haskell-mode.info, Node: Browsing Haddocks, Next: Spell checking strings and comments, Prev: Editing Cabal files, Up: Top
  1332. 15 Browsing Haddocks using ‘w3m’
  1333. ********************************
  1334. An experimental feature is use of the w3m browser to browse Haddock docs
  1335. inside Emacs.
  1336. 15.1 Get w3m
  1337. ============
  1338. Most Linux distributions will have a package for the binary:
  1339. $ sudo apt-get install w3m
  1340. Now grab ‘w3m.el’ from:
  1341. • <http://emacs-w3m.namazu.org/>
  1342. • ‘M-x’ ‘package-install’ ‘RET’ ‘w3m’ ‘RET’
  1343. Confirm installation by trying ‘M-x’ ‘w3m-browse-url’ ‘RET’
  1344. ‘haskell.org’ ‘RET’.
  1345. If this works, you’re good to go.
  1346. 15.2 Configure w3m
  1347. ==================
  1348. Now that you have w3m, you probably want to configure it to be more of a
  1349. passive viewer than a full-fledged browser. For example:
  1350. (setq w3m-mode-map (make-sparse-keymap))
  1351. (define-key w3m-mode-map (kbd "RET") 'w3m-view-this-url)
  1352. (define-key w3m-mode-map (kbd "q") 'bury-buffer)
  1353. (define-key w3m-mode-map (kbd "<mouse-1>") 'w3m-maybe-url)
  1354. (define-key w3m-mode-map [f5] 'w3m-reload-this-page)
  1355. (define-key w3m-mode-map (kbd "C-c C-d") 'haskell-w3m-open-haddock)
  1356. (define-key w3m-mode-map (kbd "M-<left>") 'w3m-view-previous-page)
  1357. (define-key w3m-mode-map (kbd "M-<right>") 'w3m-view-next-page)
  1358. (define-key w3m-mode-map (kbd "M-.") 'w3m-haddock-find-tag)
  1359. (defun w3m-maybe-url ()
  1360. (interactive)
  1361. (if (or (equal '(w3m-anchor) (get-text-property (point) 'face))
  1362. (equal '(w3m-arrived-anchor) (get-text-property (point) 'face)))
  1363. (w3m-view-this-url)))
  1364. 15.3 Import w3m-haddock
  1365. =======================
  1366. It’s not enabled by default in haskell-mode at present, so you need to
  1367. import it manually:
  1368. (require 'w3m-haddock)
  1369. 15.4 Add a hook for w3m
  1370. =======================
  1371. In order to make haddock pages a little more palatable (and add syntax
  1372. highlighting to source view), you can add this hook:
  1373. (add-hook 'w3m-display-hook 'w3m-haddock-display)
  1374. It’s a little rough around the edges, but it’s a start.
  1375. 15.5 Configure your package locations
  1376. =====================================
  1377. By default, the package locations is set to:
  1378. (defcustom haskell-w3m-haddock-dirs
  1379. '("~/.cabal/share/doc/"))
  1380. If you are using an hsenv or a custom package directory, you should
  1381. configure this variable with M-x customize-variable or by writing the
  1382. custom-set-variables code for it.
  1383. 15.6 Finally
  1384. ============
  1385. You did all that! Now you’re ready to bind a useful key:
  1386. (define-key haskell-mode-map (kbd "C-c C-d") 'haskell-w3m-open-haddock)
  1387. Now when you press ‘C-c’ ‘C-d’ it will prompt for a package to browse
  1388. to.
  1389. This feature will be improved gradually as time goes on.
  1390. 
  1391. File: haskell-mode.info, Node: Spell checking strings and comments, Next: Aligning code, Prev: Browsing Haddocks, Up: Top
  1392. 16 Using with ‘flyspell-prog-mode’
  1393. **********************************
  1394. Strings and comments can be checked for spelling mistakes. There is a
  1395. standard Emacs mode for this purpose, ‘flyspell-prog-mode’, that can be
  1396. enabled in Haskell buffers. Spelling errors are underlined using
  1397. squiggly red lines.
  1398. Documentation for ‘flyspell-prog-mode’ can be found in *Note
  1399. (emacs)Spelling::. Here we point to a couple of useful keybindings:
  1400. • ‘M-$’ - Check and correct spelling of the word at point
  1401. (‘ispell-word’).
  1402. • ‘digit’ - Replace the word, just this time, with one of the
  1403. displayed near-misses. Each near-miss is listed with a digit; type
  1404. that digit to select it.
  1405. • ‘SPC’ - Skip this word—continue to consider it incorrect, but don’t
  1406. change it here.
  1407. To enable spell checking of strings and comments add this line to
  1408. your ‘~/.emacs’ file:
  1409. ‘(add-hook 'haskell-mode-hook 'flyspell-prog-mode)’
  1410. 
  1411. File: haskell-mode.info, Node: Aligning code, Next: Rectangular commands, Prev: Spell checking strings and comments, Up: Top
  1412. 17 Aligning code
  1413. ****************
  1414. Select a region you want to align text within, ‘M-x’ ‘align-regexp’, and
  1415. type a regexp representing the alignment delimiter.
  1416. For example, I often line up my Haddock comments:
  1417. f :: a -- ^ does a
  1418. -> Foo b -- ^ and b
  1419. -> c -- ^ to c
  1420. Select the region, and let the regexp be ‘--’:
  1421. f :: a -- ^ does a
  1422. -> Foo b -- ^ and b
  1423. -> c -- ^ to c
  1424. Of course, this works for just about anything. Personally, I’ve
  1425. globally bound it to ‘C-x a r’:
  1426. (global-set-key (kbd "C-x a r") 'align-regexp)
  1427. Note that you can also just use the rules below for telling the
  1428. aligner about Haskell. Once you evaluate this, you can just use ‘M-x’
  1429. ‘align’, which I like to bind to ‘M-[’.
  1430. (add-to-list 'align-rules-list
  1431. '(haskell-types
  1432. (regexp . "\\(\\s-+\\)\\(::\\|∷\\)\\s-+")
  1433. (modes quote (haskell-mode literate-haskell-mode))))
  1434. (add-to-list 'align-rules-list
  1435. '(haskell-assignment
  1436. (regexp . "\\(\\s-+\\)=\\s-+")
  1437. (modes quote (haskell-mode literate-haskell-mode))))
  1438. (add-to-list 'align-rules-list
  1439. '(haskell-arrows
  1440. (regexp . "\\(\\s-+\\)\\(->\\|→\\)\\s-+")
  1441. (modes quote (haskell-mode literate-haskell-mode))))
  1442. (add-to-list 'align-rules-list
  1443. '(haskell-left-arrows
  1444. (regexp . "\\(\\s-+\\)\\(<-\\|←\\)\\s-+")
  1445. (modes quote (haskell-mode literate-haskell-mode))))
  1446. 
  1447. File: haskell-mode.info, Node: Rectangular commands, Next: REPL, Prev: Aligning code, Up: Top
  1448. 18 Using rectangular region commands
  1449. ************************************
  1450. Emacs has a set of commands which operate on the region as if it were
  1451. rectangular. This turns out to be extremely useful when dealing with
  1452. whitespace sensitive languages.
  1453. • ‘C-x r o’ is "Open Rectangle".
  1454. It will shift any text within the rectangle to the right side.
  1455. Also see:
  1456. • ‘C-x r t’ is "String Rectangle".
  1457. It will replace any text within the rectangle with the given string
  1458. on all the lines in the region. If comment-region didn’t already
  1459. exist, you could use this instead, for example.
  1460. • ‘C-x r d’ is "Delete Rectangle".
  1461. It will delete the contents of the rectangle and move anything on
  1462. the right over.
  1463. • ‘C-x r r’ is "Copy Rectangle to Register".
  1464. It will prompt you for a register number so it can save it for
  1465. later.
  1466. • ‘C-x r g’ is "Insert register".
  1467. This will insert the contents of the given register, overwriting
  1468. whatever happens to be within the target rectangle. (So make room)
  1469. • ‘C-x r k’ is "Kill rectangle".
  1470. Delete rectangle and save contents for:
  1471. • ‘C-x r y’ is "Yank rectangle".
  1472. This will insert the contents of the last killed rectangle.
  1473. As with all Emacs modifier combos, you can type ‘C-x r C-h’ to find
  1474. out what keys are bound beginning with the ‘C-x r’ prefix.
  1475. 
  1476. File: haskell-mode.info, Node: REPL, Next: Collapsing Haskell code, Prev: Rectangular commands, Up: Top
  1477. 19 Using GHCi REPL within Emacs
  1478. *******************************
  1479. To start the REPL you can run one of the following:
  1480. • ‘M-x run-haskell’
  1481. • ‘M-x switch-to-haskell’
  1482. This repl works with Comint
  1483. (https://www.emacswiki.org/emacs/ComintMode). So you will feel at home
  1484. if you are already using ‘M-x Shell’ or ‘M-x ielm’.
  1485. ‘Inf-Haskell’ is a Major mode for running GHCi, with comint.
  1486. Important key bindings in ‘Inf-haskell’:
  1487. ‘RET’
  1488. invokes ‘comint-send-input’. Sends the input to the GHCi process,
  1489. evaluates the line and returns the output.
  1490. ‘C-d or <delete>’
  1491. deletes the forward character
  1492. ‘<C-up> or M-p’
  1493. invokes ‘comint-previous-input’. Cycle backwards through input
  1494. history, saving input.
  1495. ‘<C-down> or M-n’
  1496. invokes ‘comint-next-input’. Cycle forwards through input history.
  1497. ‘C-c C-c’
  1498. invokes ‘comint-interrupt-subjob’. Sends KeyboardInterrupt signal.
  1499. ‘C-c C-\’
  1500. invokes ‘comint-quit-subjob’. Sends KeyboardInterrupt signal.
  1501. ‘C-c C-z’
  1502. invokes ‘comint-stop-subjob’. Kills the GHCi process.
  1503. ‘C-c M-r’
  1504. invokes ‘comint-previous-matching-input-from-input’. If you are
  1505. familiar with ‘C-r’ in bash. This is the same as that. Searches
  1506. backwards through input history for match for current input.
  1507. ‘C-c M-s’
  1508. invokes ‘comint-next-matching-input-from-input’. Searches forwards
  1509. through input history for match for current input.
  1510. ‘C-c C-l’
  1511. invokes ‘comint-dynamic-list-input-ring’. Displays a list of
  1512. recent inputs entered into the current buffer.
  1513. ‘C-c M-o’
  1514. invokes ‘comint-clear-buffer’. Clears the buffer (Only with Emacs
  1515. 25.X and above)
  1516. ‘C-c C-n’
  1517. invokes ‘comint-next-prompt’. Goes to the start of the previous
  1518. REPL prompt.
  1519. ‘C-c C-p’
  1520. invokes ‘comint-previous-prompt’. Goes to the start of the next
  1521. REPL prompt.
  1522. ‘C-c C-o’
  1523. invokes ‘comint-delete-output’. Clears the output of the most
  1524. recently evaluated expression.
  1525. ‘C-c C-e’
  1526. invokes ‘comint-show-maximum-output’. Moves the point to the end
  1527. of the buffer.
  1528. ‘C-c C-u’
  1529. invokes ‘comint-kill-input’. Kills backward, the line at point.
  1530. (Use this when you have typed in an expression into the prompt but
  1531. you dont want to evaluate it.)
  1532. ‘C-c C-w’
  1533. invokes ‘backward-kill-word’. Kills backward, the word at point
  1534. ‘C-c C-s’
  1535. invokes ‘comint-write-output’. Write output from interpreter since
  1536. last input to FILENAME. Any prompt at the end of the output is not
  1537. written.
  1538. 19.1 Relevant defcustoms:
  1539. =========================
  1540. Interpreter (defcustom) Default Possible Values
  1541. Value
  1542. ---------------------------------------------------------------------------
  1543. ‘haskell-process-type’ ‘'auto’ ‘'stack-ghci, 'cabal-repl,
  1544. 'ghci, 'auto’
  1545. ‘inferior-haskell-hook’ ‘nil’ -
  1546. ‘haskell-process-path-ghci’ ‘ghci’ -
  1547. ‘haskell-process-args-ghci’ ‘-ferror-spans’-
  1548. ‘haskell-process-path-cabal’ ‘cabal’ -
  1549. ‘haskell-process-args-cabal-repl’‘--ghc-option=-ferror-spans’-
  1550. ‘haskell-process-path-stack’ ‘stack’ -
  1551. ‘haskell-process-args-stack-ghci’‘--ghci-options=-ferror-spans-
  1552. --no-build
  1553. --no-load’
  1554. 19.2 More on ‘haskell-process-type’
  1555. ===================================
  1556. The Haskell interpreter used by ‘Inf-Haskell’ is auto-detected by
  1557. default, but is customizable with defcustom ‘haskell-process-type’. The
  1558. values recognized by it are (default is ’auto):
  1559. • ‘'stack-ghci’
  1560. • ‘'cabal-repl’
  1561. • ‘'ghci’
  1562. • ‘'auto’
  1563. if the ‘haskell-process-type’ is ‘'auto’, the directories are
  1564. searched for ‘cabal.sandbox.config’ or ‘stack.yaml’ or ‘*.cabal’ file.
  1565. If the file is present, then appropriate process is started.
  1566. When ‘cabal.sandbox.config’ is found ‘haskell-process-type’ is
  1567. ‘'cabal-repl’. Similarly, when ‘stack.yaml’ is found
  1568. ‘haskell-process-type’ is ‘'stack-ghci’. Similarly, when ‘xyz.cabal’ is
  1569. found ‘haskell-process-type’ is ‘'cabal-repl’. When nothing is found
  1570. ‘haskell-process-type’ is ‘'ghci’. When more than one file such as
  1571. ‘cabal.sandbox.config’ and ‘stack.yaml’ are found the following
  1572. preference is followed.
  1573. ‘cabal.sandbox.config’ > ‘stack.yaml’ > ‘*.cabal’
  1574. 
  1575. File: haskell-mode.info, Node: Collapsing Haskell code, Next: Getting Help and Reporting Bugs, Prev: REPL, Up: Top
  1576. 20 Collapsing Haskell code
  1577. **************************
  1578. This is ‘hs-minor-mode’ for ‘haskell-mode’. This module uses hideshow
  1579. module.
  1580. To activate this minor mode (haskell-collapse-mode)
  1581. • ‘M-x haskell-collapse-mode’ is "To start haskell-collapse-mode".
  1582. This minor mode works with indentation.
  1583. In a quick glance:
  1584. ‘C-c C-c’
  1585. is bound to ‘haskell-hide-toggle’
  1586. ‘C-c C-M-c’
  1587. ‘C-c C-M-h’
  1588. ‘C-c C-M-s’
  1589. are all bound to ‘haskell-hide-toggle-all’
  1590. How to use ‘M-x haskell-hide-toggle’?
  1591. Place your point on the code block that you want to collapse and hit
  1592. the keybinding. Now the code collapses and you can see the first line
  1593. of the block and elipsis.
  1594. Take this example code (example usage of ‘M-x haskell-hide-toggle’):
  1595. when you place the cursor here, like this (notice the thick block in the
  1596. first line):
  1597. ‘ f█x | rem i 3 == 0 = if i == 0 && (k /= 0) then (c k) else (h j) |
  1598. otherwise = 0 where i = sum x j = g x (div i 3) 0 0 [] k = zeroes x 0 ’
  1599. or
  1600. ‘ f x | rem i 3 == 0 = if i == 0 && (k /= 0) then (c k) else (h j) █
  1601. | otherwise = 0 where i = sum x j = g x (div i 3) 0 0 [] k = zeroes x 0
  1602. then when you collapse it becomes something like this:
  1603. ‘ f█x... ’
  1604. It works in terms of (indentation) blocks.
  1605. One more example:
  1606. ‘ f x | rem i 3 == 0 = if i == 0 && (k /= 0) then (c k) else (h j) |
  1607. otherwise = 0 w█ere i = sum x j = g x (div i 3) 0 0 [] k = zeroes x 0 ’
  1608. or
  1609. ‘ f x | rem i 3 == 0 = if i == 0 && (k /= 0) then (c k) else (h j) |
  1610. otherwise = 0 where i = sum x j = g x (div i 3) 0 0 [] █ k = zeroes x 0
  1611. this, will result in something like:
  1612. ‘ f x | rem i 3 == 0 = if i == 0 && (k /= 0) then (c k) else (h j) |
  1613. otherwise = 0 where i = sum █... ’
  1614. The other functionality ‘M-x haskell-hide-toggle-all’ also works only
  1615. for indentation and it collapses all toplevel functions.
  1616. So a file that looks like this:
  1617. main = interact $ show.f. map read .words
  1618. f (x:xs) = dp x xs
  1619. dp money a | money < 0 || null a = [1..1000]
  1620. dp 0 a = []
  1621. dp money a @ (coin:coins)
  1622. | (length i) <= length j = i
  1623. | otherwise = j
  1624. where i = (coin:(dp (money-coin) a))
  1625. j = (dp money coins)
  1626. will turn into this:
  1627. main = interact $ show.f. map read .words
  1628. f (x:xs) = dp x xs
  1629. dp money a | money < 0 || null a = [1..1000]
  1630. dp 0 a = []
  1631. dp money a @ (coin:coins)...
  1632. 
  1633. File: haskell-mode.info, Node: Getting Help and Reporting Bugs, Next: Concept index, Prev: Collapsing Haskell code, Up: Top
  1634. 21 Getting Help and Reporting Bugs
  1635. **********************************
  1636. Work on Haskell Mode is organized with Github ‘haskell-mode’ project.
  1637. To understand how the project is run please read the information in the
  1638. project wiki pages (https://github.com/haskell/haskell-mode/wiki).
  1639. To report any issues please use the Github’s issue mechanism
  1640. available from Haskell Mode’s GitHub Home
  1641. (https://github.com/haskell/haskell-mode).
  1642. For a quick question visit ‘#haskell-emacs’ channel on IRC
  1643. ‘irc.freenode.net’.
  1644. There is also a (now defunct) Haskellmode-emacs mailing list
  1645. (http://projects.haskell.org/cgi-bin/mailman/listinfo/haskellmode-emacs),
  1646. also available on Gmane (http://gmane.org/) via the
  1647. gmane.comp.lang.haskell.emacs
  1648. (http://dir.gmane.org/gmane.comp.lang.haskell.emacs) newsgroup.
  1649. We welcome code and non-code contributions so that we can all enjoy
  1650. coding Haskell even more.
  1651. 
  1652. File: haskell-mode.info, Node: Concept index, Next: Function index, Prev: Getting Help and Reporting Bugs, Up: Top
  1653. Concept index
  1654. *************
  1655. [index]
  1656. * Menu:
  1657. * benchmarking: Interactive Haskell. (line 472)
  1658. * CUA mode: Indentation. (line 49)
  1659. * customizing: Installation. (line 55)
  1660. * customizing <1>: Interactive Haskell. (line 53)
  1661. * haskell-mode: Editing Haskell Code.
  1662. (line 6)
  1663. * Images, rendering SVG images: Interactive Haskell. (line 614)
  1664. * indentation: Indentation. (line 6)
  1665. * layout rule: Indentation. (line 6)
  1666. * off-side rule: Indentation. (line 6)
  1667. * rectangle: Indentation. (line 49)
  1668. * Rendering SVG images: Interactive Haskell. (line 614)
  1669. * SVG images, rendering: Interactive Haskell. (line 614)
  1670. * testing: Interactive Haskell. (line 470)
  1671. * Unicode: Unicode support. (line 6)
  1672. 
  1673. File: haskell-mode.info, Node: Function index, Next: Variable index, Prev: Concept index, Up: Top
  1674. Function index
  1675. **************
  1676. [index]
  1677. * Menu:
  1678. * haskell-cabal-mode: Editing Cabal files. (line 6)
  1679. * haskell-cabal-visit-file: Editing Cabal files. (line 11)
  1680. * haskell-compile: Compilation. (line 6)
  1681. * haskell-decl-scan-mode: Declaration scanning.
  1682. (line 6)
  1683. * haskell-mode: Editing Haskell Code.
  1684. (line 6)
  1685. * haskell-session-change-target: Interactive Haskell. (line 463)
  1686. * haskell-svg-toggle-render-images: Interactive Haskell. (line 630)
  1687. 
  1688. File: haskell-mode.info, Node: Variable index, Prev: Function index, Up: Top
  1689. Variable index
  1690. **************
  1691. [index]
  1692. * Menu:
  1693. * haskell-c2hs-hook-name-face: Syntax highlighting. (line 39)
  1694. * haskell-c2hs-hook-pair-face: Syntax highlighting. (line 38)
  1695. * haskell-cabal-mode-hook: Editing Cabal files. (line 6)
  1696. * haskell-compile-cabal-build-command: Compilation. (line 35)
  1697. * haskell-compile-cabal-build-command-alt: Compilation. (line 35)
  1698. * haskell-compile-command: Compilation. (line 35)
  1699. * haskell-constructor-face: Syntax highlighting. (line 30)
  1700. * haskell-decl-scan-mode-hook: Declaration scanning.
  1701. (line 6)
  1702. * haskell-definition-face: Syntax highlighting. (line 31)
  1703. * haskell-interactive-mode-hook: Interactive Haskell. (line 463)
  1704. * haskell-keyword-face: Syntax highlighting. (line 28)
  1705. * haskell-literate-comment-face: Syntax highlighting. (line 35)
  1706. * haskell-mode-hook: Installation. (line 60)
  1707. * haskell-operator-face: Syntax highlighting. (line 33)
  1708. * haskell-pragma-face: Syntax highlighting. (line 34)
  1709. * haskell-process-args-cabal-new-repl: Interactive Haskell. (line 76)
  1710. * haskell-process-args-cabal-repl: Interactive Haskell. (line 76)
  1711. * haskell-process-args-ghci: Interactive Haskell. (line 76)
  1712. * haskell-process-args-stack-ghci: Interactive Haskell. (line 75)
  1713. * haskell-process-path-cabal: Interactive Haskell. (line 76)
  1714. * haskell-process-path-ghci: Interactive Haskell. (line 76)
  1715. * haskell-process-path-stack: Interactive Haskell. (line 76)
  1716. * haskell-process-type: Interactive Haskell. (line 76)
  1717. * haskell-quasi-quote-face: Syntax highlighting. (line 36)
  1718. * haskell-svg-render-images: Interactive Haskell. (line 635)
  1719. * haskell-type-face: Syntax highlighting. (line 29)
  1720. 
  1721. Tag Table:
  1722. Node: Top683
  1723. Node: Introduction2588
  1724. Node: Installation4173
  1725. Node: Editing Haskell Code6796
  1726. Node: Syntax highlighting10556
  1727. Node: Completion support12816
  1728. Node: Unicode support14859
  1729. Node: Indentation19531
  1730. Node: External indentation23007
  1731. Node: Autoformating23735
  1732. Node: Module templates24363
  1733. Node: Declaration scanning24793
  1734. Node: Compilation28081
  1735. Node: Interactive Haskell31986
  1736. Node: Editing Cabal files63866
  1737. Node: Browsing Haddocks64613
  1738. Node: Spell checking strings and comments67438
  1739. Node: Aligning code68544
  1740. Node: Rectangular commands70289
  1741. Node: REPL71809
  1742. Node: Collapsing Haskell code76587
  1743. Node: Getting Help and Reporting Bugs79195
  1744. Node: Concept index80239
  1745. Node: Function index81497
  1746. Node: Variable index82292
  1747. 
  1748. End Tag Table
  1749. 
  1750. Local Variables:
  1751. coding: utf-8
  1752. End: