[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: enum

From: Emanuel Berg
Subject: Re: enum
Date: Thu, 08 Sep 2022 06:50:23 +0200
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/29.0.50 (gnu/linux)

;;; -*- lexical-binding: t -*-
;; this file:
;;   https://dataswamp.org/~incal/emacs-init/enum.el

(require 'cl-lib)
(require 'subr-x)

(defun enum (&optional beg end suf)
  "Enumerate each line counting from one from BEG to END.
Use SUF as a suffix to the digits inserted.
BEG defaults to the beginning of the buffer,
END to the end of it; and
SUF to \". \""
   `(,@(if (region-active-p)
           (list (region-beginning) (region-end))
         (list nil nil) )
     ,(when current-prefix-arg
        (read-string "suffix: ") )))
  (or beg (setq beg (point-min)))
  (or end (setq end (point-max)))
  (or suf (setq suf ". "))
  (goto-char beg)
  (let*((lines   (count-lines beg end))
        (pad-len (length (number-to-string lines))) )
      for line from 1 to lines do
      (goto-char (line-beginning-position))
       (format "%s%s" (string-pad (number-to-string line) pad-len nil t) suf) )
      (forward-line) )))

underground experts united

reply via email to

[Prev in Thread] Current Thread [Next in Thread]