在 haskell-mode 2.7 中强制 haskell-indent-mode 超过 haskell-indentation-mode?
我是一名 Emacs 用户,没有配置编辑器的技能。从 haskell-mode 2.4 升级到 2.7 后,我注意到两个变化:
- 缩进不同 不知何故,以某种我不太喜欢的方式。我不能完全确定它是什么。
- 更重要的是:如果我启用了 cua 模式并突出显示了一个文本块,则退格/删除不会删除整个块,而只是删除标记中的上一个/下一个字符。
我看到 haskell-mode 2.7 默认使用次要模式 haskell-indentation-mode,而 2.4 的行为已以 haskell-indent-mode 的形式保留。如果我首先关闭前者,然后关闭后者,我想要的行为就会恢复(即缩进感觉像以前一样,退格/删除会删除突出显示的块)。
但是,每当我打开带有 .hs 后缀的文件时,我无法让这种情况自动发生。我尝试过各种类似
(remove-hook 'haskell-mode-hook 'turn-on-haskell-indentation-mode)
(add-hook 'haskell-mode-hook 'turn-on-haskell-indent-mode)
的东西,但我最终要么使用标准模式,要么使用没有缩进和文档的普通 haskell 模式。
有什么想法吗?
解决方案(感谢 nominolo):
(remove-hook 'haskell-mode-hook 'turn-on-haskell-indent)
(remove-hook 'haskell-mode-hook 'turn-on-haskell-indentation)
(add-hook 'haskell-mode-hook 'my-haskell-mode-hook)
(defun my-haskell-mode-hook ()
(haskell-indentation-mode -1) ;; turn off, just to be sure
(haskell-indent-mode 1) ;; turn on indent-mode
)
I'm an Emacs user with no skills with regards to configuring the editor. After I upgraded from haskell-mode 2.4 to 2.7, I've noticed two changes:
- Indentation is different somehow, in a way I don't quite like. I can't quite put my finger on what it is.
- More importantly: If I have cua-mode enabled and highlight a block of text, backspace/delete does not delete the entire block, just the previous/next character from my marker.
I see that haskell-mode 2.7 uses the minor mode haskell-indentation-mode by default, while 2.4's behaviour has been preserved in the form of haskell-indent-mode. If I first turn off the former, and then on the latter, the behaviour I want is restored (i.e. indentation feels like before, and backspace/delete deletes highlighted blocks).
I can't, however, get this to happen automatically whenever I open a file with a .hs suffix. I've tried various things resembling
(remove-hook 'haskell-mode-hook 'turn-on-haskell-indentation-mode)
(add-hook 'haskell-mode-hook 'turn-on-haskell-indent-mode)
and the likes of it, but I either end up with the standard mode or with plain haskell-mode without indent and doc.
Any ideas?
Solution (thanks to nominolo):
(remove-hook 'haskell-mode-hook 'turn-on-haskell-indent)
(remove-hook 'haskell-mode-hook 'turn-on-haskell-indentation)
(add-hook 'haskell-mode-hook 'my-haskell-mode-hook)
(defun my-haskell-mode-hook ()
(haskell-indentation-mode -1) ;; turn off, just to be sure
(haskell-indent-mode 1) ;; turn on indent-mode
)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
配置此类内容的最佳方法是编写自定义挂钩:
您也可以在其中粘贴匿名函数,但如果您想尝试某些设置,则使用命名函数会更容易。只需重新定义函数(并重新打开 Haskell 文件)即可获得新的行为。
The best way to configure such things is by writing a custom hook:
You could also stick an anonymous function in there, but having a named function is easier if you want to experiment with some settings. Just redefining the function (and re-opening a Haskell file) will give you the new behaviour.