[ESS] Printing *R* help pages within Emacs using doc-view

Steven McKinney smckinney at bccrc.ca
Thu Jul 26 20:48:09 CEST 2012


Very nice Stephen,

Looking forward to having this capability.

On my Mac running OSX 10.6.8 (Snow Leopard) with R-2.15.1 I get
a minibuffer message

let: Symbol's value as variable is void: ess-help-object

so the code below needs some kind of modification for Apple's
flavour of Unix.

Steven McKinney
________________________________________
From: ess-help-bounces at r-project.org [ess-help-bounces at r-project.org] On Behalf Of Stephen Eglen [S.J.Eglen at damtp.cam.ac.uk]
Sent: July 26, 2012 2:13 AM
To: ESS-help at r-project.org
Cc: Stephen Eglen
Subject: [ESS] Printing *R* help pages within Emacs using doc-view

Dear all,

Here's some proof of concept code to solve the following problem for
me.  If you'd like to see it in ESS, let me know, and if I get
sufficient feedback, I'll tidy it up and put it in.

Unix only for now.

If you are viewing a R help page in ESS, e.g. "rnorm", then if you hit
the P key, a few seconds later, you should see /tmp/rnorm.pdf opened,
which should render nicely thanks to doc-view.  Then within doc-view,
hit ! to send the PDF to a printer.  This is the only line you'll need
to configure/edit:


(setq sje-doc-view-pdf-lpr-command "lpr -Pg0 %s")  ;; docstring below

You'll need a unix command to print a pdf; our local printers can print
a pdf using a command like:

$ lpr -Pg0 /tmp/rnorm.pdf

If your printer doesn't accept pdf directly, you'll need to change it to
something else.  "g0" is the name of my local printer.  It won't print
automatically, when you hit ! you get the chance to edit the command
sent.

I've put the pdf in /tmp as I don't like them accummulating in the *R*
current working directory.

Feedback welcome!

Stephen

p.s. the code for printing pdf from doc-view is independent of ESS.

----------------------------------------------------------------------
(defun ess-r-help-pdf ()
  (interactive)
  (let
      ((cmd (format "help(%s, help_type='pdf')\n" ess-help-object))
       (pdf (format "%s.pdf" ess-help-object))
       (newpdf (format "/tmp/%s.pdf" ess-help-object))
       )
    (ess-command cmd)
    (rename-file pdf newpdf 'overwrite)
    (find-file newpdf)))


(add-hook 'ess-help-mode-hook
          '(lambda ()   (local-set-key "P" 'ess-r-help-pdf)))


;;; Now set up doc-view for printing.
(defun sje-doc-view-pdf-lpr ()
  "Send current PDF to the default printer.
The default printer command is set by `sje-doc-view-pdf-lpr-command'."
  (interactive)
  (let ((cmd (format sje-doc-view-pdf-lpr-command (buffer-file-name))))
    (shell-command
     (read-string (format "Print command (default %s): " cmd) nil nil cmd))))

;; g0 is my default printer.
(defvar sje-doc-view-pdf-lpr-command "lpr -Pg0 %s"
  "Print command to use to send a pdf to the printer.  %s will
get expanded to the name of the file associated with the current
buffer.")

(add-hook 'doc-view-mode-hook
          '(lambda ()   (local-set-key "!" 'sje-doc-view-pdf-lpr)))

______________________________________________
ESS-help at r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/ess-help



More information about the ESS-help mailing list