Drag stuff in Emacs

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.

Installation

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.

Usage

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.

Drag line

To drag a line, put the cursor on that line and press or .

For example, put the cursor on line 3 and press .

class Foo
end
attr_accessor :bar

You should now have

class Foo
attr_accessor :bar
end

Drag lines

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 .

def to_s
  ":#{bar}:"
end
class Foo
end

You should now have

class Foo
def to_s
  ":#{bar}:"
end
end

Drag region

You can drag a region left and right by selecting a region and press or .

For example. Select {bar} and press until it's at the correct place. You could also do this with by giving a prefix argument like M-3 M-right.

class Foo
  def to_s
    {bar}":#:"
  end
end

You should now have

class Foo
  def to_s
    ":#{bar}:"
  end
end

Drag word

To drag a word, just place the cursor on the word and press or .

Put the cursor on me and press a few times.

class Foo
  def to_s
    "drag me to the right"
  end
end

You should now have

class Foo
  def to_s
    "drag to the me right"
  end
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! ;)


blog comments powered by Disqus Back to Top

Fork me on GitHub