--
-MM
/"\
(No un-solicited email please.) \ / ASCII Ribbon Campaign
See following url, X Against HTML Mail
http://pages.prodigy.net/mmynsted/spamoff.htm / \
Does it help to type C-M-\, immediately after yanking the text?
> How would I hook into yank so that text that is yanked is inserted and
> indented according to the major mode? The first thing I need often do
> after inserting text is to indent the region.
The following works for me:
,----
| ;; 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))
| (indent-region (region-beginning) (region-end) nil)))
`----
Klaus
--
Klaus Berndl mailto: klaus....@sdm.de
sd&m AG http://www.sdm.de
software design & management
Thomas-Dehler-Str. 27, 81737 München, Germany
Tel +49 89 63812-392, Fax -220
Well, no. That is what I meant by the first thing I do after insert
text is to indent the region. It just seems to me that the text
should be indented AS it is inserted into the buffer. While coding
there really is no occasion when I would want to insert text, via a
yank, and not have it be correctly indented. Why should an additional
key stroke be required?
| Eli Zaretskii <el...@is.elta.co.il> writes:
|
>> Mark Mynsted wrote:
>> >
>> > How would I hook into yank so that text that is yanked is inserted and
>> > indented according to the major mode? The first thing I need often do
>> > after inserting text is to indent the region.
>>
>> Does it help to type C-M-\, immediately after yanking the text?
|
| Well, no. That is what I meant by the first thing I do after insert
| text is to indent the region. It just seems to me that the text
| should be indented AS it is inserted into the buffer. While coding
| there really is no occasion when I would want to insert text, via a
| yank, and not have it be correctly indented. Why should an additional
| key stroke be required?
I'm not Eli, but perhaps his question is the first step in designing a
solution. It is not hard to make a function which first yanks and
then does the equivalent of C-M-\. If that is what you want.
--
Stein Arild Strømme <http://www.mi.uib.no/~stromme>
> On Mon, 16 Jul 2001, Mark Mynsted wrote:
>
> > How would I hook into yank so that text that is yanked is inserted and
> > indented according to the major mode? The first thing I need often do
> > after inserting text is to indent the region.
>
> The following works for me:
>
> ,----
> | ;; 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))
> | (indent-region (region-beginning) (region-end) nil)))
> `----
>
> Klaus
That is perfect! I did not know about the advice mechanism at all.
This is an elegant solution, thank you.
KB> The following works for me:
That's really cool! I had to modify it a little, because I use
transient-mark-mode:
(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 works - is it the right way to do it?
Edric.
--
Edric M Ellis
The MathWorks, Ltd.
Tel: +44 (0) 1223 423 200 Ext: 218
Fax: +44 (0) 1223 423 289
> (let ((transient-mark-mode nil))
> (indent-region (region-beginning) (region-end) nil))))
As an alternative, you might be able to use (mark t) and (point).
Normally, (mark) barfs in transient mark mode if the region isn't
active, but (mark t) works even if the region isn't active.
kai
--
~/.signature: No such file or directory
KG> As an alternative, you might be able to use (mark t) and
KG> (point). Normally, (mark) barfs in transient mark mode if the
KG> region isn't active, but (mark t) works even if the region
KG> isn't active.
Aah, didn't know about that - thanks.