简体   繁体   English

如何在 emacs 中对齐 function 参数的 Haddock 注释?

[英]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 .似乎记录 function 参数的唯一方法是使用-- ^ docs here样式 Unfortunately, this gets very unwieldy when function parameters are of different lengths.不幸的是,当 function 参数的长度不同时,这变得非常笨拙。 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?在 Emacs 中是否有任何自动执行此操作的方法? Or is there any other, more manageable way, of writing this documentation?或者还有其他更易于管理的方式来编写此文档吗?

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:它没有回答有关如何自动化 alignment 评论的问题,但是当类型变长时,我通常依赖于不同的格式样式:

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

A simple way is using Mx align-regex -- .一种简单的方法是使用Mx align-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.再做一些工作,您可以在 haskell 钩子中添加一条 alignment 规则来对齐 EOL 注释(参见 align.el 示例),然后只需align就可以了。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM