From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: rock69 Newsgroups: gmane.emacs.help Subject: Re: Move line Date: Sat, 31 May 2008 09:53:35 -0700 (PDT) Organization: http://groups.google.com Message-ID: References: <41e8769d-18d4-4a36-82ba-adb0b26a0b9e@s50g2000hsb.googlegroups.com> NNTP-Posting-Host: lo.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit X-Trace: ger.gmane.org 1212266956 27905 80.91.229.12 (31 May 2008 20:49:16 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Sat, 31 May 2008 20:49:16 +0000 (UTC) To: help-gnu-emacs@gnu.org Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Sat May 31 22:49:57 2008 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 1K2Y1P-0006Ii-Vm for geh-help-gnu-emacs@m.gmane.org; Sat, 31 May 2008 22:49:52 +0200 Original-Received: from localhost ([127.0.0.1]:48385 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1K2Y0e-0007q9-79 for geh-help-gnu-emacs@m.gmane.org; Sat, 31 May 2008 16:49:04 -0400 Original-Path: news.stanford.edu!newsfeed.stanford.edu!postnews.google.com!c65g2000hsa.googlegroups.com!not-for-mail Original-Newsgroups: gnu.emacs.help Original-Lines: 42 Original-NNTP-Posting-Host: 151.53.51.192 Original-X-Trace: posting.google.com 1212252816 32242 127.0.0.1 (31 May 2008 16:53:36 GMT) Original-X-Complaints-To: groups-abuse@google.com Original-NNTP-Posting-Date: Sat, 31 May 2008 16:53:36 +0000 (UTC) Complaints-To: groups-abuse@google.com Injection-Info: c65g2000hsa.googlegroups.com; posting-host=151.53.51.192; posting-account=oEKbfAoAAADQ6fiSE74ec-bF1nZx2Kc_ User-Agent: G2/1.0 X-HTTP-UserAgent: Mozilla/5.0 (X11; U; Linux x86_64; en-US; rv:1.8.1.14) Gecko/20080418 Ubuntu/8.04 (hardy) Firefox/2.0.0.14, gzip(gfe), gzip(gfe) Original-Xref: news.stanford.edu gnu.emacs.help:159026 X-Mailman-Approved-At: Sat, 31 May 2008 16:48:09 -0400 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:54390 Archived-At: On May 31, 5:57 pm, rock69 wrote: > I'm rather new to emacs, but I'm addicted already. I used to use > Eclipse a lot before, and there is one thing I'm missing though I'm > pretty sure that it must be available somewhere in Emacs. I was > wondering if it's possible to move (shift) a line of text up or down > like you would do in Eclipse pressing Alt-up (or down). I did some research within this very same newsgroup, and here's what I discovered (works great!): (defun move-line (n) "Move the current line up or down by N lines." (interactive "p") (let ((col (current-column)) start end) (beginning-of-line) (setq start (point)) (end-of-line) (forward-char) (setq end (point)) (let ((line-text (delete-and-extract-region start end))) (forward-line n) (insert line-text) ;; restore point to original column in moved line (forward-line -1) (forward-char col)))) (defun move-line-up (n) "Move the current line up by N lines." (interactive "p") (move-line (if (null n) -1 (- n)))) (defun move-line-down (n) "Move the current line down by N lines." (interactive "p") (move-line (if (null n) 1 n))) (global-set-key (kbd "M-") 'move-line-up) (global-set-key (kbd "M-") 'move-line-down) Thanks all.