title: How to automatically align comments in different pieces of code?
body: <p>I have to do a very specific task to re-do over and over again and would like to have it put permanently in my <code>.emacs</code> file. But I am not versed enough in emacs-lisp to manage it:</p>
  
  <ul>
  <li>Keystroke-1, say <code>[F8]</code>
  <ul>
  <li>remember the current cursors' column position in, say, <code>xtab</code></li>
  </ul></li>
  <li>Keystroke-2, say <code>[F9]</code> while cursor is in some other line:
  <ul>
  <li>find leftmost string <code>//</code> in current line, if none is there, beep and stop</li>
  <li>insert as many spaces so the <code>//</code> gets to previously remembered column <code>xtab</code>, or do nothing if cursor is already beyond <code>xtab</code></li>
  <li>search-forward for next <code>//</code> and place the cursor on it</li>
  </ul></li>
  </ul>
  
  <p>I managed to assign it to a temporary keyboard macro, but have to re-record it for every changing <code>xtab</code> value.</p>
  
  <p>The ultimate goal is that I want to align the comments in different pieces of code easily, from</p>
  
  <pre><code>int main() {     // the enty function
      int x = 100; // my new variable
      for(int i=1; i&lt;2012; ++i) { // loop a lot
          x -= i;
      } 
  } // end of all things
  </code></pre>
  
  <p>to</p>
  
  <pre><code>int main() {                    // the entry function
      int x = 100;                // my new variable
      for(int i=1; i&lt;2012; ++i) { // loop a lot
          x -= i;
      } 
  }                               // end of all things
  </code></pre>
  
  <p>Any idea how I can automate this? What do I have to put in my <code>.emacs</code>-file to archive this -- or similar?</p>