Next: Rectangular commands, Previous: Spell checking strings and comments, Up: Top [Index]
Select a region you want to align text within, M-x
align-regexp
, and type a regexp representing the alignment
delimiter.
For example, I often line up my Haddock comments:
f :: a -- ^ does a -> Foo b -- ^ and b -> c -- ^ to c
Select the region, and let the regexp be ‘--’:
f :: a -- ^ does a -> Foo b -- ^ and b -> c -- ^ to c
Of course, this works for just about anything. Personally, I’ve globally bound it to C-x a r:
(global-set-key (kbd "C-x a r") 'align-regexp)
Note that you can also just use the rules below for telling the aligner
about Haskell. Once you evaluate this, you can just use M-x
align
, which I like to bind to M-[.
(add-to-list 'align-rules-list '(haskell-types (regexp . "\\(\\s-+\\)\\(::\\|∷\\)\\s-+") (modes quote (haskell-mode literate-haskell-mode)))) (add-to-list 'align-rules-list '(haskell-assignment (regexp . "\\(\\s-+\\)=\\s-+") (modes quote (haskell-mode literate-haskell-mode)))) (add-to-list 'align-rules-list '(haskell-arrows (regexp . "\\(\\s-+\\)\\(->\\|→\\)\\s-+") (modes quote (haskell-mode literate-haskell-mode)))) (add-to-list 'align-rules-list '(haskell-left-arrows (regexp . "\\(\\s-+\\)\\(<-\\|←\\)\\s-+") (modes quote (haskell-mode literate-haskell-mode))))