;;; ess-r-a.el -- Possible local customizations for R with ESS.12;; Copyright (C) 1997--2005 A.J. Rossini, Richard M. Heiberger, Martin3;; Maechler, Kurt Hornik, Rodney Sparapani, and Stephen Eglen.45;; Author: A.J. Rossini <[email protected]>6;; Created: 17 November 19997;; Maintainer: ESS-core <[email protected]>89;; Keywords: languages1011;; This file is part of ESS1213;; This file is free software; you can redistribute it and/or modify14;; it under the terms of the GNU General Public License as published by15;; the Free Software Foundation; either version 2, or (at your option)16;; any later version.17;;18;; This file is distributed in the hope that it will be useful,19;; but WITHOUT ANY WARRANTY; without even the implied warranty of20;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the21;; GNU General Public License for more details.22;;23;; A copy of the GNU General Public License is available at24;; http://www.r-project.org/Licenses/2526;;; Commentary:2728;; The purpose of this file is to demonstrate some of the extras that29;; have been constructed for the ESS R mode; if they prove30;; interesting, then they might be migrated to ess-r-d, the primary31;; ESS R mode tools.3233;;; Code:3435;; you can invoke ESS/R from emacs by typing36;; C-u M-x essr37;; with vsize set to (for example) 40M, and nsize set to 600000.38(defalias 'essr39(read-kbd-macro40"C-u M-x R RET - - vsize = 40M SPC - - nsize = 600000 2*RET"))4142(defun ess-r-do-region (start end &optional message)43"Send the current region to R via AppleScript."44(interactive "r\nP")45(message "Starting evaluation...")46(do-applescript (concat47"try\n"48"tell application \"R\"\n"49"activate\n"50"with timeout of 0 seconds\n"51"cmd \"" (buffer-substring start end)52"\"\n"53"end timeout\n"54"end tell\n"55"end try\n"))56(message "Finished evaluation"))5758(defun ess-r-do-line ()59"Send the current line to R via AppleScript."60(interactive) ;; "r\nP")61(message "Starting evaluation...")62(save-excursion63(let ((end (point)))64(move-to-column 0)65(do-applescript (concat66"try\n"67"tell application \"R\"\n"68"activate\n"69"with timeout of 0 seconds\n"70"cmd \"" (buffer-substring (point) end)71"\"\n"72"end timeout\n"73"end tell\n"74"end try\n"))))75(message "Finished evaluation"))7677(defun ess-r-var (beg end)78"Load the current region of numbers into an R variable. Prompts for79a variable name. If none is given, it uses a default variable name,80e. BEG and END denote the region in the current buffer to be sent."81(interactive "r")82(save-window-excursion83(let ((tmp-file (make-temp-file "ess-r-var"))84cmd85var)86(write-region beg end tmp-file)8788;; Decide on the variable name to use in R; could use completion.89(setq var (read-string "R Variable name (default e): "))90(if (equal var "")91(setq var "e"))9293;; Command to send to the R process. Get R to delete the file94;; rather than Emacs in case it takes R a long time to run the95;; scan command.96(setq cmd (concat var " <- scan(\"" tmp-file "\"); "97"unlink(\"" tmp-file "\")" ))9899;; Put the output from the scan command into the process buffer so100;; the user has a record of it.101(ess-execute cmd 'buffer))))102103104;;; Peter Dalgaard's code.105;;; This needs to be cleaned and validated!106107(defun pd::set-up-demo ()108109;; (if (not xemacs) (set-default-font "*courier-bold-r*--14**"))110(R)111(split-window-vertically 6)112(find-file "demos.R")113114;; Don't need to run this as a function -- ought to be fine if set115;; just once.116117(defun ajr::scroll-to-end::peterD (emacs)118"Goal: map prompt to bottom of the screen after every command.119Alternatively, use the scroll-in-place package, not sure where that120is)."121(interactive)122(other-buffer 1)123(if (= emacs "emacs")124(setq scroll-up-aggressively t)125(setq scroll-conservatively -4)) ;; <- change this126(other-buffer -1))127128(defun show-max-other-window ()129(interactive)130(other-window 1)131(comint-show-maximum-output)132(other-window -1))133134;; call this once135;; (ajr::scroll-to-end::peterD "xemacs")136;; (ajr::scroll-to-end::peterD "emacs")137138(global-set-key [f11] 'show-max-other-window)139(global-set-key [f12] 'ess-eval-line-and-step))140141142; Provide package143144(provide 'ess-r-a)145146; Local variables section147148;;; This file is automatically placed in Outline minor mode.149;;; The file is structured as follows:150;;; Chapters: ^L ;151;;; Sections: ;;*;;152;;; Subsections: ;;;*;;;153;;; Components: defuns, defvars, defconsts154;;; Random code beginning with a ;;;;* comment155156;;; Local variables:157;;; mode: emacs-lisp158;;; outline-minor-mode: nil159;;; mode: outline-minor160;;; outline-regexp: "\^L\\|\\`;\\|;;\\*\\|;;;\\*\\|(def[cvu]\\|(setq\\|;;;;\\*"161;;; End:162163;;; ess-r-a.el ends here164165166