From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Andreas Politz Newsgroups: gmane.emacs.help Subject: Re: Move selection up, down Date: Wed, 20 Aug 2008 02:45:02 +0200 Organization: FH-Trier Message-ID: <1219193209.777664@arno.fh-trier.de> References: <1422fa24-05d5-436b-82e2-b436af0a00a3@m3g2000hsc.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 1219196460 8690 80.91.229.12 (20 Aug 2008 01:41:00 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Wed, 20 Aug 2008 01:41:00 +0000 (UTC) To: help-gnu-emacs@gnu.org Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Wed Aug 20 03:41:53 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 1KVchs-0002M0-N5 for geh-help-gnu-emacs@m.gmane.org; Wed, 20 Aug 2008 03:41:52 +0200 Original-Received: from localhost ([127.0.0.1]:43991 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1KVcgv-0000Ub-LG for geh-help-gnu-emacs@m.gmane.org; Tue, 19 Aug 2008 21:40:53 -0400 Original-Path: news.stanford.edu!headwall.stanford.edu!newshub.sdsu.edu!newsfeed.straub-nv.de!news.k-dsl.de!news.uni-stuttgart.de!news-stu1.dfn.de!news.uni-kl.de!not-for-mail Original-Newsgroups: gnu.emacs.help Original-Lines: 55 Original-NNTP-Posting-Host: 143-93-54-11.arno.fh-trier.de Original-X-Trace: news.uni-kl.de 1219193207 87 143.93.54.11 (20 Aug 2008 00:46:47 GMT) Original-X-Complaints-To: usenet@news.uni-kl.de Original-NNTP-Posting-Date: Wed, 20 Aug 2008 00:46:47 +0000 (UTC) User-Agent: Mozilla-Thunderbird 2.0.0.16 (X11/20080724) In-Reply-To: <1422fa24-05d5-436b-82e2-b436af0a00a3@m3g2000hsc.googlegroups.com> Cache-Post-Path: arno.fh-trier.de!unknown@dslb-088-069-052-179.pools.arcor-ip.net X-Cache: nntpcache 3.0.1 (see http://www.nntpcache.org/) Original-Xref: news.stanford.edu gnu.emacs.help:161453 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:56799 Archived-At: jiri.pejchal@gmail.com wrote: > Hi, > > in Netbeans when you press M-S-up/M-S-down you move the selected text > up/down. When nothing is selected it moves the current line. > > With C-S-up/C-S-down you copy the selection up/down. When nothings is > selected it copies the current line up/down. > > Is such functionality available in emacs? > > Jiri Pejchal Heres some elisp. It binds M-S-up/down to commands which move the active region (with respect to columns) or the current line prefix arg lines up or down. Have fun. -ap (defun move-text-internal (arg) (cond ((and mark-active transient-mark-mode) (if (> (point) (mark)) (exchange-point-and-mark)) (let ((column (current-column)) (text (delete-and-extract-region (point) (mark)))) (forward-line arg) (move-to-column column t) (set-mark (point)) (insert text) (exchange-point-and-mark) (setq deactivate-mark nil))) (t (beginning-of-line) (when (or (> arg 0) (not (bobp))) (forward-line) (when (or (< arg 0) (not (eobp))) (transpose-lines arg)) (forward-line -1))))) (defun move-text-down (arg) "Move region (transient-mark-mode active) or current line arg lines down." (interactive "*p") (move-text-internal arg)) (defun move-text-up (arg) "Move region (transient-mark-mode active) or current line arg lines up." (interactive "*p") (move-text-internal (- arg))) (global-set-key [\M-\S-up] 'move-text-up) (global-set-key [\M-\S-down] 'move-text-down)