Making a region-indent-function keep the region marked

故事扮演 提交于 2019-12-22 08:22:54

问题


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?


回答1:


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)


来源:https://stackoverflow.com/questions/6529174/making-a-region-indent-function-keep-the-region-marked

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!