From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Dirk80 Newsgroups: gmane.emacs.help Subject: Re: indenting automatically after pasting in c-mode Date: Fri, 14 Aug 2009 01:09:04 -0700 (PDT) Message-ID: <24967873.post@talk.nabble.com> References: <24938448.post@talk.nabble.com> <4A83EC44.4070504@pobox.com> <24959484.post@talk.nabble.com> NNTP-Posting-Host: lo.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit X-Trace: ger.gmane.org 1250237389 9118 80.91.229.12 (14 Aug 2009 08:09:49 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Fri, 14 Aug 2009 08:09:49 +0000 (UTC) To: Help-gnu-emacs@gnu.org Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Fri Aug 14 10:09:42 2009 Return-path: Envelope-to: geh-help-gnu-emacs@m.gmane.org Original-Received: from lists.gnu.org ([199.232.76.165]) by lo.gmane.org with esmtp (Exim 4.50) id 1Mbrr3-0004Dq-Iz for geh-help-gnu-emacs@m.gmane.org; Fri, 14 Aug 2009 10:09:41 +0200 Original-Received: from localhost ([127.0.0.1]:38559 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1Mbrr2-0002kW-IE for geh-help-gnu-emacs@m.gmane.org; Fri, 14 Aug 2009 04:09:40 -0400 Original-Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1Mbrqf-0002kR-Oq for help-gnu-emacs@gnu.org; Fri, 14 Aug 2009 04:09:17 -0400 Original-Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1Mbrqb-0002k2-0u for Help-gnu-emacs@gnu.org; Fri, 14 Aug 2009 04:09:17 -0400 Original-Received: from [199.232.76.173] (port=57777 helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1Mbrqa-0002jz-PC for Help-gnu-emacs@gnu.org; Fri, 14 Aug 2009 04:09:12 -0400 Original-Received: from mx20.gnu.org ([199.232.41.8]:37324) by monty-python.gnu.org with esmtps (TLS-1.0:RSA_AES_256_CBC_SHA1:32) (Exim 4.60) (envelope-from ) id 1Mbrqa-00086c-9q for Help-gnu-emacs@gnu.org; Fri, 14 Aug 2009 04:09:12 -0400 Original-Received: from kuber.nabble.com ([216.139.236.158]) by mx20.gnu.org with esmtp (Exim 4.60) (envelope-from ) id 1MbrqZ-0007bB-Nv for Help-gnu-emacs@gnu.org; Fri, 14 Aug 2009 04:09:11 -0400 Original-Received: from isper.nabble.com ([192.168.236.156]) by kuber.nabble.com with esmtp (Exim 4.63) (envelope-from ) id 1MbrqS-0004sW-FR for Help-gnu-emacs@gnu.org; Fri, 14 Aug 2009 01:09:04 -0700 In-Reply-To: <24959484.post@talk.nabble.com> X-Nabble-From: dirk@dirkundsari.de X-Detected-Operating-System: by mx20.gnu.org: GNU/Linux 2.6 (newer, 3) X-detected-operating-system: by monty-python.gnu.org: GNU/Linux 2.6, seldom 2.4 (older, 4) X-BeenThere: help-gnu-emacs@gnu.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Users list for the GNU Emacs text editor List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Original-Sender: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Errors-To: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.help:67143 Archived-At: 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.