1 ;;; essl-sta.el --- Stata customization
3 ;; Copyright (C) 1999--2000, Thomas Lumley, A. J. Rossini, Brendan Halpin.
4 ;; Copyright (C) 1997--2004 A.J. Rossini, Rich M. Heiberger, Martin
5 ;; Maechler, Kurt Hornik, Rodney Sparapani, and Stephen Eglen.
7 ;; Original Authors: Thomas Lumley <thomas@biostat.washington.edu>,
8 ;; Brendan Halpin <brendan@essex.ac.uk>
10 ;; Maintainers: ESS-core <ESS-core@stat.math.ethz.ch>
12 ;; Keywords: start up, configuration.
14 ;; This file is part of ESS (Emacs Speaks Statistics).
16 ;; This file is free software; you can redistribute it and/or modify
17 ;; it under the terms of the GNU General Public License as published by
18 ;; the Free Software Foundation; either version 2, or (at your option)
21 ;; This file is distributed in the hope that it will be useful,
22 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
23 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
24 ;; GNU General Public License for more details.
26 ;; You should have received a copy of the GNU General Public License
27 ;; along with GNU Emacs; see the file COPYING. If not, write to
28 ;; the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
31 ;;; This is based upon Version 0.4 of Stata mode.
37 ;; Stata modes. Emacs modes for using the Stata statistical package
38 ;; Modified from S-mode, comint-mode
40 ;; (c) thomas lumley 1997
42 ;; version 0.4 20/7/97
44 ;; This file is free software; you can redistribute it and/or modify
45 ;; it under the terms of the GNU General Public License as published by
46 ;; the Free Software Foundation; either version 2, or (at your option)
49 ;; This file is distributed in the hope that it will be useful,
50 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
51 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
52 ;; GNU General Public License for more details.
54 ;; You should have received a copy of the GNU General Public License
55 ;; along with GNU Emacs; see the file COPYING. If not, write to
56 ;; the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
60 (require 'make-regexp
) ; it's now local to the directory.
61 ;;(load-library "make-regexp") ;; this is necessary for
62 ;; ado-set-font-lock-keywords
63 ;; only needed in Emacs >= 22.x and newish Xemacsen:
64 (unless (boundp 'c-emacs-features
)
65 (require 'cc-vars
));; for syntax-table
67 ;(setq max-lisp-eval-depth 500)
69 (setq max-lisp-eval-depth
(max 600 max-lisp-eval-depth
)))
71 (defconst ess-help-STA-sec-keys-alist
72 '((?d .
"Description")
76 "Help section keys for S4.
77 `key' indicates the keystroke to use to search for the section heading
78 `string' in an Stata help file. `string' is used as part of a
79 regexp-search, and so specials should be quoted.
82 (defconst ess-help-STA-sec-regex
"^[A-Z a-z]+:?\n^[-]+$"
83 "Reg(ular) Ex(pression) of section headers in help file.")
85 (defvar STA-syntax-table nil
"Syntax table for Stata code.")
88 (setq STA-syntax-table
(make-syntax-table))
89 (modify-syntax-entry ?
\\ "." STA-syntax-table
) ;nullify escape meaning
90 (modify-syntax-entry ?\$
"." STA-syntax-table
)
91 (modify-syntax-entry ?
` "(\'" STA-syntax-table
)
92 (modify-syntax-entry ?
\' ")`" STA-syntax-table
)
93 ;;--------- begin cut-and-paste from lisp/progmodes/c-langs.el
96 ((memq '8-bit c-emacs-features
)
97 (modify-syntax-entry ?
/ ". 1456" STA-syntax-table
)
98 (modify-syntax-entry ?
* ". 23" STA-syntax-table
))
100 ((memq '1-bit c-emacs-features
)
101 (modify-syntax-entry ?
/ ". 124b" STA-syntax-table
)
102 (modify-syntax-entry ?
* ". 23" STA-syntax-table
))
104 (t (error "CC Mode is incompatible with this version of Emacs"))
106 (modify-syntax-entry ?
\n "> b" STA-syntax-table
)
107 ;; Give CR the same syntax as newline, for selective-display
108 (modify-syntax-entry ?\^m
"> b" STA-syntax-table
)
109 ;;--------- end cut-and-paste ------------------
110 (modify-syntax-entry ?
+ "." STA-syntax-table
)
111 (modify-syntax-entry ?-
"." STA-syntax-table
)
112 (modify-syntax-entry ?
= "." STA-syntax-table
)
113 (modify-syntax-entry ?%
"." STA-syntax-table
)
114 (modify-syntax-entry ?
< "." STA-syntax-table
)
115 (modify-syntax-entry ?
> "." STA-syntax-table
)
116 (modify-syntax-entry ?
& "." STA-syntax-table
)
117 (modify-syntax-entry ?|
"." STA-syntax-table
)
118 (modify-syntax-entry ?~
"." STA-syntax-table
))
121 (defun ado-set-font-lock-keywords ()
122 "Create font lock keywords for Stata syntax. This is from the
123 ado-mode of Bill Rising <brising@jhsph.edu>, and uses make-regexp."
124 ;; (make-local-variable 'ado-font-lock-keywords)
127 ;; special highlighting
128 ;; program definitions
131 '(("^\\*!.*") font-lock-keyword-face
)
137 "pr" "pro" "prog" "progr" "progra" "program"
138 ) font-lock-keyword-face
)
141 "de" "def" "defi" "defin" "define"
144 "l" "li" "lis" "list"
145 ) font-lock-type-face nil
)
147 '(("[_a-z]+[_a-z0-9]*") font-lock-keyword-face nil
)
151 '(("^[ \t]*version") font-lock-reference-face
)
153 '(("1.0 2.0 2.1 3.0 3.1 4.0 5.0 6 6.0") font-lock-type-face
)
159 ) font-lock-keyword-face
)
165 '(("^[ \t]*#delimit") font-lock-reference-face
)
167 '(("\\(cr\\|;\\)\\s-*$") font-lock-type-face nil
)
169 ;; set command (with endless options!)
172 '(("^[ \t]*set") font-lock-reference-face
)
175 "b" "be" "bee" "beep" "checksum" "contents"
176 "d" "di" "dis" "disp" "displ" "displa" "display"
177 "g" "gr" "gra" "grap" "graph" "graphi" "graphic" "graphics"
180 "l" "le" "lev" "leve" "level"
183 "mat" "mats" "matsi" "matsiz" "matsize"
185 "mem" "memo" "memor" "memory"
188 "ou" "out" "outp" "outpu" "output"
190 "r" "rm" "rms" "rmsg"
191 "se" "see" "seed" "seed0" "shell"
192 "te" "tex" "text" "texts" "textsi" "textsiz" "textsize"
193 "tr" "tra" "trac" "trace"
194 "t" "ty" "typ" "type" "video"
195 "vir" "virt" "virtu" "virtua" "virtual"
197 font-lock-reference-face t
)
199 '(("[a-zA-Z0-9]*") font-lock-type-face
)
201 ;; the constraint commands
206 "cons" "const" "constr" "constra" "constrai" "constrain" "constraint"
207 ) font-lock-reference-face
)
211 "de" "def" "defi" "defin" "define"
214 "l" "li" "lis" "list"
219 ;; the confirm commands - could be a mess!
224 "conf" "confi" "confir" "confirm"
225 ) font-lock-reference-face
)
228 "e" "ex" "exi" "exis" "exist" "existe" "existen" "existenc" "existence"
229 "f" "fi" "fil" "file"
230 "n" "nu" "num" "numb" "numbe" "number"
231 "v" "va" "var" "vari" "varia" "variab" "variabl" "variable"
232 ) font-lock-type-face
)
239 "conf" "confi" "confir" "confirm"
240 ) font-lock-reference-face
)
244 ) font-lock-type-face
)
247 "n" "nu" "num" "numb" "numbe" "number"
248 ) font-lock-type-face
)
255 "conf" "confi" "confir" "confirm"
256 ) font-lock-reference-face
)
260 ) font-lock-type-face
)
263 "f" "fi" "fil" "file"
264 "v" "va" "var" "vari" "varia" "variab" "variabl" "variable"
265 ) font-lock-type-face
)
272 "conf" "confi" "confir" "confirm"
273 ) font-lock-reference-face
)
276 "byte" "double" "float" "int" "long"
278 "str" "stri" "strin" "string"
279 ) font-lock-type-face
)
282 "v" "va" "var" "vari" "varia" "variab" "variabl" "variable"
283 ) font-lock-type-face
)
286 ;;; the str# won't quite look right, but that's the breaks for using
287 ;;; a tool like this...
292 "conf" "confi" "confir" "confirm"
293 ) font-lock-reference-face
)
297 ) font-lock-type-face
)
300 "v" "va" "var" "vari" "varia" "variab" "variabl" "variable"
301 ) font-lock-type-face
)
304 ;; the estimates commands
309 "est" "esti" "estim" "estima" "estimat" "estimate" "estimates"
310 ) font-lock-reference-face
)
314 "di" "dir" "dis" "disp" "displ" "displa" "display"
316 "h" "ho" "hol" "hold"
319 "mat" "matr" "matri" "matrix"
322 "sca" "scal" "scala" "scalar"
323 "u" "un" "unh" "unho" "unhol" "unhold"
334 ) font-lock-reference-face
)
345 "vline" "vpoint" "vpoly" "vtext"
351 ;; some of the matrix commands
355 '(("mat" "matr" "matri" "matrix") font-lock-reference-face
)
357 '(("ac" "acc" "accu" "accum"
359 "coln" "colna" "colnam" "cloname" "colnames"
360 "d" "def" "defi" "defin" "define"
361 "di" "dir" "dispCns" "drop" "drop _all"
362 "glsa" "glsac" "glsacc" "glsaccu" "glsaccum"
363 "l" "li" "lis" "list" "makeCns" "mlou" "mlout" "post"
365 "rown" "rowna" "rownam" "rowname" "rownames"
367 "sub" "subs" "subst" "substi" "substit" "substitu" "substitut" "substitute"
368 "svd" "syme" "symei" "symeig" "symeige" "symeigen"
369 "veca" "vecac" "vecacc" "vecaccu" "vecaccum"
378 '(("ml") font-lock-reference-face
)
380 '(("b" "be" "beg" "begi" "begin"
382 "de" "dep" "depn" "depna" "depnam" "depname" "depnames"
383 "di" "dis" "disp" "displ" "displa" "display"
384 "f" "fu" "fun" "func" "funct" "functi" "functio" "function"
385 "gr" "gra" "grap" "graph"
387 "max" "maxi" "maxim" "maximi" "maximiz" "maximize"
388 "me" "met" "meth" "metho" "method"
389 "ml" "mlo" "mlou" "mlout"
390 "mo" "mod" "mode" "model"
393 "q" "qu" "que" "quer" "query"
394 "re" "rep" "repo" "repor" "report"
395 "sa" "sam" "samp" "sampl" "sample"
396 "se" "sea" "sear" "searc" "search"
405 '(("net") font-lock-reference-face
)
409 "d" "de" "des" "desc" "descr" "descri" "describ" "describe"
410 "from" "get" "install"
412 "q" "qu" "que" "quer" "query")
419 '(("net") font-lock-reference-face
)
421 '(("set") font-lock-reference-face
)
423 '(("ado" "other") font-lock-type-face
)
429 '(("ado") font-lock-reference-face
)
431 '(("d" "de" "des" "desc" "descr" "descri" "describ" "describe"
437 ;; the reshape commands
441 '(("reshape") font-lock-keyword-face
)
453 ;; the return commands
457 '(("ret" "retu" "retur" "return") font-lock-reference-face
)
459 '(("add" "clear" "local" "matrix" "scalar") font-lock-type-face
)
465 '(("sret" "sretu" "sretur" "sreturn") font-lock-reference-face
)
467 '(("clear" "local") font-lock-type-face
)
474 '(("sts") font-lock-reference-face
)
478 "gen" "gene" "gener" "genera" "generat" "generate"
479 "gr" "gra" "grap" "graph"
480 "l" "li" "lis" "list"
481 "t" "te" "tes" "test"
490 '(("sw") font-lock-reference-face
)
493 "cloglog" "cnreg" "cox" "ereg" "gamma" "glm" "gompertz" "hetprob"
494 "llogist" "lnormal" "logistic" "logit" "ologit" "oprobit"
495 "poisson" "probit" "qreg" "reg" "regr" "regre" "regres" "regress"
496 "scobit" "tobit" "weibull"
501 ;; the window commands
506 "win" "wind" "windo" "window"
507 ) font-lock-reference-face
)
511 "di" "dia" "dial" "dialo" "dialog"
513 "fo" "fop" "fope" "fopen"
514 "fs" "fsa" "fsav" "fsave"
517 "stop" "stopb" "stopbo" "stopbox"
518 ) font-lock-type-face
)
521 ;; the window controls
526 "win" "wind" "windo" "window"
527 ) font-lock-reference-face
)
530 "c" "co" "con" "cont" "contr" "contro" "control"
531 ) font-lock-reference-face
)
533 "button" "check" "clear"
542 ) font-lock-type-face
)
545 ;; the window manage commands
550 "win" "wind" "windo" "window"
551 ) font-lock-reference-face
)
554 "man" "mana" "manag" "manage"
555 ) font-lock-reference-face
)
571 ;; the window menu commands
576 "win" "wind" "windo" "window"
577 ) font-lock-reference-face
)
580 "m" "me" "men" "menu"
581 ) font-lock-reference-face
)
594 ;; the xwindow commands
599 "xwin" "xwind" "xwindo" "xwindow"
600 ) font-lock-reference-face
)
603 "de" "def" "defi" "defin" "define"
606 "l" "li" "lis" "list"
612 ;; all the endless Stata keywords (not in a good order)
613 ;; first those keywords which must start line
614 ;; note that these will look like text if preceded by a comment
615 ;; (but comments shouldn't be before the command, anyway)
621 "cap" "capt" "captu" "captur" "capture"
622 "char" "err" "erro" "error" "e" "ex" "exi" "exit"
625 ) font-lock-reference-face
)
628 ;; here are some keywords which appear in the middle of lines
629 ;; note that the really short abbreviations could make a mess of things
631 ;; These are split to allow compiling!
636 "_huber" "_qreg" "_robust"
639 "an" "ano" "anov" "anova" "arch"
641 "as" "ass" "asse" "asser" "assert"
645 "biprobit" "bitest" "bitesti" "blogit"
646 "boxcox" "bprobit" "br" "break" "brier"
647 "bro" "brow" "brows" "browse"
648 "bsqreg" "bstat" "by"
649 "canon" "cat" "cc" "cci" "cchart" "centile" "cf" "ci" "cii"
650 "clogi" "clogit" "clogitp" "cloglog"
652 "cnr" "cnre" "cnreg" "cnsreg" "codebook" "compare"
654 "cor" "corc" "corr" "corre" "correl" "correla" "correlat" "correlate"
657 "cox" "cprplot" "_crcswxx" "cs" "csi"
658 "ct" "ctset" "cttost"
660 font-lock-reference-face
)
667 "d" "de" "des" "desc" "descr" "descri" "describ" "describe"
668 "dfbeta" "dfuller" "di"
669 "dir" "dis" "disp" "disp_res" "disp_s"
670 "displ" "displa" "display"
672 "dprobit" "ds" "dstdize" "dwstat"
674 "fac" "fact" "facto" "factor"
675 "fit" "for" "fpredict"
676 "fracplot" "fracpoly" "fsl"
677 ) font-lock-reference-face
)
684 "gettoken" "gladder" "glm" "glmpred" "glogit" "gnbreg" "gompertz"
685 "gphdot" "gphpen" "graph" "gprobit" "greigen" "grmeanby"
686 "hadimvo" "hausman" "heckman" "heckprob" "hetprob" "hettest" "hilite"
688 "iqreg" "istdize" "iis"
689 "ins" "insp" "inspe" "inspec" "inspect"
690 "integ" "intreg" "ir" "iri" "ivreg"
691 "kap" "kappa" "kapwgt" "kdensity" "ksm" "ksmirnov" "ktau"
693 ) font-lock-reference-face
)
700 "l" "ladder" "lfit" "lincom" "linktest"
706 "lo" "loo" "look" "looku" "lookup"
707 "lpredict" "lroc" "lrtest" "ls" "lsens" "lstat" "ltable" "lv" "lvr2plot"
708 "man" "matcproc" "mcc" "mcci"
710 "mlog" "mlogi" "mlogit"
713 "n" "nbreg" "newey" "news"
715 "no" "noi" "nois" "noisi" "noisil" "noisily"
718 "olog" "ologi" "ologit"
720 "on" "one" "onew" "onewa" "oneway"
721 "oprob" "oprobi" "oprobit"
725 font-lock-reference-face
)
731 '(("pac" "pchart" "pchi" "pcorr" "pergram"
733 "pnorm" "poisgof" "poisson" "pperron"
735 "prob" "probi" "probit"
738 "q" "qchi" "qnorm" "qqplot" "qreg" "quadchk" "quantile"
739 "qu" "que" "quer" "query"
740 "qui" "quie" "quiet" "quietl" "quietly"
741 "ranksum" "rchart" "regdw" "regph"
742 "reg" "reg3" "regr" "regre" "regres" "regress" "reshape"
743 "rot" "rota" "rotat" "rotate"
745 "run" "runtest" "rvfplot" "rvpplot"
746 ) font-lock-reference-face
)
754 "sco" "scobit" "scor" "score"
755 "sdtest" "sdtesti" "search" "serrbar"
756 "sfrancia" "shell" "shelltool" "shewhart" "signrank" "signtest"
757 "sktest" "slog" "spearman" "spikeplt" "sqreg"
758 "st" "st_is" "st_show" "st_ct"
759 "stcox" "stcoxkm" "stcurv" "stdes"
761 "stereg" "stir" "stmc" "stmh" "stphplot" "stphtest"
763 "sts" "stse" "stset" "stsum" "stvary" "stweib"
764 "su" "sum" "summ" "summa" "summar" "summari" "summariz" "summarize"
766 "svydes" "svyintrg" "svyivreg" "svylc" "svylogit"
767 "svymean" "svymean" "svymlog" "svyolog" "svyoprob" "svypois" "svyprobt"
768 "svyprop" "svyratio" "svyreg" "svyset" "svytab" "svytest" "svytotal"
769 "swilk" "symmetry" "symmi" "symplot" "syntax" "sysdir"
770 ) font-lock-reference-face
)
782 "tabu" "tabul" "tabula" "tabulat" "tabulate"
784 "testnl" "testparm" "tis"
786 "token" "tokeni" "tokeniz" "tokenize"
787 "touch" "tsreport" "tsset" "tsunab" "ttest" "ttesti"
791 "verinst" "vif" "vwls"
792 "weibull" "which" "who" "wntestb" "wntestq"
794 "xtclog" "xtdes" "xtgee" "xtgls" "xthaus" "xtintreg"
795 "xtlogit" "xtnbreg" "xtpois" "xtprobit"
796 "xtrchh" "xtreg" "xtsum" "xttab" "xttest0" "xttobit" "xttrans"
798 ) font-lock-reference-face
)
802 ;; conditional statements
803 ;; if might not work right ('cuz it is also a keyword)
808 ) font-lock-reference-face t t
)
816 ) font-lock-reference-face t t
)
819 ;; else statement (which must just have a {)
824 ) font-lock-reference-face
)
828 ;; short version of list --- which can get fooled if used as a var
832 ) font-lock-reference-face
)
835 ;; all the Stata options
836 ;; commonly used options
840 '(("byte" "int" "long" "str[1-9]+[0-9]?" "float" "double"
841 "width" "maxobs" "maxvar"
842 ) font-lock-type-face
)
845 ;; special local variables (used in parsing)
848 "^[ \t]+\\(local\\)+[ \t]+"
849 '(("varlist" "exp" "weight" "if" "in" "using" "options"
850 ) font-lock-type-face nil t t
)
854 ;; things used with display
855 ;; since these are often split across lines, and Stata commands are hard
856 ;; to delimit, this will highlight even if out of context
862 "_c" "_co" "_con" "_cont" "_conti" "_contin" "_continu" "_continue"
863 "_n" "_ne" "_new" "_newl" "_newli" "_newlin" "_newline"
865 "_r" "_re" "_req" "_requ" "_reque" "_reques" "_request"
874 "_col" "_colu" "_colum" "_column"
876 "_s" "_sk" "_ski" "_skip"
885 "b" "bl" "blu" "blue"
886 "g" "gr" "gre" "gree" "green"
888 "w" "wh" "whi" "whit" "white"
889 "y" "ye" "yel" "yell" "yello" "yellow"
890 ) font-lock-type-face
)
898 '(("lab" "labe" "label"
899 ) font-lock-reference-face t
)
903 "de" "def" "defi" "defin" "define"
906 "l" "li" "lis" "list"
908 "val" "valu" "value" "values"
909 "var" "vari" "varia" "variab" "variabl" "variable"
910 ) font-lock-type-face nil t t
)
914 ;; all Stata data-altering stuff
921 "bcskew0" "bsample" "bs" "bstrap"
922 "cd" "chdir" "clear" "compress"
923 "contract" "convert" "cross"
924 "dec" "deco" "decod" "decode"
925 "discard" "drop" "dydx"
926 "ed" "edi" "edit" "egen"
927 "en" "enc" "enco" "encod" "encode"
931 "form" "forma" "format"
933 "g" "ge" "gen" "gene" "gener" "genera" "generat" "generate"
936 "infile" "infix" "input" "insheet" "integ" "ipolate"
940 ) font-lock-keyword-face
)
947 "mark" "markout" "marksample"
950 "mkdir" "mkmat" "mkspline"
951 "mleval" "mlmatsum" "mlsum""mlvecsum"
952 "modify" "mov" "move"
953 "mvdecode" "mvencode" "nlpred" "nobreak" "order"
954 "ou" "out" "outf" "outfi" "outfil" "outfile"
955 "outs" "outsh" "outshe" "outshee" "outsheet"
957 "post" "postclose" "postfile"
958 "pre" "pred" "predi" "predic" "predict"
961 "ren" "rena" "renam" "rename"
962 "renpfix" "replace" "restore" "rm"
967 "simul" "sinfile" "smerge"
970 "ssave" "ssort" "stack"
971 "stbase" "stfill" "stgen" "stjoin" "stsplit" "sttocc" "sttoct"
975 "xi" "xi:" "xtile" "xpose"
977 ) font-lock-keyword-face
)
981 ;; assignment of macros
985 '(("global" "local" "scalar"
986 ) font-lock-reference-face
)
987 '(("\\([ \t]+[a-zA-Z_]+[a-zA-Z_0-9]*\\b\\)?"
988 ) font-lock-variable-name-face t
)
990 ;; choosing temp names
994 '(("tempname" "tempfile" "tempvar"
995 ) font-lock-reference-face
)
996 '(("\\([ \t]+[a-zA-Z_]+[a-zA-Z_0-9`']*\\)+"
997 ) font-lock-type-face t
)
999 ;; all variable/macro stuff (put late so it will override)
1000 ;; internal constants
1004 '(("_merge" "_n" "_pi" "_rc" "_N"
1005 ) font-lock-variable-name-face
)
1008 ;; some generated vars
1011 '(("_result([1-9]+)"
1012 ) font-lock-variable-name-face
)
1017 '(("\\$[a-zA-Z_*]+[a-zA-Z_0-9]*"
1018 ) font-lock-variable-name-face t
)
1024 '(("[a-zA-Z_`*]+[a-zA-Z_0-9]*" ;has glitch interior ` is highlighted
1025 ) font-lock-variable-name-face t
)
1028 ;; other macro commands
1033 "ma" "mac" "macr" "macro"
1034 ) font-lock-reference-face
)
1040 "l" "li" "lis" "list"
1041 "s" "sh" "shi" "shif" "shift"
1043 font-lock-type-face
)
1046 ;; stata 'functions' i.e. things which require () after them
1051 "abs" "acos" "asin" "atan" "autocode"
1054 "chiprob" "comb" "cond" "cos"
1055 "d" "date" "digamma" "day"
1056 "dofh" "dofm" "dofq" "dofw" "dofy" "dow" "doy"
1058 "float" "fprob" "gammap" "get" "group"
1059 "h" "halfyear" "halfyearly" "hofd"
1060 "ibeta" "index" "int"
1061 "invbinomial" "invchi" "invfprob" "invgammap" "invnchi" "invnorm" "invt"
1062 "length" "ln" "lnfact" "lngamma" "log" "log10" "lower" "ltrim"
1063 "m" "matrix" "max" "mdy" "min" "missing" "mod" "mofd" "month" "monthly"
1064 "nchi" "normd" "normprob" "npnchi"
1065 "q" "qofd" "quarter" "quarterly"
1066 "r" "real" "recode" "reldif" "replay" "return" "round" "rtrim"
1067 "s" "scalar" "sign" "sin" "sqrt" "string" "substr" "sum"
1068 "tan" "tprob" "trigamma" "trim"
1069 "uniform" "uniform0" "upper"
1070 "w" "week" "weekly" "wofd"
1071 "y" "year" "yearly" "yh" "ym" "yofd" "yq" "yw"
1073 font-lock-reference-face t
)
1076 ;; stata 'functions' i.e. things which require [] after them
1080 '(("_b" "_coef" "_se")
1081 font-lock-reference-face t
)
1084 ;; common Stata options which require a () after them
1088 '(("bands" "by" "connect" "density" "gap" "iterate" "ltolerance" "margin"
1089 "psize" "saving" "tlabel" "tolerance"
1090 "xlabel" "xscale" "ylabel" "yscale")
1091 font-lock-type-face t
)
1094 ;; egen 'function' options
1097 "[ \t]*egen[ \t]+.*=[ \t]*"
1098 '(("count" "diff" "fill" "group" "iqr"
1099 "ma" "max" "mean" "median" "min" "mtr" "pctile"
1100 "rank" "rfirst" "rlast" "rmax" "rmean" "rmin" "rmiss" "robs" "rsd" "rsum"
1102 font-lock-reference-face t
)
1105 ;; All Custom ado files which are 'reliable' and which are not file killers
1106 ;; this might be a useless endeavor --- but I cannot generate tag files
1107 ;; all the s-extensions are listed under Stata's name (since they alter
1108 ;; data and will be moved tot he utils directory
1112 '(("addnote" "anypath" "autolab" "checkvar" "ck1icd9" "ckicd9"
1113 "datetoe" "dattomdy" "den2dem" "dishis" "dtapath" "dupclean" "echo"
1114 "exdupbil" "ezip2hsa" "getdate" "getlbl" "getnames" "getobs" "gplur"
1115 "icd9" "issorted" "isfile" "jultoe" "jultof" "jultomdy" "knowndup"
1117 "markit" "makewide" "missize" "mpcounts"
1118 "nodups" "notefile" "prov2zip"
1120 "random" "readraw" "readzip" "repart"
1123 "wdatetoe" "wdatomdy" "zip2ezip"
1124 "_addext" "_brclean" "_brckado" "_brdlog"
1125 "_ckbad" "_ckdunno" "_ckdupl" "_ckmiss" "_ckok" "_ckwarn"
1126 "_delimit" "_filenm" "_lookup" "_mk_ck"
1127 ) font-lock-function-name-face
)
1133 (defvar ess-STA-mode-font-lock-keywords
(ado-set-font-lock-keywords)
1134 "Set the Stata mode font-lock keywords to Bill Rising's ado-mode keywords.")
1136 (defvar STA-editing-alist
1137 '((paragraph-start .
(concat "^$\\|" page-delimiter
))
1138 (paragraph-separate .
(concat "^$\\|" page-delimiter
))
1139 (paragraph-ignore-fill-prefix . t
)
1140 (require-final-newline . t
)
1141 (comment-start .
"/\* ")
1142 (comment-end .
" \*/")
1143 (comment-start-skip .
"/\\*+ *")
1144 (comment-column .
40)
1145 ;;(comment-indent-function . 'S-comment-indent)
1146 ;;(ess-comment-indent . 'S-comment-indent)
1147 ;;(ess-indent-line . 'S-indent-line)
1148 ;;(ess-calculate-indent . 'S-calculate-indent)
1149 (indent-line-function .
'S-indent-line
)
1150 (parse-sexp-ignore-comments . t
)
1151 (ess-set-style . ess-default-style
)
1152 (ess-local-process-name . nil
)
1153 ;;(ess-keep-dump-files . 'ask)
1154 (ess-mode-syntax-table . STA-syntax-table
)
1155 (font-lock-defaults .
'(ess-STA-mode-font-lock-keywords
1156 nil nil
((?\. .
"w")))))
1157 "General options for editing Stata do and ado source files.")
1159 ;; YOU USED TO HAVE TO (with Thomas's version):
1160 ;;;;; Add the following to your .emacs file
1162 ;;(autoload 'stata "~/essl-sta.el" "inferior stata mode" t )
1163 ;;(autoload 'stata-help "stata" "stata help mode" t)
1164 ;;(autoload 'stata-mode "~/essl-sta.el" "stata mode" t)
1166 ;;(if (assoc "\\.do$" auto-mode-alist) nil
1167 ;; (setq auto-mode-alist
1169 ;; '(("\\.do$" . stata-mode)
1170 ;; ("\\.ado$" . stata-mode))
1171 ;; auto-mode-alist)))
1175 ;; QUESTIONS TO ASK THOMAS:
1176 ;; 1 - are 'help' and 'lookup' the same?
1177 ;; 2 - what is the point of the review buffer?
1181 ;; NOTE: all of Thomas's functions have been left here, to be removed
1182 ;; or merged into real locations as we work on this.
1186 ;;;;;;;;; Things to change
1188 (defvar stata-switches
"-q"
1189 "*Switches to apply to stata invocation.")
1191 (defvar stata-profile
"~/.stataprofile"
1192 "File to read on startup (nil for no file).")
1198 (defun stata-help (the-subject)
1199 "Stata help in other buffer."
1200 (interactive "sHelp on: ")
1201 (let* ((stata-process (get-process "stata"))
1202 (stata-buffer (process-buffer stata-process
))
1204 (set-buffer stata-buffer
)
1205 (setq oldpf
(process-filter stata-process
))
1206 (setq oldpb
(process-buffer stata-process
))
1207 (setq oldpm
(marker-position (process-mark stata-process
)))
1209 (if stata-process nil
(error "Stata is not running."))
1211 (if (looking-at ". ") nil
(error "Stata not ready."))
1213 (set-process-buffer stata-process
(get-buffer-create "*stata help*"))
1214 (set-buffer "*stata help*")
1215 (setq buffer-read-only nil
)
1216 (set-process-filter stata-process
'ordinary-insertion-filter
)
1218 (process-send-string stata-process
"help ")
1219 (process-send-string stata-process the-subject
)
1220 (process-send-string stata-process
"\n")
1221 (stata-prompt-wait stata-process
)
1223 (set-buffer stata-buffer
)
1224 (set-process-buffer stata-process oldpb
)
1225 (set-process-filter stata-process oldpf
)
1226 (set-marker (process-mark stata-process
) oldpm
)))
1227 (display-buffer "*stata help*")))
1229 (defun stata-lookup (the-subject) "Stata lookup in other buffer"
1230 (interactive "sLook up: ")
1231 (let* ((stata-process (get-process "stata"))
1232 (stata-buffer (process-buffer stata-process
))
1234 (set-buffer stata-buffer
)
1235 (setq oldpf
(process-filter stata-process
))
1236 (setq oldpb
(process-buffer stata-process
))
1237 (setq oldpm
(marker-position (process-mark stata-process
)))
1239 (if stata-process nil
(error "Stata is not running."))
1241 (if (looking-at ". ") nil
(error "Stata not ready."))
1243 (set-process-buffer stata-process
(get-buffer-create "*stata help*"))
1244 (set-buffer "*stata help*")
1245 (setq buffer-read-only nil
)
1246 (set-process-filter stata-process
'ordinary-insertion-filter
)
1248 (process-send-string stata-process
"lookup ")
1249 (process-send-string stata-process the-subject
)
1250 (process-send-string stata-process
"\n")
1251 (stata-prompt-wait stata-process
)
1253 (set-buffer stata-buffer
)
1254 (set-process-buffer stata-process oldpb
)
1255 (set-process-filter stata-process oldpf
)
1256 (set-marker (process-mark stata-process
) oldpm
)))
1257 (display-buffer "*stata help*")))
1259 (defun stata-variables ()
1260 "Stata variable list in other buffer."
1262 (let* ((stata-process (get-process "stata"))
1263 (stata-buffer (if stata-process
1264 (process-buffer stata-process
)
1265 (error "Stata is not running.")))
1267 (set-buffer stata-buffer
)
1268 (setq oldpf
(process-filter stata-process
))
1269 (setq oldpb
(process-buffer stata-process
))
1270 (setq oldpm
(marker-position (process-mark stata-process
)))
1272 (if stata-process nil
(error "Stata is not running."))
1274 (if (looking-at ". ") nil
(error "Stata not ready."))
1276 (set-process-buffer stata-process
1277 (get-buffer-create "*stata variables*"))
1278 (set-process-filter stata-process
'ordinary-insertion-filter
)
1279 (set-buffer "*stata variables*")
1280 (setq buffer-read-only nil
)
1282 (process-send-string stata-process
"desc \n ")
1283 (stata-prompt-wait stata-process
)
1284 (setq buffer-read-only t
)
1285 (set-buffer stata-buffer
)
1286 (set-process-buffer stata-process oldpb
)
1287 (set-marker (process-mark stata-process
) oldpm
)
1288 (set-process-filter stata-process oldpf
)))
1289 (display-buffer "*stata variables*")
1290 (goto-char (point-max))))
1292 (defun stata-review-window ()
1294 (display-buffer "*stata review*"))
1296 (defun stata-rehelp ()
1298 (stata-help (current-word)))
1301 ;;; This doesn't do anything at the moment. I have vague plans of
1302 ;;; implementing a menu interface using emacs
1304 (defun stata-watch-for-menu-filter (proc string
)
1305 (if (string-match "^!!!window!!!" string
)
1306 (stata-handle-menu-code proc string
)
1307 (comint-output-filter proc string
)))
1309 (defun stata-handle-menu-code (proc string
)
1310 (let ((old-buffer (current-buffer)))
1313 (set-buffer (process-buffer proc
))
1314 (setq moving
(= (point)
1315 (process-mark proc
)))
1317 ;; Insert the text, moving the process-marker.
1318 (goto-char (process-mark proc
))
1319 (insert "Handling menu code\n")
1320 (set-marker (process-mark proc
) (point)))
1321 (if moving
(goto-char (process-mark proc
))))
1322 (set-buffer old-buffer
))))
1326 (defun stata-add-to-review-buffer (string)
1327 "Adds input to review buffer."
1329 (set-buffer (get-buffer-create "*stata review*"))
1330 (goto-char (point-max))
1333 (defun stata-prompt-wait (proc &optional start-of-output
)
1334 "Wait for a prompt to appear at BOL of current buffer.
1335 PROC is the stata process. Does not change point."
1336 (if start-of-output nil
(setq start-of-output
(point-min)))
1339 ;; get output if there is some ready
1340 (accept-process-output proc
0 50)
1341 (goto-char (marker-position (process-mark proc
)))
1343 (if (< (point) start-of-output
) (goto-char start-of-output
))
1344 (not (looking-at "^. "))))))
1346 ;;(defvar inferior-stata-mode-map nil
1347 ;; "Keymap for Stata mode")
1349 ;;(setq inferior-stata-mode-map (cons 'keymap comint-mode-map))
1350 ;;(define-key inferior-stata-mode-map "\M-\t" 'comint-replace-by-expanded-filename)
1351 ;;(define-key inferior-stata-mode-map "\C-c\C-v" 'stata-variables)
1352 ;;(define-key inferior-stata-mode-map "\C-c\C-h" 'stata-help)
1353 ;;(define-key inferior-stata-mode-map "\C-c\C-u" 'stata-lookup)
1354 ;;(define-key inferior-stata-mode-map "\C-c\C-r" 'stata-review-window)
1355 ;;(define-key inferior-stata-mode-map [menu-bar stata]
1356 ;; (cons "Stata" (make-sparse-keymap "Stata")))
1357 ;;(define-key inferior-stata-mode-map [menu-bar stata statahelp]
1358 ;; '("Help on..." . stata-help))
1359 ;;(define-key inferior-stata-mode-map [menu-bar stata lookup]
1360 ;; '("Look up..." . stata-lookup))
1361 ;;(define-key inferior-stata-mode-map [menu-bar stata variables]
1362 ;; '("Variables" . stata-variables))
1363 ;;(define-key inferior-stata-mode-map [menu-bar stata review]
1364 ;; '("Review" . stata-review-window))
1367 ;;(defvar stata-mode-map nil
1368 ;; "Keymap for Stata mode")
1370 ;;(setq stata-mode-map (make-sparse-keymap))
1371 ;;(define-key stata-mode-map "\C-c\C-r" 'stata-eval-region)
1372 ;;(define-key stata-mode-map "\C-c\M-r" 'stata-eval-region-and-go)
1373 ;;(define-key stata-mode-map "\C-c\C-b" 'stata-eval-buffer)
1374 ;;(define-key stata-mode-map "\C-c\M-b" 'stata-eval-buffer-and-go)
1375 ;;(define-key stata-mode-map "\C-c\C-f" 'stata-eval-function)
1376 ;;(define-key stata-mode-map "\C-c\C-n" 'stata-eval-line-and-next-line)
1377 ;;(define-key stata-mode-map "\C-c\C-j" 'stata-eval-line)
1378 ;;(define-key stata-mode-map "\C-c\C-r" 'stata-review-window)
1379 ;;(define-key stata-mode-map "\C-c\M-j" 'stata-eval-line-and-go)
1380 ;;(define-key stata-mode-map "\C-c\C-y" 'stata-switch-to-stata)
1381 ;;(define-key stata-mode-map "\C-c\C-z" 'stata-switch-to-end-of-stata)
1382 ;;;;(define-key stata-mode-map "\C-c\C-l" 'stata-load-file)
1383 ;;(define-key stata-mode-map "\C-c\C-h" 'stata-help)
1384 ;;(define-key stata-mode-map "\C-c\C-v" 'stata-variables)
1385 ;;(define-key stata-mode-map "\M-\t" 'comint-replace-by-expanded-filename)
1386 ;;(define-key stata-mode-map "\177" 'backward-delete-char-untabify)
1387 ;;(define-key stata-mode-map "\C-c\C-u" 'stata-lookup)
1388 ;;(define-key stata-mode-map [menu-bar stata]
1389 ;; (cons "Stata" (make-sparse-keymap "Stata")))
1390 ;;(define-key stata-mode-map [menu-bar stata lookup]
1391 ;; '("Look up..." . stata-lookup))
1392 ;;(define-key stata-mode-map [menu-bar stata statahelp]
1393 ;; '("Help on..." . stata-help))
1394 ;;(define-key stata-mode-map [menu-bar stata variables]
1395 ;; '("Variables" . stata-variables))
1396 ;;(define-key stata-mode-map [menu-bar stata review]
1397 ;; '("Review" . stata-review-window))
1398 ;;(define-key stata-mode-map [menu-bar stata eval-line]
1399 ;; '("Eval line" . stata-eval-line))
1400 ;;(define-key stata-mode-map [menu-bar stata eval-next]
1401 ;; '("Eval line and next line" . stata-eval-line-and-next-line))
1402 ;;(define-key stata-mode-map [menu-bar stata eval-go]
1403 ;; '("Eval line and go" . stata-eval-line-and-go))
1404 ;;(define-key stata-mode-map [menu-bar stata eval-buff]
1405 ;; '("Eval buffer" . stata-eval-buffer))
1406 ;;(define-key stata-mode-map [menu-bar stata eval-buff-go]
1407 ;; '("Eval buffer and go" . stata-eval-buffer-and-go))
1408 ;;(define-key stata-mode-map [menu-bar stata to-stata]
1409 ;; '("Switch to stata" . stata-switch-to-stata))
1414 ;(defvar stata-help-mode-map nil)
1415 ;(setq stata-help-mode-map (cons 'keymap help-mode-map))
1416 ;(define-key stata-help-mode-map [mouse-2] 'stata-rehelp)
1417 ;(define-key stata-help-mode-map "\C-c\C-r" 'stata-rehelp)
1418 ;(define-key stata-help-mode-map "\C-c\C-h" 'stata-help)
1419 ;(define-key stata-help-mode-map [menu-bar stata]
1420 ; (cons "Stata" (make-sparse-keymap "Stata")))
1421 ;(define-key stata-help-mode-map [menu-bar stata statahelp]
1422 ; '("Help on..." . stata-help))
1423 ;(define-key stata-help-mode-map [menu-bar stata rehelp]
1424 ; '("rehelp (hyperlink)" . stata-rehelp))
1428 ;;(defun inferior-stata-mode ()
1429 ;;"Major mode for running Stata. Based on comint-mode.
1430 ;;Features include Help (\\[stata-help]), Review (\\[stata-review-window]) and
1431 ;;Variables (\\[stata-variables]) mimicking the help, review and
1432 ;;variables windows of Stata for Windows
1433 ;;\\{inferior-stata-mode-map}"
1435 ;; (make-comint "stata" "stata"
1436 ;; (and stata-profile
1437 ;; (or (file-exists-p stata-profile)
1438 ;; (null (message "Startup file %s not found."
1439 ;; stata-profile))) stata-profile)
1441 ;; (switch-to-buffer "*stata*" )
1442 ;; (setq comint-process-echoes t)
1443 ;; (set-process-filter (get-process "stata") 'stata-watch-for-menu-filter)
1444 ;; (setq comint-input-filter-functions
1445 ;; (cons 'stata-add-to-review-buffer comint-input-filter-functions))
1447 ;; (set-buffer (get-buffer-create "*stata review*"))
1449 ;; (setq major-mode 'inferior-stata-mode)
1450 ;; (setq mode-name "inferior Stata")
1451 ;; (use-local-map inferior-stata-mode-map))
1455 ;; (inferior-stata-mode))
1458 (defun stata-help-mode ()
1459 "Major mode for displaying Stata help in a read-only buffer.
1460 Active commands are Help (\\[stata-help]) and hyperlink
1461 (\\[stata-rehelp] or mouse-2)."
1463 (setq major-mode
'stata-help-mode
)
1464 (setq mode-name
"Stata help")
1465 ;;(use-local-map stata-help-mode-map)
1466 (setq buffer-read-only t
))
1470 ;;(defun stata-mode ()
1471 ;;"Major mode for editing Stata files. Commands for sending lines to
1472 ;;Stata (\\[stata-eval-line], \\[stata-eval-line-and-go],
1473 ;;\\[stata-eval-line-and-next-line])
1474 ;;and for displaying Stata help (\\[stata-help]), variables (\\[stata-variables])
1475 ;; and review window (\\[stata-review-window])
1476 ;;\\{stata-mode-map}"
1478 ;; (kill-all-local-variables)
1479 ;; (setq major-mode 'stata-mode)
1480 ;; (setq mode-name "Stata")
1481 ;; (use-local-map stata-mode-map))
1484 ;;(defun stata-eval-region (start end)
1485 ;; "Send the current region to the inferior stata process."
1486 ;; (interactive "r")
1487 ;; (process-send-region "stata" start end)
1488 ;; (process-send-string "stata" "\n"))
1492 ;;(defun stata-eval-buffer ()
1493 ;; "Send the current buffer to the inferior stata process."
1495 ;; (stata-eval-region (point-min) (point-max)))
1497 ;;(defun stata-eval-line ()
1498 ;; "Send the current line to the inferior stata process."
1502 ;; (let ((end (point)))
1503 ;; (beginning-of-line)
1504 ;; (stata-eval-region (point) end))))
1506 ;;(defun stata-eval-line-and-next-line ()
1507 ;; "Evaluate the current line and move to the next line."
1508 ;; ;; From an idea by Rod Ball (rod@marcam.dsir.govt.nz)
1510 ;; (display-buffer (process-buffer (get-process "stata")))
1513 ;; (let ((end (point)))
1514 ;; (beginning-of-line)
1515 ;; ;; RDB modified to go to end of S buffer so user can see result
1516 ;; ;;(stata-eval-visibly (buffer-substring (point) end) nil t)))
1517 ;; (stata-eval-region (point) end)))
1521 ;;(defun stata-eval-region-and-go (start end )
1522 ;; "Send the current region to the inferior S and switch to the process buffer."
1523 ;; (interactive "r\nP")
1524 ;; (stata-eval-region start end)
1525 ;; (stata-switch-to-stata t))
1527 ;;(defun stata-eval-buffer-and-go ()
1528 ;; "Send the current buffer to the inferior stata and switch to the process buffer."
1530 ;; (stata-eval-buffer)
1531 ;; (stata-switch-to-stata t))
1534 ;;(defun stata-eval-line-and-go ()
1535 ;; "Send the current line to the inferior stata process and switch to the
1538 ;; (stata-eval-line)
1539 ;; (stata-switch-to-stata t))
1542 ;;(defun stata-switch-to-stata (eob-p)
1543 ;; "Switch to the current inferior stata process buffer.
1544 ;;With argument, positions cursor at end of buffer."
1545 ;; (interactive "P")
1546 ;; (let (stata-process (get-process "stata"))
1547 ;; (if stata-process
1549 ;; (switch-to-buffer (process-buffer stata-process))
1550 ;; (if eob-p (goto-char (point-max))))
1552 ;; (message "No inferior stata process")
1555 ;;(defun stata-switch-to-end-of-stata nil
1556 ;; "Switch to the end of the inferior stata process buffer."
1558 ;; (stata-switch-to-stata t))
1560 ;;; Suggested function from Brendan Halpin:
1561 (defvar ess-STA-delimit-do-file
"delimit-do.do")
1563 (defun ess-STA-delimit-do ()
1565 (let ((commands (buffer-substring-no-properties (region-beginning)
1567 (set-buffer (get-buffer-create ess-STA-delimit-do-file
))
1568 (delete-region (point-min) (point-max))
1569 (insert "#delimit ;\n"
1572 (write-file ess-STA-delimit-do-file nil
)
1573 (comint-send-string "Stata"
1574 (format "do %s \n" ess-STA-delimit-do-file
)))))
1575 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1580 \f ; Local variables section
1582 ;;; This file is automatically placed in Outline minor mode.
1583 ;;; The file is structured as follows:
1586 ;;; Subsections: ;;;*;;;
1587 ;;; Components: defuns, defvars, defconsts
1588 ;;; Random code beginning with a ;;;;* comment
1590 ;;; Local variables:
1591 ;;; mode: emacs-lisp
1592 ;;; outline-minor-mode: nil
1593 ;;; mode: outline-minor
1594 ;;; outline-regexp: "\^L\\|\\`;\\|;;\\*\\|;;;\\*\\|(def[cvu]\\|(setq\\|;;;;\\*"
1597 ;;; essl-sta.el ends here