开发者

Making a region-indent-function keep the region marked

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?


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

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)
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜