<html><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space; "><div>I have written a command to "Reflow comments" in my Stata do files. The command is as follows:</div><br><div><div>#!/usr/bin/env bash</div><div><div><br></div><div><font class="Apple-style-span" face="'Andale Mono'">sed -E -e 's_^\s*//(.*)_\1_' |   # strip leading // and whitespace from each line</font></div><div><font class="Apple-style-span" face="'Andale Mono'">fmt |                            # reflow comment text</font></div><div><font class="Apple-style-span" face="'Andale Mono'">sed -E -e 's_^(.*)_//\1_'        # prefix each line with //</font></div><div><br></div><div>Input is set to "Selected Text" or "Scope", and output is set to "Replace selected text".</div><div><br></div></div></div><div>If I invoke the command with the cursor in the middle of the following comment:</div><div><br></div><div><div><font class="Apple-style-span" face="'Andale Mono'">// this is a profoundly silly comment that I'm writing just to test out how to reflow comments</font></div><div><font class="Apple-style-span" face="'Andale Mono'">// something strange happens when I select the text rather than simply execute it within the comment scope</font></div><div><font class="Apple-style-span" face="'Andale Mono'">// i wonder what's going on</font></div><div><font class="Apple-style-span" face="'Andale Mono'">// maybe i'll write to the mailing list</font></div><div><br></div><div>I get the desired output:</div><div><br></div><div><div><font class="Apple-style-span" face="'Andale Mono'">// this is a profoundly silly comment that I'm writing just to test out how to</font></div><div><font class="Apple-style-span" face="'Andale Mono'">// reflow comments something strange happens when I select the text rather</font></div><div><font class="Apple-style-span" face="'Andale Mono'">// than simply execute it within the comment scope i wonder what's going on</font></div><div><font class="Apple-style-span" face="'Andale Mono'">// maybe i'll write to the mailing list</font></div><div><br></div></div></div><div>However, if I instead select the entire block of text, I get the following mangled result:</div><div><br></div><div><div><font class="Apple-style-span" face="'Andale Mono'">// this is a profoundly silly comment that I'm writing just to test out how to</font></div><div><font class="Apple-style-span" face="'Andale Mono'">reflow comments // something strange happens when I select the text rather than</font></div><div><font class="Apple-style-span" face="'Andale Mono'">simply execute it within the comment scope // i wonder what's going on // maybe</font></div><div><font class="Apple-style-span" face="'Andale Mono'">i'll write to the mailing list</font></div></div><div><br></div><div>Can anyone explain what causes the differing behavior?</div><div><br></div><div>Thanks!</div><div><br></div><div>Michael Manti</div><div><a href="mailto:statboy3000@gmail.com">statboy3000@gmail.com</a></div></body></html>