使用区域缩进函数保持区域标记
我在使用 haml-mode 的 region-indent-function
时遇到问题,我正尝试在另一个主要模式中重用它。我们应该能够通过在评估 haml-indent-region 后保持区域标记来循环区域缩进,但它无法按预期工作。经过一些修改后,我发现在函数末尾抛出错误会使 Emacs 保留该区域的标记,如本例所示:
(defun haml-indent-region (start end)
(save-excursion
...)
(error "")) ;; Terrible hack
但我真的不喜欢它。有没有一种干净的方法可以在没有如此可怕的黑客攻击的情况下获得这种行为?
I'm having trouble with haml-mode's region-indent-function
, which I'm trying to reuse in another major mode. We're supposed to be able to cycle the region indentation by keeping the region marked after the haml-indent-region is being evaled, but it doesn't work as intended. After some hacking around, I've found out that throwing an error at the end of the function makes Emacs keep the region marked, as in this example:
(defun haml-indent-region (start end)
(save-excursion
...)
(error "")) ;; Terrible hack
But I really don't like it. Is there a clean way of getting this behavior without such an horrible hack?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
该区域在命令完成后重置,因此调用 activate-mark 不会产生任何效果。抛出错误(非本地退出)显然会阻止此步骤,但这可能是一个错误。
技巧是:
deactivate-mark
因此,只需在命令末尾执行此操作:
The region is reset after the command completes, so calling activate-mark does not have any effect. Throwing an error (a non-local exit) apparently prevents this step, but that might be a bug.
The trick is:
deactivate-mark
So just do this at the end of your command: