emacs-jupyter/jupyter-R.el

64 lines
2.2 KiB
EmacsLisp
Raw Permalink Normal View History

2019-04-12 06:56:20 -07:00
;;; jupyter-R.el --- Jupyter support for R -*- lexical-binding: t -*-
2020-04-07 15:13:51 -05:00
;; Copyright (C) 2019-2020 Nathaniel Nicandro
2019-04-12 06:56:20 -07:00
2020-03-10 22:16:04 +09:00
;; Author: Jack Kamm <jackkamm@gmail.com>
;; Nathaniel Nicandro <nathanielnicandro@gmail.com>
2019-04-12 06:56:20 -07:00
;; This program is free software; you can redistribute it and/or
;; modify it under the terms of the GNU General Public License as
2019-05-31 09:44:39 -05:00
;; published by the Free Software Foundation; either version 3, or (at
2019-04-12 06:56:20 -07:00
;; your option) any later version.
;; This program is distributed in the hope that it will be useful, but
;; WITHOUT ANY WARRANTY; without even the implied warranty of
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
;; General Public License for more details.
;; You should have received a copy of the GNU General Public License
;; along with GNU Emacs; see the file COPYING. If not, write to the
;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
;; Boston, MA 02111-1307, USA.
;;; Commentary:
;; Support methods for integration with R.
;;; Code:
(require 'jupyter-repl)
(require 'jupyter-org-client)
(require 'jupyter-mime)
(defvar ess-font-lock-keywords)
2019-04-12 06:56:20 -07:00
(cl-defmethod jupyter-repl-initialize-fontification (&context (jupyter-lang R))
(when (featurep 'ess)
(setq-local ess-font-lock-keywords 'ess-R-font-lock-keywords))
2019-04-12 06:56:20 -07:00
(cl-call-next-method))
(cl-defmethod jupyter-org-result ((_mime (eql :text/html)) content params
&context (jupyter-lang R))
2019-04-28 13:12:23 -07:00
"If html DATA is an iframe, save it to a separate file and open in browser.
Otherwise, parse it as normal."
(if (plist-get (plist-get content :metadata) :isolated)
(let* ((data (plist-get content :data))
(file (or (alist-get :file params)
(jupyter-org-image-file-name data ".html"))))
2019-04-12 06:56:20 -07:00
(with-temp-file file
(insert data))
(browse-url-of-file file)
(jupyter-org-file-link file))
2019-04-28 13:12:23 -07:00
(cl-call-next-method)))
2019-04-12 06:56:20 -07:00
(cl-defmethod jupyter-insert ((_mime (eql :text/html)) data
&context (jupyter-lang R)
&optional metadata)
(if (plist-get metadata :isolated)
(jupyter-browse-url-in-temp-file data)
(cl-call-next-method)))
2019-04-12 06:56:20 -07:00
(provide 'jupyter-R)
;;; jupyter-R.el ends here