Created
March 11, 2014 19:24
-
-
Save ydm/9493146 to your computer and use it in GitHub Desktop.
Align numeric sequences in Python programs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(defun align-numbers (start end) | |
(interactive "r") | |
(let* ((reg (buffer-substring-no-properties start end)) | |
(parts (mapcar #'y:string-strip (split-string reg ","))) | |
(widest (apply #'max (mapcar #'length parts))) | |
(full (mapcar (lambda (s) | |
(concat (make-string (- widest (length s)) ? ) s)) | |
parts)) | |
(line (mapconcat #'identity full ", "))) | |
(delete-region start end) | |
(insert-string line))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment