* yank-and-indent
@ 2002-11-20 20:28 Timur Aydin
2002-11-20 21:01 ` yank-and-indent Michael Slass
2002-11-20 21:07 ` yank-and-indent Alan Shutko
0 siblings, 2 replies; 6+ messages in thread
From: Timur Aydin @ 2002-11-20 20:28 UTC (permalink / raw)
Hi,
In programming, very often a number of lines are killed, yanked to another
location and are reindented according to the new location. Currently, the
following sequence has to be done manually:
1) Mark the lines to be killed
2) Kill the lines
3) Yank into new location
4) Mark the same lines again.
5) Hit C-M-\ to indent the lines according to new location.
I would like to reduce the procedure to:
1) Mark the lines to be killed
2) Kill the lines
3) Hit ???? to yank and indent the lines.
Any wisdom on how this can be accomplished? I am a beginner in lisp, so
hopefully there is a way that doesn't require writing a lisp function...
--
Timur
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: yank-and-indent
2002-11-20 20:28 yank-and-indent Timur Aydin
@ 2002-11-20 21:01 ` Michael Slass
2002-11-20 21:43 ` yank-and-indent Arnaldo Mandel
2002-11-20 21:07 ` yank-and-indent Alan Shutko
1 sibling, 1 reply; 6+ messages in thread
From: Michael Slass @ 2002-11-20 21:01 UTC (permalink / raw)
"Timur Aydin" <asdfweasdf@diowekfsdf.dersdre> writes:
>Hi,
>
>In programming, very often a number of lines are killed, yanked to another
>location and are reindented according to the new location. Currently, the
>following sequence has to be done manually:
>
>1) Mark the lines to be killed
>2) Kill the lines
>3) Yank into new location
>4) Mark the same lines again.
>5) Hit C-M-\ to indent the lines according to new location.
>
>I would like to reduce the procedure to:
>
>1) Mark the lines to be killed
>2) Kill the lines
>3) Hit ???? to yank and indent the lines.
>
>Any wisdom on how this can be accomplished? I am a beginner in lisp, so
>hopefully there is a way that doesn't require writing a lisp function...
>
>--
>Timur
>
>
Try this:
(defun yank-and-indent ()
"Yank and indent yanked material according to mode."
(interactive)
(save-restriction
(narrow-to-region (point) (point))
(yank)
(let ((beg (point-min))
(end (point-max)))
(widen)
(indent-region beg end nil))))
--
Mike Slass
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: yank-and-indent
2002-11-20 21:01 ` yank-and-indent Michael Slass
@ 2002-11-20 21:43 ` Arnaldo Mandel
0 siblings, 0 replies; 6+ messages in thread
From: Arnaldo Mandel @ 2002-11-20 21:43 UTC (permalink / raw)
Michael Slass wrote (on Nov 20, 2002):
> "Timur Aydin" <asdfweasdf@diowekfsdf.dersdre> writes:
>
> >Hi,
> >
> >In programming, very often a number of lines are killed, yanked to another
> >location and are reindented according to the new location. Currently, the
> >following sequence has to be done manually:
> >
> >1) Mark the lines to be killed
> >2) Kill the lines
> >3) Yank into new location
> >4) Mark the same lines again.
> >5) Hit C-M-\ to indent the lines according to new location.
> >
> >I would like to reduce the procedure to:
> >
> >1) Mark the lines to be killed
> >2) Kill the lines
> >3) Hit ???? to yank and indent the lines.
> >
> >Any wisdom on how this can be accomplished? I am a beginner in lisp, so
> >hopefully there is a way that doesn't require writing a lisp function...
> >
> >--
> >Timur
> >
> >
>
> Try this:
>
> (defun yank-and-indent ()
> "Yank and indent yanked material according to mode."
To me this seems excessive: one more function and one more binding to
remember.
What Timur should realize is that step (4) is superfluous - the yanked
lines form the region immediately after yanking. So, ???? is simply
C-y M-C-\
am
--
Arnaldo Mandel
Departamento de Ciência da Computação - Computer Science Department
Universidade de São Paulo, Bra[sz]il
am@ime.usp.br
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: yank-and-indent
2002-11-20 20:28 yank-and-indent Timur Aydin
2002-11-20 21:01 ` yank-and-indent Michael Slass
@ 2002-11-20 21:07 ` Alan Shutko
2002-11-20 21:29 ` yank-and-indent Michael Slass
2002-11-20 21:39 ` yank-and-indent Timur Aydin
1 sibling, 2 replies; 6+ messages in thread
From: Alan Shutko @ 2002-11-20 21:07 UTC (permalink / raw)
"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))))
--
Alan Shutko <ats@acm.org> - In a variety of flavors!
Parrot in a raincoat: polyunsaturated.
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: yank-and-indent
2002-11-20 21:07 ` yank-and-indent Alan Shutko
@ 2002-11-20 21:29 ` Michael Slass
2002-11-20 21:39 ` yank-and-indent Timur Aydin
1 sibling, 0 replies; 6+ messages in thread
From: Michael Slass @ 2002-11-20 21:29 UTC (permalink / raw)
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
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: yank-and-indent
2002-11-20 21:07 ` yank-and-indent Alan Shutko
2002-11-20 21:29 ` yank-and-indent Michael Slass
@ 2002-11-20 21:39 ` Timur Aydin
1 sibling, 0 replies; 6+ messages in thread
From: Timur Aydin @ 2002-11-20 21:39 UTC (permalink / raw)
"Alan Shutko" <ats@acm.org> wrote in message
news:87n0o4ez7i.fsf@wesley.springies.com...
> "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=u66crixv
e.fsf%40sdm.de&rnum=1
>
Works very nice... And best of all, no new keystroke needs to be learned.
--
Timur.
^ permalink raw reply [flat|nested] 6+ messages in thread
end of thread, other threads:[~2002-11-20 21:43 UTC | newest]
Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2002-11-20 20:28 yank-and-indent Timur Aydin
2002-11-20 21:01 ` yank-and-indent Michael Slass
2002-11-20 21:43 ` yank-and-indent Arnaldo Mandel
2002-11-20 21:07 ` yank-and-indent Alan Shutko
2002-11-20 21:29 ` yank-and-indent Michael Slass
2002-11-20 21:39 ` yank-and-indent Timur Aydin
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).