Klimi's new dotfiles with stow.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

221 regels
8.3 KiB

4 jaren geleden
  1. ;;; ess.el --- Emacs Speaks Statistics -*- lexical-binding: t; -*-
  2. ;;
  3. ;; Author: David Smith <dsmith@stats.adelaide.edu.au>
  4. ;; A.J. Rossini <blindglobe@gmail.com>
  5. ;; Richard M. Heiberger <rmh@temple.edu>
  6. ;; Kurt Hornik <Kurt.Hornik@R-project.org>
  7. ;; Martin Maechler <maechler@stat.math.ethz.ch>
  8. ;; Rodney A. Sparapani <rsparapa@mcw.edu>
  9. ;; Stephen Eglen <stephen@gnu.org>
  10. ;; Sebastian P. Luque <spluque@gmail.com>
  11. ;; Henning Redestig <henning.red@googlemail.com>
  12. ;; Vitalie Spinu <spinuvit@gmail.com>
  13. ;; Lionel Henry <lionel.hry@gmail.com>
  14. ;; J. Alexander Branham <alex.branham@gmail.com>
  15. ;;
  16. ;; Maintainer: ESS Core Team <ESS-core@r-project.org>
  17. ;; Copyright (C) 1997-2018 ESS Core Team <ESS-core@r-project.org>
  18. ;; Created: 7 Jan 1994
  19. ;; Version: 18.10.3snapshot
  20. ;; URL: https://ess.r-project.org/
  21. ;; Package-Requires: ((emacs "25.1") (julia-mode "0.3"))
  22. ;; ESSR-Version: 1.5
  23. ;;
  24. ;; This file is free software; you can redistribute it and/or modify
  25. ;; it under the terms of the GNU General Public License as published by
  26. ;; the Free Software Foundation; either version 2, or (at your option)
  27. ;; any later version.
  28. ;;
  29. ;; This file is distributed in the hope that it will be useful,
  30. ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
  31. ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  32. ;; GNU General Public License for more details.
  33. ;;
  34. ;; A copy of the GNU General Public License is available at
  35. ;; https://www.r-project.org/Licenses/
  36. ;;
  37. ;;; Commentary:
  38. ;;
  39. ;; Emacs Speaks Statistics (ESS) is a package designed to support editing of
  40. ;; scripts and interaction with various statistical analysis programs such as R,
  41. ;; S-Plus, SAS, Stata and OpenBUGS/JAGS. For more details please visit ESS home
  42. ;; page at https://ess.r-project.org/
  43. ;;
  44. ;;; Code:
  45. (require 'ess-utils)
  46. (require 'cl-generic)
  47. (defvar reporter-prompt-for-summary-p)
  48. ;; Versions
  49. (defconst ess-version (eval-when-compile
  50. (require 'lisp-mnt)
  51. (lm-version (or load-file-name buffer-file-name)))
  52. "Version of ESS currently loaded.")
  53. (defconst essr-version (eval-when-compile
  54. (require 'lisp-mnt)
  55. (save-excursion (lm-header "ESSR-Version")))
  56. "Version of ESSR package.")
  57. (defvar ess-revision nil
  58. "The revision and date of ESS.
  59. Is set by \\[ess-version-string].")
  60. ;;;###autoload
  61. (defun ess-version ()
  62. "Return a string with ESS version information."
  63. (interactive)
  64. (message (format "ess-version: %s (loaded from %s)"
  65. (ess-version-string)
  66. (file-name-directory ess-lisp-directory))))
  67. (defun ess-version-string ()
  68. (let* ((ess-dir (file-name-directory ess-lisp-directory)) ; if(<from source>) the top-level 'ess/'
  69. (is-release (file-exists-p (concat ess-etc-directory ".IS.RELEASE")))
  70. (rel-string (if is-release "Released "))
  71. (git-ref-fn (concat ess-dir ".git/HEAD"))
  72. (git-ref (when (file-exists-p git-ref-fn)
  73. (with-current-buffer (find-file-noselect git-ref-fn)
  74. (goto-char (point-min))
  75. (when (re-search-forward "ref: \\(.*\\)\n" nil t)
  76. (match-string 1)))))
  77. (git-fname (if git-ref
  78. (concat ess-dir ".git/" git-ref)
  79. ;; For release
  80. (concat ess-etc-directory "git-ref")))
  81. (git-rev (when (file-exists-p git-fname)
  82. (with-current-buffer (find-file-noselect git-fname)
  83. (goto-char (point-min))
  84. (concat "git: "(buffer-substring 1 (point-at-eol))))))
  85. (elpa-fname (concat ess-dir "ess-pkg.el"))
  86. (elpa-rev (when (file-exists-p elpa-fname)
  87. ;; Get it from ELPA dir name, (probably won't work if installed manually)
  88. (concat "elpa: "
  89. (replace-regexp-in-string "ess-" ""
  90. (file-name-nondirectory
  91. (substring ess-dir 1 -1)))))))
  92. ;; Set the "global" ess-revision:
  93. (setq ess-revision (format "%s%s%s"
  94. (or rel-string "")
  95. (or git-rev "")
  96. (or elpa-rev "")))
  97. (when (string= ess-revision "")
  98. (setq ess-revision "<unknown>"))
  99. (concat ess-version " [" ess-revision "]")))
  100. ;;; Bug Reporting
  101. ;;;###autoload
  102. (defun ess-submit-bug-report ()
  103. "Submit a bug report to the ESS maintainers."
  104. (interactive)
  105. (let ((reporter-prompt-for-summary-p 't))
  106. (reporter-submit-bug-report
  107. "ess-bugs@r-project.org"
  108. (concat "ess-mode " (ess-version-string))
  109. (list 'ess-language
  110. 'ess-dialect
  111. 'ess-ask-for-ess-directory
  112. 'ess-ask-about-transfile
  113. 'default-directory
  114. 'ess-keep-dump-files
  115. 'ess-source-directory
  116. 'ess-use-ido
  117. 'ess-use-eldoc
  118. 'ess-use-tracebug
  119. 'ess-use-auto-complete
  120. 'ess-use-company
  121. 'ess-eval-visibly-p
  122. 'ess-can-eval-in-background
  123. 'ess-local-process-name)
  124. nil
  125. (lambda ()
  126. ;;(goto-char (point-max))
  127. (rfc822-goto-eoh)
  128. (forward-line 1)
  129. (insert "\n\n-------------------------------------------------------\n")
  130. (insert "This bug report will be sent to the ESS bugs email list\n")
  131. (insert "Press C-c C-c when you are ready to send your message.\n")
  132. (insert "-------------------------------------------------------\n\n")
  133. (insert (with-current-buffer ess-dribble-buffer
  134. (goto-char (point-max))
  135. (forward-line -100)
  136. (buffer-substring-no-properties (point) (point-max))))))))
  137. ;;; Timer
  138. (defcustom ess-idle-timer-interval 1
  139. "Number of idle seconds to wait before running function in `ess-idle-timer-functions'."
  140. :type '(integer)
  141. :group 'ess)
  142. (defvar ess-idle-timer-functions nil
  143. "A list of functions to run each `ess-idle-timer-interval' idle seconds.
  144. If your function calls the process, you better use
  145. `ess-when-new-input' to wrap your call. If you call the
  146. subprocess please respect `ess-can-eval-in-background' variable.
  147. These functions are run with `run-hooks'. Use `add-hook' to add
  148. symbols to this variable.
  149. Most likely you will need a local hook. Then you should specify
  150. the LOCAL argument to `add-hook' and initialize it in
  151. `ess-mode-hook' or `ess-post-run-hook', or one of the more
  152. specialized hooks `ess-r-post-run-hook',`ess-stata-post-run-hook'
  153. etc.")
  154. (defun ess--idle-timer-function nil
  155. "Internal function executed by `ess--idle-timer'."
  156. (run-hooks 'ess-idle-timer-functions))
  157. (require 'timer)
  158. (defvar ess--idle-timer
  159. (run-with-idle-timer ess-idle-timer-interval 'repeat 'ess--idle-timer-function)
  160. "Timer used to run `ess-idle-timer-functions'.")
  161. ;;; Dispatch on ess-dialect
  162. ;; Inspired by major-mode specializer in cl-generic.el
  163. ;; FIXME: Implement a notion of derived dialects. major-mode specializer cannot
  164. ;; be used here as we need same dialect in different major-modes.
  165. ;; Two parts:
  166. ;; 1) first define a specializer (ess-dialect= DIALECT) to match symbols
  167. ;; representing ess dialects.
  168. ;; 2) then define a context-rewriter so you can write
  169. ;; `&context (ess-dialect "R")` rather than
  170. ;; `&context (ess-dialect (ess-dialect= "R"))`.
  171. (cl-generic-define-generalizer ess--generic-dialect-generalizer
  172. 95
  173. (lambda (name &rest _) `(if (stringp ,name) (intern ,name)
  174. (if (symbolp ,name) ,name)))
  175. (lambda (tag &rest _) `((ess-dialect= ,tag))))
  176. (cl-defmethod cl-generic-generalizers ((_specializer (head ess-dialect=)))
  177. "Support for (ess-dialect DIALECT) context specializer."
  178. (list ess--generic-dialect-generalizer))
  179. (cl-generic-define-context-rewriter ess-dialect (dialect)
  180. `(ess-dialect (ess-dialect= ,(if (stringp dialect)
  181. (intern dialect)
  182. dialect))))
  183. ;; (cl-defgeneric ess-print-dialect ()
  184. ;; (error "unknown dialect %s" ess-dialect))
  185. ;; (cl-defmethod ess-print-dialect (&context (ess-dialect "R"))
  186. ;; (message "dialect: R"))
  187. ;; (cl-defmethod ess-print-dialect (&context (ess-dialect "julia"))
  188. ;; (message "dialect: julia"))
  189. (provide 'ess)
  190. ;;; ess.el ends here