SlickEdit Product Discussion > Did you know?

Cut-line, Unsurround, Undo, paste, and surround

(1/1)

Dennis:
This is a pattern I find myself using frequently when I need to duplicate the logic found in an "if" or other block statement. 

Suppose you have some very contrived code like this:

--- Code: ---void generateDocComment(const string &author,
                        const string &since,
                        const string &brief_description,
                        const vector<string> &details,
                        const bool just_the_essentials /*= false*/)
{
    cout << "/**" << endl;
    cout << " * @brief" << endl;
    cout << " * " << brief_description << endl;
    if (just_the_essentials && author != "") {
        cout << " *" << endl;
        cout << " * @author " << author << endl;
    }
    cout << " *" << endl;
    cout << " * @details" << endl;
    for (const auto &line : details) {
       cout << " * " << line << endl;
    }
    cout << " *" << endl;
    cout << " * @since " << since << endl;
    cout << " */" << endl;
}

--- End code ---

And you realize that the "since" information shouldn't be there if it was blank or if they wanted just the essentials.

You can do this:

* put the cursor on the existing if statement and use cut-line (Ctrl+Backspace)
* You will get a dialog asking if you want to just delete the line, the entire block, or unsurround.
* Pick unsurround.
* Then hit Undo (Ctrl+Z)
* Then move down to the lines where the "since" block is printed.
* Paste (Ctrl+V)
* Because the clipboard is recognized as a statement shell, SlickEdit enters dynamic surround mode.
* Hit cursor-down twice to surround the next two statements.
* Fix the condition to check for (since != ""), and you are done.
It sounds more complicated than it is, but once you grow accustomed to it, it can be a time-saver.  In newer releases of SlickEdit, the first four steps can be compressed down to one step by using copy_to_clipboard (Ctrl+C) on the first line of the "if" statement and then selecting to copy the surrounding statement.

Navigation

[0] Message Index

Go to full version