summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorStefan Monnier <monnier@iro.umontreal.ca>2012-04-11 17:27:39 -0400
committerStefan Monnier <monnier@iro.umontreal.ca>2012-04-11 17:27:39 -0400
commite807db8612bc19155e703e2ad2061d9be99c7757 (patch)
treed44d1f659a7d88d98b1595e49bf5d63e88069a45
parent3de66695607816baa058f4d016b380f4ba94e28f (diff)
downloademacs-e807db8612bc19155e703e2ad2061d9be99c7757.tar.gz
Merge sml-defs.el into sml-mode.el.
* sml-mode.el: Merge code from sml-defs.el. Remove ":group 'sml" since they're now redundant. * makefile.pkg (ELFILES): Adjust.
-rw-r--r--ChangeLog7
-rw-r--r--NEWS7
-rw-r--r--TODO8
-rw-r--r--makefile.pkg2
-rw-r--r--sml-defs.el172
-rw-r--r--sml-mode.el163
-rw-r--r--sml-oldindent.el2
-rw-r--r--sml-proc.el29
8 files changed, 178 insertions, 212 deletions
diff --git a/ChangeLog b/ChangeLog
index dab2de7f5a5..c596a5340a9 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,12 @@
2012-04-11 Stefan Monnier <monnier@iro.umontreal.ca>
+ Merge sml-defs.el into sml-mode.el.
+ * sml-mode.el: Merge code from sml-defs.el.
+ Remove ":group 'sml" since they're now redundant.
+ * makefile.pkg (ELFILES): Adjust.
+
+2012-04-11 Stefan Monnier <monnier@iro.umontreal.ca>
+
* sml-mode.el (sml-mark-function): New implementation using SMIE.
* sml-defs.el (sml-mode-map): Use backtab.
Remove leftover unused sml-drag-region binding.
diff --git a/NEWS b/NEWS
index e0c16b5a1bf..4d9cc1c51a1 100644
--- a/NEWS
+++ b/NEWS
@@ -2,11 +2,14 @@ Changes since 4.1:
* New indentation code using SMIE when available.
-* sml-back-to-outer-indent is now on S-tab (aka `backtab') rather than M-tab.
+* `sml-back-to-outer-indent' is now on S-tab (aka `backtab') rather than M-tab.
* Support for electric-layout-mode and electric-indent-mode.
-* sml-mark-defun tries to be more clever.
+* `sml-mark-defun' tries to be more clever.
+
+* A single file (sml-mode.el) is needed unless you want to use an interactive
+ process like SML/NJ, or if your Emacs does not provide SMIE.
Changes since 4.0:
diff --git a/TODO b/TODO
index 15d2f373e50..b9c7d34ef96 100644
--- a/TODO
+++ b/TODO
@@ -9,19 +9,11 @@
* Add an sml-mlb-mode for ML Basis files (see http://mlton.org/Emacs)
-* improve M-C-f and M-C-b (they too often don't do the right thing) and
- add M-C-k and other such sexp-chunked operations.
-
-* if indentation is non-obvious, return a list of possible indentations
- and choose the first unless the current is one of the possible choices.
-
* make `M-x sml-compile' more generic.
* allow specifying indentation of dependent keywords (how to indent `in'
relative to `let', for example).
-* use symbols instead of strings for `sym'.
-
* recognize irrefutable patterns (with "Capital"-heuristics, for example:
a regexp like "\\([(),]\\|[_a-z][_a-z0-9]*\\)+").
This can then be used to allow indenting like
diff --git a/makefile.pkg b/makefile.pkg
index f5cd92b06c2..c538d58a834 100644
--- a/makefile.pkg
+++ b/makefile.pkg
@@ -1,5 +1,5 @@
PACKAGE = sml-mode
-ELFILES = sml-defs.el sml-mode.el sml-proc.el sml-oldindent.el
+ELFILES = sml-mode.el sml-proc.el sml-oldindent.el
default: elcfiles
diff --git a/sml-defs.el b/sml-defs.el
deleted file mode 100644
index c8094d93ab0..00000000000
--- a/sml-defs.el
+++ /dev/null
@@ -1,172 +0,0 @@
-;;; sml-defs.el --- Various definitions for sml-mode
-
-;; Copyright (C) 1999,2000,2003,2005,2007,2012 Stefan Monnier
-;;
-;; This program is free software; you can redistribute it and/or modify
-;; it under the terms of the GNU General Public License as published by
-;; the Free Software Foundation; either version 3 of the License, or
-;; (at your option) any later version.
-;;
-;; This program is distributed in the hope that it will be useful,
-;; but WITHOUT ANY WARRANTY; without even the implied warranty of
-;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-;; GNU General Public License for more details.
-;;
-;; You should have received a copy of the GNU General Public License
-;; along with this program; if not, write to the Free Software
-;; Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
-
-;;; Commentary:
-
-
-;;; Code:
-
-(eval-when-compile (require 'cl))
-
-(defgroup sml ()
- "Editing SML code."
- :group 'languages)
-
-(defvar sml-outline-regexp
- ;; `st' and `si' are to match structure and signature.
- " \\|s[ti]\\|[ \t]*\\(let[ \t]+\\)?\\(fun\\|and\\)\\>"
- "Regexp matching a major heading.
-This actually can't work without extending `outline-minor-mode' with the
-notion of \"the end of an outline\".")
-
-;;;
-;;; Internal defines
-;;;
-
-(defvar sml-mode-map
- (let ((map (make-sparse-keymap)))
- ;; Smarter cursor movement.
- ;; (define-key map [remap forward-sexp] 'sml-user-forward-sexp)
- ;; (define-key map [remap backward-sexp] 'sml-user-backward-sexp)
- ;; Text-formatting commands:
- (define-key map "\C-c\C-m" 'sml-insert-form)
- (define-key map "\C-c\C-i" 'sml-mode-info)
- (define-key map "\M-|" 'sml-electric-pipe)
- (define-key map "\M-\ " 'sml-electric-space)
- (define-key map "\;" 'sml-electric-semi)
- (define-key map [backtab] 'sml-back-to-outer-indent)
- ;; Process commands added to sml-mode-map -- these should autoload.
- (define-key map "\C-c\C-l" 'sml-load-file)
- (define-key map "\C-c\C-c" 'sml-compile)
- (define-key map "\C-c\C-s" 'switch-to-sml)
- (define-key map "\C-c\C-r" 'sml-send-region)
- (define-key map "\C-c\C-b" 'sml-send-buffer)
- map)
- "The keymap used in `sml-mode'.")
-
-(defconst sml-builtin-nested-comments-flag
- (ignore-errors
- (not (equal (let ((st (make-syntax-table)))
- (modify-syntax-entry ?\* ". 23n" st) st)
- (let ((st (make-syntax-table)))
- (modify-syntax-entry ?\* ". 23" st) st))))
- "Non-nil means this Emacs understands the `n' in syntax entries.")
-
-(defvar sml-mode-syntax-table
- (let ((st (make-syntax-table)))
- (modify-syntax-entry ?\* (if sml-builtin-nested-comments-flag
- ". 23n" ". 23") st)
- (modify-syntax-entry ?\( "()1" st)
- (modify-syntax-entry ?\) ")(4" st)
- (mapc (lambda (c) (modify-syntax-entry c "_" st)) "._'")
- (mapc (lambda (c) (modify-syntax-entry c "." st)) ",;")
- ;; `!' is not really a prefix-char, oh well!
- (mapc (lambda (c) (modify-syntax-entry c "'" st)) "~#!")
- (mapc (lambda (c) (modify-syntax-entry c "." st)) "%&$+-/:<=>?@`^|")
- st)
- "The syntax table used in `sml-mode'.")
-
-
-(easy-menu-define sml-mode-menu sml-mode-map "Menu used in `sml-mode'."
- '("SML"
- ("Process"
- ["Start default ML compiler" run-sml t]
- ["-" nil nil]
- ["run CM.make" sml-compile t]
- ["load ML source file" sml-load-file t]
- ["switch to ML buffer" switch-to-sml t]
- ["--" nil nil]
- ["send buffer contents" sml-send-buffer t]
- ["send region" sml-send-region t]
- ["send paragraph" sml-send-function t]
- ["goto next error" next-error (featurep 'sml-proc)]
- ["---" nil nil]
- ;; ["Standard ML of New Jersey" sml-smlnj (fboundp 'sml-smlnj)]
- ;; ["Poly/ML" sml-poly-ml (fboundp 'sml-poly-ml)]
- ;; ["Moscow ML" sml-mosml (fboundp 'sml-mosml)]
- ["Help for Inferior ML" (describe-function 'inferior-sml-mode) :active (featurep 'sml-proc)])
- ["electric pipe" sml-electric-pipe t]
- ["insert SML form" sml-insert-form t]
- ("Forms" :filter sml-forms-menu)
- ("Format/Mode Variables"
- ["indent region" indent-region t]
- ["outdent" sml-back-to-outer-indent t]
- ;; ["-" nil nil]
- ;; ["set indent-level" sml-indent-level t]
- ;; ["set pipe-indent" sml-pipe-indent t]
- ;; ["--" nil nil]
- ;; ["toggle type-of-indent" sml-type-of-indent t]
- ;; ["toggle nested-if-indent" sml-nested-if-indent t]
- ;; ["toggle electric-semi-mode" sml-electric-semi-mode t]
- )
- ["-----" nil nil]
- ["SML mode help (brief)" describe-mode t]
- ["SML mode *info*" sml-mode-info t]
- ["-----" nil nil]
- ["Remove overlay" (sml-error-overlay 'undo) t ;:active (sml-overlay-active-p)
- ]))
-
-;; Make's sure they appear in the menu bar when sml-mode-map is active.
-;; On the hook for XEmacs only -- see easy-menu-add in auc-menu.el.
-;; (defun sml-mode-menu-bar ()
-;; "Make sure menus appear in the menu bar as well as under mouse 3."
-;; (and (eq major-mode 'sml-mode)
-;; (easy-menu-add sml-mode-menu sml-mode-map)))
-;; (add-hook 'sml-mode-hook 'sml-mode-menu-bar)
-
-;;
-;; regexps
-;;
-
-(defun sml-syms-re (syms)
- (concat "\\<" (regexp-opt syms t) "\\>"))
-
-;;
-
-(defconst sml-module-head-syms
- '("signature" "structure" "functor" "abstraction"))
-
-
-(defconst sml-=-starter-syms
- (list* "|" "val" "fun" "and" "datatype" "type" "abstype" "eqtype"
- sml-module-head-syms)
- "Symbols that can be followed by a `='.")
-(defconst sml-=-starter-re
- (concat "\\S.|\\S.\\|" (sml-syms-re (cdr sml-=-starter-syms)))
- "Symbols that can be followed by a `='.")
-
-(defconst sml-non-nested-of-starter-re
- (sml-syms-re '("datatype" "abstype" "exception"))
- "Symbols that can introduce an `of' that shouldn't behave like a paren.")
-
-(defconst sml-starters-syms
- (append sml-module-head-syms
- '("abstype" "datatype" "exception" "fun"
- "local" "infix" "infixr" "sharing" "nonfix"
- "open" "type" "val" "and"
- "withtype" "with"))
- "The starters of new expressions.")
-
-(defconst sml-pipeheads
- '("|" "of" "fun" "fn" "and" "handle" "datatype" "abstype")
- "A `|' corresponds to one of these.")
-
-
-(provide 'sml-defs)
-
-;;; sml-defs.el ends here
diff --git a/sml-mode.el b/sml-mode.el
index 767b0c7c235..fea5cac8c35 100644
--- a/sml-mode.el
+++ b/sml-mode.el
@@ -68,21 +68,22 @@
;;; Code:
(eval-when-compile (require 'cl))
-(require 'sml-defs)
(require 'smie nil 'noerror)
(condition-case nil (require 'skeleton) (error nil))
+(defgroup sml ()
+ "Editing SML code."
+ :group 'languages)
+
;;; VARIABLES CONTROLLING INDENTATION
(defcustom sml-indent-level 4
"Indentation of blocks in ML (see also `sml-indent-rule')."
- :group 'sml
:type '(integer))
(defcustom sml-indent-args sml-indent-level
"Indentation of args placed on a separate line."
- :group 'sml
:type '(integer))
;; (defvar sml-indent-align-args t
@@ -100,7 +101,6 @@
(defcustom sml-electric-semi-mode nil
"If non-nil, `\;' will self insert, reindent the line, and do a newline.
If nil, just insert a `\;'. (To insert while t, do: \\[quoted-insert] \;)."
- :group 'sml
:type 'boolean)
(when (fboundp 'electric-layout-mode)
(make-obsolete-variable 'sml-electric-semi-mode
@@ -111,7 +111,6 @@ If nil, just insert a `\;'. (To insert while t, do: \\[quoted-insert] \;)."
If nil: If t:
datatype a = A datatype a = A
and b = B and b = B"
- :group 'sml
:type 'boolean)
;;; OTHER GENERIC MODE VARIABLES
@@ -159,6 +158,151 @@ Full documentation will be available after autoloading the function."))
;; font-lock setup
+(defvar sml-outline-regexp
+ ;; `st' and `si' are to match structure and signature.
+ " \\|s[ti]\\|[ \t]*\\(let[ \t]+\\)?\\(fun\\|and\\)\\>"
+ "Regexp matching a major heading.
+This actually can't work without extending `outline-minor-mode' with the
+notion of \"the end of an outline\".")
+
+;;
+;; Internal defines
+;;
+
+(defvar sml-mode-map
+ (let ((map (make-sparse-keymap)))
+ ;; Smarter cursor movement.
+ ;; (define-key map [remap forward-sexp] 'sml-user-forward-sexp)
+ ;; (define-key map [remap backward-sexp] 'sml-user-backward-sexp)
+ ;; Text-formatting commands:
+ (define-key map "\C-c\C-m" 'sml-insert-form)
+ (define-key map "\C-c\C-i" 'sml-mode-info)
+ (define-key map "\M-|" 'sml-electric-pipe)
+ (define-key map "\M-\ " 'sml-electric-space)
+ (define-key map "\;" 'sml-electric-semi)
+ (define-key map [backtab] 'sml-back-to-outer-indent)
+ ;; Process commands added to sml-mode-map -- these should autoload.
+ (define-key map "\C-c\C-l" 'sml-load-file)
+ (define-key map "\C-c\C-c" 'sml-compile)
+ (define-key map "\C-c\C-s" 'switch-to-sml)
+ (define-key map "\C-c\C-r" 'sml-send-region)
+ (define-key map "\C-c\C-b" 'sml-send-buffer)
+ map)
+ "The keymap used in `sml-mode'.")
+
+(defconst sml-builtin-nested-comments-flag
+ (ignore-errors
+ (not (equal (let ((st (make-syntax-table)))
+ (modify-syntax-entry ?\* ". 23n" st) st)
+ (let ((st (make-syntax-table)))
+ (modify-syntax-entry ?\* ". 23" st) st))))
+ "Non-nil means this Emacs understands the `n' in syntax entries.")
+
+(defvar sml-mode-syntax-table
+ (let ((st (make-syntax-table)))
+ (modify-syntax-entry ?\* (if sml-builtin-nested-comments-flag
+ ". 23n" ". 23") st)
+ (modify-syntax-entry ?\( "()1" st)
+ (modify-syntax-entry ?\) ")(4" st)
+ (mapc (lambda (c) (modify-syntax-entry c "_" st)) "._'")
+ (mapc (lambda (c) (modify-syntax-entry c "." st)) ",;")
+ ;; `!' is not really a prefix-char, oh well!
+ (mapc (lambda (c) (modify-syntax-entry c "'" st)) "~#!")
+ (mapc (lambda (c) (modify-syntax-entry c "." st)) "%&$+-/:<=>?@`^|")
+ st)
+ "The syntax table used in `sml-mode'.")
+
+
+(easy-menu-define sml-mode-menu sml-mode-map "Menu used in `sml-mode'."
+ '("SML"
+ ("Process"
+ ["Start default ML compiler" run-sml t]
+ ["-" nil nil]
+ ["run CM.make" sml-compile t]
+ ["load ML source file" sml-load-file t]
+ ["switch to ML buffer" switch-to-sml t]
+ ["--" nil nil]
+ ["send buffer contents" sml-send-buffer t]
+ ["send region" sml-send-region t]
+ ["send paragraph" sml-send-function t]
+ ["goto next error" next-error (featurep 'sml-proc)]
+ ["---" nil nil]
+ ;; ["Standard ML of New Jersey" sml-smlnj (fboundp 'sml-smlnj)]
+ ;; ["Poly/ML" sml-poly-ml (fboundp 'sml-poly-ml)]
+ ;; ["Moscow ML" sml-mosml (fboundp 'sml-mosml)]
+ ["Help for Inferior ML" (describe-function 'inferior-sml-mode)
+ :active (featurep 'sml-proc)])
+ ["electric pipe" sml-electric-pipe t]
+ ["insert SML form" sml-insert-form t]
+ ("Forms" :filter sml-forms-menu)
+ ("Format/Mode Variables"
+ ["indent region" indent-region t]
+ ["outdent" sml-back-to-outer-indent t]
+ ;; ["-" nil nil]
+ ;; ["set indent-level" sml-indent-level t]
+ ;; ["set pipe-indent" sml-pipe-indent t]
+ ;; ["--" nil nil]
+ ;; ["toggle type-of-indent" sml-type-of-indent t]
+ ;; ["toggle nested-if-indent" sml-nested-if-indent t]
+ ;; ["toggle electric-semi-mode" sml-electric-semi-mode t]
+ )
+ ["-----" nil nil]
+ ["SML mode help (brief)" describe-mode t]
+ ["SML mode *info*" sml-mode-info t]
+ ["Remove overlay" (sml-error-overlay 'undo)
+ :visible (or (and (boundp 'sml-error-overlay)
+ sml-error-overlay)
+ (not (fboundp 'compilation-fake-loc)))
+ :active (and (boundp 'sml-error-overlay)
+ (overlayp sml-error-overlay)
+ (overlay-start sml-error-overlay))
+ ]))
+
+;; Make's sure they appear in the menu bar when sml-mode-map is active.
+;; On the hook for XEmacs only -- see easy-menu-add in auc-menu.el.
+;; (defun sml-mode-menu-bar ()
+;; "Make sure menus appear in the menu bar as well as under mouse 3."
+;; (and (eq major-mode 'sml-mode)
+;; (easy-menu-add sml-mode-menu sml-mode-map)))
+;; (add-hook 'sml-mode-hook 'sml-mode-menu-bar)
+
+;;
+;; regexps
+;;
+
+(defun sml-syms-re (syms)
+ (concat "\\<" (regexp-opt syms t) "\\>"))
+
+;;
+
+(defconst sml-module-head-syms
+ '("signature" "structure" "functor" "abstraction"))
+
+
+(defconst sml-=-starter-syms
+ (list* "|" "val" "fun" "and" "datatype" "type" "abstype" "eqtype"
+ sml-module-head-syms)
+ "Symbols that can be followed by a `='.")
+(defconst sml-=-starter-re
+ (concat "\\S.|\\S.\\|" (sml-syms-re (cdr sml-=-starter-syms)))
+ "Symbols that can be followed by a `='.")
+
+(defconst sml-non-nested-of-starter-re
+ (sml-syms-re '("datatype" "abstype" "exception"))
+ "Symbols that can introduce an `of' that shouldn't behave like a paren.")
+
+(defconst sml-starters-syms
+ (append sml-module-head-syms
+ '("abstype" "datatype" "exception" "fun"
+ "local" "infix" "infixr" "sharing" "nonfix"
+ "open" "type" "val" "and"
+ "withtype" "with"))
+ "The starters of new expressions.")
+
+(defconst sml-pipeheads
+ '("|" "of" "fun" "fn" "and" "handle" "datatype" "abstype")
+ "A `|' corresponds to one of these.")
+
(defconst sml-keywords-regexp
(sml-syms-re '("abstraction" "abstype" "and" "andalso" "as" "before" "case"
"datatype" "else" "end" "eqtype" "exception" "do" "fn"
@@ -360,8 +504,6 @@ Regexp match data 0 points to the chars."
;;; Indentation with SMIE
(defvar sml-use-smie t)
-(unless (and sml-use-smie (fboundp 'smie-setup))
- (require 'sml-oldindent))
(defconst sml-smie-grammar
(when (fboundp 'smie-prec2->grammar)
@@ -882,7 +1024,6 @@ a newline, and indent."
(defcustom sml-max-name-components 3
"Maximum number of components to use for the current function name."
- :group 'sml
:type 'integer)
(defun sml-current-fun-name ()
@@ -1210,19 +1351,16 @@ See also `edit-kbd-macro' which is bound to \\[edit-kbd-macro]."
(defcustom sml-yacc-indent-action 16
"Indentation column of the opening paren of actions."
- :group 'sml
:type 'integer)
(defcustom sml-yacc-indent-pipe nil
"Indentation column of the pipe char in the BNF.
If nil, align it with `:' or with previous cases."
- :group 'sml
:type 'integer)
(defcustom sml-yacc-indent-term nil
"Indentation column of the (non)term part.
If nil, align it with previous cases."
- :group 'sml
:type 'integer)
(defvar sml-yacc-font-lock-keywords
@@ -1292,4 +1430,7 @@ If nil, align it with previous cases."
(provide 'sml-mode)
+(unless (and sml-use-smie (fboundp 'smie-setup))
+ (require 'sml-oldindent))
+
;;; sml-mode.el ends here
diff --git a/sml-oldindent.el b/sml-oldindent.el
index a12afa2b458..8a70c934c4d 100644
--- a/sml-oldindent.el
+++ b/sml-oldindent.el
@@ -23,7 +23,7 @@
;;; Code:
(eval-when-compile (require 'cl))
-(require 'sml-defs)
+(require 'sml-mode)
(defun sml-preproc-alist (al)
"Expand an alist AL where keys can be lists of keys into a normal one."
diff --git a/sml-proc.el b/sml-proc.el
index bdcd444b5cd..84e5e65670a 100644
--- a/sml-proc.el
+++ b/sml-proc.el
@@ -96,23 +96,19 @@
:group 'sml)
(defcustom sml-program-name "sml"
- "*Program to run as ML."
- :group 'sml-proc
+ "Program to run as ML."
:type '(string))
(defcustom sml-default-arg ""
- "*Default command line option to pass, if any."
- :group 'sml-proc
+ "Default command line option to pass, if any."
:type '(string))
(defcustom sml-host-name ""
- "*Host on which to run ML."
- :group 'sml-proc
+ "Host on which to run ML."
:type '(string))
(defcustom sml-config-file "~/.smlproc.sml"
- "*File that should be fed to the ML process when started."
- :group 'sml-proc
+ "File that should be fed to the ML process when started."
:type '(string))
(defcustom sml-compile-command "CM.make()"
@@ -124,7 +120,7 @@ See also `sml-compile-commands-alist'.")
("CMB.make()" . "pathconfig")
("CM.make()" . "sources.cm")
("use \"load-all\"" . "load-all"))
- "*Commands used by default by `sml-compile'.
+ "Commands used by default by `sml-compile'.
Each command is associated with its \"main\" file.
It is perfectly OK to associate several files with a command or several
commands with the same file.")
@@ -198,8 +194,7 @@ The format specifier \"%s\" will be converted into the directory name
specified when running the command \\[sml-cd].")
(defcustom sml-prompt-regexp "^[-=>#] *"
- "*Regexp used to recognise prompts in the inferior ML process."
- :group 'sml-proc
+ "Regexp used to recognise prompts in the inferior ML process."
:type '(regexp))
(defvar sml-error-regexp-alist
@@ -776,13 +771,13 @@ the overlay should simply be removed: \\[universal-argument] \
(when sml-error-overlay
(unless (overlayp sml-error-overlay)
(let ((ol sml-error-overlay))
- (setq sml-error-overlay (make-overlay 0 0))
+ (setq sml-error-overlay (make-overlay (point) (point)))
(overlay-put sml-error-overlay 'face (if (symbolp ol) ol 'region))))
- (if undo (move-overlay sml-error-overlay 1 1 (current-buffer))
- ;; if active regions, signals mark not active if no region set
- (let ((beg (or beg (region-beginning)))
- (end (or end (region-end))))
- (move-overlay sml-error-overlay beg end (current-buffer))))))
+ (if undo (delete-overlay sml-error-overlay)
+ ;; If active regions, signals mark not active if no region set.
+ (move-overlay sml-error-overlay
+ (or beg (region-beginning)) (or end (region-end))
+ (current-buffer)))))
(provide 'sml-proc)