;;; -*- lexical-binding: t -*- ;; ;; this file: ;; https://dataswamp.org/~incal/emacs-init/enum.el (require 'cl-lib) (require 'dwim) (require 'subr-x) (defun enum (&optional beg end) "Enumerate each line from BEG to END, counting from one. Use SUF as a suffix to the digits inserted. BEG defaults to the beginning of the buffer, END defaults to the end of the buffer," (interactive (use-region)) (unless beg (setq beg (point-min))) (unless end (setq end (point-max))) (goto-char beg) (let*((lns (count-lines beg end)) (pad (length (number-to-string lns)))) (cl-loop for line from 1 to lns do (goto-char (pos-bol)) (insert (format "%s%s" (string-pad (number-to-string line) pad nil t) ". ")) (forward-line)))) (provide 'enum)