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.

602 regels
23 KiB

5 jaren geleden
  1. ;; ess-gretl.el --- ESS gretl mode and inferior interaction -*- lexical-binding: t; -*-
  2. ;;
  3. ;; Copyright (C) 2012 Allin Cottrell
  4. ;; Copyright (C) 2012 Ahmadou DICKO
  5. ;; Copyright (C) 2013 ESS core team
  6. ;;
  7. ;; Filename: ess-gretl.el
  8. ;; Author: Ahmadou DICKO, Spinu Vitalie and Allin Cottrell (based on ess-julia.el and gretl.el)
  9. ;; Maintainer: Ahmadou DICKO
  10. ;; Created: 01-10-2012 (ESS 12.09)
  11. ;; Keywords: ESS, gretl, econometrics
  12. ;;
  13. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  14. ;;
  15. ;; This file is *NOT* part of GNU Emacs.
  16. ;;
  17. ;; This program is free software; you can redistribute it and/or
  18. ;; modify it under the terms of the GNU General Public License as
  19. ;; published by the Free Software Foundation; either version 3, any later version.
  20. ;;
  21. ;; This program is distributed in the hope that it will be useful, but WITHOUT
  22. ;; ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
  23. ;; FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
  24. ;; details.
  25. ;;
  26. ;; A copy of the GNU General Public License is available at
  27. ;; https://www.r-project.org/Licenses/
  28. ;;
  29. ;;
  30. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  31. ;;
  32. ;;; Commentary:
  33. ;; start the inferior with M-x gretl.
  34. ;;
  35. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  36. ;;
  37. (require 'compile); for compilation-* below
  38. (require 'ess-r-mode)
  39. ;;; Code:
  40. (add-to-list 'auto-mode-alist '("\\.inp$" . ess-gretl-mode))
  41. (defvar gretl-syntax-table
  42. (let ((table (make-syntax-table)))
  43. (modify-syntax-entry ?_ "w" table) ; underscores in words
  44. (modify-syntax-entry ?@ "w" table)
  45. (modify-syntax-entry ?# "<" table) ; # single-line comment start
  46. (modify-syntax-entry ?\n ">" table) ; \n single-line comment end
  47. (modify-syntax-entry ?\{ "(} " table)
  48. (modify-syntax-entry ?\} "){ " table)
  49. (modify-syntax-entry ?\[ "(] " table)
  50. (modify-syntax-entry ?\] ")[ " table)
  51. (modify-syntax-entry ?\( "() " table)
  52. (modify-syntax-entry ?\) ")( " table)
  53. (modify-syntax-entry ?\r " " table)
  54. (modify-syntax-entry ?+ "." table)
  55. (modify-syntax-entry ?- "." table)
  56. (modify-syntax-entry ?= "." table)
  57. (modify-syntax-entry ?* "." table)
  58. (modify-syntax-entry ?/ "." table)
  59. (modify-syntax-entry ?> "." table)
  60. (modify-syntax-entry ?< "." table)
  61. (modify-syntax-entry ?& "." table)
  62. (modify-syntax-entry ?| "." table)
  63. (modify-syntax-entry ?! "." table)
  64. (modify-syntax-entry ?\\ "\\" table)
  65. (modify-syntax-entry ?\' "." table)
  66. (modify-syntax-entry ?\` "w" table)
  67. (modify-syntax-entry ?\" "\"" table)
  68. (modify-syntax-entry ?. "w" table)
  69. (modify-syntax-entry ?_ "w" table)
  70. (modify-syntax-entry ?\% "." table)
  71. (modify-syntax-entry ?\# "<" table)
  72. (modify-syntax-entry ?\n ">" table)
  73. table)
  74. "Syntax table for `ess-gretl-mode'.")
  75. ;; syntax table that holds within strings
  76. (defvar ess-gretl-mode-string-syntax-table
  77. (let ((table (make-syntax-table)))
  78. table)
  79. "Syntax table for `ess-gretl-mode' that holds within strings.")
  80. (defcustom gretl-continuation-offset 4
  81. "Extra indentation applied to Gretl continuation lines."
  82. :type 'integer
  83. :group 'ess-gretl)
  84. (defvar gretl-continuation-regexp
  85. "[^#%\n]*\\(\\\\\\|\\.\\.\\.\\)\\s-*\\(\\s<.*\\)?$")
  86. (defcustom gretl-continuation-string "\\"
  87. "Character string used for Gretl continuation lines. Normally \\."
  88. :type 'string
  89. :group 'ess-gretl)
  90. ;; (defconst gretl-string-regex
  91. ;; "\"[^\"]*?\\(\\(\\\\\\\\\\)*\\\\\"[^\"]*?\\)*\"")
  92. (defconst gretl-function-header-regexp
  93. (concat "^\\s-*\\<\\(function\\)\\>"
  94. "\\([^=;\n]*=[ \t]*\\|[ \t]*\\)\\(\\w+\\)\\>")
  95. "Regexp to match a Gretl function header.
  96. The string `function' and its name are given by the first and third
  97. parenthetical grouping.")
  98. ;; (defconst ess-function-call-regexp
  99. ;; "\\s\"?\\(\\(\\sw\\|\\s_\\)+\\(<-\\)?\\)\\s\"?*\\s-*("
  100. ;; "Regexp for function names")
  101. (defvar gretl-command-words
  102. '("add" "adf" "anova" "append" "ar" "ar1" "arbond" "arch"
  103. "arima" "biprobit" "break" "boxplot" "chow" "clear" "coeffsum" "coint"
  104. "coint2" "corr" "corrgm" "cusum" "data" "dataset" "delete" "diff"
  105. "difftest" "discrete" "dpanel" "dummify" "duration" "elif" "else" "end"
  106. "endif" "endloop" "eqnprint" "equation" "estimate" "fcast" "foreign" "fractint"
  107. "freq" "function" "funcerr" "garch" "genr" "gmm" "gnuplot" "graphpg"
  108. "hausman" "heckit" "help" "hsk" "hurst" "if" "include" "info"
  109. "intreg" "kalman" "kpss" "labels" "lad" "lags" "ldiff" "leverage"
  110. "levinlin" "logistic" "logit" "logs" "loop" "mahal" "makepkg" "meantest"
  111. "mle" "modeltab" "modprint" "modtest" "mpols" "negbin" "nls" "normtest"
  112. "nulldata" "ols" "omit" "open" "orthdev" "outfile" "panel" "pca"
  113. "pergm" "textplot" "poisson" "print" "printf" "probit" "pvalue" "quantreg"
  114. "qlrtest" "qqplot" "quit" "rename" "reset" "restrict" "rmplot" "run"
  115. "runs" "scatters" "sdiff" "set" "setinfo" "setobs" "setmiss" "shell"
  116. "smpl" "spearman" "sprintf" "square" "sscanf" "store" "summary" "system"
  117. "tabprint" "tobit" "tsls" "var" "varlist" "vartest" "vecm" "vif"
  118. "wls" "xcorrgm" "xtab" "debug" "return" "catch" "for" "foreach"
  119. "while" "const" "3sls" "liml" "fiml"
  120. "sur" "params" "deriv" "orthog" "weights" "series" "scalar")
  121. "Commands in Gretl (these names are also reserved).")
  122. (defvar gretl-genr-functions
  123. '("abs" "sin" "cos" "tan" "asin" "acos" "atan" "sinh"
  124. "cosh" "tanh" "asinh" "acosh" "atanh" "log" "ln" "log10"
  125. "log2" "exp" "sqrt" "diff" "ldiff" "sdiff" "lags" "int"
  126. "round" "ceil" "floor" "sort" "dsort" "sortby" "ranking" "orthdev"
  127. "nobs" "firstobs" "lastobs" "uniform" "normal" "cum" "missing" "ok"
  128. "misszero" "lrvar" "quantile" "median" "gini" "zeromiss" "sum" "mean"
  129. "min" "max" "sd" "var" "sst" "cnorm" "dnorm" "qnorm"
  130. "gammafun" "lngamma" "digamma" "resample" "pnobs" "pmin" "pmax" "pmean"
  131. "psd" "hpfilt" "bkfilt" "bwfilt" "fracdiff" "boxcox" "cov" "corr"
  132. "movavg" "I" "zeros" "ones" "seq" "replace" "muniform" "mnormal"
  133. "sumc" "sumr" "meanc" "meanr" "sdc" "minc" "maxc" "minr"
  134. "maxr" "iminc" "imaxc" "iminr" "imaxr" "fft" "ffti" "cmult"
  135. "cdiv" "mcov" "mcorr" "mxtab" "cdemean" "cholesky" "psdroot" "inv"
  136. "invpd" "ginv" "diag" "transp" "vec" "vech" "unvech" "upper"
  137. "lower" "rows" "cols" "det" "ldet" "tr" "onenorm" "infnorm"
  138. "rcond" "rank" "qform" "mlag" "qrdecomp" "eigensym" "eigengen" "nullspace"
  139. "princomp" "mexp" "fdjac" "BFGSmax" "obsnum" "isseries" "isscalar" "islist"
  140. "isstring" "isnull" "nelem" "pdf" "cdf" "invcdf" "pvalue" "critical"
  141. "randgen" "urcpval" "values" "mshape" "svd" "mols" "mpols" "mrls"
  142. "mread" "mwrite" "selifc" "selifr" "polroots" "dummify" "wmean" "wvar"
  143. "wsd" "xpx" "filter" "kfilter" "ksmooth" "ksimul" "trimr" "getenv"
  144. "argname" "obslabel" "readfile" "grab" "strstr" "strncmp" "strlen" "sscanf"
  145. "varname" "varnum" "tolower" "colnames" "rownames" "ljungbox" "msortby" "lincomb"
  146. "imhof" "toepsolv" "diagcat" "xmin" "xmax" "corrgm" "mcovg" "fcstats"
  147. "bessel" "fraclag" "mreverse" "deseas" "pergm" "irr" "npv" "logistic"
  148. "weekday" "kdensity" "monthlen" "epochday" "setnote" "invmills" "polyfit" "chowlin"
  149. "varsimul" "strsplit" "inlist" "errmsg" "isconst" "irf" "inbundle")
  150. "Builtin functions for Gretl's genr command.")
  151. (defvar gretl-option-flags
  152. '("addstats" "all" "anova" "append"
  153. "arch" "arma-init" "asymptotic" "auto"
  154. "autocorr" "auxiliary" "balanced" "bartlett"
  155. "between" "bootstrap" "both" "breusch-pagan"
  156. "byobs" "by" "c" "close"
  157. "coded" "cols" "column" "comfac"
  158. "complete" "conditional" "contiguous" "continue"
  159. "continuous" "control" "covariance" "cross"
  160. "cross-section" "crt" "csv" "ct"
  161. "ctt" "cubes-only" "dat" "database"
  162. "dataset" "db" "degrees" "dhansen"
  163. "difference" "diffuse" "discrete" "dpdstyle"
  164. "drop-empty" "drop-first" "drop-last" "dummy"
  165. "dynamic" "equal" "exit" "exponential"
  166. "fcp" "fixed-effects" "from-file" "full"
  167. "func" "gamma" "geomean" "gls"
  168. "gmm" "gnu-R" "gnu-octave" "gph"
  169. "gzipped" "hausman-reg" "hessian" "hilu"
  170. "impulse-responses" "input" "inst" "integrate"
  171. "intervals" "inverse-fit" "iterate" "jackknife"
  172. "jbera" "jitter" "jmulti" "kendall"
  173. "lags" "lagselect" "lbfgs" "lillie"
  174. "liml" "linear-fit" "list" "loess-fit"
  175. "log" "loglogistic" "lognormal" "logs"
  176. "matrix" "matrix-diff" "medians" "ml"
  177. "model1" "multi" "multinomial" "nc"
  178. "next" "no-corc" "no-dates" "no-df-corr"
  179. "no-gradient-check" "no-header" "no-missing" "no-scaling"
  180. "no-stats" "normal" "normality" "notches"
  181. "numerical" "odbc" "omit-obs" "one-scale"
  182. "opg" "orthdev" "other" "out-of-sample"
  183. "output" "overwrite" "p-values" "panel"
  184. "panel-vars" "plot" "pooled" "preserve"
  185. "print-final" "progress-bar" "progressive" "pwe"
  186. "quadratic-fit" "quiet" "quit" "radians"
  187. "random" "random-effects" "rank-sum" "raw"
  188. "rc" "replace" "restrict" "restructure"
  189. "reverse" "robust" "rolling" "row"
  190. "rtf" "save" "save-all" "save-ehat"
  191. "save-xbeta" "scalars" "seasonals" "send-data"
  192. "sign" "signed-rank" "silent" "simple"
  193. "simple-print" "single-yaxis" "skip-df" "spearman"
  194. "special-time-series" "squares" "squares-only" "stacked-cross-section"
  195. "stacked-time-series" "static" "stdresid" "suppress-fitted"
  196. "swilk" "system" "t-ratios" "tall"
  197. "test-down" "tex" "time-dummies" "time-series"
  198. "to-file" "to_file" "traditional" "trend"
  199. "two-step" "unequal-vars" "uniform" "unit-weights"
  200. "variance-decomp" "vcv" "verbose" "wald"
  201. "weibull" "weights" "white" "white-nocross"
  202. "with-impulses" "with-lines" "write" "www"
  203. "x-12-arima" "y-diff-only" "z-scores" "zeros")
  204. "Gretl option flags.")
  205. (defvar gretl-internal-vars
  206. '("Fstat" "T" "ahat" "aic" "bic" "chisq" "coeff_ci"
  207. "coeff" "compan" "datatype" "df" "dwpval" "ec" "ehat"
  208. "error" "ess" "fcast" "fcerr" "gmmcrit" "hausman" "hqc"
  209. "h" "jalpha" "jbeta" "jvbeta" "kalman_llt" "kalman_lnl" "kalman_s2"
  210. "kalman_t" "kalman_uhat" "llt" "lnl" "mnlprobs" "ncoeff" "nobs"
  211. "nscan" "nvars" "obs" "pd" "pvalue" "rho" "rlnl"
  212. "rsq" "s00" "s01" "s11" "sample" "sargan" "sigma"
  213. "stderr" "stopwatch" "sysA" "sysB" "sysGamma" "t1" "t2"
  214. "test" "trsq" "uhat" "unit" "vcv" "version" "vma"
  215. "windows" "xlist" "xtxinv" "yhat" )
  216. "Model- and dataset-related variables.")
  217. (defconst gretl-block-start-keywords
  218. (list "loop" "foreign" "function" "gmm" "if" "system" "mle" "nls" "restrict"))
  219. (defconst gretl-block-other-keywords
  220. (list "else" "elif"))
  221. (defconst gretl-block-end-keywords
  222. (list "end" "endif" "endloop"))
  223. (defvar gretl-keywords
  224. (append gretl-block-start-keywords
  225. gretl-block-other-keywords
  226. gretl-block-end-keywords
  227. '("break"))
  228. "Reserved words in Gretl.")
  229. (defun gretl-at-keyword (kw-list)
  230. ; not a keyword if used as a field name, X.word, or quoted, :word
  231. (and (or (= (point) 1)
  232. (and (not (equal (char-before (point)) ?.))
  233. (not (equal (char-before (point)) ?:))))
  234. (not (ess-inside-string-or-comment-p (point)))
  235. (not (ess-inside-brackets-p (point)))
  236. (member (current-word) kw-list)))
  237. (defconst gretl-font-lock-keywords
  238. (list
  239. ;; Fontify all builtin keywords.
  240. (cons (concat "\\<\\("
  241. (mapconcat 'identity gretl-keywords "\\|")
  242. "\\)\\>")
  243. 'font-lock-keyword-face)
  244. ;; Fontify all option flags.
  245. (cons (concat "[ \t]--\\("
  246. (mapconcat 'identity gretl-option-flags "\\|")
  247. "\\)")
  248. 'font-lock-constant-face)
  249. ;; Fontify all command words.
  250. (cons (concat "\\<\\("
  251. (mapconcat 'identity gretl-command-words "\\|")
  252. "\\)\\>")
  253. 'font-lock-builtin-face)
  254. ;; Fontify all builtin operators.
  255. (cons "\\(&\\||\\|<=\\|>=\\|==\\|<\\|>\\|!=\\|!\\)"
  256. (if (boundp 'font-lock-builtin-face)
  257. 'font-lock-builtin-face
  258. 'font-lock-preprocessor-face))
  259. ;; Fontify all internal variables.
  260. (cons (concat "\\$\\("
  261. (mapconcat 'identity gretl-internal-vars "\\|")
  262. "\\)\\>")
  263. 'font-lock-variable-name-face)
  264. ;; Fontify all genr functions.
  265. (cons (concat "\\<\\("
  266. (mapconcat 'identity gretl-genr-functions "\\|")
  267. "\\)\\>")
  268. 'font-lock-variable-name-face)
  269. ;; Fontify all function declarations.
  270. (list gretl-function-header-regexp
  271. '(1 font-lock-keyword-face)
  272. '(3 font-lock-function-name-face nil t)))
  273. "Additional Gretl expressions to highlight.")
  274. (defvar gretl-block-begin-regexp
  275. (concat "\\<\\("
  276. (mapconcat 'identity gretl-block-start-keywords "\\|")
  277. "\\)\\>"))
  278. (defvar gretl-block-else-regexp
  279. (concat "\\<\\("
  280. (mapconcat 'identity gretl-block-other-keywords "\\|")
  281. "\\)\\>"))
  282. (defvar gretl-block-end-regexp
  283. (concat "\\<\\("
  284. (mapconcat 'identity gretl-block-end-keywords "\\|")
  285. "\\)\\>"))
  286. (defvar gretl-block-begin-or-end-regexp
  287. (concat gretl-block-begin-regexp "\\|" gretl-block-end-regexp))
  288. (defvar gretl-block-else-or-end-regexp
  289. (concat gretl-block-else-regexp "\\|" gretl-block-end-regexp))
  290. (defvar gretl-basic-offset 4)
  291. (defvar gretl-block-match-alist
  292. '(("loop" . ("endloop"))
  293. ("if" . ("else" "elif" "endif"))
  294. ("nls" . ("end"))
  295. ("mle" . ("end"))
  296. ("gmm" . ("end"))
  297. ("foreign" . ("end"))
  298. ("restrict" . ("end"))
  299. ("kalman" . ("end"))
  300. ("system" . ("end")))
  301. "Alist with Gretl's matching block keywords.
  302. Has Gretl's begin keywords as keys and a list of the matching else or
  303. end keywords as associated values.")
  304. ; get the position of the last open block
  305. (defun gretl-last-open-block-pos (min)
  306. (let ((count 0))
  307. (while (not (or (> count 0) (<= (point) min)))
  308. (backward-word 1)
  309. (setq count
  310. (cond ((gretl-at-keyword gretl-block-start-keywords)
  311. (+ count 1))
  312. ((and (zerop (string-match "\\(?:e\\(?:l\\(?:if\\|se\\)\\|nd\\(?:if\\|loop\\)?\\)\\)" (current-word)))
  313. (not (ess-inside-comment-p)) (not (ess-inside-brackets-p)))
  314. (- count 1))
  315. (t count))))
  316. (if (> count 0)
  317. (point)
  318. nil)))
  319. (defun gretl-last-open-block (min)
  320. (let ((pos (gretl-last-open-block-pos min)))
  321. (and pos
  322. (progn
  323. (goto-char pos)
  324. (+ gretl-basic-offset (current-indentation))))))
  325. ; return indent implied by a special form opening on the previous line, if any
  326. (defun gretl-form-indent ()
  327. (forward-line -1)
  328. (end-of-line)
  329. (backward-sexp)
  330. (if (gretl-at-keyword gretl-block-other-keywords)
  331. (+ gretl-basic-offset (current-indentation))
  332. (if (char-equal (char-after (point)) ?\()
  333. (progn
  334. (backward-word 1)
  335. (let ((cur (current-indentation)))
  336. (if (gretl-at-keyword gretl-block-start-keywords)
  337. (+ gretl-basic-offset cur)
  338. nil)))
  339. nil)))
  340. (defun gretl-indent-line ()
  341. "Indent current line of gretl code."
  342. (interactive)
  343. (end-of-line)
  344. (indent-line-to
  345. (or (and (ess-inside-string-p (point-at-bol)) 0)
  346. (save-excursion (ignore-errors (gretl-form-indent)))
  347. (save-excursion
  348. (let ((endtok (progn
  349. (beginning-of-line)
  350. (forward-to-indentation 0)
  351. (gretl-at-keyword gretl-block-end-keywords))))
  352. (ignore-errors (+ (gretl-last-open-block (point-min))
  353. (if endtok (- gretl-basic-offset) 0)))))
  354. ;; previous line ends in =
  355. (save-excursion
  356. (if (and (not (equal (point-min) (line-beginning-position)))
  357. (progn
  358. (forward-line -1)
  359. (end-of-line) (backward-char 1)
  360. (equal (char-after (point)) ?=)))
  361. (+ gretl-basic-offset (current-indentation))
  362. nil))
  363. ;; take same indentation as previous line
  364. (save-excursion (forward-line -1)
  365. (current-indentation))
  366. 0))
  367. (when (gretl-at-keyword gretl-block-end-keywords)
  368. (forward-word 1)))
  369. ;; (defun gretl-send-string-function (process string visibly)
  370. ;; (let ((gretl-process (get-process "gretlcli")))
  371. ;; (process-send-string process (format ess-load-command file)))
  372. ;; (defun gretl-send-string-function (process string visibly)
  373. ;; (let ((file (concat temporary-file-directory "gretl_eval_region.inp")))
  374. ;; (with-temp-file file
  375. ;; (insert string))
  376. ;; (process-send-string process (format ess-load-command file))))
  377. (defun gretl--get-words-from-command (command start-reg end-reg proc)
  378. (with-current-buffer (ess-command command nil nil nil nil proc)
  379. (goto-char (point-min))
  380. (let ((beg (or (re-search-forward start-reg nil t)
  381. (point-min)))
  382. (end (progn (goto-char (point-max))
  383. (or (re-search-backward end-reg)
  384. (point-max))))
  385. acum)
  386. (goto-char beg)
  387. (skip-chars-forward "\n")
  388. (while (re-search-forward "[^ \t\n]+" end t)
  389. (push (match-string-no-properties 0) acum))
  390. acum)))
  391. (cl-defmethod ess-help-get-topics (proc &context (ess-dialect "gretl"))
  392. (delete-dups
  393. (append gretl-command-words gretl-genr-functions
  394. gretl-block-end-keywords gretl-block-other-keywords
  395. gretl-block-start-keywords
  396. (gretl--get-words-from-command "help\n" "are:" "^For" proc)
  397. (gretl--get-words-from-command "help functions\n" "Accessors:" "^Functions" proc)
  398. (gretl--get-words-from-command "help functions\n" "^Functions" "^For" proc)
  399. )))
  400. ;; (defvar ess-gretl-error-regexp-alist '(gretl-in gretl-at)
  401. ;; "List of symbols which are looked up in `compilation-error-regexp-alist-alist'.")
  402. ;; (add-to-list 'compilation-error-regexp-alist-alist
  403. ;; '(gretl-in "^\\s-*in [^ \t\n]* \\(at \\(.*\\):\\([0-9]+\\)\\)" 2 3 nil 2 1))
  404. ;; (add-to-list 'compilation-error-regexp-alist-alist
  405. ;; '(gretl-at "^\\s-*\\(at \\(.*\\):\\([0-9]+\\)\\)" 2 3 nil 2 1))
  406. (defvar gretl-customize-alist
  407. '((comint-use-prompt-regexp . t)
  408. (inferior-ess-primary-prompt . "\\? ")
  409. (inferior-ess-secondary-prompt . "\\ ")
  410. (inferior-ess-prompt . "\\? ")
  411. (ess-local-customize-alist . 'gretl-customize-alist)
  412. (inferior-ess-program . "gretlcli")
  413. (ess-load-command . "open \"%s\"\n")
  414. ;; (ess-dump-error-re . "in \\w* at \\(.*\\):[0-9]+")
  415. ;; (ess-error-regexp . "\\(^\\s-*at\\s-*\\(?3:.*\\):\\(?2:[0-9]+\\)\\)")
  416. ;; (ess-error-regexp-alist . ess-gretl-error-regexp-alist)
  417. ;; (inferior-ess-objects-command . inferior-gretl-objects-command)
  418. ;; (inferior-ess-search-list-command . "search()\n")
  419. ;; inferior-ess-help-command . gretl-help-command)
  420. (inferior-ess-help-command . "help %s\n")
  421. (ess-language . "gretl")
  422. (ess-dialect . "gretl")
  423. (ess-suffix . "inp")
  424. (ess-dump-filename-template . (replace-regexp-in-string
  425. "S$" ess-suffix ; in the one from custom:
  426. ess-dump-filename-template-proto))
  427. (ess-change-sp-regexp . nil );ess-r-change-sp-regexp)
  428. (ess-help-sec-regex . ess-help-r-sec-regex)
  429. (ess-help-sec-keys-alist . ess-help-r-sec-keys-alist)
  430. (ess-function-pattern . ess-r-function-pattern)
  431. (ess-object-name-db-file . "ess-r-namedb.el" )
  432. ;; (ess-imenu-mode-function . nil)
  433. (ess-smart-operators . ess-r-smart-operators)
  434. (inferior-ess-exit-command . "exit\n")
  435. ;;harmful for shell-mode's C-a: -- but "necessary" for ESS-help?
  436. (inferior-ess-language-start . nil)
  437. (ess-STERM . "iESS")
  438. )
  439. "Variables to customize for Gretl -- set up later than Emacs initialization.")
  440. ;; (defcustom inferior-gretl-program "gretlcli"
  441. ;; "*The program to use for running gretl scripts."
  442. ;; :type 'string
  443. ;; :group 'ess-gretl)
  444. ;; (defvar ess-gretl-versions '("gretcli")
  445. ;; "List of partial strings for versions of Julia to access within ESS.
  446. ;; Each string specifies the start of a filename. If a filename
  447. ;; beginning with one of these strings is found on `exec-path', a M-x
  448. ;; command for that version of Julia is made available. ")
  449. (defcustom inferior-gretl-args ""
  450. "String of arguments used when starting gretl."
  451. :group 'ess-gretl
  452. :type 'string)
  453. ;;;###autoload
  454. (define-derived-mode ess-gretl-mode ess-mode "ESS[gretl]"
  455. "Major mode for editing gretl source. See `ess-mode' for more help."
  456. ;;(setq imenu-generic-expression R-imenu-generic-expression)
  457. (ess-setq-vars-local gretl-customize-alist)
  458. (setq font-lock-defaults `(,gretl-font-lock-keywords))
  459. (setq-local paragraph-start (concat "\\s-*$\\|" page-delimiter))
  460. (setq-local paragraph-separate (concat "\\s-*$\\|" page-delimiter))
  461. (setq-local paragraph-ignore-fill-prefix t)
  462. (setq-local comment-start "# ")
  463. (setq-local comment-add 1)
  464. (setq-local comment-start-skip "\\s<+\\s-*")
  465. (setq-local comment-column 40)
  466. (setq-local indent-line-function #'gretl-indent-line)
  467. (setq-local ess-local-customize-alist gretl-customize-alist)
  468. (when (fboundp 'ess-add-toolbar) (ess-add-toolbar)))
  469. (defvar ess-gretl-post-run-hook nil
  470. "Functions run in process buffer after Gretl starts.")
  471. ;;;###autoload
  472. (defun gretl (&optional start-args)
  473. "Call 'gretl',
  474. Optional prefix (C-u) allows to set command line arguments, such as
  475. --vsize. This should be OS agnostic.
  476. If you have certain command line arguments that should always be passed
  477. to gretl, put them in the variable `inferior-gretl-args'."
  478. (interactive "P")
  479. ;; get settings, notably inferior-ess-r-program :
  480. ;; (if (null inferior-gretl-program)
  481. ;; (error "'inferior-gretl-program' does not point to 'gretl-release-basic' executable")
  482. (ess-write-to-dribble-buffer ;; for debugging only
  483. (format
  484. "\n(Gretl): ess-dialect=%s, buf=%s"
  485. ess-dialect (current-buffer)))
  486. (let* ((r-start-args
  487. (concat inferior-gretl-args " " ; add space just in case
  488. (if start-args
  489. (read-string
  490. (concat "Starting Args [other than `"
  491. inferior-gretl-args
  492. "'] ? "))
  493. nil)))
  494. (inf-buf (inferior-ess r-start-args gretl-customize-alist)))
  495. (setq-local indent-line-function 'gretl-indent-line)
  496. (setq-local gretl-basic-offset 4)
  497. (setq indent-tabs-mode nil)
  498. (goto-char (point-max))
  499. ;; (if inferior-ess-language-start
  500. ;; (ess-eval-linewise inferior-ess-language-start
  501. ;; nil nil nil 'wait-prompt)))
  502. (with-current-buffer inf-buf
  503. (run-mode-hooks 'ess-gretl-post-run-hook))
  504. inf-buf))
  505. ;;;; IMENU
  506. ;; (defvar gretl-imenu-generic-expression
  507. ;; '(("Function (_)" "^\\s-*function\\s-+\\(_[^ \t\n]*\\)" 1)
  508. ;; ("Function" "^\\s-*function\\s-+\\([^_][^ \t\n]*\\)" 1)
  509. ;; ("Const" "^\\s-*const \\([^ \t\n]*\\)" 1)
  510. ;; ("Type" "^\\s-*\\w*type\\w* \\([^ \t\n]*\\)" 1)
  511. ;; ("Load" " *\\(load\\)(\\([^ \t\n)]*\\)" 2)
  512. ;; ;; ("Classes" "^.*setClass(\\(.*\\)," 1)
  513. ;; ;; ("Coercions" "^.*setAs(\\([^,]+,[^,]*\\)," 1) ; show from and to
  514. ;; ;; ("Generics" "^.*setGeneric(\\([^,]*\\)," 1)
  515. ;; ;; ("Methods" "^.*set\\(Group\\|Replace\\)?Method(\"\\(.+\\)\"," 2)
  516. ;; ;; ;;[ ]*\\(signature=\\)?(\\(.*,?\\)*\\)," 1)
  517. ;; ;; ;;
  518. ;; ;; ;;("Other" "^\\(.+\\)\\s-*<-[ \t\n]*[^\\(function\\|read\\|.*data\.frame\\)]" 1)
  519. ;; ;; ("Package" "^.*\\(library\\|require\\)(\\(.*\\)," 2)
  520. ;; ;; ("Data" "^\\(.+\\)\\s-*<-[ \t\n]*\\(read\\|.*data\.frame\\).*(" 1)))
  521. ;; ))
  522. ;; (defun ess-imenu-gretl (&optional arg)
  523. ;; "Gretl Language Imenu support for ESS."
  524. ;; (interactive)
  525. ;; (setq imenu-generic-expression gretl-imenu-generic-expression)
  526. ;; (imenu-add-to-menubar "Imenu-gretl"))
  527. ;; (defun ess-imenu-gretl (&optional arg)
  528. ;; "Gretl Language Imenu support for ESS."
  529. ;; (interactive)
  530. ;; (setq imenu-generic-expression gretl-imenu-generic-expression)
  531. ;; (imenu-add-to-menubar "Imenu-jl"))
  532. (provide 'ess-gretl)
  533. ;;; ess-gretl.el ends here