Aligning comments in Emacs
I want my per-line code comments to line up nicely, so I’ll often add a bunch of spaces by hand to make things just so. I realized that, being Emacs, there must be an easier way to handle this. Of course there is. Two minutes of searching revealed a short bit of lisp that does the job nicely: ;; Align comments in marked region ;; Via https://stackoverflow.com/a/20278032 (defun jab/align-comments (beginning end) "Align comments within marked region." (interactive "*r") (let (indent-tabs-mode align-to-tab-stop) (align-regexp beginning end (concat "\\(\\s-*\\)" (regexp-quote comment-start))))) Here’s an example of what I was working on, with horribly un-aligned comments. ...