home *** CD-ROM | disk | FTP | other *** search
- ;;;; modes.jl -- Code for handling editing modes.
- ;;; Copyright (C) 1993, 1994 John Harper <jsh@ukc.ac.uk>
-
- ;;; This file is part of Jade.
-
- ;;; Jade 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, or (at your option)
- ;;; any later version.
-
- ;;; Jade 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 Jade; see the file COPYING. If not, write to
- ;;; the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
-
- (setq mode-alist '(
- ;;; ::mode-alist-start::
- ("^c(|-mode)$" . c-mode)
- ("\\.[ch]$" . c-mode)
- ("^lisp(|-mode)$" . lisp-mode)
- ("\\.jl$" . lisp-mode)
- ("^texinfo(|-mode)$" . texinfo-mode)
- ("\\.texi(|nfo)$" . texinfo-mode)
- ;;; ::mode-alist-end::
- ))
-
- (set-buffer-variable 'major-mode)
- (set-buffer-variable 'major-mode-kill)
-
- (defun get-mode (name)
- "(get-mode NAME)
- Scan the alist `mode-alist' for a mode whose regexp matches NAME,
- returning the initialisation function of that mode (a symbol) or nil."
- (let*
- ((list mode-alist)
- (elt nil))
- (while (setq elt (car list))
- (when (regexp-match (car elt) name t)
- (return (cdr elt)))
- (setq list (cdr list)))))
-
- (defun init-mode (buf &optional name)
- "(init-mode BUF [NAME])
- Initialise an edit-mode for buffer BUF, either calls the function named
- in the buffer-local variable `major-mode' or finds a mode in `mode-alist'
- using one of the following to match against:
- 1. NAME
- 2. The value of the variable `mode-name'
- 3. The word specified on the first line of the buffer surrounded by
- `-*-...-*-' (ie, -*-texinfo-*-)
- 4. The name of the file being edited in the buffer"
- (with-buffer (unless buf (current-buffer))
- (unless (and (boundp 'major-mode) major-mode)
- (setq name (or name
- mode-name
- (regexp-expand-line "-\\*- *([^ ]+) *-\\*-" "\\1" (pos 1 1))
- (file-name buf)))
- (setq major-mode (get-mode name)))
- (when (functionp major-mode)
- (funcall major-mode name))))
-
- (defun kill-mode (&optional buf)
- "(kill-mode [BUF])
- Destroy the mode being used to edit buffer BUF with."
- (unless buf
- (setq buf (current-buffer)))
- (with-buffer buf
- (when (boundp 'major-mode-kill)
- (funcall major-mode-kill buf))))
-