1 ;;; sml-util.el --- Utility functions for sml-mode
3 ;; Copyright (C) 1999-2000, 2007, 2010 Stefan Monnier <monnier@iro.umontreal.ca>
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.
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.
24 (require 'cl
) ;for `reduce'
26 (defun sml-preproc-alist (al)
27 "Expand an alist AL where keys can be lists of keys into a normal one."
28 (reduce (lambda (x al
)
32 (append (mapcar (lambda (y) (cons y v
)) k
) al
)
42 (defun custom-create-map (m bs args
)
43 (let (inherit dense suppress
)
45 (let ((key (first args
))
48 ((eq key
:dense
) (setq dense val
))
49 ((eq key
:inherit
) (setq inherit val
))
51 ;;((eq key :suppress) (setq suppress val))
52 (t (message "Uknown argument %s in defmap" key
))))
53 (setq args
(cddr args
)))
55 (setq bs
(append m bs
))
56 (setq m
(if dense
(make-keymap) (make-sparse-keymap))))
60 (dolist (key (if (consp keys
) keys
(list keys
)))
63 (substitute-key-definition key binding m global-map
))
65 (unless (keymapp (lookup-key m key
)) (define-key m key binding
)))
66 ((let ((o (lookup-key m key
)))
67 (or (null o
) (numberp o
) (eq o
'undefined
)))
68 (define-key m key binding
))))))
70 ((keymapp inherit
) (set-keymap-parent m inherit
))
71 ((consp inherit
) (set-keymap-parents m inherit
)))
74 (defmacro defmap
(m bs doc
&rest args
)
76 (custom-create-map (if (boundp ',m
) ,m
) ,bs
,(cons 'list args
))
79 ;; defsyntax ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
81 (defun custom-create-syntax (css args
)
82 (let ((st (make-syntax-table (cadr (memq :copy args
)))))
87 (mapcar* (lambda (c) (modify-syntax-entry c syntax st
)) char
)
88 (modify-syntax-entry char syntax st
))))
91 (defmacro defsyntax
(st css doc
&rest args
)
92 `(defvar ,st
(custom-create-syntax ,css
,(cons 'list args
)) ,doc
))
95 ;;;; Compatibility info
98 (defvar sml-builtin-nested-comments-flag
100 (not (equal (let ((st (make-syntax-table)))
101 (modify-syntax-entry ?\
* ". 23n" st
) st
)
102 (let ((st (make-syntax-table)))
103 (modify-syntax-entry ?\
* ". 23" st
) st
))))
104 "Non-nil means this Emacs understands the `n' in syntax entries.")
108 ;;; sml-util.el ends here