Line mover with indentation

Hello guys,

I finally found the time to do what I wanted to do since I discovered LineMover plugin. With a help of a very small extra code it now moves lines AND then indents them in the same way as CtrlAltI does (Auto-Indent Lines). I do not invoke Auto-Indent Lines action because it move caret to a rather wrong for this plugin place. I used some code from IDEA to do the trick, so my contribution here is very limited.

I am not sure that I need to iterate to the next version the existing plugin. I suspect some people would want to use the old one instead. So I created a new plugin entry in the repository. It's called LineMoverIndent. Two these plugins can be used at the same time, just make sure you assign different keystrokes for them. I'll post the source code later on.

Here is the link to the repository http://plugins.intellij.net/plugins/view/?id=LineMoverIndent
Enjoy!

--
Dmitry Skavish
JetBrains, Inc. / "Develop with pleasure!"
http://www.jetbrains.com
-- Posted by JetBrains OmniaMea

32 comments
Comment actions Permalink

Dmitry
> I am not sure that I need to iterate to the next version the
existing plugin. I suspect some people would want to use the old one
instead. So I created a new plugin entry in the repository. It's called
LineMoverIndent. Two these plugins can be used at the same time, just
make sure you assign different keystrokes for them. I'll post the source
code later on.

I seem to remember that the plug-in fuctionalituy was to be integrated
into IDEA's core for Palada.
Am I wrong?

Alain

0
Comment actions Permalink

Alain Ravet wrote:

I seem to remember that the plug-in fuctionalituy was to be integrated
into IDEA's core for Palada.
Am I wrong?


see:
"req: move a selected line/block 1 line upward. / "
http://www.intellij.net/tracker/idea/viewSCR?publicId=2818

0
Comment actions Permalink


Very nice. LineMover is the plugin I use most on a day-to-day basis, and the lack of auto-indent has always irked me.

That said, I have absolutely no idea why this functionality isn't in the core product. IDEA has such nice line-based
features already (Ctrl-D, Ctrl-Shift-J, etc.) that these seem like natural additions.

--Dave Griffith

0
Comment actions Permalink

Alain,

AR> I seem to remember that the plug-in fuctionalituy was to be
AR> integrated into IDEA's core for Palada.
AR> Am I wrong?

Frankly I have no idea whether it is going to be included into IDEA's core or not (I am not on IDEA team). It took me a half an hour to do anyway, so even if it going to be useless in a month I did not waste a lot of time doing that :)

--
Dmitry Skavish
-- Posted by JetBrains OmniaMea

0
Comment actions Permalink

Is multi-line block moving in this plugin (or the original) supposed to work on anything other than java files? For me, it doesn't. I tried on a text file and an HTML file and in both cases the selection was lost and only one line gets moved (and if you completely undo your changes the selection reverts back to a range that's different from what you started with).

Works great for java code, though. Thanks.

thanks,

chris

0
Comment actions Permalink

Chris

> Is multi-line block moving in this plugin (or the original) supposed
> to work on anything other than java files? For me, it doesn't.
> ...
> Works great for java code, though. Thanks.

The original plugin works fine with any text type: java, txt, html, xml, ...


Alain

0
Comment actions Permalink

Is this supposed to work with Pallada?

"Dmitry Skavish (JetBrains)" <skavish@jetbrains.com> wrote in message
news:c8044d$fto$1@is.intellij.net...

Hello guys,

>

I finally found the time to do what I wanted to do since I discovered

LineMover plugin. With a help of a very small extra code it now moves lines
AND then indents them in the same way as CtrlAltI does (Auto-Indent
Lines). I do not invoke Auto-Indent Lines action because it move caret to a
rather wrong for this plugin place. I used some code from IDEA to do the
trick, so my contribution here is very limited.
>

I am not sure that I need to iterate to the next version the existing

plugin. I suspect some people would want to use the old one instead. So I
created a new plugin entry in the repository. It's called LineMoverIndent.
Two these plugins can be used at the same time, just make sure you assign
different keystrokes for them. I'll post the source code later on.
>

Here is the link to the repository

http://plugins.intellij.net/plugins/view/?id=LineMoverIndent

Enjoy!

>

--
Dmitry Skavish
JetBrains, Inc. / "Develop with pleasure!"
http://www.jetbrains.com
-- Posted by JetBrains OmniaMea



0
Comment actions Permalink

Other than the problem I mentioned above, it works for me with Pallada (build 2013, Win2k).

0
Comment actions Permalink

Hello Chris,

CB> Is multi-line block moving in this plugin (or the original) supposed
CB> to work on anything other than java files? For me, it doesn't. I

Fixed, in a sense that on non java files it works as the original one.

--
Dmitry Skavish
-- Posted by JetBrains OmniaMea

0
Comment actions Permalink

Uhm, I don't understand: are the shortcut still ctrl-shift-I ctrl-shift-K? On my system the line is correctly moved up and down, but indentation does not change!

0
Comment actions Permalink

Davide Baroncelli wrote:
> Uhm, I don't understand: are the shortcut still

This is a different plugin, with different shortcuts. See Dmitry's O.P.

Alain

0
Comment actions Permalink

Hello Davide,

DB> Uhm, I don't understand: are the shortcut still ctrl-shift-I
DB> ctrl-shift-K? On my system the line is correctly moved up and down,
DB> but indentation does not change!

Now I think that if you have two these plugins installed (with and without indentation) then only one will work because the class names are the same. So if this is the case you'll need to uninstall one of them.

--
Dmitry Skavish
-- Posted by JetBrains OmniaMea

0
Comment actions Permalink

Dmitry

> .. then only one will work because the class names are the same.


I see no reason to not consider your plugin as the next version of
LineMoverPlugin. You could simply publish it as the next version, and
reuse the old default shortcuts.
(the doc and source is on the wiki)

Should the auto-indent be an annoyance in some cases - is it? - , you
could maybe add a config option.

Alain

0
Comment actions Permalink

No, no, I didn't use the old one, I directly installed the LineMoverIndent one (I just double-checked in my plugin updater). If I open the keymap, I see that the actions bound to ctrl-shift-I and ctrl-shift-K are "Editor actions / Move line 1 Up" and "Editor actions / Move line 1 Down", so no mention to indentation is done: is this correct?

0
Comment actions Permalink

Dmitry

.. then only one will work because the class

ass names are the same.


I see no reason to not consider your plugin as the
next version of
LineMoverPlugin. You could simply publish it as the
next version, and
reuse the old default shortcuts.
(the doc and source is on the wiki)

Should the auto-indent be an annoyance in some cases
- is it? - , you
could maybe add a config option.

Alain


I find this wise, too.

0
Comment actions Permalink

Hello Davide,

DB> No, no, I didn't use the old one, I directly installed the
DB> LineMoverIndent one (I just double-checked in my plugin updater). If
DB> I open the keymap, I see that the actions bound to ctrl-shift-I and
DB> ctrl-shift-K are "Editor actions / Move line 1 Up" and "Editor
DB> actions / Move line 1 Down", so no mention to indentation is done:
DB> is this correct?

Yes, this is correct. I did not change the text for keystrokes. I have different mapping than this (CtrlShiftUp/Down).

If you use the new one then it should indent lines in Java files. It's really strange if it does not. Can it be that you tried it on non java files?

--
Dmitry Skavish
-- Posted by JetBrains OmniaMea

0
Comment actions Permalink

Hello Alain,

AR> I see no reason to not consider your plugin as the next version of
AR> LineMoverPlugin. You could simply publish it as the next version,
AR> and reuse the old default shortcuts.
AR> (the doc and source is on the wiki)

Well, thanks for the permission, I'll do that as soon as I get home :)

AR> Should the auto-indent be an annoyance in some cases - is it? - ,
AR> you could maybe add a config option.

May be I could, but IMHO it's overkill.

--
Dmitry Skavish
-- Posted by JetBrains OmniaMea

0
Comment actions Permalink

Same here, I use it a lot (and now that it also has indentation I'm gonna use it even more). It's definitelly something you'd expect in the core product.

Thanks for the enhancement.
Andrei

DG> Very nice. LineMover is the plugin I use most on a day-to-day
DG> basis, and the lack of auto-indent has always irked me.
DG>
DG> That said, I have absolutely no idea why this functionality isn't in
DG> the core product. IDEA has such nice line-based
DG>
DG> features already (Ctrl-D, Ctrl-Shift-J, etc.) that these seem like
DG> natural additions.
DG>
DG> --Dave Griffith
DG>

0
Comment actions Permalink

It is supposed to work with 4.0?

It works for me but it doesn't reindent after moving
the line, and I get this exception (with 1179):

java.lang.NoSuchMethodError:
com.intellij.openapi.editor.Editor.getProject()Lcom/intellij/openapi/project
/Project;
at
com.ravet.ideaplugins.linemover.BaseLineMover.indentLines(BaseLineMover.java
:94)
at
com.ravet.ideaplugins.linemover.LineDownMover$Handler.executeWriteAction(Lin
eDownMover.java:109)
at
com.intellij.openapi.editor.actionSystem.EditorWriteActionHandler$1.run(Edit
orWriteActionHandler.java)
at com.intellij.openapi.application.a.b.runWriteAction(b.java:299)
at
com.intellij.openapi.editor.actionSystem.EditorWriteActionHandler.execute(Ed
itorWriteActionHandler.java:5)
at
com.intellij.openapi.editor.actionSystem.EditorAction$1.run(EditorAction.jav
a)
at com.intellij.openapi.command.impl.a.executeCommand(a.java:94)
at
com.intellij.openapi.editor.actionSystem.EditorAction.actionPerformed(Editor
Action.java:19)
at
com.intellij.openapi.editor.actionSystem.EditorAction.actionPerformed(Editor
Action.java:24)
at com.intellij.openapi.a.a.d.a(d.java:59)
at com.intellij.openapi.a.a.d.b(d.java:25)
at com.intellij.openapi.a.a.d.a(d.java:2)
at com.intellij.ide.q.a(q.java:94)
at com.intellij.ide.q.dispatchEvent(q.java:48)
at
java.awt.EventDispatchThread.pumpOneEventForHierarchy(EventDispatchThread.ja
va:201)
at
java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java
:151)
at
java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:145)
at
java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:137)
at java.awt.EventDispatchThread.run(EventDispatchThread.java:100)

Thanks,

Vince.


0
Comment actions Permalink

Hey, thanks, it works great.

Another problem: if I move multiple lines (in java code) to a position which causes a syntax error, then the selection is lost. Here's how to reproduce it with the code shown below:

1) Select the two lines within the try block.
2) Move them up 1 line, so that they're located between the try and the opening brace.
3) IDEA recognizes this as a syntax error (as it should), but the selection is lost. Further attempts to move the block fail, and only a single line is moved.

0
Comment actions Permalink

line mover is also one of my most frequently used plugins...

but I also do not get the auto indenting:

-I am using 4.0.3 on WinXP
-I have removed the old plugin

Florian

0
Comment actions Permalink

Hello Vincent,

VM> It is supposed to work with 4.0?

Hmm, I guess it only works with latest EAP builds. I'll see what I can do later today. May be I can make it work with 4.0 as well.

--
Dmitry Skavish
-- Posted by JetBrains OmniaMea

0
Comment actions Permalink

Well, after much hair pulling I've determined that the key combination
CtrlShiftI doesn't work for me. I reassigned the Line Mover to
Ctrl+UpArrow and it works fine. Don't know why that certain combination
doesn't work. Doesn't even register if I try to set it to a 'command'.

"Dmitry Skavish (JetBrains)" <skavish@jetbrains.com> wrote in message
news:c83655$ppv$1@is.intellij.net...

Hello Vincent,

>

VM> It is supposed to work with 4.0?

>

Hmm, I guess it only works with latest EAP builds. I'll see what I can do

later today. May be I can make it work with 4.0 as well.
>

--
Dmitry Skavish
-- Posted by JetBrains OmniaMea



0
Comment actions Permalink

If you are on windows, you might want to verify that you don't have a desktop or quickstart icons with shortcut. They will take precedence over any application's.

Jacques

0
Comment actions Permalink

Do you know if there is a way to verify that? Just hitting CtrlShiftI
doesn't seem to do anything.

"Jacques Morel" <jacmorel@yahoo.com> wrote in message
news:17333794.1084563251497.JavaMail.itn@is.intellij.net...

If you are on windows, you might want to verify that you don't have a

desktop or quickstart icons with shortcut. They will take precedence over
any application's.
>

Jacques



0
Comment actions Permalink

How about ICQ?

Vince.


0
Comment actions Permalink

Nope, don't have it.

"Vincent Mallet" <xmalletva@tripos.com> wrote in message
news:c8395c$b47$1@is.intellij.net...

How about ICQ?

>

Vince.

>
>


0
Comment actions Permalink

Try assigning the shortcut to any desktop icon. Windows won't let you if it's already in use. It won't tell you who's using it, though, but that wouldn't be the first "surprise" you got from Windows, would it? :)

HTH,
Andrei

B> Do you know if there is a way to verify that? Just hitting
B> CtrlShiftI doesn't seem to do anything.
B>
B> "Jacques Morel" <jacmorel@yahoo.com> wrote in message
B> news:17333794.1084563251497.JavaMail.itn@is.intellij.net...
B>
>> If you are on windows, you might want to verify that you don't have a
>>
B> desktop or quickstart icons with shortcut. They will take precedence
B> over any application's.
B>
>> Jacques
>>

0
Comment actions Permalink

You could certainly provide two sets of actions that could be bound to keys: "Move line up and reindent" and "Move line up", and release this as the next LineMover. Then, everyone would be happy.

0
Comment actions Permalink

No, no, of course I did try with a java file!

0

Please sign in to leave a comment.