How could you get emacs to write line numbers to a file?
3 answers
Here's a quick elisp function that does it:
(defun write-line-numbers (n) (interactive "nNumber of lines: ") (save-excursion (with-output-to-temp-buffer "*lines*" (dotimes (line n) (princ (format "%d\n" (1+ line)))) (set-buffer "*lines*") (write-file "lines.txt"))))
You run it with (write-line-numbers 8)
elisp or with M-x write-line-numbers 8interactive mode.
Or you can save the above as a script and run emacs like this:
emacs -Q --script write-line-numbers.el --eval '(write-line-numbers 8)'
But as Moritz points out, there are better ways to do this outside of emacs.
+5
source to share
M-: (c-temp-file "foo.txt" (dotimes (i 15) (insert (format "% 2d \ n" (1+ i)))))
If you do this often enough, make it a function:
(defun write-sequence (length output-file) (interactive "nLength of sequence: \nFOutput file: ") (with-temp-file output-file (dotimes (i length) (insert (format "%d\n" (1+ i))))))
+1
source to share