Minor edits.
[emacs/old-mirror.git] / sml-defs.el
blob899dc51ea38de06f2c673d3204ee75fe65e439b5
1 ;;; sml-defs.el --- Various definitions for sml-mode
3 ;; Copyright (C) 1999,2000,2003,2005,2007,2010 Stefan Monnier <monnier@gnu.org>
4 ;;
5 ;; This program is free software; you can redistribute it and/or modify
6 ;; it under the terms of the GNU General Public License as published by
7 ;; the Free Software Foundation; either version 3 of the License, or
8 ;; (at your option) any later version.
9 ;;
10 ;; This program is distributed in the hope that it will be useful,
11 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
12 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 ;; GNU General Public License for more details.
15 ;; You should have received a copy of the GNU General Public License
16 ;; along with this program; if not, write to the Free Software
17 ;; Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
19 ;;; Commentary:
22 ;;; Code:
24 (eval-when-compile (require 'cl))
26 (defgroup sml ()
27 "Editing SML code."
28 :group 'languages)
30 (defvar sml-outline-regexp
31 ;; `st' and `si' are to match structure and signature.
32 "\f\\|s[ti]\\|[ \t]*\\(let[ \t]+\\)?\\(fun\\|and\\)\\>"
33 "Regexp matching a major heading.
34 This actually can't work without extending `outline-minor-mode' with the
35 notion of \"the end of an outline\".")
37 ;;;
38 ;;; Internal defines
39 ;;;
41 (defvar sml-mode-map
42 (let ((map (make-sparse-keymap)))
43 ;; Text-formatting commands:
44 (define-key map "\C-c\C-m" 'sml-insert-form)
45 (define-key map "\C-c\C-i" 'sml-mode-info)
46 (define-key map "\M-|" 'sml-electric-pipe)
47 (define-key map "\M-\ " 'sml-electric-space)
48 (define-key map "\;" 'sml-electric-semi)
49 (define-key map "\M-\t" 'sml-back-to-outer-indent)
50 ;; Process commands added to sml-mode-map -- these should autoload
51 (define-key map "\C-c\C-l" 'sml-load-file)
52 (define-key map "\C-c\C-c" 'sml-compile)
53 (define-key map "\C-c\C-s" 'switch-to-sml)
54 (define-key map "\C-c\C-r" 'sml-send-region)
55 (define-key map "\C-c\C-b" 'sml-send-buffer)
56 (define-key map [(meta shift down-mouse-1)] 'sml-drag-region)
57 map)
58 "The keymap used in `sml-mode'.")
60 (defvar sml-builtin-nested-comments-flag
61 (ignore-errors
62 (not (equal (let ((st (make-syntax-table)))
63 (modify-syntax-entry ?\* ". 23n" st) st)
64 (let ((st (make-syntax-table)))
65 (modify-syntax-entry ?\* ". 23" st) st))))
66 "Non-nil means this Emacs understands the `n' in syntax entries.")
68 (defvar sml-mode-syntax-table
69 (let ((st (make-syntax-table)))
70 (modify-syntax-entry ?\* (if sml-builtin-nested-comments-flag
71 ". 23n" ". 23") st)
72 (modify-syntax-entry ?\( "()1" st)
73 (modify-syntax-entry ?\) ")(4" st)
74 (mapc (lambda (c) (modify-syntax-entry c "_" st)) "._'")
75 (mapc (lambda (c) (modify-syntax-entry c "." st)) ",;")
76 ;; `!' is not really a prefix-char, oh well!
77 (mapc (lambda (c) (modify-syntax-entry c "'" st)) "~#!")
78 (mapc (lambda (c) (modify-syntax-entry c "." st)) "%&$+-/:<=>?@`^|")
79 st)
80 "The syntax table used in `sml-mode'.")
83 (easy-menu-define sml-mode-menu sml-mode-map "Menu used in `sml-mode'."
84 '("SML"
85 ("Process"
86 ["Start default ML compiler" run-sml t]
87 ["-" nil nil]
88 ["run CM.make" sml-compile t]
89 ["load ML source file" sml-load-file t]
90 ["switch to ML buffer" switch-to-sml t]
91 ["--" nil nil]
92 ["send buffer contents" sml-send-buffer t]
93 ["send region" sml-send-region t]
94 ["send paragraph" sml-send-function t]
95 ["goto next error" next-error (featurep 'sml-proc)]
96 ["---" nil nil]
97 ;; ["Standard ML of New Jersey" sml-smlnj (fboundp 'sml-smlnj)]
98 ;; ["Poly/ML" sml-poly-ml (fboundp 'sml-poly-ml)]
99 ;; ["Moscow ML" sml-mosml (fboundp 'sml-mosml)]
100 ["Help for Inferior ML" (describe-function 'inferior-sml-mode) :active (featurep 'sml-proc)])
101 ["electric pipe" sml-electric-pipe t]
102 ["insert SML form" sml-insert-form t]
103 ("Forms" :filter sml-forms-menu)
104 ("Format/Mode Variables"
105 ["indent region" indent-region t]
106 ["outdent" sml-back-to-outer-indent t]
107 ;; ["-" nil nil]
108 ;; ["set indent-level" sml-indent-level t]
109 ;; ["set pipe-indent" sml-pipe-indent t]
110 ;; ["--" nil nil]
111 ;; ["toggle type-of-indent" sml-type-of-indent t]
112 ;; ["toggle nested-if-indent" sml-nested-if-indent t]
113 ;; ["toggle electric-semi-mode" sml-electric-semi-mode t]
115 ["-----" nil nil]
116 ["SML mode help (brief)" describe-mode t]
117 ["SML mode *info*" sml-mode-info t]
118 ["-----" nil nil]
119 ["Remove overlay" (sml-error-overlay 'undo) t ;:active (sml-overlay-active-p)
122 ;; Make's sure they appear in the menu bar when sml-mode-map is active.
123 ;; On the hook for XEmacs only -- see easy-menu-add in auc-menu.el.
124 ;; (defun sml-mode-menu-bar ()
125 ;; "Make sure menus appear in the menu bar as well as under mouse 3."
126 ;; (and (eq major-mode 'sml-mode)
127 ;; (easy-menu-add sml-mode-menu sml-mode-map)))
128 ;; (add-hook 'sml-mode-hook 'sml-mode-menu-bar)
131 ;; regexps
134 (defun sml-syms-re (syms)
135 (concat "\\<" (regexp-opt syms t) "\\>"))
139 (defconst sml-module-head-syms
140 '("signature" "structure" "functor" "abstraction"))
143 (defconst sml-begin-syms
144 '("let" "abstype" "local" "struct" "sig")
145 "Symbols matching the `end' symbol.")
147 (defconst sml-begin-syms-re
148 (sml-syms-re sml-begin-syms)
149 "Symbols matching the `end' symbol.")
151 ;; (defconst sml-user-begin-symbols-re
152 ;; (sml-syms-re '("let" "abstype" "local" "struct" "sig" "in" "with"))
153 ;; "Symbols matching (loosely) the `end' symbol.")
155 (defconst sml-sexp-head-symbols-re
156 (sml-syms-re `("let" "abstype" "local" "struct" "sig" "in" "with"
157 "if" "then" "else" "case" "of" "fn" "fun" "val" "and"
158 "datatype" "type" "exception" "open" "infix" "infixr" "nonfix"
159 ,@sml-module-head-syms
160 "handle" "raise"))
161 "Symbols starting an sexp.")
163 ;; (defconst sml-not-arg-start-re
164 ;; (sml-syms-re '("in" "of" "end" "andalso"))
165 ;; "Symbols that can't be found at the head of an arg.")
167 ;; (defconst sml-not-arg-re
168 ;; (sml-syms-re '("in" "of" "end" "andalso"))
169 ;; "Symbols that should not be confused with an arg.")
171 (defconst sml-=-starter-syms
172 (list* "|" "val" "fun" "and" "datatype" "type" "abstype" "eqtype"
173 sml-module-head-syms)
174 "Symbols that can be followed by a `='.")
175 (defconst sml-=-starter-re
176 (concat "\\S.|\\S.\\|" (sml-syms-re (cdr sml-=-starter-syms)))
177 "Symbols that can be followed by a `='.")
179 (defconst sml-non-nested-of-starter-re
180 (sml-syms-re '("datatype" "abstype" "exception"))
181 "Symbols that can introduce an `of' that shouldn't behave like a paren.")
183 (defconst sml-starters-syms
184 (append sml-module-head-syms
185 '("abstype" "datatype" "exception" "fun"
186 "local" "infix" "infixr" "sharing" "nonfix"
187 "open" "type" "val" "and"
188 "withtype" "with"))
189 "The starters of new expressions.")
191 (defconst sml-pipeheads
192 '("|" "of" "fun" "fn" "and" "handle" "datatype" "abstype")
193 "A `|' corresponds to one of these.")
196 (provide 'sml-defs)
198 ;;; sml-defs.el ends here