Klimi's new dotfiles with stow.
Nie możesz wybrać więcej, niż 25 tematów Tematy muszą się zaczynać od litery lub cyfry, mogą zawierać myślniki ('-') i mogą mieć do 35 znaków.

154 wiersze
4.8 KiB

4 lat temu
  1. ;;; ess-r-a.el -- Possible local customizations for R with ESS. -*- lexical-binding: t; -*-
  2. ;; Copyright (C) 1997--2005 A.J. Rossini, Richard M. Heiberger, Martin
  3. ;; Maechler, Kurt Hornik, Rodney Sparapani, and Stephen Eglen.
  4. ;; Author: A.J. Rossini <blindglobe@gmail.com>
  5. ;; Created: 17 November 1999
  6. ;; Maintainer: ESS-core <ESS-core@r-project.org>
  7. ;; Keywords: languages
  8. ;; This file is part of ESS
  9. ;; This file is free software; you can redistribute it and/or modify
  10. ;; it under the terms of the GNU General Public License as published by
  11. ;; the Free Software Foundation; either version 2, or (at your option)
  12. ;; any later version.
  13. ;;
  14. ;; This file is distributed in the hope that it will be useful,
  15. ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
  16. ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  17. ;; GNU General Public License for more details.
  18. ;;
  19. ;; A copy of the GNU General Public License is available at
  20. ;; https://www.r-project.org/Licenses/
  21. ;;; Commentary:
  22. ;; The purpose of this file is to demonstrate some of the extras that
  23. ;; have been constructed for the ESS R mode; if they prove
  24. ;; interesting, then they might be migrated to ess-r-mode, the primary
  25. ;; ESS R mode tools.
  26. ;;; Code:
  27. (require 'ess-inf)
  28. (require 'ess-r-mode)
  29. ;; you can invoke ESS/R from emacs by typing
  30. ;; C-u M-x essr
  31. ;; with vsize set to (for example) 40M, and nsize set to 600000.
  32. ;; Undefined on non-apple devices
  33. (declare-function ns-do-applescript "nsfns.m" (script))
  34. (declare-function do-applescript "ess-r-a" (script))
  35. (unless (fboundp 'do-applescript)
  36. (defalias 'do-applescript 'ns-do-applescript))
  37. (defalias 'essr
  38. (read-kbd-macro
  39. "C-u M-x R RET - - vsize = 40M SPC - - nsize = 600000 2*RET"))
  40. (defun ess-r-do-region (start end)
  41. "Send from START to END to R via AppleScript."
  42. (interactive "r\nP")
  43. (message "Starting evaluation...")
  44. (do-applescript (concat
  45. "try\n"
  46. "tell application \"R\"\n"
  47. "activate\n"
  48. "with timeout of 0 seconds\n"
  49. "cmd \"" (buffer-substring start end)
  50. "\"\n"
  51. "end timeout\n"
  52. "end tell\n"
  53. "end try\n"))
  54. (message "Finished evaluation"))
  55. (defun ess-r-do-line ()
  56. "Send the current line to R via AppleScript."
  57. (interactive) ;; "r\nP")
  58. (message "Starting evaluation...")
  59. (save-excursion
  60. (let ((end (point)))
  61. (move-to-column 0)
  62. (do-applescript (concat
  63. "try\n"
  64. "tell application \"R\"\n"
  65. "activate\n"
  66. "with timeout of 0 seconds\n"
  67. "cmd \"" (buffer-substring (point) end)
  68. "\"\n"
  69. "end timeout\n"
  70. "end tell\n"
  71. "end try\n"))))
  72. (message "Finished evaluation"))
  73. (defun ess-r-var (beg end)
  74. "Load the current region of numbers into an R variable.
  75. Prompts for a variable name. If none is given, it uses a default
  76. variable name, e. BEG and END denote the region in the current
  77. buffer to be sent."
  78. (interactive "r")
  79. (save-window-excursion
  80. (let ((tmp-file (make-temp-file "ess-r-var"))
  81. cmd
  82. var)
  83. (write-region beg end tmp-file)
  84. ;; Decide on the variable name to use in R; could use completion.
  85. (setq var (read-string "R Variable name (default e): "))
  86. (if (equal var "")
  87. (setq var "e"))
  88. ;; Command to send to the R process. Get R to delete the file
  89. ;; rather than Emacs in case it takes R a long time to run the
  90. ;; scan command.
  91. (setq cmd (concat var " <- scan(\"" tmp-file "\"); "
  92. "unlink(\"" tmp-file "\")" ))
  93. ;; Put the output from the scan command into the process buffer so
  94. ;; the user has a record of it.
  95. (ess-execute cmd 'buffer))))
  96. ;;; Peter Dalgaard's code.
  97. ;;; This needs to be cleaned and validated!
  98. (defun pd::set-up-demo ()
  99. (run-ess-r)
  100. (split-window-vertically 6)
  101. (find-file "demos.R")
  102. ;; Don't need to run this as a function -- ought to be fine if set
  103. ;; just once.
  104. (defun ajr::scroll-to-end::peterD (emacs)
  105. "Goal: map prompt to bottom of the screen after every command.
  106. Alternatively, use the scroll-in-place package, not sure where that
  107. is)."
  108. (interactive)
  109. (other-buffer 1)
  110. (if (= emacs "emacs")
  111. (setq scroll-up-aggressively t)
  112. (setq scroll-conservatively -4)) ;; <- change this
  113. (other-buffer -1))
  114. (defun show-max-other-window ()
  115. (interactive)
  116. (other-window 1)
  117. (comint-show-maximum-output)
  118. (other-window -1))
  119. ;; call this once
  120. ;; (ajr::scroll-to-end::peterD "emacs")
  121. (global-set-key [f11] 'show-max-other-window)
  122. (global-set-key [f12] 'ess-eval-line-visibly-and-step))
  123. ; Provide package
  124. (provide 'ess-r-a)
  125. ;;; ess-r-a.el ends here