Next: , Previous: , Up: Top   [Index]


7 Declaration scannning

haskell-decl-scan-mode is a minor mode which performs declaration scanning and provides M-x imenu support (see (emacs)Imenu 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 ‘> ’, is assumed.

When haskell-decl-scan-mode is active, the standard Emacs top-level definition movement commands (see (emacs)Moving by Defuns) are enabled to operate on Haskell declarations:

C-M-a

Move to beginning of current or preceding declaration (beginning-of-defun).

C-M-e

Move to end of current or following declaration (end-of-defun).

C-M-h

Select whole current or following declaration (mark-defun).

Moreover, if enabled via the option 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 (see (emacs)Font Lock) as haskell-decl-scan-mode ignores text highlighted with font-lock-comment-face.

As usual, in order to activate haskell-decl-scan-mode automatically for Haskell buffers, add haskell-decl-scan-mode to haskell-mode-hook:

(add-hook 'haskell-mode-hook 'haskell-decl-scan-mode)

haskell-decl-scan-mode enables the use of features that build upon imenu support such as Speedbar Frames (see (emacs)Speedbar) or the global “Which Function” minor mode (see (emacs)Which Function).

In order to enable which-function-mode for Haskell buffers you need to add the following to your Emacs initialization:

(eval-after-load "which-func"
  '(add-to-list 'which-func-modes 'haskell-mode))

7.1 Speedbar

Haskell-mode comes with declaration scanning support. This means that if you enable Haskell support for speedbar:

(speedbar-add-supported-extension ".hs")

And open speedbar with

M-x speedbar

It gives a listing of each module and under each module:

    Imports
    Instances
    Data types
    Classes
    Bindings

You will get a bar that looks like this:

~/Projects/ace/src/ACE/
0:<+> Types
0:[+] Combinators.hs
0:[-] Datalog.hs
1:   {-} Classes
2:      > ToTerm
1:   {-} Imports
2:      > ACE.Types.Syntax
2:      > Database.Datalog
1:   {-} Instances
2:    {+} ToTerm A
2:    {+} ToTerm Co to ToTerm Gen
2:    {+} ToTerm Intransitive to ToTerm N
2:    {+} ToTerm P
2:    {+} ToTerm Quotation to ToTerm Un
2:    {+} ToTerm V
0:[-] Html.hs
1:   {+} Imports
1:   {+} Instances
1:     > mtoMarkup
1:     > toMarkupm
1:     > wrap
0:[-] Parsers.hs
1:   {+} Imports
1:   {-} Datatypes
2:      > ACEParser
0:[+] Pretty.hs
0:[+] Tokenizer.hs

The hierarchy is expandable/collapsible and each entry will jump to the line in the right file when clicked/selected.


Next: , Previous: , Up: Top   [Index]