NuSphere Forums Forum Index
NuSphere Forums
Reply to topic
Swap lines Editor command


Joined: 08 Mar 2006
Posts: 63
Reply with quote
Two really useful editor commands present in some editors are Swap lines. These exist in Eclipse and Emacs, and can be emulated with a little scripting in some others. They work like this:

Swap line up: The line containing the cursor is swapped with the line above. The cursor position is moved along, and thus remains in the same textual position as before.

Swap line down: The same, but the current line is swapped with the line below.

These commands are, when bound to suitable keys, very handy to e.g. reorder variable declarations or assignment blocks.

I don't think PhpED already has these, but I could have missed them. If so, please let me know where to find these commands so I can start using them right away Smile
View user's profileFind all posts by svenaxSend private message
Veteran

Joined: 24 Jan 2006
Posts: 311
Reply with quote
Hi Sven, no PhpED doesn't have it yet. How about writing a script doing it and calling it from tools->integration Wink
Thanks for the awsome post on PhpED for windows forum!
View user's profileFind all posts by yfaktorSend private message


Joined: 08 Mar 2006
Posts: 63
Reply with quote
Well, I would if I could, but that is something which unfortunately cannot be done without real scripting support. But here's a Python script for ActiveState Komodo that does this Wink

Swap line up
Code:
komodo.editor.beginUndoAction()
try:
    if komodo.view: komodo.view.setFocus()
    col = komodo.editor.getColumn(komodo.editor.currentPos)
    line = komodo.editor.lineFromPosition(komodo.editor.currentPos)
    komodo.editor.lineTranspose()
    pos = komodo.editor.positionFromLine(line-1) + col
    komodo.editor.setSel(pos, pos)
finally:
    komodo.editor.endUndoAction()


Swap line down
Code:
komodo.editor.beginUndoAction()
try:
    if komodo.view: komodo.view.setFocus()
    col = komodo.editor.getColumn(komodo.editor.currentPos)
    line = komodo.editor.lineFromPosition(komodo.editor.currentPos)
    komodo.editor.lineDown()
    komodo.editor.lineTranspose()
    pos = komodo.editor.positionFromLine(line+1) + col
    komodo.editor.setSel(pos, pos)
finally:
    komodo.editor.endUndoAction()
View user's profileFind all posts by svenaxSend private message
Swap lines Editor command
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
All times are GMT - 5 Hours  
Page 1 of 1  

  
  
 Reply to topic