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/trunk/sml-mode/sml-mode.el
ViewVC logotype

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

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

revision 767, Sun Dec 24 19:59:41 2000 UTC revision 768, Sun Dec 24 19:59:53 2000 UTC
# Line 73  Line 73 
73  (require 'sml-util)  (require 'sml-util)
74  (require 'sml-move)  (require 'sml-move)
75  (require 'sml-defs)  (require 'sml-defs)
76    (condition-case nil (require 'skeleton) (error nil))
77    
78  ;;; VARIABLES CONTROLLING INDENTATION  ;;; VARIABLES CONTROLLING INDENTATION
79    
# Line 285  Line 286 
286         'sml-current-fun-name)         'sml-current-fun-name)
287    ;; forward-sexp-function is an experimental variable in my hacked Emacs.    ;; forward-sexp-function is an experimental variable in my hacked Emacs.
288    (set (make-local-variable 'forward-sexp-function) 'sml-user-forward-sexp)    (set (make-local-variable 'forward-sexp-function) 'sml-user-forward-sexp)
289      ;; For XEmacs
290      (easy-menu-add sml-mode-menu)
291      ;; Compatibility
292      (unless (boundp 'skeleton-positions) (set (make-local-variable '@) nil))
293    (sml-mode-variables))    (sml-mode-variables))
294    
295  (defun sml-mode-variables ()  (defun sml-mode-variables ()
# Line 302  Line 307 
307    ;;(set (make-local-variable 'block-comment-start) "* ")    ;;(set (make-local-variable 'block-comment-start) "* ")
308    ;;(set (make-local-variable 'block-comment-end) "")    ;;(set (make-local-variable 'block-comment-end) "")
309    (set (make-local-variable 'comment-column) 40)    (set (make-local-variable 'comment-column) 40)
310    (set (make-local-variable 'comment-start-skip) "(\\*+\\s-*")    (set (make-local-variable 'comment-start-skip) "(\\*+\\s-*"))
   (set (make-local-variable 'comment-indent-function) 'sml-comment-indent))  
311    
312  (defun sml-electric-pipe ()  (defun sml-electric-pipe ()
313    "Insert a \"|\".    "Insert a \"|\".
# Line 372  Line 376 
376    (interactive)    (interactive)
377    (mark-paragraph))    (mark-paragraph))
378    
 ;; (defun sml-indent-region (begin end)  
 ;;   "Indent region of ML code."  
 ;;   (interactive "r")  
 ;;   (message "Indenting region...")  
 ;;   (save-excursion  
 ;;     (goto-char end) (setq end (point-marker)) (goto-char begin)  
 ;;     (while (< (point) end)  
 ;;       (skip-chars-forward "\t\n ")  
 ;;       (indent-according-to-mode)  
 ;;       (end-of-line))  
 ;;     (move-marker end nil))  
 ;;   (message "Indenting region... done"))  
   
379  (defun sml-indent-line ()  (defun sml-indent-line ()
380    "Indent current line of ML code."    "Indent current line of ML code."
381    (interactive)    (interactive)
# Line 667  Line 658 
658        fullname)))        fullname)))
659    
660    
 (defun sml-comment-indent ()  
   (if (looking-at "^(\\*")              ; Existing comment at beginning  
       0                                 ; of line stays there.  
     comment-column))  
   
661  ;;; INSERTING PROFORMAS (COMMON SML-FORMS)  ;;; INSERTING PROFORMAS (COMMON SML-FORMS)
662    
663  (defvar sml-forms-alist nil  (defvar sml-forms-alist nil
# Line 688  Line 674 
674  signature, structure, and functor by default.")  signature, structure, and functor by default.")
675    
676  (defmacro sml-def-skeleton (name interactor &rest elements)  (defmacro sml-def-skeleton (name interactor &rest elements)
677      (when (fboundp 'define-skeleton)
678    (let ((fsym (intern (concat "sml-form-" name))))    (let ((fsym (intern (concat "sml-form-" name))))
679      `(progn      `(progn
680         (add-to-list 'sml-forms-alist ',(cons name fsym))         (add-to-list 'sml-forms-alist ',(cons name fsym))
# Line 696  Line 683 
683           ,(format "SML-mode skeleton for `%s..' expressions" name)           ,(format "SML-mode skeleton for `%s..' expressions" name)
684           ,interactor           ,interactor
685           ,(concat name " ") >           ,(concat name " ") >
686           ,@elements))))             ,@elements)))))
687  (put 'sml-def-skeleton 'lisp-indent-function 2)  (put 'sml-def-skeleton 'lisp-indent-function 2)
688    
689  (sml-def-skeleton "let" nil  (sml-def-skeleton "let" nil
690    _ "\nin" > "\nend" >)    @ "\nin " > _ "\nend" >)
691    
692  (sml-def-skeleton "if" nil  (sml-def-skeleton "if" nil
693    _ " then " > "\nelse " >)    @ " then " > _ "\nelse " > _)
694    
695  (sml-def-skeleton "local" nil  (sml-def-skeleton "local" nil
696    _ "\nin" > "\nend" >)    @ "\nin" > _ "\nend" >)
697    
698  (sml-def-skeleton "case" "Case expr: "  (sml-def-skeleton "case" "Case expr: "
699    str "\nof " > _ " => ")    str "\nof " > _ " => ")
# Line 735  Line 722 
722    _ "\nend" >)    _ "\nend" >)
723    
724  (sml-def-skeleton "val" nil  (sml-def-skeleton "val" nil
725    _ " = " >)    @ " = " > _)
726    
727  (sml-def-skeleton "fn" nil  (sml-def-skeleton "fn" nil
728    _ " =>" >)    @ " =>" > _)
729    
730  (sml-def-skeleton "fun" nil  (sml-def-skeleton "fun" nil
731    _ " =" >)    @ " =" > _)
732    
733  ;;  ;;
734    
735  (defun sml-forms-menu (menu)  (defun sml-forms-menu (menu)
   (easy-menu-filter-return  
    (easy-menu-create-menu "Forms"  
736           (mapcar (lambda (x)           (mapcar (lambda (x)
737                     (let ((name (car x))                     (let ((name (car x))
738                           (fsym (cdr x)))                           (fsym (cdr x)))
739                       (vector name fsym t)))                       (vector name fsym t)))
740                   sml-forms-alist))))            sml-forms-alist))
741    
742  (defvar sml-last-form "let")  (defvar sml-last-form "let")
743    
# Line 819  Line 804 
804  ;;;;  SML/NJ's Compilation Manager support  ;;;;  SML/NJ's Compilation Manager support
805  ;;;;  ;;;;
806    
807    (defvar sml-cm-mode-syntax-table sml-mode-syntax-table)
808    (defvar sml-cm-font-lock-keywords
809     `(,(concat "\\<" (regexp-opt '("library" "group" "is" "structure"
810                                    "functor" "signature" "funsig") t)
811                "\\>")))
812  ;;;###autoload  ;;;###autoload
813  (add-to-list 'completion-ignored-extensions "CM/")  (add-to-list 'completion-ignored-extensions "CM/")
814  ;;;###autoload  ;;;###autoload
815  (add-to-list 'auto-mode-alist '("\\.cm\\'" . sml-cm-mode))  (add-to-list 'auto-mode-alist '("\\.cm\\'" . sml-cm-mode))
816  ;;;###autoload  ;;;###autoload
817  (define-generic-mode 'sml-cm-mode  (define-derived-mode sml-cm-mode fundamental-mode "SML-CM"
818    '(("(*" . "*)"))    "Major mode for SML/NJ's Compilation Manager configuration files."
819    '("library" "Library" "LIBRARY" "group" "Group" "GROUP" "is" "IS"    (local-set-key "\C-c\C-c" 'sml-compile)
820      "structure" "functor" "signature" "funsig")    (set (make-local-variable 'font-lock-defaults)
821    nil '("\\.cm\\'")         '(sml-cm-font-lock-keywords nil t nil nil)))
   (list (lambda () (local-set-key "\C-c\C-c" 'sml-compile)))  
   "Generic mode for SML/NJ's Compilation Manager configuration files.")  
822    
823  ;;;;  ;;;;
824  ;;;; ML-Yacc (and ML-lex) support  ;;;; ML-Lex support
825  ;;;;  ;;;;
826    
827  ;; That seems to be good enough for now ;-)  (defvar sml-lex-font-lock-keywords
828      (append
829       '(("^%\\sw+" . font-lock-builtin-face)
830         ("^%%" . font-lock-module-def-face))
831       sml-font-lock-keywords))
832    (defconst sml-lex-font-lock-defaults
833      (cons 'sml-lex-font-lock-keywords (cdr sml-font-lock-defaults)))
834    
835  ;;;###autoload  ;;;###autoload
836  (define-derived-mode sml-lex-mode sml-mode "SML-Lex")  (define-derived-mode sml-lex-mode sml-mode "SML-Lex"
837      "Major Mode for editing ML-Lex files."
838      (set (make-local-variable 'font-lock-defaults) sml-lex-font-lock-defaults))
839    
840    ;;;;
841    ;;;; ML-Yacc support
842    ;;;;
843    
844  (defface sml-yacc-bnf-face  (defface sml-yacc-bnf-face
845    '((t (:foreground "darkgreen")))    '((t (:foreground "darkgreen")))
# Line 863  Line 864 
864    :type 'integer)    :type 'integer)
865    
866  (defvar sml-yacc-font-lock-keywords  (defvar sml-yacc-font-lock-keywords
867    (cons '("^\\(\\sw+\\s-*:\\|\\s-*|\\)\\(\\s-*\\sw+\\)*"    (cons '("^\\(\\sw+\\s-*:\\|\\s-*|\\)\\(\\s-*\\sw+\\)*\\s-*\\(\\(%\\sw+\\)\\s-+\\sw+\\|\\)"
868            (0 (save-excursion            (0 (save-excursion
869                 (save-match-data                 (save-match-data
870                   (goto-char (match-beginning 0))                   (goto-char (match-beginning 0))
871                   (unless (or (re-search-forward "\\<of\\>" (match-end 0) 'move)                   (unless (or (re-search-forward "\\<of\\>" (match-end 0) 'move)
872                               (progn (sml-forward-spaces)                               (progn (sml-forward-spaces)
873                                      (not (looking-at "("))))                                      (not (looking-at "("))))
874                     sml-yacc-bnf-face)))))                     sml-yacc-bnf-face))))
875          sml-font-lock-keywords))            (4 font-lock-builtin-face t t))
876            sml-lex-font-lock-keywords))
877  (defconst sml-yacc-font-lock-defaults  (defconst sml-yacc-font-lock-defaults
878    (cons sml-yacc-font-lock-keywords (cdr sml-font-lock-defaults)))    (cons 'sml-yacc-font-lock-keywords (cdr sml-font-lock-defaults)))
879    
880  (defun sml-yacc-indent-line ()  (defun sml-yacc-indent-line ()
881    "Indent current line of ML-Yacc code."    "Indent current line of ML-Yacc code."
# Line 919  Line 921 
921  (add-to-list 'auto-mode-alist '("\\.grm\\'" . sml-yacc-mode))  (add-to-list 'auto-mode-alist '("\\.grm\\'" . sml-yacc-mode))
922  ;;;###autoload  ;;;###autoload
923  (define-derived-mode sml-yacc-mode sml-mode "SML-Yacc"  (define-derived-mode sml-yacc-mode sml-mode "SML-Yacc"
924      "Major Mode for editing ML-Yacc files."
925    (set (make-local-variable 'indent-line-function) 'sml-yacc-indent-line)    (set (make-local-variable 'indent-line-function) 'sml-yacc-indent-line)
926    (set (make-local-variable 'font-lock-defaults) sml-yacc-font-lock-defaults))    (set (make-local-variable 'font-lock-defaults) sml-yacc-font-lock-defaults))
927    

Legend:
Removed from v.767  
changed lines
  Added in v.768

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