Klimi's new dotfiles with stow.
Du kannst nicht mehr als 25 Themen auswählen Themen müssen entweder mit einem Buchstaben oder einer Ziffer beginnen. Sie können Bindestriche („-“) enthalten und bis zu 35 Zeichen lang sein.

289 Zeilen
10 KiB

vor 4 Jahren
  1. ;;; ess-bugs-l.el --- ESS[BUGS] languages -*- lexical-binding: t; -*-
  2. ;; Copyright (C) 2006-2011 Rodney Sparapani
  3. ;; Author: Rodney Sparapani
  4. ;; Created: 16 August 2006
  5. ;; Maintainer: ESS-help <ess-help@r-project.org>
  6. ;; This file is part of ESS
  7. ;; This file is free software; you can redistribute it and/or modify
  8. ;; it under the terms of the GNU General Public License as published by
  9. ;; the Free Software Foundation; either version 2, or (at your option)
  10. ;; any later version.
  11. ;;
  12. ;; This file is distributed in the hope that it will be useful,
  13. ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. ;; GNU General Public License for more details.
  16. ;;
  17. ;; A copy of the GNU General Public License is available at
  18. ;; https://www.r-project.org/Licenses/
  19. ;;; Code:
  20. (require 'shell)
  21. (require 'ess-utils)
  22. (defvar ess-bugs-command)
  23. (defvar ess-bugs-chains)
  24. (defvar ess-jags-command)
  25. (defvar ess-jags-chains)
  26. (defvar ess-bugs-default-bins)
  27. (declare-function ess-bugs-na-bug "ess-bugs-d")
  28. (declare-function ess-jags-na-bug "ess-jags-d")
  29. (declare-function ess-bugs-na-bmd "ess-bugs-d")
  30. (declare-function ess-jags-na-jmd "ess-jags-d")
  31. (defgroup ess-bugs nil
  32. "ESS: BUGS."
  33. :group 'ess
  34. :prefix "ess-")
  35. (defcustom ess-bugs-batch-method
  36. (if (and ess-microsoft-p
  37. (fboundp 'w32-shell-dos-semantics)
  38. (w32-shell-dos-semantics))
  39. 'dos
  40. 'sh)
  41. "Method used by `ess-bugs-batch'.
  42. The default is based on the value of the Emacs variable `system-type'
  43. and, on Windows machines, the function `w32-shell-dos-semantics'.
  44. 'sh if *shell* runs a Bourne-like or a C-like Unix shell
  45. 'dos if *shell* runs a DOS-like Windows shell
  46. Unix users will get 'sh by default.
  47. Windows users running a DOS-like *shell* will get 'dos by default,
  48. while those running a Unix-like *shell* will get 'sh by default.
  49. Users whose default is not 'sh, but are accessing a remote machine with
  50. `telnet' or `ssh', should have the following in their init file:
  51. (setq-default ess-bugs-batch-method 'sh)"
  52. :group 'ess-bugs
  53. :type '(choice (const 'sh :tag "Bourne/C-like Unix Shell")
  54. (const 'dos :tag "DOS-like Windows shell")))
  55. (defcustom ess-bugs-batch-post-command
  56. (if (equal ess-bugs-batch-method 'sh) "&" " ")
  57. "ESS[BUGS]: Modifiers at the end of the batch BUGS command line."
  58. :group 'ess-bugs
  59. :type 'string
  60. )
  61. (defcustom ess-bugs-batch-pre-command
  62. (if (equal ess-bugs-batch-method 'sh) "nohup nice time"
  63. (if ess-microsoft-p "start"))
  64. "ESS[BUGS]: Modifiers at the beginning of the batch BUGS command line."
  65. :group 'ess-bugs
  66. :type 'string
  67. )
  68. (defcustom ess-bugs-default-burn-in "500"
  69. "ESS[BUGS]: Burn-in iterations to discard."
  70. :group 'ess-bugs
  71. :type 'string
  72. )
  73. (defcustom ess-bugs-default-update "1000"
  74. "ESS[BUGS]: Iterations to store."
  75. :group 'ess-bugs
  76. :type 'string
  77. )
  78. (defvar ess-bugs-batch-command ";"
  79. "ESS[BUGS]: The name of the command to run BUGS in batch mode."
  80. )
  81. (defvar ess-bugs-file "."
  82. "ESS[BUGS]: BUGS file with PATH.")
  83. (defvar ess-bugs-file-root "."
  84. "ESS[BUGS]: Root of BUGS file.")
  85. (defvar ess-bugs-file-suffix "."
  86. "ESS[BUGS]: Suffix of BUGS file.")
  87. (defvar ess-bugs-file-dir "."
  88. "ESS[BUGS]: Directory of BUGS file.")
  89. (defvar ess-bugs-file-data "..."
  90. "ESS[BUGS]: BUGS data file.")
  91. (defcustom ess-bugs-inits-suffix ".in"
  92. "ESS[BUGS]: BUGS init file suffix."
  93. :group 'ess-bugs
  94. :type 'string
  95. )
  96. (defcustom ess-bugs-data-suffix ".dat"
  97. "ESS[BUGS]: BUGS data file suffix."
  98. :group 'ess-bugs
  99. :type 'string
  100. )
  101. (defcustom ess-bugs-mode-hook nil
  102. "ESS[BUGS]: List of functions to call upon entering mode."
  103. :group 'ess-bugs
  104. :type 'hook)
  105. (defvar ess-bugs-monitor-vars " "
  106. "ESS[BUGS]: List of BUGS variables to be written out to a file.")
  107. (defvar ess-bugs-stats-vars " "
  108. "ESS[BUGS]: List of BUGS variables to be summarized with statistics.")
  109. (defvar ess-bugs-mode-map
  110. (let ((map (make-sparse-keymap)))
  111. (define-key map (quote [f2]) #'ess-revert-wisely)
  112. (define-key map "\C-c\C-c" #'ess-bugs-next-action)
  113. (define-key map "=" #'ess-bugs-hot-arrow)
  114. (define-key map "_" #'ess-bugs-hot-arrow)
  115. map)
  116. "ESS[BUGS]: Keymap for mode.")
  117. (defvar ess-bugs-syntax-table
  118. (let ((table (make-syntax-table)))
  119. (modify-syntax-entry ?\\ "." table)
  120. (modify-syntax-entry ?# "<" table)
  121. (modify-syntax-entry ?\n ">" table)
  122. (modify-syntax-entry ?\( "()" table)
  123. (modify-syntax-entry ?\) ")(" table)
  124. (modify-syntax-entry ?. "w" table)
  125. table)
  126. "ESS[BUGS]: Syntax table for mode.")
  127. (defun ess-bugs-file ()
  128. "ESS[BUGS]: Set internal variables dealing with BUGS files.
  129. Set `ess-bugs-file', `ess-bugs-file-root', `ess-bugs-file-suffix'
  130. and `ess-bugs-file-dir'."
  131. (let ((ess-bugs-temp-string (buffer-name)))
  132. (setq ess-bugs-file (expand-file-name ess-bugs-temp-string))
  133. (setq ess-bugs-file-dir
  134. (convert-standard-filename (file-name-directory ess-bugs-file)))
  135. (setq ess-bugs-file-root
  136. (file-name-nondirectory (file-name-sans-extension ess-bugs-file)))
  137. (if (fboundp 'file-name-extension)
  138. (setq ess-bugs-file-suffix (file-name-extension ess-bugs-temp-string))
  139. ;;else
  140. (setq ess-bugs-file-suffix (car (last (split-string ess-bugs-temp-string "[.]")))))
  141. (setq ess-bugs-file-suffix
  142. (downcase (car (split-string (concat "." ess-bugs-file-suffix) "[<]"))))
  143. (setq ess-bugs-file (concat ess-bugs-file-dir ess-bugs-file-root ess-bugs-file-suffix))
  144. )
  145. )
  146. (defun ess-bugs-exit-notify-sh (string)
  147. "ESS[BUGS]: Detect completion or failure of submitted job and notify the user."
  148. (let* ((exit-done "\\[[0-9]+\\] *\\+* *\\(Exit\\|Done\\)[^\r\n]*")
  149. (beg (string-match exit-done string)))
  150. (if beg (message "%s" (substring string beg (match-end 0))))))
  151. (defun ess-bugs-hot-arrow ()
  152. "ESS[BUGS]: Substitute <- for = key press"
  153. (interactive)
  154. (insert " <- "))
  155. (defun ess-bugs-next-action ()
  156. "ESS[BUGS/JAGS]: Perform the appropriate next action."
  157. (interactive)
  158. (ess-bugs-file)
  159. (cond ((equal ".bug" ess-bugs-file-suffix) (ess-bugs-na-bug))
  160. ((equal ".jag" ess-bugs-file-suffix) (ess-jags-na-bug))
  161. ((equal ".bmd" ess-bugs-file-suffix)
  162. (ess-save-and-set-local-variables)
  163. (ess-bugs-na-bmd ess-bugs-command ess-bugs-chains))
  164. ((equal ".jmd" ess-bugs-file-suffix)
  165. (ess-save-and-set-local-variables)
  166. (ess-jags-na-jmd ess-jags-command ess-jags-chains)))
  167. )
  168. (defun ess-bugs-sci-to-round-4-dp ()
  169. "ESS[BUGS]: round output from +/-0.000E+/-0 to 4 decimal places."
  170. (interactive)
  171. (setq buffer-read-only nil)
  172. (save-excursion (goto-char 0)
  173. (save-match-data (let ((ess-bugs-replacement-string nil)
  174. (ess-bugs-replacement-9 0)
  175. (ess-bugs-replacement-diff 0))
  176. (while (search-forward-regexp "-?[0-9][.][0-9][0-9][0-9]E[+-][0-9]" nil t)
  177. (setq ess-bugs-replacement-string
  178. (int-to-string (string-to-number (match-string 0))))
  179. (setq ess-bugs-replacement-diff (- (match-end 0) (match-beginning 0)))
  180. (save-match-data
  181. (setq ess-bugs-replacement-9
  182. (string-match "99999999999$" ess-bugs-replacement-string))
  183. (if (not ess-bugs-replacement-9)
  184. (setq ess-bugs-replacement-9
  185. (string-match "000000000001$" ess-bugs-replacement-string))))
  186. (if ess-bugs-replacement-9
  187. (setq ess-bugs-replacement-string
  188. (substring ess-bugs-replacement-string 0 ess-bugs-replacement-9)))
  189. (setq ess-bugs-replacement-diff
  190. (- ess-bugs-replacement-diff (string-width ess-bugs-replacement-string)))
  191. (while (> ess-bugs-replacement-diff 0)
  192. (setq ess-bugs-replacement-string (concat ess-bugs-replacement-string " "))
  193. (setq ess-bugs-replacement-diff (- ess-bugs-replacement-diff 1)))
  194. (replace-match ess-bugs-replacement-string))))))
  195. ;;; ESS[BUGS-Shell] for running BUGS interactively
  196. (defgroup ess-bugs-shell nil
  197. "ESS: BUGS-Shell."
  198. :group 'ess-bugs
  199. :prefix "ess-")
  200. (defcustom ess-bugs-shell-buffer-name "BUGS"
  201. "ESS[BUGS-Shell]: The name of the BUGS-Shell buffer."
  202. :group 'ess-bugs-shell
  203. :type 'string)
  204. (defcustom ess-bugs-shell-command "OpenBUGS"
  205. "ESS[BUGS-Shell]: The name of the command to run BUGS interactively.
  206. Set to the name of the batch BUGS script that comes with ESS or
  207. to the name of BUGS command. Make sure it is in your PATH or
  208. add path to the command name."
  209. :group 'ess-bugs-shell
  210. :type 'string)
  211. (defcustom ess-bugs-shell-default-output-file-root "bugs"
  212. "ESS[BUGS-Shell]: Default value for the root of output files."
  213. :group 'ess-bugs-shell
  214. :type 'string)
  215. (defcustom ess-bugs-shell-mode-hook nil
  216. "ESS[BUGS-Shell]: List of functions to call upon entering mode."
  217. :group 'ess-bugs-shell
  218. :type 'hook)
  219. (defun ess-bugs-shell ()
  220. "Create a buffer with BUGS running as a subprocess."
  221. (interactive)
  222. (pop-to-buffer-same-window (concat "*" ess-bugs-shell-buffer-name "*"))
  223. (make-comint ess-bugs-shell-buffer-name ess-bugs-shell-command nil
  224. ess-bugs-default-bins ess-bugs-shell-default-output-file-root)
  225. (comint-mode)
  226. (setq shell-dirtrackp t
  227. major-mode 'bugs-shell-mode
  228. mode-name "ESS[BUGS-Shell]"
  229. comint-prompt-regexp "^Bugs> *")
  230. (make-local-variable 'font-lock-defaults)
  231. (setq font-lock-defaults '(ess-bugs-font-lock-keywords nil t))
  232. (run-mode-hooks 'ess-bugs-shell-mode-hook)
  233. )
  234. (provide 'ess-bugs-l)
  235. ;;; ess-bugs-l.el ends here