开发者

about elisp's highlight region

look at this simple procedure:

(defun test ()
  (interactive)
  (push-mark)
  (setq mark-active t)
  (search-forward "a" nil nil 1))

It moves cursor to the nearest 'a',and highlight the path.Of course,It's obvious.

But it behaves differently depending on what's your next input after this procedure's execution,For example,开发者_运维知识库you input a char,like 'b',or \C-g,the highlight disappeared,but if you input \C-f,or \C-e,the highlight keeps. So Here is my question: what makes these input behave differently?


From the Emacs manual:

Setting the mark at a position in the text also activates it. When the mark is active, Emacs indicates the extent of the region by highlighting the text within it, using the region face (see Face Customization). After certain non-motion commands, including any command that changes the text in the buffer, Emacs automatically deactivates the mark; this turns off the highlighting. You can also explicitly deactivate the mark at any time, by typing C-g (see Quitting).


In addition to what JB said, you can prevent the automatic deactivation of the mark he referred to by doing this at the end of your command:

(setq deactivate-mark  nil)

Here's the doc string. Note the last sentence (which is what JB was saying).

deactivate-mark is a variable defined in `C source code'.
Its value is nil

Documentation:
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.
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜