help-gnu-emacs
[Top][All Lists]
Advanced

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

Re: emacs insert icrement numbers


From: Bill Wohler
Subject: Re: emacs insert icrement numbers
Date: Tue, 22 Aug 2006 17:37:10 -0700
User-agent: Gnus/5.11 (Gnus v5.11) Emacs/22.0.50 (gnu/linux)

Step0ut <step0ut@yahoo.gr> writes:

> Is it possible to insert numbers that increament in each line?

Here's some lisp I wrote to do this 20 years ago which I still use today...

(defun bw-inc-column (column start inc begin end)
  "Increment the numbers in a column.
The numbers are created in COLUMN and start with number START and are
incremented by INC in the region.
In programs, the region is defined by BEGIN and END.
Note that the columns are basically defined by `forward-word' so any space or
punctuation character will split columns."
  (interactive "nColumn: \nnStart: \nnIncrement: \nr")
  (save-restriction
    (save-excursion
      (narrow-to-region begin end)
      (goto-char (point-min))
      (let ((n start))
        (while (< (point) (point-max))
          (beginning-of-line)
          (forward-word column)
          (forward-word -1)
          (let ((begin (point)))
            (forward-word 1)
            (delete-region begin (point))
            (message (format "n=%d" n))
            (insert (int-to-string n)))
          (setq n (+ n inc))
          (forward-line 1))))))
-- 
Bill Wohler <wohler@newt.com>  http://www.newt.com/wohler/  GnuPG ID:610BD9AD





reply via email to

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