Klimi's new dotfiles with stow.
Du kan inte välja fler än 25 ämnen Ämnen måste starta med en bokstav eller siffra, kan innehålla bindestreck ('-') och vara max 35 tecken långa.

198 rader
7.2 KiB

4 år sedan
  1. ;;; ess-sp6-d.el --- S-Plus 6 & 7 & 8 customization
  2. ;; Copyright (C) 2001--2005 A.J. Rossini, Richard M. Heiberger, Martin
  3. ;; Maechler, Kurt Hornik, Rodney Sparapani, and Stephen Eglen.
  4. ;; Author: A.J. Rossini <rossini@u.washington.edu>
  5. ;; Created: 2001/02/06
  6. ;; Maintainer: ESS Core Team <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. ;; This file is distributed in the hope that it will be useful,
  14. ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. ;; GNU General Public License for more details.
  17. ;; A copy of the GNU General Public License is available at
  18. ;; https://www.r-project.org/Licenses/
  19. ;;; Commentary:
  20. ;; AJR copied S+5 to be S+6.
  21. ;; AJR copied S4 to be S+5.
  22. ;; DB contributed the changes from ess-sp3-d.el to
  23. ;; ess-s4-d.el. (removed the old ugly approach).
  24. ;; This file defines Sp5 customizations for ess-mode. Lots of thanks
  25. ;; to RMH and JMC for code and suggestions
  26. ;; Thanks to MM for making this sensible.
  27. ;;; Code:
  28. (require 'ess-mode)
  29. (require 'ess-inf)
  30. (require 'ess-s-lang)
  31. (require 'ess-trns)
  32. ;; You now need to make sure you've defined if you are running 5.0 or 5.1.
  33. ;; Lots of things are broken between them, GRR...
  34. (defun S+-directory-p (directory)
  35. "Splus 5++ directories have a .Data directory and a __Meta directory within."
  36. (and directory
  37. (file-directory-p (concat directory ".Data"))
  38. (file-directory-p (concat directory ".Data/__Meta"))))
  39. (defvar S+-directory-function #'inferior-ess-default-directory)
  40. (defvaralias 'S+6-setup-directory-function 'S+-setup-directory-function)
  41. (defvar S+-setup-directory-function
  42. (lambda (startdir)
  43. (when (and startdir (S+-directory-p startdir))
  44. (setenv "S_WORK"
  45. (if (getenv "S_WORK")
  46. (concat startdir ":" (getenv "S_WORK"))
  47. ;;(message "adding %s to S_WORK" startdir)
  48. startdir)))))
  49. (defvaralias 'S+6-customize-alist 'S+-customize-alist)
  50. (defvar S+-customize-alist
  51. (append
  52. '((ess-local-customize-alist . 'S+-customize-alist)
  53. (ess-dialect . S+-dialect-name)
  54. (ess-function-pattern . ess-r-function-pattern)
  55. (ess-object-name-db-file . "ess-sp6-namedb.el")
  56. (inferior-ess-program . inferior-S+-program)
  57. (inferior-ess-help-command . "help(\"%s\", pager=\"slynx -dump\", window=FALSE)\n")
  58. (inferior-ess-search-list-command . "searchPaths()\n")
  59. (ess-directory-function . S+-directory-function)
  60. (ess-setup-directory-function . S+-setup-directory-function)
  61. (ess-STERM . "iESS"))
  62. S+common-cust-alist)
  63. "Variables to customize for S+.")
  64. (defvar ess-S+-post-run-hook nil
  65. "Functions run in process buffer after the initialization of S+
  66. process.")
  67. (defvar ess-S+--injected-code
  68. ".ess_funargs <- function(funname){
  69. ## funname <- deparse(substitute(object))
  70. fun <- try(eval(parse(text=funname)), silent = TRUE)
  71. if(is.function(fun)) {
  72. special <- grepl('[:$@[]', funname)
  73. args <- args(fun)
  74. fmls <- formals(args)
  75. fmls.names <- names(fmls)
  76. fmls <- gsub('\\\"', '\\\\\\\"', as.character(fmls), fixed = TRUE)
  77. args.alist <- sprintf(\"'(%s)\", paste(\"(\\\"\", fmls.names, \"\\\" . \\\"\", fmls, \"\\\")\", sep = '', collapse = ' '))
  78. ## envname <- environmentName(environment(fun))
  79. envname <- if (special) '' else 'S+'
  80. cat(sprintf('(list \\\"%s\\\" %s )\\n', envname, args.alist))
  81. }
  82. }
  83. ")
  84. (defalias 'S+6 'S+)
  85. (defun S+ (&optional proc-name)
  86. "Call 'Splus6', based on S version 4, from Bell Labs.
  87. New way to do it."
  88. (interactive)
  89. (ess-write-to-dribble-buffer
  90. (format "\n(S+): ess-dialect=%s, buf=%s\n" ess-dialect (current-buffer)))
  91. (let ((inf-buf (inferior-ess nil S+-customize-alist)))
  92. (ess-command ess-S+--injected-code)
  93. (when inferior-ess-language-start
  94. (ess-eval-linewise inferior-ess-language-start))
  95. (with-current-buffer inf-buf
  96. (run-mode-hooks 'ess-S+-post-run-hook))
  97. inf-buf))
  98. (defalias 'S+6-mode 'S+-mode)
  99. ;;;###autoload
  100. (defun S+-mode (&optional proc-name)
  101. "Major mode for editing S+ source. See `ess-mode' for more help."
  102. (interactive)
  103. (setq-local ess-local-customize-alist S+-customize-alist)
  104. (ess-mode)
  105. (if (fboundp 'ess-add-toolbar) (ess-add-toolbar))
  106. (setq imenu-generic-expression ess-imenu-S-generic-expression)
  107. (when ess-imenu-use-S (imenu-add-to-menubar "Imenu-S")))
  108. (defalias 'S+6-transcript-mode 'S+-transcript-mode)
  109. (define-derived-mode S+-transcript-mode ess-transcript-mode "ESS S Transcript"
  110. "S-PLUS 6 transcript mode."
  111. :syntax-table S-syntax-table
  112. :group 'ess-S)
  113. (defvar ess-s-versions '("Splus")
  114. "List of partial strings for versions of S to access within ESS.
  115. Each string specifies the start of a filename. If a filename
  116. beginning with one of these strings is found on `exec-path', a M-x
  117. command for that version of S is made available. For example, if the
  118. file \"Splus7\" is found and this variable includes the string
  119. \"Splus\", a function called `M-x Splus7' will be available to run that
  120. version of S.
  121. If duplicate versions of the same program are found (which happens if
  122. the same path is listed on `exec-path' more than once), they are
  123. ignored by calling `delete-dups'.
  124. Set this variable to nil to disable searching for other versions
  125. of S using this method.
  126. If you set this variable, you need to restart Emacs (and set this variable
  127. before ess-site is loaded) for it to take effect.")
  128. (define-obsolete-variable-alias
  129. 'ess-s-versions-created 'ess-s-created-runners "ESS 18.10")
  130. (defvar ess-s-created-runners)
  131. (defun ess-s-define-runners ()
  132. "Generate functions for starting other versions of S.
  133. See `ess-s-versions' for strings that determine which functions are created.
  134. It assumes these versions of S can be run as a substitute for Splus6.
  135. This function returns the list of functions, if any, that were
  136. created. The functions will normally be placed on the menubar upon
  137. ESS initialization."
  138. (when ess-s-versions
  139. (let ((versions
  140. (delete-dups
  141. (mapcar #'file-name-nondirectory
  142. (apply #'nconc
  143. (mapcar #'ess-find-exec-completions
  144. ess-s-versions))))))
  145. ;; Iterate over each string in VERSIONS, creating a new defun
  146. ;; each time.
  147. (setq ess-s-created-runners
  148. (mapc (lambda (v) (ess-define-runner v "S")) versions))
  149. ;; Add to menu
  150. (when ess-s-created-runners
  151. ;; new-menu will be a list of 3-vectors, of the form:
  152. ;; ["R-1.8.1" R-1.8.1 t]
  153. (let ((new-menu (mapcar (lambda (x) (vector x (intern x) t))
  154. ess-s-created-runners)))
  155. (easy-menu-add-item ess-mode-menu '("Start Process")
  156. (cons "Other" new-menu)))))))
  157. ;; Define the runners
  158. (ess-s-define-runners)
  159. (define-obsolete-function-alias
  160. 'ess-s-versions-create 'ess-s-define-runners "ESS 18.10")
  161. ; Provide package
  162. (provide 'ess-sp6-d)
  163. ;;; ess-sp6-d.el ends here