|
# Emacs tips and tricks
|
|
# Emacs tips and tricks
|
|
|
|
|
|
|
|
|
|
Most of us use Emacs for GHC development. This page lists various Emacs configuration tips and tricks used by GHC developers in hope that they will be useful to others. Each entry includes a short description and instruction how to enable given setting (if it contains only a block of lisp code it means you need to add it to your `.emacs` configuration file). All configuration is given for Emacs 24, unless otherwise noted. It is assumed that you know how to install packages in Emacs (e.g. with ELPA).
|
|
Most of us use Emacs for GHC development. This page lists various Emacs configuration tips and tricks used by GHC developers. It is meant to be self-contained so that you can grab relevant piece of configuration, put it into your config file and benefit from it instantly. The only exception are two larger extensions for Emacs (haskell-mode and ghc-mod), where we direct you to external installation instructions and tutorials.
|
|
|
|
|
|
|
|
|
|
|
|
Each entry includes a short description and instruction how to enable given setting (if it contains only a block of lisp code it means you need to add it to your `.emacs` configuration file). All configuration is given for Emacs 24, unless otherwise noted.
|
|
|
|
|
|
|
|
|
|
|
|
It is assumed that you know how to install packages in Emacs (e.g. with ELPA). *TODO Let's not assume it. Can we create a section "Installing extensions with ELPA" and give a short introduction on using it? I admit I don't remember how to use ELPA and would have to google it - JS.*
|
|
|
|
|
|
# General
|
|
# General
|
|
|
|
|
|
## IDO mode
|
|
## IDO mode
|
|
|
|
|
|
**Description**: IDO stands for Interactively Do Things and it greatly improves file opening and switching between buffers. When opening a file it shows the list of files and directories in a current directory, allows to navigate the directory tree in an easy manner, provides intuitive filtering capabilities and allows to select a file by selecting its name using arrow keys. Similar behaviour is provided when switching between opened buffers. A nice introductory tutorial to IDO can be found [ here](http://www.masteringemacs.org/articles/2010/10/10/introduction-to-ido-mode/).
|
|
**Description**: IDO stands for Interactively Do Things and it greatly improves file opening and switching between buffers. When opening a file it shows list of files and directories in current directory, allows to navigate the directory tree in an easy manner, provides intuitive filtering capabilities and allows to select a file by selecting its name using arrow keys. Similar behaviour is provided when switching between opened buffers. A nice introductory tutorial to IDO can be found [ here](http://www.masteringemacs.org/articles/2010/10/10/introduction-to-ido-mode/).
|
|
|
|
|
|
**How to enable**:
|
|
**How to enable**:
|
|
|
|
|
... | @@ -37,7 +43,7 @@ Most of us use Emacs for GHC development. This page lists various Emacs configur |
... | @@ -37,7 +43,7 @@ Most of us use Emacs for GHC development. This page lists various Emacs configur |
|
|
|
|
|
## Automatically removes trailing whitespaces when file is saved
|
|
## Automatically removes trailing whitespaces when file is saved
|
|
|
|
|
|
**Description**: Currently source code of GHC contains lots of trailing whitespaces, which means that **this setting is dangerous**. It will remove ALL trailing whitespaces in every file that you edit, which means you might have one or two lines changed by you and a hundred lines automatically changed by removing trailing whitespaces. This will require you to separate whitespaces into a separate commit by using `git add -i`. This is tedious, so be warned.
|
|
**Description**: Currently source code of GHC contains lots of trailing whitespaces, which means that **this setting is dangerous**. It will remove ALL trailing whitespaces in every file that you edit, so you might have one or two lines changed by you and a hundred lines automatically changed by removing trailing whitespaces. This will require you to separate whitespaces into a separate commit by using `git add -i`. This is tedious, so be warned.
|
|
|
|
|
|
**How to enable**:
|
|
**How to enable**:
|
|
|
|
|
... | @@ -45,11 +51,9 @@ Most of us use Emacs for GHC development. This page lists various Emacs configur |
... | @@ -45,11 +51,9 @@ Most of us use Emacs for GHC development. This page lists various Emacs configur |
|
(add-hook'before-save-hook'delete-trailing-whitespace)
|
|
(add-hook'before-save-hook'delete-trailing-whitespace)
|
|
```
|
|
```
|
|
|
|
|
|
*TODO describe how to enable this setting only if the file was already free of trailing-whitespaces at load-time*
|
|
|
|
|
|
|
|
## Highlight trailing whitespaces
|
|
## Highlight trailing whitespaces
|
|
|
|
|
|
**Description**: See [ (emacs)Useless Whitespace](http://www.gnu.org/software/emacs/manual/html_node/emacs/Useless-Whitespace.html) section for more details.
|
|
**Description**: Automatic removal of trailing whitespaces described above can be a bit inconvenient to use. One of the alternative approaches to problem of trailing whitespaces is making them visible, so that you notice when you accidentally introduce them into a file. You will also see already existing trailing whitespaces. For more details see [ Useless Whitespace](http://www.gnu.org/software/emacs/manual/html_node/emacs/Useless-Whitespace.html) section of Emacs documentation.
|
|
|
|
|
|
**How to enable**:
|
|
**How to enable**:
|
|
|
|
|
... | @@ -57,9 +61,9 @@ Most of us use Emacs for GHC development. This page lists various Emacs configur |
... | @@ -57,9 +61,9 @@ Most of us use Emacs for GHC development. This page lists various Emacs configur |
|
(setq-defaultshow-trailing-whitespacet)(setq-defaultindicate-empty-linest)
|
|
(setq-defaultshow-trailing-whitespacet)(setq-defaultindicate-empty-linest)
|
|
```
|
|
```
|
|
|
|
|
|
## C-k kills whole line and newline if at beginning of line
|
|
## Kill whole line and newline with C-k if at beginning of line
|
|
|
|
|
|
**Description**: Allows to avoid typing `C-k` twice when cursor is placed at the beginning of a line.
|
|
**Description**: IF you place cursor at the beginning of line, the default behaviour of C-k is to fill all text until newline, but not the newline itself. You need to type C-k again to remove that newline. This setting allows to avoid typing `C-k` twice by killing all text until the newline and newline itself (but only when cursor is placed at the beginning of a line).
|
|
|
|
|
|
**How to enable**:
|
|
**How to enable**:
|
|
|
|
|
... | @@ -89,36 +93,63 @@ Most of us use Emacs for GHC development. This page lists various Emacs configur |
... | @@ -89,36 +93,63 @@ Most of us use Emacs for GHC development. This page lists various Emacs configur |
|
|
|
|
|
## Switch between windows with Alt-\<window number\>
|
|
## Switch between windows with Alt-\<window number\>
|
|
|
|
|
|
**Description**: Enhances switching between multiple windows. Number of each windows is displayed in the mode line.
|
|
**Description**: Enhances switching between multiple windows. To switch to another window use pressing Alt-\<window number\>. Number of each window is displayed in red in the mode line.
|
|
|
|
|
|
**How to enable**:
|
|
**How to enable**:
|
|
You need to install package `window-number` and add this to your configuration:
|
|
You need to install [ window-number](http://www.emacswiki.org/emacs/window-number.el) extension and add this to your configuration:
|
|
|
|
|
|
```wiki
|
|
```
|
|
(require 'window-number)
|
|
(require'window-number)(window-number-mode)(window-number-meta-mode)
|
|
(window-number-mode)
|
|
|
|
(window-number-meta-mode)
|
|
|
|
```
|
|
```
|
|
|
|
|
|
## Cycle buffer
|
|
## Switch to next/previous buffer with a single key
|
|
|
|
|
|
*Will add this later*
|
|
**Description**: This extension allows you to switch between next and previous buffer with F9 and F10 (by default). Emacs buffers (like \*messages\*) are ignored - use Shift-F9 and Shift-F10 to include them as well. Note that this extension maintains a list of buffers. After selecting a buffer it is moved to the beginning of the list. This means that buffers are ordered by the time of their recent use.
|
|
|
|
|
|
|
|
**How to enable**:
|
|
|
|
You need to install [ cycle-buffer](http://www.emacswiki.org/emacs/cycle-buffer.el) extension and add this to your configuration:
|
|
|
|
|
|
|
|
```
|
|
|
|
(autoload'cycle-buffer"cycle-buffer""Cycle forward."t)(autoload'cycle-buffer-backward"cycle-buffer""Cycle backward."t)(autoload'cycle-buffer-permissive"cycle-buffer""Cycle forward allowing *buffers*."t)(autoload'cycle-buffer-backward-permissive"cycle-buffer""Cycle backward allowing *buffers*."t)(autoload'cycle-buffer-toggle-interesting"cycle-buffer""Toggle if this buffer will be considered."t)(global-set-key[(f9)]'cycle-buffer-backward)(global-set-key[(f10)]'cycle-buffer)(global-set-key[(shiftf9)]'cycle-buffer-backward-permissive)(global-set-key[(shiftf10)]'cycle-buffer-permissive)
|
|
|
|
```
|
|
|
|
|
|
# Haskell-specific
|
|
# Haskell-specific
|
|
|
|
|
|
## Haskell mode
|
|
## Haskell mode
|
|
|
|
|
|
**Description**: Haskell mode is a major mode for Emacs. Major features include syntax highlighting, GHCi integration and automatic indentation.
|
|
**Description**: Haskell mode is a major mode for Emacs. Features include: syntax highlighting, GHCi integration and automatic indentation. See [ online manual](http://haskell.github.io/haskell-mode/manual/latest/) for details.
|
|
|
|
|
|
**How to enable**: See installation instructions on [ github](https://github.com/haskell/haskell-mode) and [ manual](http://haskell.github.io/haskell-mode/manual/latest/).
|
|
**How to enable**: See installation instructions on [ github](https://github.com/haskell/haskell-mode).
|
|
|
|
|
|
## ghc-mod
|
|
## ghc-mod
|
|
|
|
|
|
**Description**: *I'm not using this one. Can someone (Kazu?) complete this section?*
|
|
**Description**: Extends haskell-mode. Features include: building on the fly with flymake, hlint integration, auto-completion of keywords. See [ here](http://www.mew.org/~kazu/proj/ghc-mod/en/emacs.html) for a complete list.
|
|
|
|
|
|
|
|
**How to enable**: See installation instructions [ here](http://www.mew.org/~kazu/proj/ghc-mod/en/).
|
|
|
|
|
|
|
|
## Using tags to quickly locate definitions in a project
|
|
|
|
|
|
|
|
**Description**: Emacs can use a special index file, called "tags file", that stores locations of various definitions (functions, modules, data types) in a given directory. Once you've generated tags file (see installation instructions below) you can type `M-.` and enter name of identifier definition to jump to. Emacs by default jumps to identifier currently under the cursor.
|
|
|
|
|
|
|
|
**How to enable**: Begin by installing `hasktags` package from Hackage:
|
|
|
|
|
|
|
|
```wiki
|
|
|
|
cabal install hasktags
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
|
|
Now go to the directory for which you want to generate tags and run:
|
|
|
|
|
|
|
|
```wiki
|
|
|
|
hasktags --ignore-close-implementation .
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
|
|
In Emacs type `M-x visit-tags-table` and point to the generated `TAGS`.
|
|
|
|
|
|
**How to enable**: See installation instructions [ here](http://www.mew.org/~kazu/proj/ghc-mod/en/)
|
|
**Note on hasktags**: `hasktags` program used to generate tags file has problems with correctly recognizing declarations of value constructors in a data type. It often mistakes pattern matching of the form `(DataConstructor {})` as a data declaration and jumps to that pattern match instead of declaration.
|
|
|
|
|
|
## Hask-tags
|
|
**Note on using tags for GHC sources**: Generating tags for top directory of GHC source tree. so that index is generated for the compiler sources as well as boot libraries, gives rather bad results. The problem is that many libraries have definitions of identical functions, e.g. `integer-gmp` and `integer-simple` define the same functions and `hoopl` has lots of obsolete source files that contain definitions of exactly identical functions. This makes jumping to definitions unreliable - you will often be taken to some unused definition. Therefore we recommend to generate tags file only for `compiler/` directory.
|
|
|
|
|
|
# GHC-specific
|
|
# GHC-specific
|
|
|
|
|
... | | ... | |