Skip to content

Instantly share code, notes, and snippets.

@ydm
Created March 11, 2014 19:24
Show Gist options
  • Save ydm/9493146 to your computer and use it in GitHub Desktop.
Save ydm/9493146 to your computer and use it in GitHub Desktop.
Align numeric sequences in Python programs
(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