Erlang 缩进的正确方法是什么?
直到昨天,我还是开箱即用的 emacs + erlang-mode 的快乐用户。然后我的同事开始为该项目做出贡献(使用一些Windows编辑器),他似乎对erlang-mode默认使用的混合缩进模式不太满意。 这是一个例子。这是函数的一部分,在 erlang 模式下使用自动缩进编写。
handle_info(get_gss_latest_versions, State) ->
GetReqIds = fun(Branch) ->
GetInfoUri = State#state.gss_uri ++ Branch ++ "/api/getinfo",
case ibrowse:send_req(GetInfoUri, [], get, [], [{stream_to, self()}]) of
{ibrowse_req_id, ReqId} ->
{ReqId, Branch};
{error, Reason} ->
如果您仔细观察,您会发现第 2 行(以 GetReqIds 开头)缩进了 4 个空格。第 3 行缩进了 3 个制表符。第 5 行缩进了 3 个制表符 + 4 个空格。第 6 行缩进了 4 个制表符。因此,大多数(愚蠢的)编辑器(与 emacs 不同)以相同的缩进级别显示第 5 行和第 6 行(以 {ibrowse 和 {ReqId 开头的行)。看起来很丑。 (甚至 stackoverflow 也以这种方式显示了它们)。
我查看了几个著名的 erlang 软件(例如 gproc),其中大多数似乎都使用仅空格缩进模式。
所以我的问题是:
- 我做错了吗(对我来说似乎很可能)。
- 如果仅空格是主要的缩进方式,为什么 erlang-mode 没有实现它(或者默认情况下没有配置为使用它)?
- 如何配置 erlang-mode 来强制仅使用空格?
- 到底什么是“正确的方法”?诸如跨编辑器兼容性之类的事情似乎很重要,而且我们无法让所有编辑器都像 emacs 一样智能。
Till yesterday, I was a happy user of out-of-the-box emacs + erlang-mode. Then my colleague started contributing to the project (using some windows editor), and it seems he is not very happy with the mixed indent mode used by default by erlang-mode.
Here is an example. This a part of a function, written using auto-indent on erlang-mode
handle_info(get_gss_latest_versions, State) ->
GetReqIds = fun(Branch) ->
GetInfoUri = State#state.gss_uri ++ Branch ++ "/api/getinfo",
case ibrowse:send_req(GetInfoUri, [], get, [], [{stream_to, self()}]) of
{ibrowse_req_id, ReqId} ->
{ReqId, Branch};
{error, Reason} ->
If you take a closer look, you'll see that line 2 (starting with GetReqIds) is indented with 4 spaces. Line 3 is indented with 3 tabs. Line 5 is indented with 3 tabs + 4 spaces. Line 6 is indented with 4 tabs. As a result, most (dumb) editors (unlike emacs) display lines 5 and 6 (the ones starting with {ibrowse and {ReqId) at the same indentation level. Which looks ugly. (even stackoverflow shows them that way).
I had a look at several prominent erlang softwares (like gproc) and most of them seem to use spaces-only indentation mode.
So my questions are:
- Am I doing it wrong (seems likely to me).
- If spaces-only is the predominant indentation way, why is erlang-mode not implementing it (or not configured to using it by default)?
- How can I configure erlang-mode to force spaces-only?
- What's the "right way" after all? Things like cross-editor compatibility seem to matter, and we can't make all editors as smart as emacs.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
这对我来说似乎是正确的解决方案,就在此刻(放入〜/.emacs):
我无耻地从这里复制了它:
http://erlang.2086793.n4.nabble.com/erlang-mode-emacs-tabs-vs-spaces-td2096289.html
This seems to be the right solution for me, right at the moment (put in ~/.emacs) :
I shamelessly copied it from here:
http://erlang.2086793.n4.nabble.com/erlang-mode-emacs-tabs-vs-spaces-td2096289.html
通常,不仅要禁用缩进中的制表符,而且对于 erlang 模式也要禁用制表符,请使用:
To generally disable tabs in indention, not only, but also for erlang-mode, use: