Search code examples
cvisual-studio-2010code-formattingvisual-studio-macros

Need suggestions for method to format c comment via a keystroke macro


for visualization, pretend the '_' is actually a blank.

Consider the following

/*!
____This_is_a_comment_about_a_function
____and_its_purpose
____and_arguments
____and_things_of_that_ilk
*/

What I would like to do is select that chunk of text, press a button, and whammo! It is changed to this form.

/*!____________________________________
____This_is_a_comment_about_a_function_
____and_its_purpose____________________
____and_arguments______________________
____and_things_of_that_ilk_____________
_____________________________________*/

Why do I want this? The second form easies my eye strain when reviewing code. For me, it is enough of a problem that something should be done.

What have I tried so far? Mostly Googling for macro examples. Nothing has popped up which suggests a direction that might be productive. A bit of struggling to try to understand the macro ide. Some searching here on SO

What is my question?

Can you point me to links? Give me a hint? Take a guess? on what I need to study to figure out how to do this.

Thank you for your attention.

Evil.


Solution

  • Have you looked for macro examples of getting and replacing selected text using a macro, and the macro equivalent of string padding? I would think those three things could be combined, with a loop over each line to construct the final string to replace the original selection.

    Psuedocode:

    selText = getSelectedText();
    selTextSplit = selText.split("\n");
    selTextPadded = "";
    for (i = 0; i < selTextSplit.length; i++) {
        selTextPadded += selTextSplit[i].padRight(80, ' ') + "\n";
    }
    replaceSelectedText(selTextPadded);