134
134
["Watch" ess-watch (and (ess-process-live-p)
135
135
(ess-process-get 'tracebug))]
136
136
["Error action cycle" ess-debug-toggle-error-action (and (ess-process-live-p)
137
(ess-process-get 'tracebug))]
137
(ess-process-get 'tracebug))]
139
139
["Flag for debugging" ess-debug-flag-for-debugging ess-local-process-name]
140
140
["Unflag for debugging" ess-debug-unflag-for-debugging ess-local-process-name]
193
193
(ess-build-tags-command . "rtags('%s', recursive = TRUE, pattern = '\\\\.[RrSs](rw)?$',ofile = '%s')")
194
194
(ess-traceback-command . "local({cat(geterrmessage(), \"---------------------------------- \n\", fill=TRUE);try(traceback(), silent=TRUE)})\n")
195
195
(ess-call-stack-command . "traceback(1)\n")
196
(ess-eval-command . ".ess_eval(\"%s\", FALSE, FALSE, file=\"%f\")\n")
197
(ess-eval-visibly-command . ".ess_eval(\"%s\", TRUE, TRUE, 300, file=\"%f\")\n")
198
(ess-eval-visibly-noecho-command . ".ess_eval(\"%s\", FALSE, TRUE, 300, file=\"%f\")\n")
199
(ess-load-command . ".ess_source(\"%s\", FALSE, FALSE)\n")
200
(ess-load-visibly-command . ".ess_source(\"%s\", TRUE, TRUE, 300)\n")
201
(ess-load-visibly-noecho-command . ".ess_source(\"%s\", FALSE, TRUE, 300)\n")
196
(ess-eval-command . ".ess.eval(\"%s\", FALSE, FALSE, file=\"%f\")\n")
197
(ess-eval-visibly-command . ".ess.eval(\"%s\", TRUE, TRUE, 300, file=\"%f\")\n")
198
(ess-eval-visibly-noecho-command . ".ess.eval(\"%s\", FALSE, TRUE, 300, file=\"%f\")\n")
199
(ess-load-command . ".ess.source(\"%s\", FALSE, FALSE)\n")
200
(ess-load-visibly-command . ".ess.source(\"%s\", TRUE, TRUE, 300)\n")
201
(ess-load-visibly-noecho-command . ".ess.source(\"%s\", FALSE, TRUE, 300)\n")
202
202
(ess-dump-filename-template . (ess-replace-regexp-in-string
203
203
"S$" ess-suffix ; in the one from custom:
204
204
ess-dump-filename-template-proto))
229
229
(ess-describe-object-at-point-commands . 'ess-R-describe-object-at-point-commands)
230
230
(ess-STERM . "iESS")
231
231
(ess-editor . R-editor)
232
(ess-pager . R-pager))
232
(ess-pager . R-pager)
233
(prettify-symbols-alist . '(("<-" . ?←)
233
237
S-common-cust-alist)
234
238
"Variables to customize for R -- set up later than emacs initialization.")
241
(defvar R-editing-alist
242
;; copy the S-alist and modify :
243
(let ((S-alist (copy-alist S-editing-alist)))
244
(setcdr (assoc 'ess-font-lock-defaults S-alist)
245
'(ess--extract-default-fl-keywords ess-R-font-lock-keywords))
246
(setcdr (assoc 'ess-font-lock-keywords S-alist)
247
(quote 'ess-R-font-lock-keywords))
249
"General options for editing R source files.")
236
252
(defvar ess-R-error-regexp-alist '(R R1 R2 R3 R4 R-recover)
237
253
"List of symbols which are looked up in `compilation-error-regexp-alist-alist'.")
254
270
;; precede R4 and allowes spaces in file path
255
271
(add-to-list 'compilation-error-regexp-alist-alist
256
'(R3 "\\(?:^ +\\|: +\\)\\([^:\n]*\\):\\([0-9]+\\):\\([0-9]+\\):" 1 2 3 2 1))
272
;; start with bol,: but don't start with digit
273
'(R3 "\\(?:^ +\\|: +\\)\\([^-+[:digit:]\n][^:\n]*\\):\\([0-9]+\\):\\([0-9]+\\):" 1 2 3 2 1))
258
275
(add-to-list 'compilation-error-regexp-alist-alist
259
'(R4 "\\([^: \t\n]+\\):\\([0-9]+\\):\\([0-9]+\\):" 1 2 3 2 1))
276
;; don't start with digit, don't contain spaces
277
'(R4 "\\([^-+ [:digit:]][^: \t\n]+\\):\\([0-9]+\\):\\([0-9]+\\):" 1 2 3 2 1))
261
279
(add-to-list 'compilation-error-regexp-alist-alist
262
280
'(R-recover " *[0-9]+: +\\([^:\n\t]+?\\)#\\([0-9]+:\\)" 1 2 nil 2 1))
276
294
ignored by calling `ess-uniq-list'.
277
295
Set this variable to nil to disable searching for other versions of R.
278
296
If you set this variable, you need to restart Emacs (and set this variable
279
before ess-site is loaded) for it to take effect.")
297
before ess-site is loaded) for it to take effect."))
282
299
(defvar ess-R-post-run-hook nil
283
300
"Functions run in process buffer after the initialization of R
303
(defun ess--R-load-ESSR ()
304
"Load/INSTALL/Update ESSR"
305
(let* ((ESSR-directory (expand-file-name "ESSR" ess-etc-directory))
306
(src-dir (expand-file-name "R" ESSR-directory)))
308
(if (not (or (and (boundp 'ess-remote) ess-remote)
309
(file-remote-p (ess-get-process-variable 'default-directory))))
312
source('%s/.load.R', local=TRUE) #define load.ESSR
315
(ess-write-to-dribble-buffer (format "load-ESSR cmd:\n%s\n" cmd))
316
(with-current-buffer (ess-command cmd)
317
(let ((msg (buffer-string)))
318
(when (> (length msg) 1)
319
(message (format "load ESSR: %s" msg))))))
321
(let* ((verfile (expand-file-name "VERSION" ESSR-directory))
322
(loadremote (expand-file-name "LOADREMOTE" ESSR-directory))
323
(version (if (file-exists-p verfile)
325
(insert-file-contents verfile)
327
(error "Cannot find ESSR source code")))
328
(r-load-code (with-temp-buffer
329
(insert-file-contents loadremote)
331
(ess-write-to-dribble-buffer (format "version file: %s\nloadremote file: %s\n"
333
(unless (ess-boolean-command (format r-load-code version))
334
(let ((errmsg (with-current-buffer " *ess-command-output*" (buffer-string)))
335
(files (directory-files src-dir t "\\.R$")))
336
(ess-write-to-dribble-buffer (format "error loading ESSR.rda: \n%s\n" errmsg))
337
;; should not happen, unless extrem conditions (ancient R or failed download))
338
(message "Failed to download ESSR.rda (see *ESS* buffer). Injecting ESSR code from local machine")
339
(ess-command (format ".ess.ESSRversion <- '%s'\n" version)) ; cannot do this at R level
340
(mapc #'ess--inject-code-from-file files)))))))
288
344
(defun R (&optional start-args)
320
376
(setq use-dialog-box nil)
321
377
(if ess-microsoft-p ;; default-process-coding-system would break UTF locales on Unix
322
378
(setq default-process-coding-system '(undecided-dos . undecided-dos))))
324
(inferior-ess r-start-args)
380
(inferior-ess r-start-args)
326
382
(ess-process-put 'funargs-pre-cache ess-R--funargs-pre-cache)
328
384
(remove-hook 'completion-at-point-functions 'ess-filename-completion 'local) ;; should be first
334
390
(ess-write-to-dribble-buffer
335
391
(format "(R): inferior-ess-language-start=%s\n"
336
392
inferior-ess-language-start))
337
;; can test only now that R is running:
338
(ess-write-to-dribble-buffer
339
(format "(R): version %s\n"
340
(ess-get-words-from-vector "as.character(getRversion())\n")))
342
(ess--inject-code-from-file (format "%sESSR.R" ess-etc-directory))
344
394
(when ess-can-eval-in-background
345
395
(ess-async-command-delayed
347
397
;; "invisible(Sys.sleep(10))\n" nil (get-process ess-local-process-name) ;; test only
348
398
(lambda (proc) (process-put proc 'packages-cached? t))))
350
402
(if inferior-ess-language-start
351
403
(ess-eval-linewise inferior-ess-language-start
352
404
nil nil nil 'wait-prompt))
593
645
(defun ess-current-R-version ()
594
646
"Get the version of R currently running in the ESS buffer as a string"
595
647
(ess-make-buffer-current)
596
(car (ess-get-words-from-vector "as.character(getRversion())\n")))
648
(car (ess-get-words-from-vector "as.character(.ess.Rversion)\n")))
598
650
(defun ess-current-R-at-least (version)
599
651
"Is the version of R (in the ESS buffer) at least (\">=\") VERSION ?
602
654
(ess-make-buffer-current)
604
656
(car (ess-get-words-from-vector
605
(format "as.character(getRversion() >= \"%s\")\n" version)))))
657
(format "as.character(.ess.Rversion >= \"%s\")\n" version)))))
607
659
(defvar ess-temp-newest nil)
919
971
;; always return a non-nil value to prevent history expansions
920
972
(or (comint-dynamic-simple-complete pattern components) 'none))))
922
(make-obsolete 'ess-internal-complete-object-name nil "ESS13.09")
974
;; Hmm... shouldn't we keep and use this for R <= 2.6.x ???
975
(make-obsolete 'ess-internal-complete-object-name nil "ESS 13.09")
924
977
(defun ess-R-get-rcompletions (&optional start end)
925
978
"Call R internal completion utilities (rcomp) for possible completions.
976
1029
"OBJECTS + ARGS"
977
1030
(let ((args (ess-ac-args)))
978
1031
;; sort of intrusive but right
979
(if (< (length ac-prefix) ac-auto-start)
1032
(if (and ac-auto-start
1033
(< (length ac-prefix) ac-auto-start))
982
1036
(append args (ess-ac-objects t))
1059
1113
(mapcar (lambda (a) (concat a ess-ac-R-argument-suffix))
1062
;; (defun ess-ac-action-args ()
1063
;; (when (looking-back "=")
1068
1116
(defun ess-ac-help-arg (sym)
1069
1117
"Help string for ac."
1070
1118
(setq sym (replace-regexp-in-string " *= *\\'" "" sym))
1071
(let ((buff (get-buffer-create " *ess-command-output*"))
1072
(fun (car ess--funname.start))
1074
(ess-command (format ess--ac-help-arg-command sym fun) buff)
1075
(with-current-buffer buff
1119
(let ((fun (car ess--funname.start)))
1120
(with-current-buffer (ess-command (format ess--ac-help-arg-command sym fun))
1076
1121
(goto-char (point-min))
1078
(setq doc (buffer-substring-no-properties (point) (point-max))))))
1123
(buffer-substring-no-properties (point) (point-max)))))
1081
1126
(defvar ess--ac-help-arg-command
1242
1287
"Cache var to store package names. Used by
1243
1288
`ess-install.packages'.")
1247
(defun ess-R-install.packages (&optional update)
1290
(defun ess-R-install.packages (&optional update pack)
1248
1291
"Prompt and install R package. With argument, update cached packages list."
1249
1292
(interactive "P")
1250
1293
(when (equal "@CRAN@" (car (ess-get-words-from-vector "getOption('repos')[['CRAN']]\n")))
1251
1294
(ess-setCRANMiror)
1252
1295
(ess-wait-for-process (get-process ess-current-process-name))
1296
(unless pack (setq update t)))
1254
1297
(when (or update
1255
1298
(not ess--packages-cache))
1256
1299
(message "Fetching R packages ... ")
1257
1300
(setq ess--packages-cache
1258
1301
(ess-get-words-from-vector "print(rownames(available.packages()), max=1e6)\n")))
1259
(let ((ess-eval-visibly-p t)
1261
(setq pack (ess-completing-read "Package to install" ess--packages-cache))
1302
(let* ((ess-eval-visibly-p t)
1304
(ess-completing-read "Package to install" ess--packages-cache))))
1262
1305
(process-send-string (get-process ess-current-process-name)
1263
1306
(format "install.packages('%s')\n" pack))
1264
1307
(display-buffer (buffer-name (process-buffer (get-process ess-current-process-name))))
1286
1329
(defun ess-setCRANMiror ()
1287
1330
"Set cran mirror"
1289
(let* ((M1 (ess-get-words-from-vector "local({out <- getCRANmirrors(); print(paste(out$Name,'[',out$URL,']', sep=''))})\n"))
1332
(let* ((M1 (ess-get-words-from-vector "local({out <- getCRANmirrors(local.only=TRUE); print(paste(out$Name,'[',out$URL,']', sep=''))})\n"))
1290
1333
(M2 (mapcar (lambda (el)
1291
1334
(string-match "\\(.*\\)\\[\\(.*\\)\\]$" el)
1292
1335
(propertize (match-string 1 el) 'URL (match-string 2 el)))
1318
1361
(defun ess-load-library ()
1319
1362
"Prompt and load dialect specific library/package/module.
1321
Note that add-on code in R are called 'packages' and the name of
1322
this function has nothing to do with R package mechanism, but it
1364
Note that add-ons in R are called 'packages' and the name of this
1365
function has nothing to do with R package mechanism, but it
1323
1366
rather serves a generic, dialect independent purpose. It is also
1324
similar to `load-library' emacs function.
1367
similar to `load-library' emacs function."
1327
1369
(if (not (string-match "^R" ess-dialect))
1328
1370
(message "Sorry, not available for %s" ess-dialect)