unofficial mirror of help-gnu-emacs@gnu.org
 help / color / mirror / Atom feed
* Moving regions up and down by lines
@ 2007-06-30 17:25 Dave Benjamin
  0 siblings, 0 replies; 4+ messages in thread
From: Dave Benjamin @ 2007-06-30 17:25 UTC (permalink / raw)
  To: help-gnu-emacs

Greetings,

I have these two functions defined, which allow me to move the region up 
and down by one or more lines, displacing the text around it. This works 
pretty well, but after the call to yank, the region is no longer 
selected (I use transient-mark-mode). I've tried calling 
exchange-point-and-mark after the yank, but it has no effect. Does 
anyone know how to accomplish this?

(defun move-region-up (arg)
   (interactive "p")
   (kill-region (region-beginning) (region-end))
   (unwind-protect
       (previous-line arg)
     (yank)))

(defun move-region-down (arg)
   (interactive "p")
   (kill-region (region-beginning) (region-end))
   (unwind-protect
       (next-line arg)
     (yank)))

Thanks,
Dave

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: Moving regions up and down by lines
@ 2007-06-30 21:32 martin rudalics
  0 siblings, 0 replies; 4+ messages in thread
From: martin rudalics @ 2007-06-30 21:32 UTC (permalink / raw)
  To: ramen; +Cc: help-gnu-emacs

You should use `transpose-regions'.  Have a look at the attachment of

http://lists.gnu.org/archive/html/emacs-devel/2007-03/msg01230.html

for a treatment of this.

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: Moving regions up and down by lines
       [not found] <mailman.2886.1183239069.32220.help-gnu-emacs@gnu.org>
@ 2007-07-01  6:48 ` Dave Benjamin
  0 siblings, 0 replies; 4+ messages in thread
From: Dave Benjamin @ 2007-07-01  6:48 UTC (permalink / raw)
  To: help-gnu-emacs

martin rudalics wrote:
> You should use `transpose-regions'.  Have a look at the attachment of
> 
> http://lists.gnu.org/archive/html/emacs-devel/2007-03/msg01230.html
> 
> for a treatment of this.

Thanks for the pointers! A call to (setq deactivate-mark nil) at the end 
of each function is all I needed. I like your idea of dragging the 
current line if the mark is not active.

Are you planning on releasing m&d somewhere? It looks like quite an 
ambitious effort.

Dave

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: Moving regions up and down by lines
@ 2007-07-01 12:05 martin rudalics
  0 siblings, 0 replies; 4+ messages in thread
From: martin rudalics @ 2007-07-01 12:05 UTC (permalink / raw)
  To: ramen; +Cc: help-gnu-emacs

 > Thanks for the pointers! A call to (setq deactivate-mark nil) at the end
 > of each function is all I needed.

Though a kill and a subsequent yank is an overkill.  `transpose-regions'
is now working reliably, you should use it.

 > Are you planning on releasing m&d somewhere? It looks like quite an
 > ambitious effort.

Earlier versions worked well with text-mode and broke with programming
languages.  Currently, it doesn't work nicely with interpunctuation in
text modes.  I'd have to fix that eventually.

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2007-07-01 12:05 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2007-06-30 21:32 Moving regions up and down by lines martin rudalics
  -- strict thread matches above, loose matches on Subject: below --
2007-07-01 12:05 martin rudalics
     [not found] <mailman.2886.1183239069.32220.help-gnu-emacs@gnu.org>
2007-07-01  6:48 ` Dave Benjamin
2007-06-30 17:25 Dave Benjamin

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).