当前位置:  开发笔记 > 开发工具 > 正文

应该如何格式化多行协议方法文档字符串?

如何解决《应该如何格式化多行协议方法文档字符串?》经验,为你挑选了0个好方法。

多行功能或协议文档字符串可以轻松格式化:

(defn foo
  "Does a very complicated thing that I need to explain in excruciating detail.
  Firstly, this function stringifies x with the standard greeting of 'Hello'.
  Secondly, it appends the necessary exclamation point to the resulting string.
  Finally, it prints the resulting result to *out*, followed by a newline and
  the appropriate flush."
  [x]
  (println (str "Hello, " x "!")))

(defprotocol Bar
  "A retail business establishment that serves alcoholic beverages, such as
  beer, wine, liquor, cocktails, and other beverages like mineral water and soft
  drinks and often sells snack foods, like crisps or peanuts, for consumption on
  premises.")

但那两种不可避免的组合怎么样:协议方法呢?它们应该只用两个空格缩进到下一行吗?

(defprotocol Baz
  (qux [thing2 thing1] "Lorem ipsum dolor sit amet, consectetur adipiscing elit,
  sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad
  minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea
  commodo consequat."))

这在代码中看起来很好,但如果我打电话(doc qux),我会得到

-------------------------
user/qux
([thing2 thing1])
  Lorem ipsum dolor sit amet, consectetur adipiscing elit,
  sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad
  minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea
  commodo consequat.

现在第一行看起来很奇怪.这是唯一不会导致Emacs M-q对你不利的选择,所以这样的事情不会飞:

(defprotocol Baz
  (qux [thing2 thing1]
  "Lorem ipsum dolor sit amet, consectetur adipiscing elit,sed do eiusmod tempor
  incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis
  nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo
  consequat."))

即使这并没有打破autoformat,它对我来说只是有点奇怪.

我应该放弃吗?我是否应该只使用非常短的文档字符串进行协议方法,并且可能只是在协议的主文档字符串中包含更全面的文档?

(defprotocol Baz
  "Lorem ipsum dolor sit amet, consectetur adipiscing elit,sed do eiusmod tempor
  incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis
  nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo
  consequat."
  (qux [thing2 thing1] "Does a thing to thing1 depending on thing2."))

或者,还有更好的方法?

推荐阅读
LEEstarmmmmm
这个屌丝很懒,什么也没留下!
DevBox开发工具箱 | 专业的在线开发工具网站    京公网安备 11010802040832号  |  京ICP备19059560号-6
Copyright © 1998 - 2020 DevBox.CN. All Rights Reserved devBox.cn 开发工具箱 版权所有