~ubuntu-branches/ubuntu/edgy/ess/edgy

« back to all changes in this revision

Viewing changes to lisp/essa-r.el

  • Committer: Bazaar Package Importer
  • Author(s): Camm Maguire
  • Date: 2005-03-22 13:48:07 UTC
  • mfrom: (1.2.1 upstream) (2.1.2 hoary)
  • Revision ID: james.westby@ubuntu.com-20050322134807-9mpmbb799jugf248
Tags: 5.2.6-1
* New upstream release
* chmod -R u+w on orig source

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
;;; essa-r.el -- Possible local customizations for R with ESS.
2
2
 
3
 
;; Copyright (C) 1997--2000     A.J. Rossini, Martin Maechler,
4
 
;;                              Kurt Hornik, and Richard M. Heiberger.
 
3
;; Copyright (C) 1997--2004 A.J. Rossini, Rich M. Heiberger, Martin
 
4
;;      Maechler, Kurt Hornik, Rodney Sparapani, and Stephen Eglen.
5
5
 
6
 
;; Author: A.J. Rossini <rossini@biostat.washington.edu>
7
 
;; Maintainer: A.J. Rossini <rossini@biostat.washington.edu>
 
6
;; Original Author: A.J. Rossini <rossini@u.washington.edu>
8
7
;; Created: 17 November 1999
9
 
;; Modified: $Date: 2001/12/27 23:31:19 $
10
 
;; Version: $Revision: 1.5 $
11
 
;; RCS: $Id: essa-r.el,v 1.5 2001/12/27 23:31:19 ess Exp $
 
8
;; Maintainers: ESS-core <ESS-core@stat.math.ethz.ch>
12
9
 
13
10
;; Keywords: editing and process modes.
14
11
 
34
31
 
35
32
;;; Code:
36
33
 
 
34
;;; The purpose of this file is to demonstrate some of the extras that
 
35
;;; have been constructed for the ESS R mode; if they prove
 
36
;;; interesting, then they might be migrated to essd-r, the primary
 
37
;;; ESS R mode tools.
 
38
 
 
39
 
 
40
 
 
41
 
37
42
;; you can invoke ESS/R from emacs by typing
38
43
;;      C-u M-x essr
39
44
;; with vsize set to (for example) 40M, and nsize set to 600000.
46
51
  "Send the current region to R via AppleScript."
47
52
  (interactive "r\nP")
48
53
  (message "Starting evaluation...")
49
 
  (do-applescript (concat 
 
54
  (do-applescript (concat
50
55
    "try\n"
51
56
        "tell application \"R\"\n"
52
57
                "activate\n"
65
70
  (save-excursion
66
71
  (let ((end (point)))
67
72
  (move-to-column 0)
68
 
  (do-applescript (concat 
 
73
  (do-applescript (concat
69
74
    "try\n"
70
75
        "tell application \"R\"\n"
71
76
                "activate\n"
78
83
  ))
79
84
  (message "Finished evaluation"))
80
85
 
 
86
(defun ess-r-var (beg end)
 
87
  "Load the current region of numbers into an R variable.  Prompts for
 
88
a variable name.  If none is given, it uses a default variable name,
 
89
e.  BEG and END denote the region in the current buffer to be sent."
 
90
  (interactive "r")
 
91
  (save-window-excursion
 
92
    (let ( (tmp-file (make-temp-file "ess-r-var"))
 
93
           cmd
 
94
           var)
 
95
      (write-region beg end tmp-file)
 
96
 
 
97
      ;; Decide on the variable name to use in R; could use completion.
 
98
      (setq var (read-string "R Variable name (default e): "))
 
99
      (if (equal var "")
 
100
          (setq var "e"))
 
101
 
 
102
      ;; Command to send to the R process.  Get R to delete the file
 
103
      ;; rather than Emacs in case it takes R a long time to run the
 
104
      ;; scan command.
 
105
      (setq cmd (concat var " <- scan(\""  tmp-file "\"); "
 
106
                        "unlink(\"" tmp-file "\")" ))
 
107
 
 
108
      ;; Put the output from the scan command into the process buffer so
 
109
      ;; the user has a record of it.
 
110
      (ess-execute cmd 'buffer))))
 
111
 
 
112
 
 
113
;;; Peter Dalgaard's code.
 
114
;;; This needs to be cleaned and validated!
 
115
 
 
116
(defun pd::set-up-demo ()
 
117
 
 
118
  ;; (if (not xemacs) (set-default-font "*courier-bold-r*--14**"))
 
119
  (R)
 
120
  (split-window-vertically 6)
 
121
  (find-file "demos.R")
 
122
 
 
123
  ;; Don't need to run this as a function -- ought to be fine if set
 
124
  ;; just once.
 
125
 
 
126
  (defun ajr::scroll-to-end::peterD (emacs)
 
127
    "Goal: map prompt to bottom of the screen after every command.
 
128
Alternatively, use the scroll-in-place package, not sure where that
 
129
is)."
 
130
    (interactive)
 
131
    (other-buffer 1)
 
132
    (if (= emacs "emacs")
 
133
        (setq scroll-up-aggressively t)
 
134
      (setq scroll-conservatively -4)) ;; <- change this
 
135
    (other-buffer -1))
 
136
 
 
137
  (defun show-max-other-window ()
 
138
    (interactive)
 
139
    (other-window 1)
 
140
    (comint-show-maximum-output)
 
141
    (other-window -1))
 
142
 
 
143
  ;; call this once
 
144
  ;; (ajr::scroll-to-end::peterD "xemacs")
 
145
  ;; (ajr::scroll-to-end::peterD "emacs")
 
146
 
 
147
  (global-set-key [f11] 'show-max-other-window)
 
148
  (global-set-key [f12] 'ess-eval-line-and-step))
 
149
 
 
150
 
 
151
 
 
152
 
81
153
 ; Provide package
82
154
 
83
155
(provide 'essa-r)