~ubuntu-branches/ubuntu/saucy/ess/saucy-proposed

« back to all changes in this revision

Viewing changes to lisp/ess-rdired.el

  • Committer: Bazaar Package Importer
  • Author(s): Dirk Eddelbuettel
  • Date: 2010-11-08 16:52:27 UTC
  • mfrom: (1.2.18 upstream)
  • Revision ID: james.westby@ubuntu.com-20101108165227-u844l0tlegcdn89k
Tags: 5.12-1
* New upstream version released today

* debian/emacen-startup: Follow suggestion by Kevin Ryde in #594750 and
  use debian-pkg-add-load-path-item as well; also improved emacsen-install
  script by using soft links instead of copies  (Closes: #594750)

Show diffs side-by-side

added added

removed removed

Lines of Context:
84
84
 
85
85
 
86
86
(defvar ess-rdired-objects ".rdired.objects <- function(objs) {
87
 
  if (length(objs)==0)
 
87
  if (length(objs)==0) {
88
88
    \"No objects to view!\"
89
 
  else {
 
89
  } else {
90
90
  mode <- sapply(objs, function(my.x) {
91
 
    eval(parse(text=(paste('data.class(',my.x,')',sep=''))))})
 
91
    eval( parse( text=sprintf('data.class(get(\"%s\"))', my.x))) })
92
92
  length <- sapply(objs, function(my.x) {
93
 
    eval(parse(text=(paste('length(',my.x,')',sep=''))))
94
 
  })
 
93
    eval( parse( text=sprintf('length(get(\"%s\"))', my.x))) })
95
94
  d <- data.frame(mode, length)
96
 
  row.names(d) <- paste('  ', row.names(d), sep='')
 
95
  
 
96
  var.names <- row.names(d)
 
97
 
 
98
  ## If any names contain spaces, we need to quote around them.
 
99
  quotes = rep('', length(var.names))
 
100
  spaces = grep(' ', var.names)
 
101
  if (any(spaces))
 
102
    quotes[spaces] <- '\"'
 
103
  var.names = paste(quotes, var.names, quotes, sep='')
 
104
  row.names(d) <- paste('  ', var.names, sep='')
97
105
  d
98
106
  }
99
107
}; .rdired.objects(ls())"
192
200
  )
193
201
 
194
202
(defun ess-rdired-object ()
195
 
  "Return name of object on current line."
 
203
  "Return name of object on current line.
 
204
Handle special case when object contains spaces."
196
205
  (save-excursion
197
206
    (beginning-of-line)
198
207
    (forward-char 2)
199
 
    (if (looking-at " ")
200
 
        nil                             ;on first line
201
 
      ;;
202
 
      (let (beg end)
203
 
        (setq beg (point))
204
 
        (search-forward " ")            ;assume space follows object name.
205
 
        (buffer-substring-no-properties beg (1- (point)))))))
 
208
 
 
209
    (cond ((looking-at " ")             ; First line?
 
210
           nil)
 
211
          ((looking-at "\"")            ; Object name contains spaces?
 
212
           (let (beg)
 
213
             (setq beg (point))
 
214
             (forward-char 1)
 
215
             (search-forward "\"")
 
216
             (buffer-substring-no-properties beg (point))))
 
217
           (t                           ;should be a regular object.
 
218
            (let (beg)
 
219
              (setq beg (point))
 
220
              (search-forward " ") ;assume space follows object name.
 
221
              (buffer-substring-no-properties beg (1- (point))))))))
206
222
 
207
223
(defun ess-rdired-edit ()
208
224
  "Edit (fix) the object at point."
214
230
  "View the object at point."
215
231
  (interactive)
216
232
  (let ((objname (ess-rdired-object)))
217
 
    (ess-execute objname nil "R view" )))
 
233
    (ess-execute (ess-rdired-get objname)
 
234
                 nil "R view" )))
 
235
 
 
236
(defun ess-rdired-get (name) 
 
237
  "Generate R code to get the value of the variable name.
 
238
This is complicated because some variables might have spaces in their names.
 
239
Otherwise, we could just pass the variable name directly to *R*."
 
240
  (concat "get(" (ess-rdired-quote name) ")")
 
241
  )
 
242
 
 
243
(defun ess-rdired-quote (name)
 
244
  "Quote name if not already quoted."
 
245
  (if (equal (substring name 0 1) "\"")
 
246
      name
 
247
    (concat "\"" name "\"")))
 
248
 
218
249
 
219
250
(defun ess-rdired-View ()
220
251
  "View the object at point in its own buffer.
221
252
Like `ess-rdired-view', but the object gets its own buffer name."
222
253
  (interactive)
223
254
  (let ((objname (ess-rdired-object)))
224
 
    (ess-execute ;;(concat "edit(" objname ")\n")
225
 
     objname
 
255
    (ess-execute 
 
256
     (ess-rdired-get objname)
226
257
     nil (concat "R view " objname ))))
227
258
 
228
259
(defun ess-rdired-plot ()
229
260
  "Plot the object on current line."
230
261
  (interactive)
231
262
  (let ((objname (ess-rdired-object)))
232
 
    (ess-command (concat "plot(" objname ")\n"))))
 
263
    (ess-command (concat "plot(" (ess-rdired-get objname) ")\n"))))
233
264
 
234
265
(defun ess-rdired-type ()
235
266
  "Run the mode() on command at point.
236
 
Named type because of similarity
237
 
with the dired command bound to y key."
 
267
Named type because of similarity with the dired command bound to
 
268
y key."
238
269
  (interactive)
239
270
  (let ((objname (ess-rdired-object))
240
271
        ;; create a temp buffer, and then show output in echo area
241
272
        (tmpbuf (get-buffer-create "**ess-rdired-mode**")))
242
273
    (if objname
243
274
        (progn
244
 
          (ess-command (concat "mode(" objname ")\n")  tmpbuf )
 
275
          (ess-command (concat "mode(" (ess-rdired-get objname) ")\n")
 
276
                       tmpbuf )
245
277
          (set-buffer tmpbuf)
246
278
          (message (concat
247
279
                    objname ": "
292
324
  (let ((objs "rm(")
293
325
        (count 0))
294
326
    (save-excursion
295
 
      (goto-line 2)
 
327
      (goto-char (point-min)) (forward-line 1)
296
328
      (while (< (count-lines (point-min) (point))
297
329
                (count-lines (point-min) (point-max)))
298
330
        (beginning-of-line)