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