(defun generate-sequence-and-insert (prefix suffix width start end step)
"生成指定格式的数字序列并插入到当前行的行首。
参数:
PREFIX: 前缀字符串
SUFFIX: 后缀字符串
WIDTH: 数字位数(用0补足)
START: 起始数字
END: 终止数字
STEP: 步长
示例: (generate-sequence-and-insert \"w\" \"m\" 2 3 21 3)
在当前行的行首分别插入: w03m, w06m, w09m, w12m, w15m, w18m, w21m"
(interactive "s前缀: \ns后缀: \nn位数: \nn起始数字: \nn终止数字: \nn步长: ")
(save-excursion
(let ((current start))
;; 移动到当前行的行首
(beginning-of-line)
(while (<= current end)
(let ((padded-number (format (concat "%0" (number-to-string width) "d") current)))
;; 在当前行的行首插入序列项
(insert prefix padded-number suffix)
;; 移动到下一行的行首
(forward-line 1)
(beginning-of-line)
(setq current (+ current step)))))))
(global-set-key (kbd "C-c s") 'generate-sequence-and-insert)