Home My Page Projects Code Snippets Project Openings SML/NJ
Summary Activity Forums Tracker Lists Tasks Docs Surveys News SCM Files

SCM Repository

[smlnj] Diff of /sml-mode/trunk/sml-mode.el
ViewVC logotype

Diff of /sml-mode/trunk/sml-mode.el

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 706, Sat Oct 7 03:21:46 2000 UTC revision 707, Sat Oct 7 03:21:59 2000 UTC
# Line 4  Line 4 
4  ;; Copyright (C) 1994-1997  Matthew J. Morley  ;; Copyright (C) 1994-1997  Matthew J. Morley
5  ;; Copyright (C) 1999-2000  Stefan Monnier  ;; Copyright (C) 1999-2000  Stefan Monnier
6    
7    ;; Author: Lars Bo Nielsen
8    ;;      Olin Shivers
9    ;;      Fritz Knabe (?)
10    ;;      Steven Gilmore (?)
11    ;;      Matthew Morley <mjm@scs.leeds.ac.uk> (aka <matthew@verisity.com>)
12    ;;      Matthias Blume <blume@cs.princeton.edu> (aka <blume@kurims.kyoto-u.ac.jp>)
13    ;;      (Stefan Monnier) monnier@cs.yale.edu
14    ;; Maintainer: (Stefan Monnier) monnier+lists/emacs/sml@flint.cs.yale.edu
15    ;; Keywords: SML
16  ;; $Revision$  ;; $Revision$
17  ;; $Date$  ;; $Date$
18    
19  ;; This file is not part of GNU Emacs, but it is distributed under the  ;; This file is not part of GNU Emacs, but it is distributed under the
20  ;; same conditions.  ;; same conditions.
21    
 ;; ====================================================================  
   
22  ;; This program is free software; you can redistribute it and/or  ;; This program is free software; you can redistribute it and/or
23  ;; modify it under the terms of the GNU General Public License as  ;; modify it under the terms of the GNU General Public License as
24  ;; published by the Free Software Foundation; either version 2, or (at  ;; published by the Free Software Foundation; either version 2, or (at
# Line 26  Line 33 
33  ;; along with GNU Emacs; see the file COPYING. If not, write to the  ;; along with GNU Emacs; see the file COPYING. If not, write to the
34  ;; Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.  ;; Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
35    
 ;; ====================================================================  
   
   
36  ;;; Commentary:  ;;; Commentary:
 ;;  
37    
38  ;;; HISTORY  ;;; HISTORY
39    
# Line 43  Line 46 
46  ;; font-lock patterns, some of Steven Gilmore's (reduced) easy-menus,  ;; font-lock patterns, some of Steven Gilmore's (reduced) easy-menus,
47  ;; and numerous bugs and bug-fixes.  ;; and numerous bugs and bug-fixes.
48    
 ;; Author: Lars Bo Nielsen  
 ;;      Olin Shivers  
 ;;      Fritz Knabe (?)  
 ;;      Steven Gilmore (?)  
 ;;      Matthew Morley <mjm@scs.leeds.ac.uk> (aka <matthew@verisity.com>)  
 ;;      Matthias Blume <blume@cs.princeton.edu> (aka <blume@kurims.kyoto-u.ac.jp>)  
 ;;      (Stefan Monnier) monnier@cs.yale.edu  
 ;; Maintainer: (Stefan Monnier) monnier+lists/emacs/sml@tequila.cs.yale.edu  
 ;; Keywords: SML  
   
49  ;;; DESCRIPTION  ;;; DESCRIPTION
50    
51  ;; See accompanying info file: sml-mode.info  ;; See accompanying info file: sml-mode.info
# Line 62  Line 55 
55  ;; If sml-mode.el lives in some non-standard directory, you must tell  ;; If sml-mode.el lives in some non-standard directory, you must tell
56  ;; emacs where to get it. This may or may not be necessary:  ;; emacs where to get it. This may or may not be necessary:
57    
58  ;; (setq load-path (cons (expand-file-name "~jones/lib/emacs") load-path))  ;; (add-to-list 'load-path "~jones/lib/emacs/")
59    
60  ;; Then to access the commands autoload sml-mode with that command:  ;; Then to access the commands autoload sml-mode with that command:
61    
62  ;; (autoload 'sml-mode "sml-mode" "Major mode for editing ML programs." t)  ;; (load "sml-mode-startup")
 ;;  
 ;; If files ending in ".sml" or ".ML" are hereafter considered to contain  
 ;; Standard ML source, put their buffers into sml-mode automatically:  
   
 ;; (setq auto-mode-alist  
 ;;       (cons '(("\\.sml$" . sml-mode)  
 ;;               ("\\.ML$"  . sml-mode)) auto-mode-alist))  
   
 ;; Here's an example of setting things up in the sml-mode-hook:  
   
 ;; (setq sml-mode-hook  
 ;;       '(lambda() "ML mode hacks"  
 ;;          (setq sml-indent-level 2         ; conserve on horiz. space  
 ;;                indent-tabs-mode nil)))    ; whatever  
63    
64  ;; sml-mode-hook is run whenever a new sml-mode buffer is created.  ;; sml-mode-hook is run whenever a new sml-mode buffer is created.
65    
# Line 162  Line 141 
141         "This function is part of sml-proc, and has not yet been loaded.         "This function is part of sml-proc, and has not yet been loaded.
142  Full documentation will be available after autoloading the function."))  Full documentation will be available after autoloading the function."))
143    
   (autoload 'run-sml            "sml-proc"   sml-no-doc t)  
144    (autoload 'sml-compile        "sml-proc"   sml-no-doc t)    (autoload 'sml-compile        "sml-proc"   sml-no-doc t)
145    (autoload 'sml-load-file      "sml-proc"   sml-no-doc t)    (autoload 'sml-load-file      "sml-proc"   sml-no-doc t)
146    (autoload 'switch-to-sml      "sml-proc"   sml-no-doc t)    (autoload 'switch-to-sml      "sml-proc"   sml-no-doc t)
# Line 260  Line 238 
238    '(sml-font-lock-keywords nil nil ((?_ . "w") (?' . "w")) nil    '(sml-font-lock-keywords nil nil ((?_ . "w") (?' . "w")) nil
239                             (font-lock-syntactic-keywords . sml-font-lock-syntactic-keywords)))                             (font-lock-syntactic-keywords . sml-font-lock-syntactic-keywords)))
240    
241    ;;;;
242    ;;;; Imenu support
243    ;;;;
244    
245    (defvar sml-imenu-regexp
246      (concat "^[ \t]*\\(let[ \t]+\\)?"
247              (regexp-opt (append sml-module-head-syms
248                                  '("and" "fun" "datatype" "abstype" "type")) t)
249              "\\>"))
250    
251    (defun sml-imenu-create-index ()
252      (let (alist)
253        (goto-char (point-max))
254        (while (re-search-backward sml-imenu-regexp nil t)
255          (save-excursion
256            (let ((kind (match-string 2))
257                  (column (progn (goto-char (match-beginning 2)) (current-column)))
258                  (location
259                   (progn (goto-char (match-end 0)) (sml-forward-spaces) (point)))
260                  (name (sml-forward-sym)))
261              ;; Eliminate trivial renamings.
262              (when (or (not (member kind '("structure" "signature")))
263                        (progn (search-forward "=")
264                               (sml-forward-spaces)
265                               (looking-at "sig\\|struct")))
266                (push (cons (concat (make-string (/ column 2) ?\ ) name) location)
267                      alist)))))
268        alist))
269    
270  ;;; MORE CODE FOR SML-MODE  ;;; MORE CODE FOR SML-MODE
271    
# Line 273  Line 279 
279  \\{sml-mode-map}"  \\{sml-mode-map}"
280    (set (make-local-variable 'font-lock-defaults) sml-font-lock-defaults)    (set (make-local-variable 'font-lock-defaults) sml-font-lock-defaults)
281    (set (make-local-variable 'outline-regexp) sml-outline-regexp)    (set (make-local-variable 'outline-regexp) sml-outline-regexp)
282      (set (make-local-variable 'imenu-create-index-function)
283           'sml-imenu-create-index)
284    (set (make-local-variable 'add-log-current-defun-function)    (set (make-local-variable 'add-log-current-defun-function)
285         'sml-current-fun-name)         'sml-current-fun-name)
286    ;; forward-sexp-function is an experimental variable in my hacked Emacs.    ;; forward-sexp-function is an experimental variable in my hacked Emacs.
# Line 630  Line 638 
638    
639  (defun sml-beginning-of-defun ()  (defun sml-beginning-of-defun ()
640    (let ((sym (sml-find-matching-starter sml-starters-syms)))    (let ((sym (sml-find-matching-starter sml-starters-syms)))
641      (if (member sym '("fun" "functor" "signature" "structure"      (if (member sym '("fun" "and" "functor" "signature" "structure"
642                        "abstraction" "datatype" "abstype"))                        "abstraction" "datatype" "abstype"))
643          (save-excursion (sml-forward-sym) (sml-forward-spaces)          (save-excursion (sml-forward-sym) (sml-forward-spaces)
644                          (sml-forward-sym))                          (sml-forward-sym))
# Line 807  Line 815 
815      (message "Macro bound to %s" fsym)      (message "Macro bound to %s" fsym)
816      (add-to-list 'sml-forms-alist (cons name fsym))))      (add-to-list 'sml-forms-alist (cons name fsym))))
817    
818  ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;  ;;;;
819  ;;;;  SML/NJ's Compilation Manager support  ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;  ;;;;  SML/NJ's Compilation Manager support
820  ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;  ;;;;
821    
822  ;;;###autoload  ;;;###autoload
823  (add-to-list 'completion-ignored-extensions "CM/")  (add-to-list 'completion-ignored-extensions "CM/")
# Line 824  Line 832 
832    (list (lambda () (local-set-key "\C-c\C-c" 'sml-compile)))    (list (lambda () (local-set-key "\C-c\C-c" 'sml-compile)))
833    "Generic mode for SML/NJ's Compilation Manager configuration files.")    "Generic mode for SML/NJ's Compilation Manager configuration files.")
834    
835    ;;;;
836    ;;;; ML-Yacc (and ML-lex) support
837    ;;;;
838    
839    ;; That seems to be good enough for now ;-)
840    ;;;###autoload
841    (define-derived-mode sml-lex-mode sml-mode "SML-Lex")
842    
843    (defface sml-yacc-bnf-face
844      '((t (:foreground "darkgreen")))
845      "Face used to highlight (non)terminals in `sml-yacc-mode'.")
846    (defvar sml-yacc-bnf-face 'sml-yacc-bnf-face)
847    
848    (defcustom sml-yacc-indent-action 16
849      "Indentation column of the opening paren of actions."
850      :group 'sml
851      :type 'integer)
852    
853    (defcustom sml-yacc-indent-pipe nil
854      "Indentation column of the pipe char in the BNF.
855    If nil, align it with `:' or with previous cases."
856      :group 'sml
857      :type 'integer)
858    
859    (defcustom sml-yacc-indent-term nil
860      "Indentation column of the (non)term part.
861    If nil, align it with previous cases."
862      :group 'sml
863      :type 'integer)
864    
865    (defvar sml-yacc-font-lock-keywords
866      (cons '("^\\(\\sw+\\s-*:\\|\\s-*|\\)\\(\\s-*\\sw+\\)*"
867              (0 (save-excursion
868                   (save-match-data
869                     (goto-char (match-beginning 0))
870                     (unless (or (re-search-forward "\\<of\\>" (match-end 0) 'move)
871                                 (progn (sml-forward-spaces)
872                                        (not (looking-at "("))))
873                       sml-yacc-bnf-face)))))
874            sml-font-lock-keywords))
875    (defconst sml-yacc-font-lock-defaults
876      (cons sml-yacc-font-lock-keywords (cdr sml-font-lock-defaults)))
877    
878    (defun sml-yacc-bnf-p ()
879    
880    
881    (defun sml-yacc-indent-line ()
882      "Indent current line of ML-Yacc code."
883      (let ((savep (> (current-column) (current-indentation)))
884            (indent (max (or (ignore-errors (sml-yacc-indentation)) 0) 0)))
885        (if savep
886            (save-excursion (indent-line-to indent))
887          (indent-line-to indent))))
888    
889    (defun sml-yacc-indentation ()
890      (save-excursion
891        (back-to-indentation)
892        (or (and (looking-at "%\\|\\(\\sw\\|\\s_\\)+\\s-*:") 0)
893            (when (save-excursion
894                    (condition-case nil (progn (up-list -1) nil) (scan-error t)))
895              ;; We're outside an action.
896              (cond
897               ;; Special handling of indentation inside %term and %nonterm
898               ((save-excursion
899                  (and (re-search-backward "^%\\(\\sw+\\)" nil t)
900                       (member (match-string 1) '("term" "nonterm"))))
901                (if (numberp sml-yacc-indent-term) sml-yacc-indent-term
902                  (let ((offset (if (looking-at "|") -2 0)))
903                    (forward-line -1)
904                    (looking-at "\\s-*\\(%\\sw*\\||\\)?\\s-*")
905                    (goto-char (match-end 0))
906                    (+ offset (current-column)))))
907               ((looking-at "(") sml-yacc-indent-action)
908               ((looking-at "|")
909                (if (numberp sml-yacc-indent-pipe) sml-yacc-indent-pipe
910                  (backward-sexp 1)
911                  (while (progn (sml-backward-spaces)
912                                (/= 0 (skip-syntax-backward "w_"))))
913                  (sml-backward-spaces)
914                  (if (not (looking-at "\\s-$"))
915                      (1- (current-column))
916                    (skip-syntax-forward " ")
917                    (- (current-column) 2))))))
918            ;; default to SML rules
919            (sml-calculate-indentation))))
920    
921    ;;;###autoload
922    (add-to-list 'auto-mode-alist '("\\.grm\\'" . sml-yacc-mode))
923    ;;;###autoload
924    (define-derived-mode sml-yacc-mode sml-mode "SML-Yacc"
925      (set (make-local-variable 'indent-line-function) 'sml-yacc-indent-line)
926      (set (make-local-variable 'font-lock-defaults) sml-yacc-font-lock-defaults))
927    
928  (provide 'sml-mode)  (provide 'sml-mode)
929    

Legend:
Removed from v.706  
changed lines
  Added in v.707

root@smlnj-gforge.cs.uchicago.edu
ViewVC Help
Powered by ViewVC 1.0.0