home *** CD-ROM | disk | FTP | other *** search
/ Fresh Fish 4 / FreshFish_May-June1994.bin / bbs / may94 / util / edit / jade.lha / Jade / lisp / modes.jl < prev    next >
Lisp/Scheme  |  1994-04-16  |  3KB  |  74 lines

  1. ;;;; modes.jl -- Code for handling editing modes.
  2. ;;;  Copyright (C) 1993, 1994 John Harper <jsh@ukc.ac.uk>
  3.  
  4. ;;; This file is part of Jade.
  5.  
  6. ;;; Jade is free software; you can redistribute it and/or modify it
  7. ;;; under the terms of the GNU General Public License as published by
  8. ;;; the Free Software Foundation; either version 2, or (at your option)
  9. ;;; any later version.
  10.  
  11. ;;; Jade is distributed in the hope that it will be useful, but
  12. ;;; WITHOUT ANY WARRANTY; without even the implied warranty of
  13. ;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  14. ;;; GNU General Public License for more details.
  15.  
  16. ;;; You should have received a copy of the GNU General Public License
  17. ;;; along with Jade; see the file COPYING.  If not, write to
  18. ;;; the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
  19.  
  20. (setq mode-alist '(
  21. ;;; ::mode-alist-start::
  22.   ("^c(|-mode)$" . c-mode)
  23.   ("\\.[ch]$" . c-mode)
  24.   ("^lisp(|-mode)$" . lisp-mode)
  25.   ("\\.jl$" . lisp-mode)
  26.   ("^texinfo(|-mode)$" . texinfo-mode)
  27.   ("\\.texi(|nfo)$" . texinfo-mode)
  28. ;;; ::mode-alist-end::
  29. ))
  30.  
  31. (set-buffer-variable 'major-mode)
  32. (set-buffer-variable 'major-mode-kill)
  33.  
  34. (defun get-mode (name)
  35.   "(get-mode NAME)
  36. Scan the alist `mode-alist' for a mode whose regexp matches NAME,
  37. returning the initialisation function of that mode (a symbol) or nil."
  38.   (let*
  39.       ((list mode-alist)
  40.        (elt nil))
  41.     (while (setq elt (car list))
  42.       (when (regexp-match (car elt) name t)
  43.     (return (cdr elt)))
  44.       (setq list (cdr list)))))
  45.  
  46. (defun init-mode (buf &optional name)
  47.   "(init-mode BUF [NAME])
  48. Initialise an edit-mode for buffer BUF, either calls the function named
  49. in the buffer-local variable `major-mode' or finds a mode in `mode-alist'
  50. using one of the following to match against:
  51.   1. NAME
  52.   2. The value of the variable `mode-name'
  53.   3. The word specified on the first line of the buffer surrounded by
  54.      `-*-...-*-' (ie, -*-texinfo-*-)
  55.   4. The name of the file being edited in the buffer"
  56.   (with-buffer (unless buf (current-buffer))
  57.     (unless (and (boundp 'major-mode) major-mode)
  58.       (setq name (or name
  59.              mode-name
  60.              (regexp-expand-line "-\\*- *([^ ]+) *-\\*-" "\\1" (pos 1 1))
  61.              (file-name buf)))
  62.       (setq major-mode (get-mode name)))
  63.     (when (functionp major-mode)
  64.       (funcall major-mode name))))
  65.  
  66. (defun kill-mode (&optional buf)
  67.   "(kill-mode [BUF])
  68. Destroy the mode being used to edit buffer BUF with."
  69.   (unless buf
  70.     (setq buf (current-buffer)))
  71.   (with-buffer buf
  72.     (when (boundp 'major-mode-kill)
  73.       (funcall major-mode-kill buf))))
  74.