Reputation: 303
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?
Upvotes: 0
Views: 507
Reputation: 30718
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.
Upvotes: 5
Reputation: 42154
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).
Upvotes: 6