emacs string-insert-rectangle vector of numbers?

后端 未结 4 1286
萌比男神i
萌比男神i 2020-12-28 11:12

How can I use emacs string-insert-rectangle operation to add a vector of numbers to a series of lines? For example, I\'ve got this shortened version of a bunch of text entri

4条回答
  •  庸人自扰
    2020-12-28 11:36

    This is a way to do it in emacs, unfortunately, this approach doesn't use string-insert-rectangle. Also, this approach rudely assumes there are more than 10 characters on every line. Hilarity will ensue if that's not the case. M-x doit will invoke it.

    (defun doit ()
      (interactive)
      (save-excursion
        (beginning-of-buffer)
         (let ((n 1))
          (while (< (point) (point-max))
            (forward-char 10)
            (insert "id" (int-to-string n) " ")
            (end-of-line)
            (forward-line)
            (incf n)))))
    

提交回复
热议问题