Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

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.

share|improve this question
    
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 –  pushpen 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. –  pushpen Apr 4 '13 at 12:01
add comment

1 Answer

up vote 2 down vote accepted

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 :

M-xcustomize-variableRETshift-select-modeRET

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)
share|improve this answer
    
oh yes!! region-active-p is the secret. thank you. And the shift-select-mode also works perfectly. Thanks –  pushpen Apr 4 '13 at 12:16
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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