Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

I want an elisp script to highlight a region of text.
Upon exit, the highlighted selection should disappear when a key is pressed.
Everything I've tried results in the highlighting hanging on like the shift key is pressed. What does it need to make the selection transient?

(defun TEST ()
  (interactive)
  (transient-mark-mode t) ;; I have this true normally anyhow
  (set-mark (point))
  (forward-char 2)
  (setq mark-active t))
(global-set-key [C-S-f2] 'TEST)
share|improve this question
add comment

1 Answer

up vote 2 down vote accepted

This works for me in Emacs 24:

(setq transient-mark-mode t)

(defun foo ()
  (interactive)
  (push-mark (point))
  (forward-char 2)
  (activate-mark))
share|improve this answer
    
(one week later) On double-checking, it turns out that I asked the wrong question. I used the wrong terminology; "transient" means something different to what i thought... I finally resolved my issue via another related quesiton, when I realized that C-x C-e evaluating behaved differently from CUA mode, which in turn behaved differently from "non CUA" mode... Here is the link for anyone intereted: Different results when run different ways ... Thanks for the help. –  Peter.O Dec 1 '11 at 13:31
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.