使区域缩进功能保持标记区域 [英] Making a region-indent-function keep the region marked

查看:93
本文介绍了使区域缩进功能保持标记区域的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在haml-mode的 region-indent-function 中遇到麻烦,我试图在另一个主要模式中重用。我们应该能够通过将区域标记在haml-indent-region被评估之后来区分区域缩进,但是它不按预期工作。在一些黑客之后,我发现在功能结束时抛出错误使Emacs保持区域标记,如下例所示:

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?

推荐答案

该区域在命令完成,所以调用activate-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.

诀窍是: deactivate-mark


如果编辑命令将其设置为t,则之后停用该标记。
命令循环在每个命令
之前将其设置为nil,并在命令返回时测试该值。
缓冲区修改存储在此变量中。

If an editing command sets this to t, deactivate the mark afterward. The command loop sets this to nil before each command, and tests the value when the command returns. Buffer modification stores t in this variable.

所以只需在命令结束时执行此操作:

So just do this at the end of your command:


  (setq deactivate-mark nil)

这篇关于使区域缩进功能保持标记区域的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆