SCM Repository
[smlnj] / sml / trunk / sml-mode / sml-util.el |
View of /sml/trunk/sml-mode/sml-util.el
Parent Directory
|
Revision Log
Revision 332 -
(download)
(annotate)
Tue Jun 15 00:51:38 1999 UTC (21 years, 10 months ago) by monnier
File size: 3713 byte(s)
Tue Jun 15 00:51:38 1999 UTC (21 years, 10 months ago) by monnier
File size: 3713 byte(s)
*** empty log message ***
;;; sml-util.el (defconst rcsid-sml-util "@(#)$Name$:$Id$") ;; Copyright (C) 1999-1999 Stefan Monnier <monnier@cs.yale.edu> ;; ;; 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 2 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. (require 'cl) (require 'sml-compat) ;; (defmacro concatq (&rest ss) "Concatenate all the arguments and make the result a string. As opposed to `concat', `concatq' does not evaluate its arguments and is hence executed at macro-expansion-time." (apply 'concat ss)) (defun flatten (ls &optional acc) (if (null ls) acc (let ((rest (flatten (cdr ls) acc)) (head (car ls))) (if (listp head) (flatten head rest) (cons head rest))))) ;;; ;;; temp files ;;; (defvar temp-file-dir temporary-file-directory "Directory where to put temp files.") (defvar temp-directories ()) (defun delete-temp-dirs () (dolist (dir temp-directories) (when (file-directory-p dir) (let ((default-directory dir)) (dolist (file (directory-files ".")) (ignore-errors (delete-file file)))) (delete-directory dir)))) (add-hook 'kill-emacs-hook 'delete-temp-dirs) (defun make-temp-dir (s) (let* ((prefix (expand-file-name s temp-file-dir)) (dir (make-temp-name prefix))) (if (not (ignore-errors (make-directory dir t) t)) (make-temp-dir prefix) (push dir temp-directories) dir))) (defun make-temp-file (s) (unless (file-name-absolute-p s) (unless (equal (user-uid) (third (file-attributes temporary-file-directory))) (setq temporary-file-directory (make-temp-dir "emacs"))) (setq s (expand-file-name s temporary-file-directory))) (let ((file (make-temp-name s))) (write-region 1 1 file nil 'silent) file)) ;; defmap ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; (defun custom-create-map (m bs args) (unless (keymapp m) (setq bs (append m bs)) (setq m (make-sparse-keymap))) (dolist (b bs) (let ((key (car b)) (binding (cdr b))) (cond ((symbolp key) (substitute-key-definition key binding m global-map)) ((let ((o (lookup-key m key))) (or (null o) (numberp o))) (define-key m key binding))))) (while args (let ((key (first args)) (val (second args))) (cond ((eq key :inherit) (cond ((keymapp val) (set-keymap-parent m val)) (t (set-keymap-parents m val)))) (t (error "Uknown argument %s in defmap" key)))) (setq args (cddr args))) m) (defmacro defmap (m bs doc &rest args) `(defconst ,m (custom-create-map (if (boundp ',m) ,m) ,bs ,(cons 'list args)) ,doc)) ;; defsyntax ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; (defun custom-create-syntax (css args) (let ((st (make-syntax-table (cadr (memq :copy args))))) (dolist (cs css) (let ((char (car cs)) (syntax (cdr cs))) (if (sequencep char) (mapcar* (lambda (c) (modify-syntax-entry c syntax st)) char) (modify-syntax-entry char syntax st)))) st)) (defmacro defsyntax (st css doc &rest args) `(defconst ,st (custom-create-syntax ,css ,(cons 'list args)) doc)) ;; (provide 'sml-util)
root@smlnj-gforge.cs.uchicago.edu | ViewVC Help |
Powered by ViewVC 1.0.0 |