-
Notifications
You must be signed in to change notification settings - Fork 347
/
Copy pathhaskell-mode.texi
1864 lines (1482 loc) · 50.9 KB
/
haskell-mode.texi
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
\input texinfo @c -*-texinfo-*-
@c %**start of header
@setfilename haskell-mode.info
@documentencoding UTF-8
@settitle Haskell Mode 16.1-git
@c %**end of header
@c Macro used to mark references of defcustom variables
@macro defcustom{var}
@vrindex \var\
@code{\var\}
@end macro
@dircategory Emacs
@direntry
* Haskell Mode: (haskell-mode). Haskell Development Environment for Emacs(en)
@end direntry
@copying
This manual is for Haskell mode, version 16.1-git
Copyright @copyright{} 2013-2017 Haskell Mode contributors.
@quotation
Permission is granted to copy, distribute and/or modify this document
under the terms of the @uref{http://www.gnu.org/licenses/fdl.html,GNU
Free Documentation License}, Version 1.3 or any later version published
by the Free Software Foundation; with no Invariant Sections, no
Front-Cover Texts and no Back-Cover Texts.
@end quotation
@end copying
@iftex
@titlepage
@title Haskell Mode
@subtitle Haskell Development Environment for Emacs
@page
@vskip 0pt plus 1filll
@insertcopying
@end titlepage
@contents
@end iftex
@ifnottex
@node Top
@top Haskell Mode
Haskell Mode is an Haskell development Environment for GNU Emacs version
24.3 or later. It provides syntax-based indentation, font locking,
editing cabal files, and supports running an inferior Haskell
interpreter (e.g. GHCi).
@end ifnottex
@menu
* Introduction:: An introduction to Haskell Mode
* Installation:: How to get started
* Editing Haskell Code:: How to edit code
* Syntax highlighting:: Haskell Mode has colors
* Completion support:: Autocomplete
* Unicode support:: How to use Unicode
* Indentation:: Notes about indentation
* External indentation:: Other ways to indent code
* Autoformating:: Using external formatters
* Module templates:: Module templates
* Declaration scanning:: How to navigate in a source file
* Compilation:: How to compile
* Interactive Haskell:: How to interact with GHCi
* Editing Cabal files:: Cabal support
* Browsing Haddocks:: Using @code{w3m} to browse documentation
* Spell checking strings and comments:: Using @code{flyspell-prog-mode}
* Aligning code:: Aligning code using @code{align-regexp}
* Rectangular commands:: Manage indentation manually
* REPL:: GHCi REPL
* Global-Eldoc:: Shows documentation at point
* Collapsing Haskell code:: View more code on screen
* Getting Help and Reporting Bugs:: How to improve Haskell Mode
* Concept index:: Index of Haskell Mode concepts
* Function index:: Index of commands
* Variable index:: Index of options and types
@end menu
@ifhtml
@insertcopying
@end ifhtml
@node Introduction
@chapter Introduction
@dfn{Haskell Mode} is a major mode providing a convenient environment
for editing @uref{http://www.haskell.org,Haskell} programs.
Some of its major features are:
@itemize
@item
Syntax highlighting (font lock),
@item
automatic semi-intelligent indentation,
@item
on-the-fly documentation,
@item
interaction with inferior GHCi/Hugs instance,
@item
project building with cabal and stack
@item
scanning declarations and placing them in a menu.
@end itemize
The name Haskell Mode refers to the whole collection of modules in this
package. There is specifically a file @file{haskell-mode.el} which
defines a major mode called @code{haskell-mode}. Generally, in this
documentation they will be distinguished by normal font and title case
(Haskell Mode) and code font (@code{haskell-mode}).
@section History
@code{haskell-mode} has a long history. It goes all the way back
to 1992. Since then, it has received many contributions in many
forms. Some design choices that remain in haskell-mode today are
historical. Some modules are outdated or no longer used, or are used
by a few people.
Historically there hasn't been a single individual or set of
individuals directing the package's architecture for a long period of
time, rather, patches and new modules were accepted in liberally and
we are left with a box full of interesting toys that may or may not
work.
As of 2016 Haskell Mode is coordinated using Github at
@uref{https://github.com/haskell/haskell-mode}.
@node Installation
@chapter Installation
Haskell Mode is distributed as a package in
@uref{https://melpa.org,MELPA repository}. To use MELPA as Emacs package
archive do the following:
@enumerate
@item
Customize @code{package-archives} using
@example
M-x customize-option RET package-archives
@end example
@item
Use @kbd{INS} to add new archive, use:
@example
Archive name: melpa-stable
URL or directory name: http://stable.melpa.org/packages/
@end example
@item
Fetch new packages using:
@example
M-x package-refresh-contents
@end example
@item
Install Haskell Mode using:
@example
M-x package-install RET haskell-mode RET
@end example
@end enumerate
Voila! @code{haskell-mode} is installed! You should be able to edit Haskell
source code in color now.
The above steps should result in the following snippet in your @file{.emacs}:
@lisp
(require 'package)
(custom-set-variables
;; custom-set-variables was added by Custom.
;; If you edit it by hand, you could mess it up, so be careful.
;; Your init file should contain only one such instance.
;; If there is more than one, they won't work right.
'(package-archives
(quote
(("gnu" . "http://elpa.gnu.org/packages/")
("melpa-stable" . "http://stable.melpa.org/packages/")))))
@end lisp
Haskell Mode supports GNU Emacs versions 24.3+, including 25
(snapshot).
Haskell Mode is available from
@uref{http://stable.melpa.org,melpa-stable (releases)} and
@uref{http://melpa.org, melpa (git snapshots)}.
Other means of obtaining @code{haskell-mode} include
@uref{https://github.com/dimitri/el-get, el-get},
@uref{https://github.com/bbatsov/prelude, Emacs Prelude} and
@uref{https://packages.debian.org/search?keywords=haskell-mode, Debian package}.
Last version of @code{haskell-mode} that supported Emacs 23, 24.1, and 24.2 is
@code{haskell-mode} 13.16 available at
@uref{https://github.com/haskell/haskell-mode/releases/tag/v13.16}.
@section Customizing
@cindex customizing
Most of Haskell Mode's settings are configurable via customizable
variables (@pxref{Easy Customization,,,emacs}, for details). You can use
@kbd{M-x customize-group @key{RET} haskell} to browse the @code{haskell}
customization sub-tree.
@vindex haskell-mode-hook
One of the important setting you should customize is the
@code{haskell-mode-hook} variable (@pxref{Hooks,,,emacs}) which gets run
right after the @code{haskell-mode} major mode is initialized for a
buffer. You can customize @code{haskell-mode-hook} by
@example
M-x customize-variable RET haskell-mode-hook
@end example
There you can enable or disable a couple of predefined options or add
any function to the list.
@node Editing Haskell Code
@chapter Editing Haskell Code
@findex haskell-mode
@cindex @code{haskell-mode}
Haskell Mode as one of its components provides a major mode for editing
Haskell source code called @code{haskell-mode}, which gave the name to
the whole project. There is a derived mode provided called
@code{literate-haskell-mode} that support Literate Haskell source code
both in Bird and in Latex forms.
Haskell Mode supports files with the following extensions:
@table @file
@item .hs
official file extension for Haskell files. Haskell Mode out of the box
supports most of GHC extensions.
@item .lhs
official file extension for Literate Haskell files. Both Bird and Latex
styles are supported.
@item .hsc
Haskell interfaces to C code used by @uref{http://www.haskell.org/ghc/docs/latest/html/users_guide/hsc2hs.html,hsc2hs}
pre-processor.
@item .cpphs
Haskell source with CPP pragmas used with @uref{http://projects.haskell.org/cpphs,cpphs}
pre-processor.
@item .c2hs
Haskell FFI bindings to C libraries used with @uref{https://github.com/haskell/c2hs,c2hs}
pre-processor.
@end table
Haskell Mode offers many productivity tools described in following
chapters in this manual.
@section Managing imports
There are a few functions for managing imports.
@subsection Jump to imports
To jump to your import list, run
@kbd{M-x} @code{haskell-navigate-imports}
It's nicer to have a keybinding to do this, for example:
@lisp
(define-key haskell-mode-map (kbd "<f8>") 'haskell-navigate-imports)
@end lisp
You can hit it repeatedly to jump between groups of imports. It will
cycle.
@subsection Format imports
To generally format (sort, align) your imports, you can run
@kbd{M-x} @code{haskell-mode-format-imports}
Or @kbd{C-c C-,}.
@subsection Sort imports
To just sort imports, jump to an import section and run
@kbd{M-x} @code{haskell-sort-imports}
@subsection Align imports
To just align imports, jump to an import section and run
@kbd{M-x} @code{haskell-align-imports}
@subsection stylish-haskell
As an alternative to the elisp functions described above, haskell-mode
can use the program
@url{http://hackage.haskell.org/package/stylish-haskell,
stylish-haskell} to format imports. You can set this behavior by
typing: @kbd{M-x} @code{customize-variable} @kbd{RET}
@code{haskell-stylish-on-save}. You can install
@code{stylish-haskell} by running @code{stack install
stylish-haskell}, or if you have not installed @code{stack},
@code{cabal install stylish-haskell}.
@section Haskell Tags
@code{haskell-mode} can generate tags when saving source files. To
generate tags @code{haskell-mode} uses external program —
@url{https://github.com/MarcWeber/hasktags, Hasktags}
(@url{https://wiki.haskell.org/Tags, wiki-article}). To turn on tags
generatation customize or set to @code{t} @code{haskell-tags-on-save}
variable. Also, you may find useful to revert tags tables
automatically, this can be done by customizing
@code{tags-revert-without-query} variable (either globally or for
Haskell buffers only).
@section Profiling and Debugging support
When profiling code with GHC, it is often useful to add
@uref{https://downloads.haskell.org/~ghc/latest/docs/html/users_guide/profiling.html#cost-centres,
cost centres} by hand. These allow finer-grained information about
program behavior. @code{haskell-mode} provides the function
@code{haskell-mode-toggle-scc-at-point} to make this more convenient.
It will remove an SCC annotation at point if one is present, or add
one if point is over whitespace. By default it is bound to @kbd{C-c C-s}.
@node Syntax highlighting
@chapter Syntax highlighting
@code{haskell-mode} supports @dfn{syntax highlighting} via Emacs' Font
Lock minor mode which should be enabled by default in current
Emacsen. @xref{Font Lock,,,emacs}, for more information on how to
control @code{font-lock-mode}.
@ifhtml
@image{anim/font-lock}
@end ifhtml
Syntax highlighting facilities parse strings and string escape sequences
and are able to highlight unrecognized constructs.
@ifhtml
@image{anim/string-escape-highlight}
@end ifhtml
Haskell Mode shows keywords, identifiers, operators, constructors and
types in different colors.
@ifhtml
@image{anim/font-lock-types}
@end ifhtml
There is also support to use mode-specific syntax highlighing for
quasiquotes.
@ifhtml
@image{anim/font-lock-quasi-quotes}
@end ifhtml
At this point quasi quotes for HTML, XML, shell scripts, Hamlet
templates and SQL are supported out of the box. Customize
@code{haskell-font-lock-quasi-quote-modes} to make sure your quoters are
supported.
The following customization variables are responsible for faces applied:
@itemize @code
@item @defcustom{haskell-keyword-face}: for keywords
@item @defcustom{haskell-type-face}: for type names and type class names
@item @defcustom{haskell-constructor-face}: for constructors
@item @defcustom{haskell-definition-face}: function and operator name at the definition place
@item @defcustom{haskell-operator-face}: operators
@item @defcustom{haskell-pragma-face}: GHC pragmas
@item @defcustom{haskell-literate-comment-face}: literate comments
@item @defcustom{haskell-quasi-quote-face}: quasi quotes unless using mode specific highlighting
@item @defcustom{haskell-c2hs-hook-pair-face}: c2hs hooks
@item @defcustom{haskell-c2hs-hook-name-face}: c2hs hook names
@end itemize
All the above are available for customization.
GHC quasi quote syntax is ambiguous with list comprehension therefore
syntax highlighting might get confused with situations like these:
@example
result = [html| html <- htmlList]
result = [html| <html><body>...</body></html> |]
@end example
Please use spaces around a list comprehension variable to make this
unambiguous. Any of the following will work:
@example
result = [ html| html <- htmlList]
result = [html | html <- htmlList]
@end example
GHC's ambiguity is an accident of the past but it is unlikely to be
fixed due to backward compatibility baggage.
@node Completion support
@chapter Completion support
@code{haskell-mode} can complete symbols, pragma directives, language
extensions, and language keywords out-of-box. @code{haskell-mode}
completes identifiers (symbols) using tags (see ``Tags''), however you
can get more precise completions with @code{haskell-interactive-mode}.
In interactive mode completion candidates are produced by querying
GHCi REPL.
@ifhtml
@image{anim/company-mode-language-pragma}
@end ifhtml
If @code{haskell-interactive-mode} is enabled and working Haskell mode
provides completions for import statements taking into account
currently loaded and available packages. Also it completes symbols
querying REPL with @code{:complete} command, hence completion
candidate list also includes symbols from imported modules.
@ifhtml
@image{anim/company-mode-import-statement}
@end ifhtml
Unfortunatelly, it is not possible to provide candidates for
identifiers defined locally in @code{let} and @code{where} blocks even
in interactive mode. But if you're using
@url{http://company-mode.github.io/, company-mode} you can override
@code{company-backends} variable for Haskell buffers to combine
completion candidates from completion-at-point function
(@code{company-capf} backend) and dynamic abbrevs.
@code{company-mode} provides special backend for dabbrev code
completions, namely @code{company-dabbrev-code}. To combine
completions from diffrent backends you can create grouped backends, it
is very easy — a grouped backend is just a list of backends, for
example:
@lisp
(add-hook 'haskell-mode-hook
(lambda ()
(set (make-local-variable 'company-backends)
(append '((company-capf company-dabbrev-code))
company-backends))))
@end lisp
If you use a GHCi version prior to 8.0.1 you might want to set
@code{haskell-completions-complete-operators} to @code{nil}, if you
experience major slowdown while trying to complete after an Haskell
operator (See @url{https://ghc.haskell.org/trac/ghc/ticket/10576, GHC-Bug 10576}).
@node Unicode support
@chapter Unicode support
@cindex Unicode
See the Haskell Wiki's entry on
@uref{http://www.haskell.org/haskellwiki/Unicode-symbols, Unicode
Symbols} for general information about Unicode support in Haskell.
As Emacs supports editing files containing Unicode out of the box, so
does Haskell Mode. As an add-on, Haskell Mode includes the
@code{haskell-unicode} input method which allows you to easily type a
number of Unicode symbols that are useful when writing Haskell code;
@xref{Input Methods,,,emacs}, for more details.
To automatically enable the @code{haskell-unicode} input method in
haskell-mode buffers use @kbd{M-x customize-variable @key{RET}
haskell-mode-hook} or put the following code in your @file{.emacs} file:
@lisp
(add-hook 'haskell-mode-hook 'turn-on-haskell-unicode-input-method)
@end lisp
@noindent
To temporarily enable this input method for a single buffer you can use
@kbd{M-x turn-on-haskell-unicode-input-method}.
When the @code{haskell-unicode} input method is active, you can simply
type @samp{->} and it is immediately replaced with @samp{→}. Use
@kbd{C-\} to toggle the input method. To see a table of all key
sequences use @kbd{M-x describe-input-method @key{RET}
haskell-unicode}. A sequence like @samp{<=} is ambiguous and can mean
either @samp{⇐} or @samp{≤}. Typing it presents you with a choice. Type
@kbd{1} or @kbd{2} to select an option or keep typing to use the default
option.
Currently defined sequences are listed in the following table:
@multitable @columnfractions .08 .15 .08 .15 .08 .15 .08 .15
@headitem Sequence @tab Unicode @tab Sequence @tab Unicode @tab Sequence @tab Unicode @tab Sequence @tab Unicode
@item alpha
@tab α
@tab Alpha
@tab Α
@tab beta
@tab β
@tab Beta
@tab Β
@item gamma
@tab γ
@tab Gamma
@tab Γ
@tab delta
@tab δ
@tab Delta
@tab Δ
@item epsilon
@tab ε
@tab Epsilon
@tab Ε
@tab zeta
@tab ζ
@tab Zeta
@tab Ζ
@item eta
@tab η
@tab Eta
@tab Η
@tab theta
@tab θ
@tab Theta
@tab Θ
@item iota
@tab ι
@tab Iota
@tab Ι
@tab kappa
@tab κ
@tab Kappa
@tab Κ
@item lambda
@tab λ
@tab Lambda
@tab Λ
@tab lamda
@tab λ
@tab Lamda
@tab Λ
@item mu
@tab μ
@tab Mu
@tab Μ
@tab nu
@tab ν
@tab Nu
@tab Ν
@item xi
@tab ξ
@tab Xi
@tab Ξ
@tab omicron
@tab ο
@tab Omicron
@tab Ο
@item pi
@tab π
@tab Pi
@tab Π
@tab rho
@tab ρ
@tab Rho
@tab Ρ
@item sigma
@tab σ
@tab Sigma
@tab Σ
@tab tau
@tab τ
@tab Tau
@tab Τ
@item upsilon
@tab υ
@tab Upsilon
@tab Υ
@tab phi
@tab φ
@tab Phi
@tab Φ
@item chi
@tab χ
@tab Chi
@tab Χ
@tab psi
@tab ψ
@tab Psi
@tab Ψ
@item omega
@tab ω
@tab Omega
@tab Ω
@tab digamma
@tab ϝ
@tab Digamma
@tab Ϝ
@item san
@tab ϻ
@tab San
@tab Ϻ
@tab qoppa
@tab ϙ
@tab Qoppa
@tab Ϙ
@item sampi
@tab ϡ
@tab Sampi
@tab Ϡ
@tab stigma
@tab ϛ
@tab Stigma
@tab Ϛ
@item heta
@tab ͱ
@tab Heta
@tab Ͱ
@tab sho
@tab ϸ
@tab Sho
@tab Ϸ
@item |A|
@tab 𝔸
@tab |B|
@tab 𝔹
@tab |C|
@tab ℂ
@tab |D|
@tab 𝔻
@item |E|
@tab 𝔼
@tab |F|
@tab 𝔽
@tab |G|
@tab 𝔾
@tab |H|
@tab ℍ
@item |I|
@tab 𝕀
@tab |J|
@tab 𝕁
@tab |K|
@tab 𝕂
@tab |L|
@tab 𝕃
@item |M|
@tab 𝕄
@tab |N|
@tab ℕ
@tab |O|
@tab 𝕆
@tab |P|
@tab ℙ
@item |Q|
@tab ℚ
@tab |R|
@tab ℝ
@tab |S|
@tab 𝕊
@tab |T|
@tab 𝕋
@item |U|
@tab 𝕌
@tab |V|
@tab 𝕍
@tab |W|
@tab 𝕎
@tab |X|
@tab 𝕏
@item |Y|
@tab 𝕐
@tab |Z|
@tab ℤ
@tab |gamma|
@tab ℽ
@tab |Gamma|
@tab ℾ
@item |pi|
@tab ℼ
@tab |Pi|
@tab ℿ
@tab ::
@tab ∷
@tab forall
@tab ∀
@item exists
@tab ∃
@tab ->
@tab →
@tab <-
@tab ←
@tab =>
@tab ⇒
@item ~>
@tab ⇝
@tab <~
@tab ⇜
@tab &&
@tab ∧
@tab ||
@tab ∨
@item ==
@tab ≡
@tab /=
@tab ≢, ≠
@tab <=
@tab ≤
@tab >=
@tab ≥
@item /<
@tab ≮
@tab />
@tab ≯
@tab *
@tab ⋅
@tab elem
@tab ∈
@item notElem
@tab ∉
@tab member
@tab ∈
@tab notMember
@tab ∉
@tab union
@tab ∪
@item intersection
@tab ∩
@tab isSubsetOf
@tab ⊆
@tab isProperSubsetOf
@tab ⊂
@tab <<<
@tab ⋘
@item >>>
@tab ⋙
@tab <|
@tab ⊲
@tab |>
@tab ⊳
@tab ><
@tab ⋈
@item mappend
@tab ⊕
@tab .
@tab ∘
@tab undefined
@tab ⊥
@tab :=
@tab ≔
@item =:
@tab ≕
@tab =def
@tab ≝
@tab =?
@tab ≟
@tab ...
@tab …
@item _0
@tab ₀
@tab _1
@tab ₁
@tab _2
@tab ₂
@tab _3
@tab ₃
@item _4
@tab ₄
@tab _5
@tab ₅
@tab _6
@tab ₆
@tab _7
@tab ₇
@item _8
@tab ₈
@tab _9
@tab ₉
@tab ^0
@tab ⁰
@tab ^1
@tab ¹
@item ^2
@tab ²
@tab ^3
@tab ³
@tab ^4
@tab ⁴
@tab ^5
@tab ⁵
@item ^6
@tab ⁶
@tab ^7
@tab ⁷
@tab ^8
@tab ⁸
@tab ^9
@tab ⁹
@end multitable
If you don't like the highlighting of partially matching tokens you can
turn it off by setting @code{input-method-highlight-flag} to @code{nil}
via @kbd{M-x customize-variable}.
@node Indentation
@chapter Indentation
@cindex indentation
@cindex layout rule
@cindex off-side rule
In Haskell, code indentation has semantic meaning as it defines the
block structure. Haskell also supports braces and semicolons
notation for conveying the block structure. However, most Haskell
programs written by humans use indentation for block structuring.
Haskell Mode ships with two indentation modes:
@itemize
@item @code{haskell-indentation-mode} (default).
This is a semi-intelligent indentation mode doing a decent job at
recognizing Haskell syntactical constructs. It is based on a recursive
descent Haskell parser. @kbd{TAB} selects the next potential indentation
position, @kbd{S-TAB} selects the previous one. If a block is selected
you can use @kbd{TAB} to indent the block more and @kbd{S-TAB} to indent
the block less.
When @code{electric-indent-mode} is enabled or the variable
@code{haskell-indentation-electric-flag} is non-nil, the insertion of
some characters (by default @kbd{,} @kbd{;} @kbd{)} @kbd{@}} @kbd{]})
may trigger auto reindentation under appropriate conditions. See the
documentation of @code{haskell-indentation-common-electric-command} for
more details.
@item @code{haskell-indent-mode} (optional).
This is a semi-intelligent indentation mode doing a decent job at
recognizing Haskell syntactical constructs. It is based on a decision
table. Sadly it is no longer developed and does not recognize newer
Haskell syntax. @kbd{TAB} cycles through all available indentation
positions.
To use @code{haskell-indent-mode}, add this to your @file{~/.emacs}
file:
@lisp
(add-hook 'haskell-mode-hook 'turn-on-haskell-indent)
@end lisp
Note that @code{turn-on-haskell-indent} will disable
@code{haskell-indentation-mode}.
@end itemize
For general information about indentation support in GNU Emacs,
@pxref{Indentation,,,emacs}.
@section Rectangle Commands
@cindex rectangle
@cindex CUA mode
GNU Emacs provides so-called @dfn{rectangle commands} which operate on
rectangular areas of text, which are particularly useful for languages
with a layout rule such as Haskell. @xref{Rectangles,,,emacs}, to learn
more about rectangle commands.
Moreover, CUA mode (@pxref{CUA Bindings,,,emacs}) provides enhanced
rectangle support with visible rectangle highlighting. When CUA mode is
active, you can initiate a rectangle selection by @kbd{C-RET} and extend
it simply by movement commands. You don't have to enable full CUA mode
to benefit from these enhanced rectangle commands; you can activate CUA
selection mode (without redefining @kbd{C-x},@kbd{C-c},@kbd{C-v}, and
@kbd{C-z}) by calling @kbd{M-x cua-selection-mode} (or adding
@code{(cua-selection-mode nil)} to your @code{haskell-mode-hook}).
@section Region indent is a no-op
There is a @code{indent-region} function that supposedly could be used
to indent code region without changing its semantics. Sadly it does not
work that way because usual use case for @code{indent-region} is:
@enumerate
@item
Alter first line of code in region.
@item
Call @code{indent-region} to fix indentation for remaining lines.
@end enumerate
Note that between 1 and 2 program is already semantically broken and
knowing how to indent it preserving semantic from before step 1 would
require time travel.
To stay on the safe side @code{indent-region-function} is bound to a
no-op in @code{haskell-mode}.
@node External indentation
@chapter Other ways to indent code
@section Indentation with tabs, not spaces
Some projects require indenting code with tabs and forbid indenting it
with spaces. For hacking on such projects, check out
@uref{https://spwhitton.name/tech/code/haskell-tab-indent,haskell-tab-indent-mode}.
@section Structured indentation
Another alternative is to install
@uref{https://github.com/chrisdone/structured-haskell-mode,structured-haskell-mode}.
which indents code by parsing the code with a full Haskell parser and
deciding where to indent based on that.
@node Autoformating
@chapter Using external formatters
You can enable @uref{https://github.com/jaspervdj/stylish-haskell,stylish-haskell} by
installing it:
@example
$ cabal install stylish-haskell
@end example
And by enabling it with a customization
@lisp
(custom-set-variables
'(haskell-stylish-on-save t))
@end lisp
Now when you run @code{save-buffer} (or @kbd{C-x C-s}) the module will
be automatically formatted.
Alternatively, you can run the function directly on demand with
@kbd{M-x} @code{haskell-mode-stylish-buffer}.
@node Module templates
@chapter Module templates
To enable auto-insertion of module templates, enable:
@lisp
(add-hook 'haskell-mode-hook 'haskell-auto-insert-module-template)
@end lisp
When you open a file called @file{Foo.hs}, it will auto-insert
@example
-- |
module Foo where
@end example
And put your cursor in the comment section.
@node Declaration scanning
@chapter Declaration scannning
@findex haskell-decl-scan-mode
@vindex haskell-decl-scan-mode-hook
@code{haskell-decl-scan-mode} is a minor mode which performs declaration
scanning and provides @kbd{M-x imenu} support (@pxref{Imenu,,,emacs} for
more information).
For non-literate and @TeX{}-style literate scripts, the common
convention that top-level declarations start at the first column is
assumed. For Bird-style literate scripts, the common convention that
top-level declarations start at the third column, ie. after @samp{> },
is assumed.
When @code{haskell-decl-scan-mode} is active, the standard Emacs
top-level definition movement commands (@pxref{Moving by
Defuns,,,emacs}) are enabled to operate on Haskell declarations:
@table @kbd
@item C-M-a
Move to beginning of current or preceding declaration
(@code{beginning-of-defun}).
@item C-M-e
Move to end of current or following declaration (@code{end-of-defun}).
@item C-M-h
Select whole current or following declaration (@code{mark-defun}).
@end table
Moreover, if enabled via the option
@code{haskell-decl-scan-add-to-menubar}, a menu item ``Declarations'' is
added to the menu bar listing the scanned declarations and allowing to
jump to declarations in the source buffer.
It's recommended to have font lock mode enabled (@pxref{Font
Lock,,,emacs}) as @code{haskell-decl-scan-mode} ignores text highlighted
with @code{font-lock-comment-face}.
As usual, in order to activate @code{haskell-decl-scan-mode}
automatically for Haskell buffers, add @code{haskell-decl-scan-mode}
to @code{haskell-mode-hook}: