all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: Bernardo <bernardo.bacic@pobox.com>
To: Help-gnu-emacs@gnu.org
Subject: Re: indenting automatically after pasting in c-mode
Date: Thu, 13 Aug 2009 20:34:44 +1000	[thread overview]
Message-ID: <4A83EC44.4070504@pobox.com> (raw)
In-Reply-To: <24938448.post@talk.nabble.com>

> 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	other threads:[~2009-08-13 10:34 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2009-08-12 15:01 indenting automatically after pasting in c-mode Dirk80
2009-08-13 10:34 ` Bernardo [this message]
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

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=4A83EC44.4070504@pobox.com \
    --to=bernardo.bacic@pobox.com \
    --cc=Help-gnu-emacs@gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/emacs.git
	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.