001: ; * insert-linenum
002: ; 行番号を挿入します。
003: (defun insert-linenum (firstcolumn num)
004: "Insert numbers in the region"
005: (interactive
006: "n行番号の挿入位置(行頭は1, 0なら文頭指定): ¥nn行番号の初期値: ")
007: (let
008: (startposition endposition startline lastline cline lnum)
009: ; (setq firstcolumn (+ firstcolumn 1))
010: (setq startposition (region-beginning))
011: (setq endposition (region-end))
012: (setq startline (count-lines 1 startposition))
013: (setq lastline (count-lines 1 endposition))
014: (setq lnum (+ (- lastline startline) num 1))
015: (goto-char startposition)
016: (if (= firstcolumn 0)
017: (progn
018: (back-to-indentation)
019: (setq firstcolumn (+ (current-column) 1))
020: ))
021: (goto-char startposition)
022: (setq cline startline)
023: (while (< cline lastline)
024: (beginning-of-line)
025: (if (> firstcolumn 0)
026: (forward-char (- firstcolumn 1)))
027: (insert (format nil "~3,'0D: " num))
028: (setq num (+ num 1))
029: (setq cline (+ cline 1))
030: (forward-line 1))
031: ))