~ubuntu-branches/ubuntu/vivid/ess/vivid-proposed

« back to all changes in this revision

Viewing changes to lisp/ess-r-d.el

  • Committer: Package Import Robot
  • Author(s): Dirk Eddelbuettel
  • Date: 2014-09-13 09:03:04 UTC
  • mfrom: (1.2.33)
  • Revision ID: package-import@ubuntu.com-20140913090304-ckjf1ajwpap2h1ny
Tags: 14.09-1
New upstream version released today 

Show diffs side-by-side

added added

removed removed

Lines of Context:
23
23
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
24
24
;; GNU General Public License for more details.
25
25
 
26
 
;; You should have received a copy of the GNU General Public License
27
 
;; along with GNU Emacs; see the file COPYING.  If not, write to
28
 
;; the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
 
26
;; A copy of the GNU General Public License is available at
 
27
;; http://www.r-project.org/Licenses/
29
28
 
30
29
;;; Commentary:
31
30
 
270
269
;; precede R4 and allowes spaces in file path
271
270
(add-to-list 'compilation-error-regexp-alist-alist
272
271
             ;; start with bol,: but don't start with digit
273
 
             '(R3 "\\(?:^ +\\|: +\\)\\([^-+[:digit:]\n][^:\n]*\\):\\([0-9]+\\):\\([0-9]+\\):"  1 2 3 2 1))
 
272
             '(R3 "\\(?:^ +\\|: +\\)\\([^-+[:digit:]\n]:?[^:\n]*\\):\\([0-9]+\\):\\([0-9]+\\):"  1 2 3 2 1))
274
273
 
275
274
(add-to-list 'compilation-error-regexp-alist-alist
276
275
             ;; don't start with digit, don't contain spaces
279
278
(add-to-list 'compilation-error-regexp-alist-alist
280
279
             '(R-recover " *[0-9]+: +\\([^:\n\t]+?\\)#\\([0-9]+:\\)"  1 2 nil 2 1))
281
280
 
 
281
;; gnu C errors
 
282
;; (add-to-list 'compilation-error-regexp-alist-alist
 
283
;;              '(R_C "^\\([^-+ [:digit:]][^: \t\n]+\\):\\([0-9]+\\):\\([0-9]+\\):"  2 3 nil 2 1))
 
284
 
282
285
(let ((r-ver '("R-1" "R-2" "R-3" "R-devel" "R-patched")))
283
286
  (defvar ess-r-versions
284
287
    (if (eq system-type 'darwin) (append r-ver '("R32" "R64")) r-ver)
301
304
  process.")
302
305
 
303
306
(defun ess--R-load-ESSR ()
304
 
  "Load/INSTALL/Update ESSR"
 
307
  "Load/INSTALL/Update ESSR."
305
308
  (let* ((ESSR-directory (expand-file-name "ESSR" ess-etc-directory))
306
309
         (src-dir (expand-file-name "R" ESSR-directory)))
307
310
 
330
333
                            (buffer-string))))
331
334
        (ess-write-to-dribble-buffer (format "version file: %s\nloadremote file: %s\n"
332
335
                                             verfile loadremote))
333
 
        (unless (ess-boolean-command (format r-load-code version))
 
336
        (unless (ess-boolean-command (format r-load-code version) nil 0.1)
334
337
          (let ((errmsg (with-current-buffer " *ess-command-output*" (buffer-string)))
335
338
                (files (directory-files src-dir t "\\.R$")))
336
339
            (ess-write-to-dribble-buffer (format "error loading ESSR.rda: \n%s\n" errmsg))
348
351
If you have certain command line arguments that should always be passed
349
352
to R, put them in the variable `inferior-R-args'."
350
353
  (interactive "P")
351
 
  ;; get settings, notably inferior-R-program-name :
352
 
  (setq ess-customize-alist R-customize-alist)
353
354
  (ess-write-to-dribble-buffer   ;; for debugging only
354
355
   (format
355
356
    "\n(R): ess-dialect=%s, buf=%s, start-arg=%s\n current-prefix-arg=%s\n"
369
370
                                   (concat " [other than '" r-always-arg "']"))
370
371
                               " ? "))
371
372
                    nil)))
 
373
         (cust-alist (copy-alist R-customize-alist))
 
374
         (gdbp (string-match-p "gdb" r-start-args))
372
375
         use-dialog-box)
373
376
 
 
377
    (when gdbp
 
378
      (setcdr (assoc 'inferior-ess-secondary-prompt cust-alist)
 
379
              (format "\\(%s\\)\\|\\((gdb) \\)"
 
380
                      (cdr (assoc 'inferior-ess-secondary-prompt cust-alist)))))
 
381
 
374
382
    (when (or ess-microsoft-p
375
383
              (eq system-type 'cygwin))
376
384
      (setq use-dialog-box nil)
377
 
      (if ess-microsoft-p ;; default-process-coding-system would break UTF locales on Unix
378
 
          (setq default-process-coding-system '(undecided-dos . undecided-dos))))
 
385
      (when ess-microsoft-p ;; default-process-coding-system would break UTF locales on Unix
 
386
        (setq default-process-coding-system '(undecided-dos . undecided-dos))))
379
387
 
380
 
    (inferior-ess r-start-args)
 
388
    (inferior-ess r-start-args cust-alist gdbp)
381
389
 
382
390
    (ess-process-put 'funargs-pre-cache ess-R--funargs-pre-cache)
 
391
    ;; We need to use callback, because R might start with a gdb process
 
392
    (ess-process-put 'callbacks '(R-initialize-on-start))
 
393
    ;; trigger the callback
 
394
    (process-send-string (get-process ess-local-process-name) "\n")
383
395
 
384
396
    (remove-hook 'completion-at-point-functions 'ess-filename-completion 'local) ;; should be first
385
397
    (add-hook 'completion-at-point-functions 'ess-R-object-completion nil 'local)
386
398
    (add-hook 'completion-at-point-functions 'ess-filename-completion nil 'local)
387
 
 
388
 
    ;;-------------------------
389
399
    (setq comint-input-sender 'inferior-R-input-sender)
 
400
 
390
401
    (ess-write-to-dribble-buffer
391
402
     (format "(R): inferior-ess-language-start=%s\n"
392
 
             inferior-ess-language-start))
393
 
 
394
 
    (when ess-can-eval-in-background
395
 
      (ess-async-command-delayed
396
 
       "invisible(installed.packages())\n" nil (get-process ess-local-process-name)
397
 
       ;; "invisible(Sys.sleep(10))\n" nil (get-process ess-local-process-name) ;; test only
398
 
       (lambda (proc) (process-put proc 'packages-cached? t))))
399
 
 
400
 
    (ess--R-load-ESSR)
401
 
 
402
 
    (if inferior-ess-language-start
403
 
        (ess-eval-linewise inferior-ess-language-start
404
 
                           nil nil nil 'wait-prompt))
405
 
 
406
 
    (with-ess-process-buffer nil
407
 
      (run-mode-hooks 'ess-R-post-run-hook))))
408
 
 
 
403
             inferior-ess-language-start))))
 
404
 
 
405
(defun R-initialize-on-start (&optional proc string)
 
406
  "This function is run after the first R prompt.
 
407
Executed in process buffer."
 
408
  (interactive)
 
409
 
 
410
  (when ess-can-eval-in-background
 
411
    (ess-async-command-delayed
 
412
     "invisible(installed.packages())\n" nil (get-process ess-local-process-name)
 
413
     ;; "invisible(Sys.sleep(10))\n" nil (get-process ess-local-process-name) ;; test only
 
414
     (lambda (proc) (process-put proc 'packages-cached? t))))
 
415
 
 
416
  (ess--R-load-ESSR)
 
417
 
 
418
  (when inferior-ess-language-start
 
419
    (ess-eval-linewise inferior-ess-language-start
 
420
                       nil nil nil 'wait-prompt))
 
421
 
 
422
  (with-ess-process-buffer nil
 
423
    (run-mode-hooks 'ess-R-post-run-hook)))
409
424
 
410
425
 
411
426
;; (defun ess--R-cache-installed-packages ()
451
466
  (ad-activate 'fill-paragraph)
452
467
  (ad-activate 'move-beginning-of-line)
453
468
  (ad-activate 'newline-and-indent)
 
469
  (ad-activate 'ess-eval-line-and-step)
454
470
  (if ess-roxy-hide-show-p
455
471
    (ad-activate 'ess-indent-command))
456
472
 
907
923
  (sit-for 2 t)
908
924
  )
909
925
 
910
 
;; this one will be removed soon
 
926
;; This one is needed for R <= 2.6.x -- hence *not* obsoleting it
911
927
(defun ess-internal-complete-object-name ()
912
928
  "Perform completion on `ess-language' object preceding point.
913
929
The object is compared against those objects known by
971
987
        ;; always return a non-nil value to prevent history expansions
972
988
        (or (comint-dynamic-simple-complete  pattern components) 'none))))
973
989
 
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")
 
990
;; *NOT* doing this, as it is needed for R <= 2.6.x
 
991
;;(make-obsolete 'ess-internal-complete-object-name nil "ESS 13.09")
976
992
 
977
993
(defun ess-R-get-rcompletions (&optional start end)
978
994
  "Call R internal completion utilities (rcomp) for possible completions.
1076
1092
    (when (string-match ":+\\(.*\\)" sym)
1077
1093
      (setq sym (match-string 1 sym)))
1078
1094
    (ess-with-current-buffer buf
1079
 
      (ess--flush-help-into-current-buffer sym))
 
1095
      (ess--flush-help-into-current-buffer sym nil t))
1080
1096
    (with-current-buffer buf
1081
1097
      (ess-help-underline)
1082
1098
      (goto-char (point-min))