help-gnu-emacs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

RE: How to create new buffer with t-m-m active region?


From: Drew Adams
Subject: RE: How to create new buffer with t-m-m active region?
Date: Sat, 4 Sep 2010 17:25:52 -0700

> How would I generate a new buffer containing an active region 
> such that the next command issued in the new buffer will act
> on the region? (And so that the region is highlighted)
> 
> For example, this function doesn't do what it wants to do:
> 
> (defun new-buffer-w-active-region ()
>   (interactive)
>   (let ((transient-mark-mode t))
>     (switch-to-buffer (get-buffer-create "region-test"))
>     (delete-region (point-min) (point-max))
>     (insert "I want these lines\n")
>     (insert "to be in an active region with t-m-m on\n")
>     (insert "such that comment-region comments them out\n")
>     (emacs-lisp-mode)
>     (push-mark (point-min) nil 'activate)))
> 
> 
> With that function, the following doesn't do what is intended:
> 
> M-x new-buffer-w-active-region
> M-;

Yes, this is a common gotcha that you just have to learn once if you do this
kind of thing: Add this sexp at the end of your command:

(setq deactivate-mark  nil)




reply via email to

[Prev in Thread] Current Thread [Next in Thread]