The basic problem I have is that mark-mode works like a toggle button. Every time you call set-mark-command, "C-Space" you get in or get out of mark mode. I could bind any key combo to

(defun foo () "" (progn (set-mark-command) (left-word)))

but the next time I call foo my selection would be deselected.

Is there a function that only enters the selection mode instead of toggling it? Then i could select text more freely which I really need since I am annotating a large text corpus.

  • This is quite confusing. set-mark-command doesn't go in nor out of a mark mode (since there is no mark mode), it sets the mark at the cursor position. If you call it and move your cursor, assuming you have activated transient-mark-mode, your temporary selection will be highlighted. If you call it again, the mark will be at the new position of your cursor, and if you move your cursor again, the new selection (starting at the new mark position) will be highlighted. What are you actually trying to do? Since you want to bind your command to the mouse, can't you just use the mouse for selection? – m4573r Apr 4 '13 at 11:49
  • thanks m4. What i want to do is to make a function that would only set the mark only if its not already set so that even if I call it again the mark is not reset. Right now when I press Ctrl-Space then I get a message mark-activated, when I again press Ctrl-Space I get the message mark-deactivated. And Ctrl-Space is bound to set-mark-command – Pushpendre Apr 4 '13 at 11:58
  • Also, I dont want to bind my command to the mouse, I meant the left/right arrow key, apologies for the confusion. – Pushpendre Apr 4 '13 at 12:01

I'm not sure I understand your question correctly, but here are a few thoughts on this:

1) If the shift-select-mode variable is set to t, all combinations of Shift and a command moving point will temporarily activate the region and extend it:

  • S-C-<right>: extend the region by one word on the right
  • S-<right>: extend the region by one char on the right

You can set shift-select-mode using either the customize infrastructure :


or in your init file:

(setq shift-select-mode t)

2) Starting from you sample code, you could write a command activating the region and extending it in the following way:

(defun foo ()
  (interactive) ;; this is a command (i.e. can be interactively used)

  (when (not (region-active-p))  ;; if the region is not active...
    (push-mark (point) t t))     ;; ... set the mark and activate it

  (backward-word))               ;; move point

;; Bind the command to a key
(global-set-key (kbd "C-S-<left>") 'foo)
  • oh yes!! region-active-p is the secret. thank you. And the shift-select-mode also works perfectly. Thanks – Pushpendre Apr 4 '13 at 12:16

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.