Skip to content

Instantly share code, notes, and snippets.

@ctipper
Last active June 25, 2017 12:26
Show Gist options
  • Save ctipper/d2210b252615e427497298068c181bbb to your computer and use it in GitHub Desktop.
Save ctipper/d2210b252615e427497298068c181bbb to your computer and use it in GitHub Desktop.
Fix emacs 25 ps-print-buffer with own routine

Emacs 25 does not print visual-line-mode correctly words are split at the page boundary. This fixes it, I recommend installing it to local site-lisp and referencing from init. Maybe you will need to install longlines-mode.

The inspiration is a post about rendering to pdf at https://stackoverflow.com/q/7442100

(eval-when-compile
;; silence the old byte-compiler
(defvar byte-compile-dynamic nil)
(set (make-local-variable 'byte-compile-dynamic) t))
(defun harden-newlines ()
(interactive)
"Make all the newlines in the buffer hard."
(save-excursion
(goto-char (point-min))
(while (search-forward "\n" nil t)
(backward-char)
(put-text-property (point) (1+ (point)) 'hard t)
(forward-char))))
(defun spool-buffer-given-name (name)
(let ((ps-left-header (list (format "(%s)" name))))
(ps-spool-buffer-with-faces)))
(defun my-spool-buffer ()
"Print the current file to PS printer"
(interactive)
(let ((wbuf (generate-new-buffer "*Wrapped*"))
(sbuf (current-buffer)))
(jit-lock-fontify-now (point-max))
(save-current-buffer
(set-buffer wbuf)
(insert-buffer-substring sbuf)
(setq fill-column 80)
(longlines-mode t)
(harden-newlines)
(message (buffer-name sbuf))
(spool-buffer-given-name (buffer-name sbuf))
(kill-buffer wbuf)
(switch-to-buffer "*PostScript*")
(ps-despool))
))
(provide 'my-spool-buffer)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment