rejeep / drag-stuff.el

Drag stuff around in Emacs
233 stars 12 forks source link

Drag defuns #2

Open gvol opened 12 years ago

gvol commented 12 years ago

Several times I have found myself wanting the ability to drag a (mode-specific) defun up and down (swapping places with other defuns, not a line at a time). I don't have time to work on this right now, so I thought I would put it here in case someone else wants to implement it before I get around to it.

I think the hardest part will be the interface i.e. how to I indicate that I want to drag a defun instead of a region. It might also be nice to drag sexp's, though that is easier to deal with since there is transpose-sexps.

rejeep commented 12 years ago

This would be a nice feature!

One simple solution is to use expand-region to select the function/sexp/whatever and then use drag-stuff to move the region around.

gvol commented 12 years ago

I was actually thinking the same thing. It would be very cool if you could expand-region and then when you drag it would know what the last expansion (easy to add to expand-region) was and then drag by that unit (hard if not impossible in general). As an example, you could expand until you get a sentence and it would then drag sentences, or expand to a paragraph and it would drag by paragraphs.

I think this would be quite useful when writing prose, but drag-stuff would end up having to be very smart. Or at least I don't see an easy way at the moment. The only general solution I can think of is to move point forward (or back) and run the last expansion function every time until they don't overlap and then swap the two regions. But I imagine this would be way too slow to actually use.

rejeep commented 12 years ago

Depending on how advanced this feature is, drag-stuff would have to be smart or not. In the most simple case expand-region can be used to select what is to be dragged and the use drag-stuff to drag the lines. But that would not work in situations like this:

if(condition) {
  // foo
} else {
  // bar
}

It would be nice to be able to drag just the if-part.

This could be a very cool feature, but it would require some job...