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: Bernardo
Subject: Re: indenting automatically after pasting in c-mode
Date: Thu, 13 Aug 2009 20:34:44 +1000
User-agent: Thunderbird 2.0.0.22 (X11/20090605)

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)))






reply via email to

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