Put semicolon at the end of line


I was trying to use simple function, that I found very usable - to put missing semicolon on the end of the line. I tried to prepare a macro for that. I'm just missing one feature - I would like to have my cursor on same position after using the macro. Whenever I hit my macro shortcut, just the semicolon on the end would be added. Is there any way how to influence that macro? Could someone help?

Comment actions Permalink

Hmm... I'd use navigation history back command but it is not affected by normal caret movement.. So no idea.
What is your use case? May be we can figure some other solution..
Also related: http://youtrack.jetbrains.net/issue/WI-76

Comment actions Permalink

For example, when writing something like

if ($something !=) {
     $result = $object->someMethod($another->anotherMethod());

when writing the if block, I start with "$result = $object->someMethod()", which I get autocompleted. Then I start to finish expression within the brackets "$another->anotherMethod()", still with no semicolon at the end. After that I realize, that the condition is wrong, so I jump and correct the condition - with missing semicolon on next line.

I guess this is really individual, but I found the way "move down + press shorcut" better than "move down, move to the end, write semicolon". When not using mouse, its faster. But as I say - its individual.

It would be enough to have an option to "remember and can use caret position" in macro, that would be enough for me. You know - "Trifles make perfection, but perfection is no trifle."

BTW: I found this in NetBeans

Comment actions Permalink

I understand your pursuit of perfection.
Please file a feature request for macro save/restore caret position, It may be useful in many cases anyway...

As for this specific usecase - how about finishing completion with ";" - this will both insert selected variant and a typed character.
Also, for "move to the end" you don't need to use mouse - just use the End key.

Comment actions Permalink

Nobody's perfect. If I'm, I won't need this :-)

Thanks for tips, but these solve only that given example. In real there could be more examples of that (I mean of me forgetting to put semicolon on the end of line) . And I repeat - it's not problem of the editor, it's my problem. I'm just looking for a way how to make my job comfortable. As you say, saving/restoring caret position could be used in many ways...

Feature requested (http://youtrack.jetbrains.net/issue/WI-2384?projectKey=WI)

Thanks for help

Comment actions Permalink

I often want to do the same thing.  I have found the following pattern useful:
1.  Start the macro by hitting enter to create a new line.
2.  Do your work on the new line.
3.  Finish the macro by joining the two lines back together again, leaving the cursor at the same position as when the macro started.

Here is an example of how I append a semicolon:


Comment actions Permalink
ctrl + shift + enter if I want to add the semi-colon at the end of a statement;

Please sign in to leave a comment.