Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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 ()
  (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
up vote 2 down vote accepted

This works for me in Emacs 24:

(setq transient-mark-mode t)

(defun foo ()
  (push-mark (point))
  (forward-char 2)
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

Your Answer


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.