By using shift-select-mode
, I can select some region via holding down Shift + arrow keys. When I then stop pushing Shift and press other keys the region get deselected. But this is not the case when using push-mark
function from Elisp code - the region stays selected when I move the cursor.
Here's an example of my function to select current symbol under cursor:
(defun sandric/select-symbol-under-cursor ()
"Select symbol under cursor."
(interactive)
(when (not (region-active-p))
(let (bounds pos1 pos2 mything)
(setq bounds (bounds-of-thing-at-point 'symbol))
(setq beginning (car bounds))
(setq ending (cdr bounds))
(goto-char beginning)
(push-mark beginning t t)
(goto-char ending))))
It works as expected (leaving aside little redundance with setq and not using let bounds for now), and if I place cursor on a symbol and call the function it selects the symbol at point as the region.
The problem occurs when I press the right
arrow key afterwards. The region is not deselected - instead it expands.
How can I make cursor movements after using my command not expand/decrease the region unless the Shift key is pressed, like the usual shift-select-mode
behavior.