A simple but hacky way, of course, would be to temporarily paste line numbers directly into the buffer
C-< CM-% ^ RET \,(1+ \
then print it
Mx print-buffer
and then cancel the line numbers again:
C-/ Cu C-SPC
The result is not very beautiful, but useful. There are three main problems:
- You are making changes to the buffer. In particular, this means that the buffer should not be read-only.
- line numbers are left-justified, which means that you get different indentation depending on the number of digits of the line number.
- your main mode will turn off line numbers and you will lose syntax highlighting. If you are printing on a black and white printer, this is not a problem.
You can fix the second point using a more complex replacement string:
\,(format "%4d " (1+ \
but then you should know what is the maximum line number, so you can specify the correct number of digits between % and d . Of course, you can just quickly jump to the end of the buffer to check the maximum line number. But more importantly, it becomes painful to print all this every time you want to print line numbers.
source share