* indenting automatically after pasting in c-mode
@ 2009-08-12 15:01 Dirk80
2009-08-13 10:34 ` Bernardo
0 siblings, 1 reply; 5+ messages in thread
From: Dirk80 @ 2009-08-12 15:01 UTC (permalink / raw)
To: Help-gnu-emacs
Hi,
I use emacs mainly to write c-code.
For example I paste 10 lines of code into a function. Now this 10 lines of
code are just inserted into the buffer as they are and not indented. I have
to mark these 10 lines, and then pressing TAB (indent-for-tab-command) and
everything is fine.
It would be great if the 10 lines would be intended automatically (without
marking the 10 lines and then pressing tab) when I paste them.
How could I solve this? Do I have to write an own elisp-function which is
doing the job and then binding it in c-mode to C-y. Or is this behaviour
already implemented?
Thanks for your answers.
Dirk
--
View this message in context: http://www.nabble.com/indenting-automatically-after-pasting-in-c-mode-tp24938448p24938448.html
Sent from the Emacs - Help mailing list archive at Nabble.com.
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: indenting automatically after pasting in c-mode
[not found] <mailman.4471.1250089337.2239.help-gnu-emacs@gnu.org>
@ 2009-08-12 15:08 ` Colin S. Miller
0 siblings, 0 replies; 5+ messages in thread
From: Colin S. Miller @ 2009-08-12 15:08 UTC (permalink / raw)
To: help-gnu-emacs
Dirk80 wrote:
> Hi,
>
> I use emacs mainly to write c-code.
>
> For example I paste 10 lines of code into a function. Now this 10 lines of
> code are just inserted into the buffer as they are and not indented. I have
> to mark these 10 lines, and then pressing TAB (indent-for-tab-command) and
> everything is fine.
>
> It would be great if the 10 lines would be intended automatically (without
> marking the 10 lines and then pressing tab) when I paste them.
>
> How could I solve this? Do I have to write an own elisp-function which is
> doing the job and then binding it in c-mode to C-y. Or is this behaviour
> already implemented?
>
> Thanks for your answers.
> Dirk
Not sure if it help much,
but ident-region will reindent a block of text correctly.
HTH,
Colin S. Miller
--
Replace the obvious in my email address with the first three letters of the hostname to reply.
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: indenting automatically after pasting in c-mode
2009-08-12 15:01 indenting automatically after pasting in c-mode Dirk80
@ 2009-08-13 10:34 ` Bernardo
2009-08-13 21:52 ` Dirk80
0 siblings, 1 reply; 5+ messages in thread
From: Bernardo @ 2009-08-13 10:34 UTC (permalink / raw)
To: Help-gnu-emacs
> Hi,
>
> I use emacs mainly to write c-code.
>
> For example I paste 10 lines of code into a function. Now this 10 lines of
> code are just inserted into the buffer as they are and not indented. I have
> to mark these 10 lines, and then pressing TAB (indent-for-tab-command) and
> everything is fine.
>
> It would be great if the 10 lines would be intended automatically (without
> marking the 10 lines and then pressing tab) when I paste them.
>
> How could I solve this? Do I have to write an own elisp-function which is
> doing the job and then binding it in c-mode to C-y. Or is this behaviour
> already implemented?
>
> Thanks for your answers.
> Dirk
this slightly modified tip from
http://emacs.wordpress.com/2007/01/22/killing-yanking-and-copying-lines/
seems to work fine
(defadvice yank (after indent-region activate)
(when (member major-mode '(c++-mode emacs-lisp-mode python-mode c-mode))
(unless mark-active
(exchange-point-and-mark))
(indent-region (region-beginning) (region-end) nil)))
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: indenting automatically after pasting in c-mode
2009-08-13 10:34 ` Bernardo
@ 2009-08-13 21:52 ` Dirk80
2009-08-14 8:09 ` Dirk80
0 siblings, 1 reply; 5+ messages in thread
From: Dirk80 @ 2009-08-13 21:52 UTC (permalink / raw)
To: Help-gnu-emacs
Fantastic. This is exactly what I was looking for. Thank you very much.
Bernardo Bacic wrote:
>
>> Hi,
>>
>> I use emacs mainly to write c-code.
>>
>> For example I paste 10 lines of code into a function. Now this 10 lines
>> of
>> code are just inserted into the buffer as they are and not indented. I
>> have
>> to mark these 10 lines, and then pressing TAB (indent-for-tab-command)
>> and
>> everything is fine.
>>
>> It would be great if the 10 lines would be intended automatically
>> (without
>> marking the 10 lines and then pressing tab) when I paste them.
>>
>> How could I solve this? Do I have to write an own elisp-function which is
>> doing the job and then binding it in c-mode to C-y. Or is this behaviour
>> already implemented?
>>
>> Thanks for your answers.
>> Dirk
>
>
> this slightly modified tip from
> http://emacs.wordpress.com/2007/01/22/killing-yanking-and-copying-lines/
> seems to work fine
>
> (defadvice yank (after indent-region activate)
> (when (member major-mode '(c++-mode emacs-lisp-mode python-mode
> c-mode))
> (unless mark-active
> (exchange-point-and-mark))
> (indent-region (region-beginning) (region-end) nil)))
>
>
>
>
>
>
--
View this message in context: http://www.nabble.com/indenting-automatically-after-pasting-in-c-mode-tp24938448p24959484.html
Sent from the Emacs - Help mailing list archive at Nabble.com.
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: indenting automatically after pasting in c-mode
2009-08-13 21:52 ` Dirk80
@ 2009-08-14 8:09 ` Dirk80
0 siblings, 0 replies; 5+ messages in thread
From: Dirk80 @ 2009-08-14 8:09 UTC (permalink / raw)
To: Help-gnu-emacs
Because I like to continue after the yanked code I repositioned the point
after indentation.
(defadvice yank (after indent-region activate)
(when (member major-mode '(c++-mode emacs-lisp-mode python-mode c-mode))
(unless mark-active
(exchange-point-and-mark))
(indent-region (region-beginning) (region-end) nil)
(goto-char (region-end))))
Now it is doing exactly what I want.
Dirk80 wrote:
>
> Fantastic. This is exactly what I was looking for. Thank you very much.
>
>
> Bernardo Bacic wrote:
>>
>>> Hi,
>>>
>>> I use emacs mainly to write c-code.
>>>
>>> For example I paste 10 lines of code into a function. Now this 10 lines
>>> of
>>> code are just inserted into the buffer as they are and not indented. I
>>> have
>>> to mark these 10 lines, and then pressing TAB (indent-for-tab-command)
>>> and
>>> everything is fine.
>>>
>>> It would be great if the 10 lines would be intended automatically
>>> (without
>>> marking the 10 lines and then pressing tab) when I paste them.
>>>
>>> How could I solve this? Do I have to write an own elisp-function which
>>> is
>>> doing the job and then binding it in c-mode to C-y. Or is this behaviour
>>> already implemented?
>>>
>>> Thanks for your answers.
>>> Dirk
>>
>>
>> this slightly modified tip from
>> http://emacs.wordpress.com/2007/01/22/killing-yanking-and-copying-lines/
>> seems to work fine
>>
>> (defadvice yank (after indent-region activate)
>> (when (member major-mode '(c++-mode emacs-lisp-mode python-mode
>> c-mode))
>> (unless mark-active
>> (exchange-point-and-mark))
>> (indent-region (region-beginning) (region-end) nil)))
>>
>>
>>
>>
>>
>>
>
>
--
View this message in context: http://www.nabble.com/indenting-automatically-after-pasting-in-c-mode-tp24938448p24967873.html
Sent from the Emacs - Help mailing list archive at Nabble.com.
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2009-08-14 8:09 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2009-08-12 15:01 indenting automatically after pasting in c-mode Dirk80
2009-08-13 10:34 ` Bernardo
2009-08-13 21:52 ` Dirk80
2009-08-14 8:09 ` Dirk80
[not found] <mailman.4471.1250089337.2239.help-gnu-emacs@gnu.org>
2009-08-12 15:08 ` Colin S. Miller
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).