I got a comment in my last post regarding dragging a line up and down. I remembered that I once started working on a minor mode “drag stuff”. Whatever happened to that I don’t know.
Having a few hours to spare this weekend I decided to create the mode. The mode is called drag-stuff-mode. The source is at Github.
First download the source from Github and make sure it’s in Emcacs load-path. Then require it. A more detailed installation description is given in the README and lisp source file.
First off, start the mode with M-x drag-stuff-mode
. Note that all
command takes a prefix argument to repeat the command that many times.
To drag a line, put the cursor on that line and press <M-up>
or <M-down>
.
For example, put the cursor on line 3 and press <M-up>
.
1 class Foo
2 end
3 attr_accessor :bar
You should now have
1 class Foo
2 attr_accessor :bar
3 end
Drag lines work like drag line except for that you can move more than one line. Note that you don’t have to select the complete lines. It’s enough that some part of the first and last lines are selected.
Mark the to_s method and press <M-down>
.
1 def to_s
2 ":#{bar}:"
3 end
4 class Foo
5 end
You should now have
1 class Foo
2 def to_s
3 ":#{bar}:"
4 end
5 end
You can drag a region left and right by selecting a region and press
<M-left>
or <M-right>
.
For example. Select {bar}
and press <M-right>
until it’s at
the correct place. You could also do this with by giving a prefix
argument like M-3 M-right
.
1 class Foo
2 def to_s
3 {bar}":#:"
4 end
5 end
You should now have
1 class Foo
2 def to_s
3 ":#{bar}:"
4 end
5 end
To drag a word, just place the cursor on the word and press
<M-left>
or <M-right>
.
Put the cursor on me
and press <M-right>
a few times.
1 class Foo
2 def to_s
3 "drag me to the right"
4 end
5 end
You should now have
1 class Foo
2 def to_s
3 "drag to the me right"
4 end
5 end
There are obviously more things you can drag. These were what I came up with. If you think that my selection is stupid and I should change something, leave a comment with a good reason an I’ll see what I can do! ;)