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

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

Re: indenting automatically after pasting in c-mode


From: Dirk80
Subject: Re: indenting automatically after pasting in c-mode
Date: Fri, 14 Aug 2009 01:09:04 -0700 (PDT)

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.





reply via email to

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