From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: "Lennart Borgman (gmail)" Newsgroups: gmane.emacs.help Subject: Re: Move line Date: Sat, 31 May 2008 23:22:57 +0200 Message-ID: <4841C1B1.8060009@gmail.com> 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; format=flowed Content-Transfer-Encoding: 7bit X-Trace: ger.gmane.org 1212269034 1229 80.91.229.12 (31 May 2008 21:23:54 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Sat, 31 May 2008 21:23:54 +0000 (UTC) Cc: help-gnu-emacs@gnu.org To: Eli Zaretskii Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Sat May 31 23:24:35 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 1K2YYf-0001NG-F6 for geh-help-gnu-emacs@m.gmane.org; Sat, 31 May 2008 23:24:13 +0200 Original-Received: from localhost ([127.0.0.1]:39014 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1K2YXt-0003Dz-Fj for geh-help-gnu-emacs@m.gmane.org; Sat, 31 May 2008 17:23:25 -0400 Original-Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1K2YXc-0003Di-6p for help-gnu-emacs@gnu.org; Sat, 31 May 2008 17:23:08 -0400 Original-Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1K2YXZ-0003DW-Qh for help-gnu-emacs@gnu.org; Sat, 31 May 2008 17:23:06 -0400 Original-Received: from [199.232.76.173] (port=37755 helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1K2YXZ-0003DT-MF for help-gnu-emacs@gnu.org; Sat, 31 May 2008 17:23:05 -0400 Original-Received: from ch-smtp02.sth.basefarm.net ([80.76.149.213]:54595) by monty-python.gnu.org with esmtps (TLS-1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.60) (envelope-from ) id 1K2YXU-0004wJ-Uf; Sat, 31 May 2008 17:23:01 -0400 Original-Received: from c83-254-145-59.bredband.comhem.se ([83.254.145.59]:63207 helo=[127.0.0.1]) by ch-smtp02.sth.basefarm.net with esmtp (Exim 4.68) (envelope-from ) id 1K2YXS-00054D-8u; Sat, 31 May 2008 23:22:59 +0200 User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.9) Gecko/20071031 Thunderbird/2.0.0.9 Mnenhy/0.7.5.666 In-Reply-To: X-Antivirus: avast! (VPS 080531-1, 2008-05-31), Outbound message X-Antivirus-Status: Clean X-Originating-IP: 83.254.145.59 X-Scan-Result: No virus found in message 1K2YXS-00054D-8u. X-Scan-Signature: ch-smtp02.sth.basefarm.net 1K2YXS-00054D-8u 9f4d10b3430d3cd1c3fbd8fbb40aa974 X-detected-kernel: by monty-python.gnu.org: Linux 2.6? (barebone, rare!) 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:54392 Archived-At: Eli Zaretskii wrote: >> From: rock69 >> Date: Sat, 31 May 2008 09:53:35 -0700 (PDT) >> >> (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. > > I have this in my ~/.emacs, which I think does what you want with much > less fuss: > > (global-set-key "\M-z" (function (lambda () (interactive) (scroll-down 1)))) > (global-set-key "\C-z" (function (lambda () (interactive) (scroll-up 1)))) > > Of course, I'm used to different keybindings, but the point is that > the code is much simpler and shorter. But it moves the point instead of the line ...