如何使用 elisp 在当前缓冲区中插入一个字符串作为新行

How to insert a string as a new line in current buffer using elisp

有插入功能,没有插入行功能。我需要的是插入一行“commit;”当前缓冲区中每 1000 行。所以我需要循环然后需要一些像

这样的函数
(insert-line 1000 "commit;")

这是一个非常基本的版本:

(defun insert-lines (skip text)
  "Insert `text' every `skip' lines."
  (while (zerop (forward-line skip))
    (insert text)))

您可以将它与 M- 一起使用:(插入第 10 行 "commit;\n")RET.

你可以自己添加花里胡哨的东西,比如interactive and save-excursion