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

SCM Repository

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

Annotation of /sml-mode/trunk/sml-util.el

Parent Directory Parent Directory | Revision Log Revision Log


Revision 2817 - (view) (download)

1 : monnier 541 ;;; sml-util.el --- Utility functions for sml-mode
2 : monnier 319
3 : monnier 2817 ;; Copyright (C) 1999-2000, 2007 Stefan Monnier <monnier@cs.yale.edu>
4 : monnier 319 ;;
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 : monnier 2817 ;; the Free Software Foundation; either version 3 of the License, or
8 : monnier 319 ;; (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.
14 :     ;;
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.
18 :    
19 : monnier 541
20 :     ;;; Commentary:
21 :    
22 :     ;;; Code:
23 :    
24 :     (require 'cl) ;for `reduce'
25 : monnier 319 (require 'sml-compat)
26 :    
27 : monnier 334 (defun sml-preproc-alist (al)
28 : monnier 541 "Expand an alist AL where keys can be lists of keys into a normal one."
29 : monnier 334 (reduce (lambda (x al)
30 :     (let ((k (car x))
31 :     (v (cdr x)))
32 :     (if (consp k)
33 :     (append (mapcar (lambda (y) (cons y v)) k) al)
34 :     (cons x al))))
35 :     al
36 :     :initial-value nil
37 :     :from-end t))
38 :    
39 : monnier 332 ;;;
40 : monnier 535 ;;; defmap
41 : monnier 332 ;;;
42 :    
43 : monnier 319 (defun custom-create-map (m bs args)
44 : monnier 535 (let (inherit dense suppress)
45 : monnier 341 (while args
46 :     (let ((key (first args))
47 :     (val (second args)))
48 : monnier 319 (cond
49 : monnier 341 ((eq key :dense) (setq dense val))
50 :     ((eq key :inherit) (setq inherit val))
51 : monnier 535 ((eq key :group) )
52 :     ;;((eq key :suppress) (setq suppress val))
53 : monnier 341 (t (message "Uknown argument %s in defmap" key))))
54 :     (setq args (cddr args)))
55 :     (unless (keymapp m)
56 :     (setq bs (append m bs))
57 :     (setq m (if dense (make-keymap) (make-sparse-keymap))))
58 :     (dolist (b bs)
59 : monnier 535 (let ((keys (car b))
60 : monnier 341 (binding (cdr b)))
61 : monnier 535 (dolist (key (if (consp keys) keys (list keys)))
62 :     (cond
63 :     ((symbolp key)
64 :     (substitute-key-definition key binding m global-map))
65 :     ((null binding)
66 :     (unless (keymapp (lookup-key m key)) (define-key m key binding)))
67 :     ((let ((o (lookup-key m key)))
68 :     (or (null o) (numberp o) (eq o 'undefined)))
69 :     (define-key m key binding))))))
70 : monnier 341 (cond
71 :     ((keymapp inherit) (set-keymap-parent m inherit))
72 :     ((consp inherit) (set-keymap-parents m inherit)))
73 :     m))
74 : monnier 319
75 :     (defmacro defmap (m bs doc &rest args)
76 : monnier 2817 `(defvar ,m
77 : monnier 332 (custom-create-map (if (boundp ',m) ,m) ,bs ,(cons 'list args))
78 :     ,doc))
79 : monnier 319
80 : monnier 332 ;; defsyntax ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
81 :    
82 :     (defun custom-create-syntax (css args)
83 :     (let ((st (make-syntax-table (cadr (memq :copy args)))))
84 :     (dolist (cs css)
85 :     (let ((char (car cs))
86 :     (syntax (cdr cs)))
87 :     (if (sequencep char)
88 :     (mapcar* (lambda (c) (modify-syntax-entry c syntax st)) char)
89 :     (modify-syntax-entry char syntax st))))
90 :     st))
91 :    
92 : monnier 319 (defmacro defsyntax (st css doc &rest args)
93 : monnier 2817 `(defvar ,st (custom-create-syntax ,css ,(cons 'list args)) ,doc))
94 : monnier 319
95 : monnier 535 ;;;;
96 :     ;;;; Compatibility info
97 :     ;;;;
98 :    
99 :     (defvar sml-builtin-nested-comments-flag
100 :     (ignore-errors
101 :     (not (equal (let ((st (make-syntax-table)))
102 :     (modify-syntax-entry ?\* ". 23n" st) st)
103 :     (let ((st (make-syntax-table)))
104 :     (modify-syntax-entry ?\* ". 23" st) st))))
105 : monnier 541 "Non-nil means this Emacs understands the `n' in syntax entries.")
106 : monnier 535
107 : monnier 319 (provide 'sml-util)
108 : monnier 541
109 :     ;;; sml-util.el ends here

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