From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Eli Zaretskii Newsgroups: gmane.emacs.help Subject: Re: Move line Date: Sun, 01 Jun 2008 00:15:07 +0300 Message-ID: References: <41e8769d-18d4-4a36-82ba-adb0b26a0b9e@s50g2000hsb.googlegroups.com> NNTP-Posting-Host: lo.gmane.org X-Trace: ger.gmane.org 1212268576 32204 80.91.229.12 (31 May 2008 21:16:16 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Sat, 31 May 2008 21:16: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 23:16: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 1K2YQx-0006Mk-Ft for geh-help-gnu-emacs@m.gmane.org; Sat, 31 May 2008 23:16:15 +0200 Original-Received: from localhost ([127.0.0.1]:36198 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1K2YQB-0000Ht-F5 for geh-help-gnu-emacs@m.gmane.org; Sat, 31 May 2008 17:15:27 -0400 Original-Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1K2YPq-0000Hd-F6 for help-gnu-emacs@gnu.org; Sat, 31 May 2008 17:15:06 -0400 Original-Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1K2YPo-0000HR-TI for help-gnu-emacs@gnu.org; Sat, 31 May 2008 17:15:05 -0400 Original-Received: from [199.232.76.173] (port=37238 helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1K2YPo-0000HO-N6 for help-gnu-emacs@gnu.org; Sat, 31 May 2008 17:15:04 -0400 Original-Received: from mtaout4.012.net.il ([84.95.2.10]:47632) by monty-python.gnu.org with esmtp (Exim 4.60) (envelope-from ) id 1K2YPo-0003MN-GL for help-gnu-emacs@gnu.org; Sat, 31 May 2008 17:15:04 -0400 Original-Received: from HOME-C4E4A596F7 ([84.228.202.9]) by i_mtaout4.012.net.il (HyperSendmail v2004.12) with ESMTPA id <0K1R0033L51TJ1U0@i_mtaout4.012.net.il> for help-gnu-emacs@gnu.org; Sun, 01 Jun 2008 00:29:54 +0300 (IDT) In-reply-to: X-012-Sender: halo1@inter.net.il X-detected-kernel: by monty-python.gnu.org: Solaris 9.1 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:54391 Archived-At: > 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.