[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: yank-and-indent
From: |
Michael Slass |
Subject: |
Re: yank-and-indent |
Date: |
Wed, 20 Nov 2002 21:29:06 GMT |
User-agent: |
Gnus/5.09 (Gnus v5.9.0) Emacs/21.2 |
Alan Shutko <ats@acm.org> writes:
>"Timur Aydin" <asdfweasdf@diowekfsdf.dersdre> writes:
>
>> In programming, very often a number of lines are killed, yanked to another
>> location and are reindented according to the new location.
>
>Try this. No idea where i got it. Actually, looks like I got it
>from
>http://groups.google.com/groups?hl=en&lr=&ie=UTF-8&oe=UTF-8&threadm=u66crixve.fsf%40sdm.de&rnum=1
>
>;; automatically indenting yanked text if in programming-modes
>(defadvice yank (after indent-region activate)
> (if (member major-mode '(emacs-lisp-mode
> c-mode c++-mode
> tcl-mode sql-mode
> perl-mode cperl-mode
> java-mode jde-mode
> LaTeX-mode TeX-mode))
> (let ((transient-mark-mode nil))
> (indent-region (region-beginning) (region-end) nil))))
>
This is better than my solution --- it uses the fact that yank sets
the point and mark around the yanked text, so you don't need the
chicanery I used.
I'm adding this to my .emacs right now.
--
Mike Slass