I'm running Emacs 23.0.60.1, downloaded from here, on Windows XP, with a network printer configured as the default printer.
How do I setup Emacs to easily print buffer contents?
The documentation of the patched Emacs version for Win32 mentions "quick and easy" printing, but the "Quick Print" menu entry does not appear and the regular entries ("Print Buffer", "Postscript Print Buffer") don't seem to do anything.
EDIT:
I'm having the same issue with the official windows build of Emacs 22.3. Therefore setup/troubleshooting instructions for any version would be appreciated.
EDIT2:
I went with the PrintFile solution presented by Joe Casadonte below, which works nicely. I'd still be interested in any ideas why the "proper" way is not working, though.
(By the way, is this an appropriate SO question, being only marginally programming related?)
I will describe everything for Windows 7 with a common USB Printer. Adapt the process where needed to your version. Network can usually be accessed the same way. Just use //NetworkComputerName/SharedPrinterName
instead of //MyComputer/MyPrinter and skip steps 1.-6..
MyPrinter
or something that you can remember and has no spaces. MyComputer
)(setq printer-name "//MyComputer/MyPrinter")
or put it in your .emacs.el fileM-x print-buffer
It's not the "proper" way, but I've been doing it this way for years and it works wonderfully. I use PrintFile, a freeware print program (which can also be used stand-alone). Then I have this in my .emacs:
(defun joc-make-fname-from-buffer-name (buffer-name-in)
"Returns a valid filename from a given buffer name"
(interactive "b")
(save-match-data
(let* ((start (string-match "[^ \*]" buffer-name-in))
(end (string-match "[ \*]*$" buffer-name-in (match-end 0)))
(rc (substring buffer-name-in start end)))
;; remove some special characters
(while (string-match "[:]+" rc)
(setq rc (replace-match "_" t t rc)))
rc)))
(when is-win32
(defun joc-print-buffer-or-region (prefix)
"Prints buffer or region via PrintFile32. If a prefix arg is set (via C-u) then
the current region is printed, otherwise the current buffer is printed."
(interactive "P")
;; ----- set the print directory, fname and args -----
(let* ((print-dir (expand-file-name "~/emacs/print"))
(print-fname (joc-make-fname-from-buffer-name (buffer-name)))
(print-fullpath (concat print-dir "/" print-fname))
(print-args "/delete")
;; ----- set rstart and rend to the current region -----
(rstart (point-min)) (rend (point-max)))
;; ----- if prefix given, set them to region -----
(if (and prefix)
(if (and (point) (mark) (/= (point) (mark)))
(progn (setq rstart (min (point) (mark)))
(setq rend (max (point) (mark))))
(error "No region defined")))
;; ----- make the directory -----
(if (not (file-directory-p print-dir))
(make-directory print-dir))
;; ----- write buffer/region to a temp file, print it, delete directory -----
(write-region rstart rend print-fullpath)
(call-process "prfile32" nil t nil print-args print-fullpath)
(delete-directory print-dir))))
I haven't looked at it in years cause it just works, so I'm sure it could be improved.
add the following line to your emacs init file
(setq printer-name "//domain/printer-name")
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With