[lice @ some bug fixes, a makefile, autoconf support]
[lice.git] / major-mode.lisp
blob12d3ac68fc258f927fc015eacfe68ccd21ac0048
1 ;;; Implement the major mode system
3 (in-package "LICE")
5 (defclass major-mode ()
6 ((name :type string :initarg :name :accessor major-mode-name)
7 (map :type keymap :initarg :map :accessor major-mode-map)
8 (syntax :initarg :syntax-table :accessor major-mode-syntax-table)
9 (hook :initarg :hook :accessor major-mode-hook)
10 (init :initarg :init :accessor major-mode-init)
11 (inherit-map :type list :initarg :inherit-map :accessor major-mode-inherit-map)
12 (inherit-syntax :type list :initarg :inherit-syntax :accessor major-mode-inherit-syntax)
13 (inherit-init :type list :initarg :inherit-init :accessor major-mode-inherit-init))
14 (:default-initargs
15 :map (make-sparse-keymap)
16 :syntax-table *standard-syntax-table*
17 :inherit-map nil
18 :inherit-syntax nil
19 :inherit-init nil
20 :hook nil
21 :init nil)
22 (:documentation "A Major Mode class."))
24 (defun set-major-mode (mm)
25 "Set the current buffer's major mode."
26 (check-type mm symbol)
27 (let ((mode (symbol-value mm)))
28 ;; Call All inherited init functions
29 (mapc 'set-major-mode (major-mode-inherit-init mode))
31 (when (major-mode-map mode)
32 (use-local-map (major-mode-map mode)))
33 (when (major-mode-syntax-table mode)
34 (set-syntax-table (major-mode-syntax-table mode)))
36 ;; Now call this mm's init function
37 (when (major-mode-init mode)
38 (funcall (major-mode-init mode)))
40 ;; Finally, set the mode and call the hook
41 (setf (buffer-major-mode (current-buffer)) mm)
42 (run-hooks (major-mode-hook mode))))
44 (provide :lice-0.1/major-mode)