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
64 ;(setq max-lisp-eval-depth 500)
66 (setq max-lisp-eval-depth (max 600 max-lisp-eval-depth)))
68 (defconst ess-help-STA-sec-keys-alist
69 '((?d . "Description")
73 "Help section keys for S4.
74 `key' indicates the keystroke to use to search for the section heading
75 `string' in an Stata help file. `string' is used as part of a
76 regexp-search, and so specials should be quoted.
79 (defconst ess-help-STA-sec-regex "^[A-Z a-z]+:?\n^[-]+$"
80 "Reg(ular) Ex(pression) of section headers in help file.")
82 (defvar STA-syntax-table nil "Syntax table for Stata code.")
85 (setq STA-syntax-table (make-syntax-table))
86 (modify-syntax-entry ?\\ "." STA-syntax-table) ;nullify escape meaning
87 (modify-syntax-entry ?\$ "." STA-syntax-table)
88 (modify-syntax-entry ?` "(\'" STA-syntax-table)
89 (modify-syntax-entry ?\' ")`" STA-syntax-table)
90 (modify-syntax-entry ?/ ". 14" STA-syntax-table)
91 (modify-syntax-entry ?* ". 23" STA-syntax-table)
92 (modify-syntax-entry ?+ "." STA-syntax-table)
93 (modify-syntax-entry ?- "." STA-syntax-table)
94 (modify-syntax-entry ?= "." STA-syntax-table)
95 (modify-syntax-entry ?% "." STA-syntax-table)
96 (modify-syntax-entry ?< "." STA-syntax-table)
97 (modify-syntax-entry ?> "." STA-syntax-table)
98 (modify-syntax-entry ?& "." STA-syntax-table)
99 (modify-syntax-entry ?| "." STA-syntax-table)
100 (modify-syntax-entry ?~ "." STA-syntax-table))
103 (defun ado-set-font-lock-keywords ()
104 "Create font lock keywords for Stata syntax. This is from the
105 ado-mode of Bill Rising <brising@jhsph.edu>, and uses make-regexp."
106 ;; (make-local-variable 'ado-font-lock-keywords)
109 ;; special highlighting
110 ;; program definitions
113 '(("^\\*!.*") font-lock-keyword-face)
119 "pr" "pro" "prog" "progr" "progra" "program"
120 ) font-lock-keyword-face)
123 "de" "def" "defi" "defin" "define"
126 "l" "li" "lis" "list"
127 ) font-lock-type-face nil)
129 '(("[_a-z]+[_a-z0-9]*") font-lock-keyword-face nil)
133 '(("^[ \t]*version") font-lock-reference-face)
135 '(("1.0 2.0 2.1 3.0 3.1 4.0 5.0 6 6.0") font-lock-type-face)
141 ) font-lock-keyword-face)
147 '(("^[ \t]*#delimit") font-lock-reference-face)
149 '(("\\(cr\\|;\\)\\s-*$") font-lock-type-face nil)
151 ;; set command (with endless options!)
154 '(("^[ \t]*set") font-lock-reference-face)
157 "b" "be" "bee" "beep" "checksum" "contents"
158 "d" "di" "dis" "disp" "displ" "displa" "display"
159 "g" "gr" "gra" "grap" "graph" "graphi" "graphic" "graphics"
162 "l" "le" "lev" "leve" "level"
165 "mat" "mats" "matsi" "matsiz" "matsize"
167 "mem" "memo" "memor" "memory"
170 "ou" "out" "outp" "outpu" "output"
172 "r" "rm" "rms" "rmsg"
173 "se" "see" "seed" "seed0" "shell"
174 "te" "tex" "text" "texts" "textsi" "textsiz" "textsize"
175 "tr" "tra" "trac" "trace"
176 "t" "ty" "typ" "type" "video"
177 "vir" "virt" "virtu" "virtua" "virtual"
179 font-lock-reference-face t)
181 '(("[a-zA-Z0-9]*") font-lock-type-face)
183 ;; the constraint commands
188 "cons" "const" "constr" "constra" "constrai" "constrain" "constraint"
189 ) font-lock-reference-face)
193 "de" "def" "defi" "defin" "define"
196 "l" "li" "lis" "list"
201 ;; the confirm commands - could be a mess!
206 "conf" "confi" "confir" "confirm"
207 ) font-lock-reference-face)
210 "e" "ex" "exi" "exis" "exist" "existe" "existen" "existenc" "existence"
211 "f" "fi" "fil" "file"
212 "n" "nu" "num" "numb" "numbe" "number"
213 "v" "va" "var" "vari" "varia" "variab" "variabl" "variable"
214 ) font-lock-type-face)
221 "conf" "confi" "confir" "confirm"
222 ) font-lock-reference-face)
226 ) font-lock-type-face)
229 "n" "nu" "num" "numb" "numbe" "number"
230 ) font-lock-type-face)
237 "conf" "confi" "confir" "confirm"
238 ) font-lock-reference-face)
242 ) font-lock-type-face)
245 "f" "fi" "fil" "file"
246 "v" "va" "var" "vari" "varia" "variab" "variabl" "variable"
247 ) font-lock-type-face)
254 "conf" "confi" "confir" "confirm"
255 ) font-lock-reference-face)
258 "byte" "double" "float" "int" "long"
260 "str" "stri" "strin" "string"
261 ) font-lock-type-face)
264 "v" "va" "var" "vari" "varia" "variab" "variabl" "variable"
265 ) font-lock-type-face)
268 ;;; the str# won't quite look right, but that's the breaks for using
269 ;;; a tool like this...
274 "conf" "confi" "confir" "confirm"
275 ) font-lock-reference-face)
279 ) font-lock-type-face)
282 "v" "va" "var" "vari" "varia" "variab" "variabl" "variable"
283 ) font-lock-type-face)
286 ;; the estimates commands
291 "est" "esti" "estim" "estima" "estimat" "estimate" "estimates"
292 ) font-lock-reference-face)
296 "di" "dir" "dis" "disp" "displ" "displa" "display"
298 "h" "ho" "hol" "hold"
301 "mat" "matr" "matri" "matrix"
304 "sca" "scal" "scala" "scalar"
305 "u" "un" "unh" "unho" "unhol" "unhold"
316 ) font-lock-reference-face)
327 "vline" "vpoint" "vpoly" "vtext"
333 ;; some of the matrix commands
337 '(("mat" "matr" "matri" "matrix") font-lock-reference-face)
339 '(("ac" "acc" "accu" "accum"
341 "coln" "colna" "colnam" "cloname" "colnames"
342 "d" "def" "defi" "defin" "define"
343 "di" "dir" "dispCns" "drop" "drop _all"
344 "glsa" "glsac" "glsacc" "glsaccu" "glsaccum"
345 "l" "li" "lis" "list" "makeCns" "mlou" "mlout" "post"
347 "rown" "rowna" "rownam" "rowname" "rownames"
349 "sub" "subs" "subst" "substi" "substit" "substitu" "substitut" "substitute"
350 "svd" "syme" "symei" "symeig" "symeige" "symeigen"
351 "veca" "vecac" "vecacc" "vecaccu" "vecaccum"
360 '(("ml") font-lock-reference-face)
362 '(("b" "be" "beg" "begi" "begin"
364 "de" "dep" "depn" "depna" "depnam" "depname" "depnames"
365 "di" "dis" "disp" "displ" "displa" "display"
366 "f" "fu" "fun" "func" "funct" "functi" "functio" "function"
367 "gr" "gra" "grap" "graph"
369 "max" "maxi" "maxim" "maximi" "maximiz" "maximize"
370 "me" "met" "meth" "metho" "method"
371 "ml" "mlo" "mlou" "mlout"
372 "mo" "mod" "mode" "model"
375 "q" "qu" "que" "quer" "query"
376 "re" "rep" "repo" "repor" "report"
377 "sa" "sam" "samp" "sampl" "sample"
378 "se" "sea" "sear" "searc" "search"
387 '(("net") font-lock-reference-face)
391 "d" "de" "des" "desc" "descr" "descri" "describ" "describe"
392 "from" "get" "install"
394 "q" "qu" "que" "quer" "query")
401 '(("net") font-lock-reference-face)
403 '(("set") font-lock-reference-face)
405 '(("ado" "other") font-lock-type-face)
411 '(("ado") font-lock-reference-face)
413 '(("d" "de" "des" "desc" "descr" "descri" "describ" "describe"
419 ;; the reshape commands
423 '(("reshape") font-lock-keyword-face)
435 ;; the return commands
439 '(("ret" "retu" "retur" "return") font-lock-reference-face)
441 '(("add" "clear" "local" "matrix" "scalar") font-lock-type-face)
447 '(("sret" "sretu" "sretur" "sreturn") font-lock-reference-face)
449 '(("clear" "local") font-lock-type-face)
456 '(("sts") font-lock-reference-face)
460 "gen" "gene" "gener" "genera" "generat" "generate"
461 "gr" "gra" "grap" "graph"
462 "l" "li" "lis" "list"
463 "t" "te" "tes" "test"
472 '(("sw") font-lock-reference-face)
475 "cloglog" "cnreg" "cox" "ereg" "gamma" "glm" "gompertz" "hetprob"
476 "llogist" "lnormal" "logistic" "logit" "ologit" "oprobit"
477 "poisson" "probit" "qreg" "reg" "regr" "regre" "regres" "regress"
478 "scobit" "tobit" "weibull"
483 ;; the window commands
488 "win" "wind" "windo" "window"
489 ) font-lock-reference-face)
493 "di" "dia" "dial" "dialo" "dialog"
495 "fo" "fop" "fope" "fopen"
496 "fs" "fsa" "fsav" "fsave"
499 "stop" "stopb" "stopbo" "stopbox"
500 ) font-lock-type-face)
503 ;; the window controls
508 "win" "wind" "windo" "window"
509 ) font-lock-reference-face)
512 "c" "co" "con" "cont" "contr" "contro" "control"
513 ) font-lock-reference-face)
515 "button" "check" "clear"
524 ) font-lock-type-face)
527 ;; the window manage commands
532 "win" "wind" "windo" "window"
533 ) font-lock-reference-face)
536 "man" "mana" "manag" "manage"
537 ) font-lock-reference-face)
553 ;; the window menu commands
558 "win" "wind" "windo" "window"
559 ) font-lock-reference-face)
562 "m" "me" "men" "menu"
563 ) font-lock-reference-face)
576 ;; the xwindow commands
581 "xwin" "xwind" "xwindo" "xwindow"
582 ) font-lock-reference-face)
585 "de" "def" "defi" "defin" "define"
588 "l" "li" "lis" "list"
594 ;; all the endless Stata keywords (not in a good order)
595 ;; first those keywords which must start line
596 ;; note that these will look like text if preceded by a comment
597 ;; (but comments shouldn't be before the command, anyway)
603 "cap" "capt" "captu" "captur" "capture"
604 "char" "err" "erro" "error" "e" "ex" "exi" "exit"
607 ) font-lock-reference-face)
610 ;; here are some keywords which appear in the middle of lines
611 ;; note that the really short abbreviations could make a mess of things
613 ;; These are split to allow compiling!
618 "_huber" "_qreg" "_robust"
621 "an" "ano" "anov" "anova" "arch"
623 "as" "ass" "asse" "asser" "assert"
627 "biprobit" "bitest" "bitesti" "blogit"
628 "boxcox" "bprobit" "br" "break" "brier"
629 "bro" "brow" "brows" "browse"
630 "bsqreg" "bstat" "by"
631 "canon" "cat" "cc" "cci" "cchart" "centile" "cf" "ci" "cii"
632 "clogi" "clogit" "clogitp" "cloglog"
634 "cnr" "cnre" "cnreg" "cnsreg" "codebook" "compare"
636 "cor" "corc" "corr" "corre" "correl" "correla" "correlat" "correlate"
639 "cox" "cprplot" "_crcswxx" "cs" "csi"
640 "ct" "ctset" "cttost"
642 font-lock-reference-face)
649 "d" "de" "des" "desc" "descr" "descri" "describ" "describe"
650 "dfbeta" "dfuller" "di"
651 "dir" "dis" "disp" "disp_res" "disp_s"
652 "displ" "displa" "display"
654 "dprobit" "ds" "dstdize" "dwstat"
656 "fac" "fact" "facto" "factor"
657 "fit" "for" "fpredict"
658 "fracplot" "fracpoly" "fsl"
659 ) font-lock-reference-face)
666 "gettoken" "gladder" "glm" "glmpred" "glogit" "gnbreg" "gompertz"
667 "gphdot" "gphpen" "graph" "gprobit" "greigen" "grmeanby"
668 "hadimvo" "hausman" "heckman" "heckprob" "hetprob" "hettest" "hilite"
670 "iqreg" "istdize" "iis"
671 "ins" "insp" "inspe" "inspec" "inspect"
672 "integ" "intreg" "ir" "iri" "ivreg"
673 "kap" "kappa" "kapwgt" "kdensity" "ksm" "ksmirnov" "ktau"
675 ) font-lock-reference-face)
682 "l" "ladder" "lfit" "lincom" "linktest"
688 "lo" "loo" "look" "looku" "lookup"
689 "lpredict" "lroc" "lrtest" "ls" "lsens" "lstat" "ltable" "lv" "lvr2plot"
690 "man" "matcproc" "mcc" "mcci"
692 "mlog" "mlogi" "mlogit"
695 "n" "nbreg" "newey" "news"
697 "no" "noi" "nois" "noisi" "noisil" "noisily"
700 "olog" "ologi" "ologit"
702 "on" "one" "onew" "onewa" "oneway"
703 "oprob" "oprobi" "oprobit"
707 font-lock-reference-face)
713 '(("pac" "pchart" "pchi" "pcorr" "pergram"
715 "pnorm" "poisgof" "poisson" "pperron"
717 "prob" "probi" "probit"
720 "q" "qchi" "qnorm" "qqplot" "qreg" "quadchk" "quantile"
721 "qu" "que" "quer" "query"
722 "qui" "quie" "quiet" "quietl" "quietly"
723 "ranksum" "rchart" "regdw" "regph"
724 "reg" "reg3" "regr" "regre" "regres" "regress" "reshape"
725 "rot" "rota" "rotat" "rotate"
727 "run" "runtest" "rvfplot" "rvpplot"
728 ) font-lock-reference-face)
736 "sco" "scobit" "scor" "score"
737 "sdtest" "sdtesti" "search" "serrbar"
738 "sfrancia" "shell" "shelltool" "shewhart" "signrank" "signtest"
739 "sktest" "slog" "spearman" "spikeplt" "sqreg"
740 "st" "st_is" "st_show" "st_ct"
741 "stcox" "stcoxkm" "stcurv" "stdes"
743 "stereg" "stir" "stmc" "stmh" "stphplot" "stphtest"
745 "sts" "stse" "stset" "stsum" "stvary" "stweib"
746 "su" "sum" "summ" "summa" "summar" "summari" "summariz" "summarize"
748 "svydes" "svyintrg" "svyivreg" "svylc" "svylogit"
749 "svymean" "svymean" "svymlog" "svyolog" "svyoprob" "svypois" "svyprobt"
750 "svyprop" "svyratio" "svyreg" "svyset" "svytab" "svytest" "svytotal"
751 "swilk" "symmetry" "symmi" "symplot" "syntax" "sysdir"
752 ) font-lock-reference-face)
764 "tabu" "tabul" "tabula" "tabulat" "tabulate"
766 "testnl" "testparm" "tis"
768 "token" "tokeni" "tokeniz" "tokenize"
769 "touch" "tsreport" "tsset" "tsunab" "ttest" "ttesti"
773 "verinst" "vif" "vwls"
774 "weibull" "which" "who" "wntestb" "wntestq"
776 "xtclog" "xtdes" "xtgee" "xtgls" "xthaus" "xtintreg"
777 "xtlogit" "xtnbreg" "xtpois" "xtprobit"
778 "xtrchh" "xtreg" "xtsum" "xttab" "xttest0" "xttobit" "xttrans"
780 ) font-lock-reference-face)
784 ;; conditional statements
785 ;; if might not work right ('cuz it is also a keyword)
790 ) font-lock-reference-face t t)
798 ) font-lock-reference-face t t)
801 ;; else statement (which must just have a {)
806 ) font-lock-reference-face)
810 ;; short version of list --- which can get fooled if used as a var
814 ) font-lock-reference-face)
817 ;; all the Stata options
818 ;; commonly used options
822 '(("byte" "int" "long" "str[1-9]+[0-9]?" "float" "double"
823 "width" "maxobs" "maxvar"
824 ) font-lock-type-face)
827 ;; special local variables (used in parsing)
830 "^[ \t]+\\(local\\)+[ \t]+"
831 '(("varlist" "exp" "weight" "if" "in" "using" "options"
832 ) font-lock-type-face nil t t)
836 ;; things used with display
837 ;; since these are often split across lines, and Stata commands are hard
838 ;; to delimit, this will highlight even if out of context
844 "_c" "_co" "_con" "_cont" "_conti" "_contin" "_continu" "_continue"
845 "_n" "_ne" "_new" "_newl" "_newli" "_newlin" "_newline"
847 "_r" "_re" "_req" "_requ" "_reque" "_reques" "_request"
856 "_col" "_colu" "_colum" "_column"
858 "_s" "_sk" "_ski" "_skip"
867 "b" "bl" "blu" "blue"
868 "g" "gr" "gre" "gree" "green"
870 "w" "wh" "whi" "whit" "white"
871 "y" "ye" "yel" "yell" "yello" "yellow"
872 ) font-lock-type-face)
880 '(("lab" "labe" "label"
881 ) font-lock-reference-face t)
885 "de" "def" "defi" "defin" "define"
888 "l" "li" "lis" "list"
890 "val" "valu" "value" "values"
891 "var" "vari" "varia" "variab" "variabl" "variable"
892 ) font-lock-type-face nil t t)
896 ;; all Stata data-altering stuff
903 "bcskew0" "bsample" "bs" "bstrap"
904 "cd" "chdir" "clear" "compress"
905 "contract" "convert" "cross"
906 "dec" "deco" "decod" "decode"
907 "discard" "drop" "dydx"
908 "ed" "edi" "edit" "egen"
909 "en" "enc" "enco" "encod" "encode"
913 "form" "forma" "format"
915 "g" "ge" "gen" "gene" "gener" "genera" "generat" "generate"
918 "infile" "infix" "input" "insheet" "integ" "ipolate"
922 ) font-lock-keyword-face)
929 "mark" "markout" "marksample"
932 "mkdir" "mkmat" "mkspline"
933 "mleval" "mlmatsum" "mlsum""mlvecsum"
934 "modify" "mov" "move"
935 "mvdecode" "mvencode" "nlpred" "nobreak" "order"
936 "ou" "out" "outf" "outfi" "outfil" "outfile"
937 "outs" "outsh" "outshe" "outshee" "outsheet"
939 "post" "postclose" "postfile"
940 "pre" "pred" "predi" "predic" "predict"
943 "ren" "rena" "renam" "rename"
944 "renpfix" "replace" "restore" "rm"
949 "simul" "sinfile" "smerge"
952 "ssave" "ssort" "stack"
953 "stbase" "stfill" "stgen" "stjoin" "stsplit" "sttocc" "sttoct"
957 "xi" "xi:" "xtile" "xpose"
959 ) font-lock-keyword-face)
963 ;; assignment of macros
967 '(("global" "local" "scalar"
968 ) font-lock-reference-face)
969 '(("\\([ \t]+[a-zA-Z_]+[a-zA-Z_0-9]*\\b\\)?"
970 ) font-lock-variable-name-face t)
972 ;; choosing temp names
976 '(("tempname" "tempfile" "tempvar"
977 ) font-lock-reference-face)
978 '(("\\([ \t]+[a-zA-Z_]+[a-zA-Z_0-9`']*\\)+"
979 ) font-lock-type-face t)
981 ;; all variable/macro stuff (put late so it will override)
982 ;; internal constants
986 '(("_merge" "_n" "_pi" "_rc" "_N"
987 ) font-lock-variable-name-face)
990 ;; some generated vars
994 ) font-lock-variable-name-face)
999 '(("\\$[a-zA-Z_*]+[a-zA-Z_0-9]*"
1000 ) font-lock-variable-name-face t)
1006 '(("[a-zA-Z_`*]+[a-zA-Z_0-9]*" ;has glitch interior ` is highlighted
1007 ) font-lock-variable-name-face t)
1010 ;; other macro commands
1015 "ma" "mac" "macr" "macro"
1016 ) font-lock-reference-face)
1022 "l" "li" "lis" "list"
1023 "s" "sh" "shi" "shif" "shift"
1025 font-lock-type-face)
1028 ;; stata 'functions' i.e. things which require () after them
1033 "abs" "acos" "asin" "atan" "autocode"
1036 "chiprob" "comb" "cond" "cos"
1037 "d" "date" "digamma" "day"
1038 "dofh" "dofm" "dofq" "dofw" "dofy" "dow" "doy"
1040 "float" "fprob" "gammap" "get" "group"
1041 "h" "halfyear" "halfyearly" "hofd"
1042 "ibeta" "index" "int"
1043 "invbinomial" "invchi" "invfprob" "invgammap" "invnchi" "invnorm" "invt"
1044 "length" "ln" "lnfact" "lngamma" "log" "log10" "lower" "ltrim"
1045 "m" "matrix" "max" "mdy" "min" "missing" "mod" "mofd" "month" "monthly"
1046 "nchi" "normd" "normprob" "npnchi"
1047 "q" "qofd" "quarter" "quarterly"
1048 "r" "real" "recode" "reldif" "replay" "return" "round" "rtrim"
1049 "s" "scalar" "sign" "sin" "sqrt" "string" "substr" "sum"
1050 "tan" "tprob" "trigamma" "trim"
1051 "uniform" "uniform0" "upper"
1052 "w" "week" "weekly" "wofd"
1053 "y" "year" "yearly" "yh" "ym" "yofd" "yq" "yw"
1055 font-lock-reference-face t)
1058 ;; stata 'functions' i.e. things which require [] after them
1062 '(("_b" "_coef" "_se")
1063 font-lock-reference-face t)
1066 ;; common Stata options which require a () after them
1070 '(("bands" "by" "connect" "density" "gap" "iterate" "ltolerance" "margin"
1071 "psize" "saving" "tlabel" "tolerance"
1072 "xlabel" "xscale" "ylabel" "yscale")
1073 font-lock-type-face t)
1076 ;; egen 'function' options
1079 "[ \t]*egen[ \t]+.*=[ \t]*"
1080 '(("count" "diff" "fill" "group" "iqr"
1081 "ma" "max" "mean" "median" "min" "mtr" "pctile"
1082 "rank" "rfirst" "rlast" "rmax" "rmean" "rmin" "rmiss" "robs" "rsd" "rsum"
1084 font-lock-reference-face t)
1087 ;; All Custom ado files which are 'reliable' and which are not file killers
1088 ;; this might be a useless endeavor --- but I cannot generate tag files
1089 ;; all the s-extensions are listed under Stata's name (since they alter
1090 ;; data and will be moved tot he utils directory
1094 '(("addnote" "anypath" "autolab" "checkvar" "ck1icd9" "ckicd9"
1095 "datetoe" "dattomdy" "den2dem" "dishis" "dtapath" "dupclean" "echo"
1096 "exdupbil" "ezip2hsa" "getdate" "getlbl" "getnames" "getobs" "gplur"
1097 "icd9" "issorted" "isfile" "jultoe" "jultof" "jultomdy" "knowndup"
1099 "markit" "makewide" "missize" "mpcounts"
1100 "nodups" "notefile" "prov2zip"
1102 "random" "readraw" "readzip" "repart"
1105 "wdatetoe" "wdatomdy" "zip2ezip"
1106 "_addext" "_brclean" "_brckado" "_brdlog"
1107 "_ckbad" "_ckdunno" "_ckdupl" "_ckmiss" "_ckok" "_ckwarn"
1108 "_delimit" "_filenm" "_lookup" "_mk_ck"
1109 ) font-lock-function-name-face)
1115 (defvar ess-STA-mode-font-lock-keywords (ado-set-font-lock-keywords)
1116 "Set the Stata mode font-lock keywords to Bill Rising's ado-mode keywords.")
1118 (defvar STA-editing-alist
1119 '((paragraph-start . (concat "^$\\|" page-delimiter))
1120 (paragraph-separate . (concat "^$\\|" page-delimiter))
1121 (paragraph-ignore-fill-prefix . t)
1122 (require-final-newline . t)
1123 (comment-start . "/\* ")
1124 (comment-end . " \*/")
1125 (comment-start-skip . "/\\*+ *")
1126 (comment-column . 40)
1127 ;;(comment-indent-function . 'S-comment-indent)
1128 ;;(ess-comment-indent . 'S-comment-indent)
1129 ;;(ess-indent-line . 'S-indent-line)
1130 ;;(ess-calculate-indent . 'S-calculate-indent)
1131 (indent-line-function . 'S-indent-line)
1132 (parse-sexp-ignore-comments . t)
1133 (ess-set-style . ess-default-style)
1134 (ess-local-process-name . nil)
1135 ;;(ess-keep-dump-files . 'ask)
1136 (ess-mode-syntax-table . STA-syntax-table)
1137 (font-lock-defaults . '(ess-STA-mode-font-lock-keywords
1138 nil nil ((?\. . "w")))))
1139 "General options for editing Stata do and ado source files.")
1141 ;; YOU USED TO HAVE TO (with Thomas's version):
1142 ;;;;; Add the following to your .emacs file
1144 ;;(autoload 'stata "~/essl-sta.el" "inferior stata mode" t )
1145 ;;(autoload 'stata-help "stata" "stata help mode" t)
1146 ;;(autoload 'stata-mode "~/essl-sta.el" "stata mode" t)
1148 ;;(if (assoc "\\.do$" auto-mode-alist) nil
1149 ;; (setq auto-mode-alist
1151 ;; '(("\\.do$" . stata-mode)
1152 ;; ("\\.ado$" . stata-mode))
1153 ;; auto-mode-alist)))
1157 ;; QUESTIONS TO ASK THOMAS:
1158 ;; 1 - are 'help' and 'lookup' the same?
1159 ;; 2 - what is the point of the review buffer?
1163 ;; NOTE: all of Thomas's functions have been left here, to be removed
1164 ;; or merged into real locations as we work on this.
1168 ;;;;;;;;; Things to change
1170 (defvar stata-switches "-q"
1171 "*Switches to apply to stata invocation.")
1173 (defvar stata-profile "~/.stataprofile"
1174 "File to read on startup (nil for no file).")
1180 (defun stata-help (the-subject)
1181 "Stata help in other buffer."
1182 (interactive "sHelp on: ")
1183 (let* ((stata-process (get-process "stata"))
1184 (stata-buffer (process-buffer stata-process))
1186 (set-buffer stata-buffer)
1187 (setq oldpf (process-filter stata-process))
1188 (setq oldpb (process-buffer stata-process))
1189 (setq oldpm (marker-position (process-mark stata-process)))
1191 (if stata-process nil (error "Stata is not running."))
1193 (if (looking-at ". ") nil (error "Stata not ready."))
1195 (set-process-buffer stata-process (get-buffer-create "*stata help*"))
1196 (set-buffer "*stata help*")
1197 (setq buffer-read-only nil)
1198 (set-process-filter stata-process 'ordinary-insertion-filter)
1200 (process-send-string stata-process "help ")
1201 (process-send-string stata-process the-subject)
1202 (process-send-string stata-process "\n")
1203 (stata-prompt-wait stata-process)
1205 (set-buffer stata-buffer)
1206 (set-process-buffer stata-process oldpb)
1207 (set-process-filter stata-process oldpf)
1208 (set-marker (process-mark stata-process) oldpm)))
1209 (display-buffer "*stata help*")))
1211 (defun stata-lookup (the-subject) "Stata lookup in other buffer"
1212 (interactive "sLook up: ")
1213 (let* ((stata-process (get-process "stata"))
1214 (stata-buffer (process-buffer stata-process))
1216 (set-buffer stata-buffer)
1217 (setq oldpf (process-filter stata-process))
1218 (setq oldpb (process-buffer stata-process))
1219 (setq oldpm (marker-position (process-mark stata-process)))
1221 (if stata-process nil (error "Stata is not running."))
1223 (if (looking-at ". ") nil (error "Stata not ready."))
1225 (set-process-buffer stata-process (get-buffer-create "*stata help*"))
1226 (set-buffer "*stata help*")
1227 (setq buffer-read-only nil)
1228 (set-process-filter stata-process 'ordinary-insertion-filter)
1230 (process-send-string stata-process "lookup ")
1231 (process-send-string stata-process the-subject)
1232 (process-send-string stata-process "\n")
1233 (stata-prompt-wait stata-process)
1235 (set-buffer stata-buffer)
1236 (set-process-buffer stata-process oldpb)
1237 (set-process-filter stata-process oldpf)
1238 (set-marker (process-mark stata-process) oldpm)))
1239 (display-buffer "*stata help*")))
1241 (defun stata-variables ()
1242 "Stata variable list in other buffer."
1244 (let* ((stata-process (get-process "stata"))
1245 (stata-buffer (if stata-process
1246 (process-buffer stata-process)
1247 (error "Stata is not running.")))
1249 (set-buffer stata-buffer)
1250 (setq oldpf (process-filter stata-process))
1251 (setq oldpb (process-buffer stata-process))
1252 (setq oldpm (marker-position (process-mark stata-process)))
1254 (if stata-process nil (error "Stata is not running."))
1256 (if (looking-at ". ") nil (error "Stata not ready."))
1258 (set-process-buffer stata-process
1259 (get-buffer-create "*stata variables*"))
1260 (set-process-filter stata-process 'ordinary-insertion-filter)
1261 (set-buffer "*stata variables*")
1262 (setq buffer-read-only nil)
1264 (process-send-string stata-process "desc \n ")
1265 (stata-prompt-wait stata-process)
1266 (setq buffer-read-only t)
1267 (set-buffer stata-buffer)
1268 (set-process-buffer stata-process oldpb)
1269 (set-marker (process-mark stata-process) oldpm)
1270 (set-process-filter stata-process oldpf)))
1271 (display-buffer "*stata variables*")
1272 (goto-char (point-max))))
1274 (defun stata-review-window ()
1276 (display-buffer "*stata review*"))
1278 (defun stata-rehelp ()
1280 (stata-help (current-word)))
1282 (defun ordinary-insertion-filter (proc string)
1283 (let ((old-buffer (current-buffer)))
1286 (set-buffer (process-buffer proc))
1287 (setq moving (= (point) (process-mark proc)))
1289 ;; Insert the text, moving the process-marker.
1290 (goto-char (process-mark proc))
1292 (set-marker (process-mark proc) (point)))
1293 (if moving (goto-char (process-mark proc))))
1294 (set-buffer old-buffer))))
1298 ;;; This doesn't do anything at the moment. I have vague plans of
1299 ;;; implementing a menu interface using emacs
1301 (defun stata-watch-for-menu-filter (proc string)
1302 (if (string-match "^!!!window!!!" string)
1303 (stata-handle-menu-code proc string)
1304 (comint-output-filter proc string)))
1306 (defun stata-handle-menu-code (proc string)
1307 (let ((old-buffer (current-buffer)))
1310 (set-buffer (process-buffer proc))
1311 (setq moving (= (point)
1312 (process-mark proc)))
1314 ;; Insert the text, moving the process-marker.
1315 (goto-char (process-mark proc))
1316 (insert "Handling menu code\n")
1317 (set-marker (process-mark proc) (point)))
1318 (if moving (goto-char (process-mark proc))))
1319 (set-buffer old-buffer))))
1323 (defun stata-add-to-review-buffer (string)
1324 "Adds input to review buffer."
1326 (set-buffer (get-buffer-create "*stata review*"))
1327 (goto-char (point-max))
1330 (defun stata-prompt-wait (proc &optional start-of-output)
1331 "Wait for a prompt to appear at BOL of current buffer.
1332 PROC is the stata process. Does not change point."
1333 (if start-of-output nil (setq start-of-output (point-min)))
1336 ;; get output if there is some ready
1337 (accept-process-output proc 0 50)
1338 (goto-char (marker-position (process-mark proc)))
1340 (if (< (point) start-of-output) (goto-char start-of-output))
1341 (not (looking-at "^. "))))))
1343 ;;(defvar inferior-stata-mode-map nil
1344 ;; "Keymap for Stata mode")
1346 ;;(setq inferior-stata-mode-map (cons 'keymap comint-mode-map))
1347 ;;(define-key inferior-stata-mode-map "\M-\t" 'comint-replace-by-expanded-filename)
1348 ;;(define-key inferior-stata-mode-map "\C-c\C-v" 'stata-variables)
1349 ;;(define-key inferior-stata-mode-map "\C-c\C-h" 'stata-help)
1350 ;;(define-key inferior-stata-mode-map "\C-c\C-u" 'stata-lookup)
1351 ;;(define-key inferior-stata-mode-map "\C-c\C-r" 'stata-review-window)
1352 ;;(define-key inferior-stata-mode-map [menu-bar stata]
1353 ;; (cons "Stata" (make-sparse-keymap "Stata")))
1354 ;;(define-key inferior-stata-mode-map [menu-bar stata statahelp]
1355 ;; '("Help on..." . stata-help))
1356 ;;(define-key inferior-stata-mode-map [menu-bar stata lookup]
1357 ;; '("Look up..." . stata-lookup))
1358 ;;(define-key inferior-stata-mode-map [menu-bar stata variables]
1359 ;; '("Variables" . stata-variables))
1360 ;;(define-key inferior-stata-mode-map [menu-bar stata review]
1361 ;; '("Review" . stata-review-window))
1364 ;;(defvar stata-mode-map nil
1365 ;; "Keymap for Stata mode")
1367 ;;(setq stata-mode-map (make-sparse-keymap))
1368 ;;(define-key stata-mode-map "\C-c\C-r" 'stata-eval-region)
1369 ;;(define-key stata-mode-map "\C-c\M-r" 'stata-eval-region-and-go)
1370 ;;(define-key stata-mode-map "\C-c\C-b" 'stata-eval-buffer)
1371 ;;(define-key stata-mode-map "\C-c\M-b" 'stata-eval-buffer-and-go)
1372 ;;(define-key stata-mode-map "\C-c\C-f" 'stata-eval-function)
1373 ;;(define-key stata-mode-map "\C-c\C-n" 'stata-eval-line-and-next-line)
1374 ;;(define-key stata-mode-map "\C-c\C-j" 'stata-eval-line)
1375 ;;(define-key stata-mode-map "\C-c\C-r" 'stata-review-window)
1376 ;;(define-key stata-mode-map "\C-c\M-j" 'stata-eval-line-and-go)
1377 ;;(define-key stata-mode-map "\C-c\C-y" 'stata-switch-to-stata)
1378 ;;(define-key stata-mode-map "\C-c\C-z" 'stata-switch-to-end-of-stata)
1379 ;;;;(define-key stata-mode-map "\C-c\C-l" 'stata-load-file)
1380 ;;(define-key stata-mode-map "\C-c\C-h" 'stata-help)
1381 ;;(define-key stata-mode-map "\C-c\C-v" 'stata-variables)
1382 ;;(define-key stata-mode-map "\M-\t" 'comint-replace-by-expanded-filename)
1383 ;;(define-key stata-mode-map "\177" 'backward-delete-char-untabify)
1384 ;;(define-key stata-mode-map "\C-c\C-u" 'stata-lookup)
1385 ;;(define-key stata-mode-map [menu-bar stata]
1386 ;; (cons "Stata" (make-sparse-keymap "Stata")))
1387 ;;(define-key stata-mode-map [menu-bar stata lookup]
1388 ;; '("Look up..." . stata-lookup))
1389 ;;(define-key stata-mode-map [menu-bar stata statahelp]
1390 ;; '("Help on..." . stata-help))
1391 ;;(define-key stata-mode-map [menu-bar stata variables]
1392 ;; '("Variables" . stata-variables))
1393 ;;(define-key stata-mode-map [menu-bar stata review]
1394 ;; '("Review" . stata-review-window))
1395 ;;(define-key stata-mode-map [menu-bar stata eval-line]
1396 ;; '("Eval line" . stata-eval-line))
1397 ;;(define-key stata-mode-map [menu-bar stata eval-next]
1398 ;; '("Eval line and next line" . stata-eval-line-and-next-line))
1399 ;;(define-key stata-mode-map [menu-bar stata eval-go]
1400 ;; '("Eval line and go" . stata-eval-line-and-go))
1401 ;;(define-key stata-mode-map [menu-bar stata eval-buff]
1402 ;; '("Eval buffer" . stata-eval-buffer))
1403 ;;(define-key stata-mode-map [menu-bar stata eval-buff-go]
1404 ;; '("Eval buffer and go" . stata-eval-buffer-and-go))
1405 ;;(define-key stata-mode-map [menu-bar stata to-stata]
1406 ;; '("Switch to stata" . stata-switch-to-stata))
1411 ;(defvar stata-help-mode-map nil)
1412 ;(setq stata-help-mode-map (cons 'keymap help-mode-map))
1413 ;(define-key stata-help-mode-map [mouse-2] 'stata-rehelp)
1414 ;(define-key stata-help-mode-map "\C-c\C-r" 'stata-rehelp)
1415 ;(define-key stata-help-mode-map "\C-c\C-h" 'stata-help)
1416 ;(define-key stata-help-mode-map [menu-bar stata]
1417 ; (cons "Stata" (make-sparse-keymap "Stata")))
1418 ;(define-key stata-help-mode-map [menu-bar stata statahelp]
1419 ; '("Help on..." . stata-help))
1420 ;(define-key stata-help-mode-map [menu-bar stata rehelp]
1421 ; '("rehelp (hyperlink)" . stata-rehelp))
1425 ;;(defun inferior-stata-mode ()
1426 ;;"Major mode for running Stata. Based on comint-mode.
1427 ;;Features include Help (\\[stata-help]), Review (\\[stata-review-window]) and
1428 ;;Variables (\\[stata-variables]) mimicking the help, review and
1429 ;;variables windows of Stata for Windows
1430 ;;\\{inferior-stata-mode-map}"
1432 ;; (make-comint "stata" "stata"
1433 ;; (and stata-profile
1434 ;; (or (file-exists-p stata-profile)
1435 ;; (null (message "Startup file %s not found."
1436 ;; stata-profile))) stata-profile)
1438 ;; (switch-to-buffer "*stata*" )
1439 ;; (setq comint-process-echoes t)
1440 ;; (set-process-filter (get-process "stata") 'stata-watch-for-menu-filter)
1441 ;; (setq comint-input-filter-functions
1442 ;; (cons 'stata-add-to-review-buffer comint-input-filter-functions))
1444 ;; (set-buffer (get-buffer-create "*stata review*"))
1446 ;; (setq major-mode 'inferior-stata-mode)
1447 ;; (setq mode-name "inferior Stata")
1448 ;; (use-local-map inferior-stata-mode-map))
1452 ;; (inferior-stata-mode))
1455 (defun stata-help-mode ()
1456 "Major mode for displaying Stata help in a read-only buffer.
1457 Active commands are Help (\\[stata-help]) and hyperlink
1458 (\\[stata-rehelp] or mouse-2)."
1460 (setq major-mode 'stata-help-mode)
1461 (setq mode-name "Stata help")
1462 ;;(use-local-map stata-help-mode-map)
1463 (setq buffer-read-only t))
1467 ;;(defun stata-mode ()
1468 ;;"Major mode for editing Stata files. Commands for sending lines to
1469 ;;Stata (\\[stata-eval-line], \\[stata-eval-line-and-go],
1470 ;;\\[stata-eval-line-and-next-line])
1471 ;;and for displaying Stata help (\\[stata-help]), variables (\\[stata-variables])
1472 ;; and review window (\\[stata-review-window])
1473 ;;\\{stata-mode-map}"
1475 ;; (kill-all-local-variables)
1476 ;; (setq major-mode 'stata-mode)
1477 ;; (setq mode-name "Stata")
1478 ;; (use-local-map stata-mode-map))
1481 ;;(defun stata-eval-region (start end)
1482 ;; "Send the current region to the inferior stata process."
1483 ;; (interactive "r")
1484 ;; (process-send-region "stata" start end)
1485 ;; (process-send-string "stata" "\n"))
1489 ;;(defun stata-eval-buffer ()
1490 ;; "Send the current buffer to the inferior stata process."
1492 ;; (stata-eval-region (point-min) (point-max)))
1494 ;;(defun stata-eval-line ()
1495 ;; "Send the current line to the inferior stata process."
1499 ;; (let ((end (point)))
1500 ;; (beginning-of-line)
1501 ;; (stata-eval-region (point) end))))
1503 ;;(defun stata-eval-line-and-next-line ()
1504 ;; "Evaluate the current line and move to the next line."
1505 ;; ;; From an idea by Rod Ball (rod@marcam.dsir.govt.nz)
1507 ;; (display-buffer (process-buffer (get-process "stata")))
1510 ;; (let ((end (point)))
1511 ;; (beginning-of-line)
1512 ;; ;; RDB modified to go to end of S buffer so user can see result
1513 ;; ;;(stata-eval-visibly (buffer-substring (point) end) nil t)))
1514 ;; (stata-eval-region (point) end)))
1518 ;;(defun stata-eval-region-and-go (start end )
1519 ;; "Send the current region to the inferior S and switch to the process buffer."
1520 ;; (interactive "r\nP")
1521 ;; (stata-eval-region start end)
1522 ;; (stata-switch-to-stata t))
1524 ;;(defun stata-eval-buffer-and-go ()
1525 ;; "Send the current buffer to the inferior stata and switch to the process buffer."
1527 ;; (stata-eval-buffer)
1528 ;; (stata-switch-to-stata t))
1531 ;;(defun stata-eval-line-and-go ()
1532 ;; "Send the current line to the inferior stata process and switch to the
1535 ;; (stata-eval-line)
1536 ;; (stata-switch-to-stata t))
1539 ;;(defun stata-switch-to-stata (eob-p)
1540 ;; "Switch to the current inferior stata process buffer.
1541 ;;With argument, positions cursor at end of buffer."
1542 ;; (interactive "P")
1543 ;; (let (stata-process (get-process "stata"))
1544 ;; (if stata-process
1546 ;; (switch-to-buffer (process-buffer stata-process))
1547 ;; (if eob-p (goto-char (point-max))))
1549 ;; (message "No inferior stata process")
1552 ;;(defun stata-switch-to-end-of-stata nil
1553 ;; "Switch to the end of the inferior stata process buffer."
1555 ;; (stata-switch-to-stata t))
1557 ;;; Suggested function from Brendan Halpin:
1558 (defvar ess-STA-delimit-do-file "delimit-do.do")
1560 (defun ess-STA-delimit-do ()
1562 (let ((commands (buffer-substring-no-properties (region-beginning)
1564 (set-buffer (get-buffer-create ess-STA-delimit-do-file))
1565 (delete-region (point-min) (point-max))
1566 (insert "#delimit ;\n"
1569 (write-file ess-STA-delimit-do-file nil)
1570 (comint-send-string "Stata"
1571 (format "do %s \n" ess-STA-delimit-do-file)))))
1572 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1577 \f ; Local variables section
1579 ;;; This file is automatically placed in Outline minor mode.
1580 ;;; The file is structured as follows:
1583 ;;; Subsections: ;;;*;;;
1584 ;;; Components: defuns, defvars, defconsts
1585 ;;; Random code beginning with a ;;;;* comment
1587 ;;; Local variables:
1588 ;;; mode: emacs-lisp
1589 ;;; outline-minor-mode: nil
1590 ;;; mode: outline-minor
1591 ;;; outline-regexp: "\^L\\|\\`;\\|;;\\*\\|;;;\\*\\|(def[cvu]\\|(setq\\|;;;;\\*"
1594 ;;; essl-sta.el ends here