Emacs Haskell 缩进
请帮我在 Emacs haskell 模式下设置正确的缩进
当我尝试输入 ADT 或记录之类的内容时,按
后我进入了错误的列,并且按
不会切换到正确的位置,直到我输入 |
或 ';' !
data MyADT = Oh
| Hi
| Hello
| <- the cursor is here again!
尝试解决我在 .emacs
文件中设置的问题
(define-key global-map (kbd "RET") 'reindent-then-newline-and-indent)
,但按
时也不会缩进当前行!
另一个奇怪的行为:大小写缩进
oneChar c = case lookup c simpleEscapes of
| <- what? here?!
Please help me set up proper indentation in Emacs haskell-mode
When I'm trying to type down something like ADT or a record, I'm getting on the wrong column after pressing <ENTER>
, and pressing <TAB>
won't switch to the right one until I enter either |
or ';'!
data MyADT = Oh
| Hi
| Hello
| <- the cursor is here again!
Trying to solve the problem I set
(define-key global-map (kbd "RET") 'reindent-then-newline-and-indent)
in my .emacs
file, but it won't indent the current line on pressing <enter>
too!
Another strange behaviour: indentation of case
oneChar c = case lookup c simpleEscapes of
| <- what? here?!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
听起来就像您键入
,然后键入“|
”,然后键入
。如果我这样做,我会得到相同的结果。但是,如果我输入
,然后输入
,然后再次输入
,它会自动插入“|
”并正确排列,如下所示:当我使用
Mx eval-expression haskell-version
检查我的 haskell 模式版本时,我得到“v2_4”。Emacs haskell-mode 没有完全分析源代码,因此我认为“自动”功能是近似的。在新行上多次键入
会循环显示几种可能的缩进,有时还会插入代数数据类型的文本,如“|
”。It sounds like you type
<Enter>
and then "|
" and then<Tab>
. If I do that, I get the same results. But if I type<Enter>
and then<Tab>
and then<Tab>
again it automatically inserts the "|
" and lines it up correctly, like so:When I check my haskell-mode version using
M-x eval-expression haskell-version <Enter>
I get "v2_4".Emacs haskell-mode doesn't fully analyze the source code, so the "automatic" features are approximate, I think. Typing
<Tab>
several times on a new line cycles through several possible indentations, and also sometimes inserts text like the "|
" for algebraic data types.警告:我不是 Haskell 用户,所以对此持保留态度。
当您在
Hello
之后按 RET 时,Emacs 并不知道您要添加|
(快速搜索显示您可以有其他符号)。 Haskell 人员认为正确的缩进应该直接排列在Hello
中的H
下方。如果缩进自动与上一行的|
对齐,那么您不键入|
的所有情况都会导致不正确的缩进。如果你这样做了就该死,如果你不这样做就该死...其他编程模式(C/C++、Lisp、Tcl...)也有同样的问题 - 他们无法提前知道你要在上面放什么下一行,所以缩进可能不是你所希望的。
一种解决方案是使用 “电动” 键,也就是说它们插入字符并强制重新缩进。您可以使用以下代码轻松地将 | 定义为电动:
我添加了一个检查以确保插入的
|
前面只有空格,您可以根据需要进行自定义或完全删除支票。我认为 Haskell 中可能还有其他值得用电来表示的符号。
Caveat: I'm not a Haskell user, so take this with a grain of salt.
When you press RET after the
Hello
, Emacs doesn't know you're going to add a|
(quick search shows you can have other symbols). The Haskell folks have deemed the proper indentation to be lined up directly below theH
inHello
. If the indentation were to automatically line up with the|
on the line above, then all the cases where you don't type a|
will result in improper indentation. Damned if you do, damned if you don't...Other programming modes (C/C++, Lisp, Tcl, ...) have the same problem - they cannot know ahead of time what you're going to put on the next line, so the indentation my not be what you'd hoped for.
One solution is to use "electric" keys, which is to say that they insert characters and also force re-indentation. You could easily define | to be electric with the following code:
I added a check to ensure that the
|
inserted is preceded by only whitespace, you can customize that however you want or remove the check altogether.I presume there might also be other symbols in Haskell that would be worth making electric.
我评论了这一行
,现在我得到了一个很好的“选项卡”行为:至少,它允许我选择一列,并且不会将我束缚在它喜欢的列上。但没有自动缩进让我有点烦恼,所以我希望这是一个临时解决方案
I commented the line
And now I'm getting a good "tab" behavior: at least, it allows me to choose a column and does not tie down me to the one it likes. But no auto-indent at all annoys me a little bit, so I'm hoping it is a temporary solution