Saurabh Nanda
Saurabh Nanda

Reputation: 6793

How to align Haddock comments for function parameters in emacs?

It seems that the only way to document function parameters is to use the -- ^ docs here style. Unfortunately, this gets very unwieldy when function parameters are of different lengths. For example:

myFunc :: (Int -> String -> Bool -> IO ())   -- ^ documentation string #1
       -> Int    -- ^ documentation string #2
       -> String    -- ^ documentation string #3                         
       -> Bool   -- ^ documentation string #4
       -> IO ()   -- ^ documentation string #5

Converting the above to the following, takes a lot of manual effort:

myFunc :: (Int -> String -> Bool -> IO ())   -- ^ documentation string #1
       -> Int                                -- ^ documentation string #2
       -> String                             -- ^ documentation string #3                         
       -> Bool                               -- ^ documentation string #4
       -> IO ()                              -- ^ documentation string #5

Is there any automated way of doing this in Emacs? Or is there any other, more manageable way, of writing this documentation?

Upvotes: 0

Views: 204

Answers (2)

Shersh
Shersh

Reputation: 9179

It doesn't answer the question on how to automate alignment of comments, but when types become long, I usually rely on a different formatting style:

myFunc
    :: (Int -> String -> Bool -> IO ())
    -- ^ documentation string #1
    -> Int
    -- ^ documentation string #2
    -> String
    -- ^ documentation string #3                         
    -> Bool
    -- ^ documentation string #4
    -> IO ()
    -- ^ documentation string #5

Upvotes: 4

Rorschach
Rorschach

Reputation: 32446

A simple way is using M-xalign-regex --. With a little more work, you could add an alignment rule in your haskell hook to align EOL comments (see align.el for examples), and then just align should do the trick.

Upvotes: 0

Related Questions