Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Emacs: print with line numbers

Tags:

emacs

printing

Does anyone know how to print with the line numbers of the code in the margin? I can display the line number, cannot have that in the printout. Thanks!

like image 355
Chris Avatar asked Jan 14 '23 21:01

Chris


1 Answers

You can add the line numbers with temporary overlays and convert the buffer to HTML using the htmlize package, after which you can save the HTML and print using lpr or a browser.

(defun htmlize-with-line-numbers ()
  (interactive)
  (goto-char (point-min))
  (let ((n 1))
    (while (not (eobp))
      (htmlize-make-tmp-overlay (point) (point) `(before-string ,(format "%4d " n)))
      (setq n (1+ n))
      (forward-line 1)))
  (switch-to-buffer (htmlize-buffer)))

This will require a recent version of htmlize.

like image 104
user4815162342 Avatar answered Jan 22 '23 09:01

user4815162342