[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Emacs-diffs] Changes to emacs/lisp/derived.el
From: |
Stefan Monnier |
Subject: |
[Emacs-diffs] Changes to emacs/lisp/derived.el |
Date: |
Mon, 09 Sep 2002 19:55:56 -0400 |
Index: emacs/lisp/derived.el
diff -c emacs/lisp/derived.el:1.31 emacs/lisp/derived.el:1.32
*** emacs/lisp/derived.el:1.31 Fri Jun 28 10:57:08 2002
--- emacs/lisp/derived.el Mon Sep 9 19:55:56 2002
***************
*** 126,131 ****
--- 126,142 ----
BODY: forms to execute just before running the
hooks for the new mode. Do not use `interactive' here.
+ BODY can start with a bunch of keyword arguments. The following keyword
+ arguments are currently understood:
+ :group GROUP
+ Declare the customization group that corresponds to this mode.
+ :syntax-table TABLE
+ Use TABLE instead of the default.
+ A nil value means to simply use the same syntax-table as the parent.
+ :abbrev-table TABLE
+ Use TABLE instead of the default.
+ A nil value means to simply use the same abbrev-table as the parent.
+
Here is how you could define LaTeX-Thesis mode as a variant of LaTeX mode:
(define-derived-mode LaTeX-thesis-mode LaTeX-mode \"LaTeX-Thesis\")
***************
*** 155,169 ****
(let ((map (derived-mode-map-name child))
(syntax (derived-mode-syntax-table-name child))
(abbrev (derived-mode-abbrev-table-name child))
(hook (derived-mode-hook-name child))
! (docstring (derived-mode-make-docstring parent child docstring)))
`(progn
(defvar ,map (make-sparse-keymap))
! (defvar ,syntax (make-syntax-table))
! (defvar ,abbrev
! (progn (define-abbrev-table ',abbrev nil) ,abbrev))
(put ',child 'derived-mode-parent ',parent)
(defun ,child ()
,docstring
--- 166,196 ----
(let ((map (derived-mode-map-name child))
(syntax (derived-mode-syntax-table-name child))
(abbrev (derived-mode-abbrev-table-name child))
+ (declare-abbrev t)
+ (declare-syntax t)
(hook (derived-mode-hook-name child))
! (group nil))
!
! ;; Process the keyword args.
! (while (keywordp (car body))
! (case (pop body)
! (:group (setq group (pop body)))
! (:abbrev-table (setq abbrev (pop body)) (setq declare-abbrev nil))
! (:syntax-table (setq syntax (pop body)) (setq declare-syntax nil))))
!
!
! (setq docstring (derived-mode-make-docstring
! parent child docstring syntax abbrev))
`(progn
(defvar ,map (make-sparse-keymap))
! ,(if declare-syntax
! `(defvar ,syntax (make-syntax-table)))
! ,(if declare-abbrev
! `(defvar ,abbrev
! (progn (define-abbrev-table ',abbrev nil) ,abbrev)))
(put ',child 'derived-mode-parent ',parent)
+ ,(if group `(put ',child 'custom-group ,group))
(defun ,child ()
,docstring
***************
*** 184,203 ****
; Set up maps and tables.
(unless (keymap-parent ,map)
(set-keymap-parent ,map (current-local-map)))
! (let ((parent (char-table-parent ,syntax)))
! (unless (and parent (not (eq parent (standard-syntax-table))))
! (set-char-table-parent ,syntax (syntax-table))))
! (when local-abbrev-table
! (mapatoms
! (lambda (symbol)
! (or (intern-soft (symbol-name symbol) ,abbrev)
! (define-abbrev ,abbrev (symbol-name symbol)
! (symbol-value symbol) (symbol-function symbol))))
! local-abbrev-table))))
(use-local-map ,map)
! (set-syntax-table ,syntax)
! (setq local-abbrev-table ,abbrev)
; Splice in the body (if any).
,@body
)
--- 211,235 ----
; Set up maps and tables.
(unless (keymap-parent ,map)
(set-keymap-parent ,map (current-local-map)))
! ,(when declare-syntax
! `(let ((parent (char-table-parent ,syntax)))
! (unless (and parent
! (not (eq parent (standard-syntax-table))))
! (set-char-table-parent ,syntax (syntax-table)))))
! ,(when declare-abbrev
! `(when local-abbrev-table
! (mapatoms
! (lambda (symbol)
! (or (intern-soft (symbol-name symbol) ,abbrev)
! (define-abbrev ,abbrev
! (symbol-name symbol)
! (symbol-value symbol)
! (symbol-function symbol))))
! local-abbrev-table)))))
(use-local-map ,map)
! ,(when syntax `(set-syntax-table ,syntax))
! ,(when abbrev `(setq local-abbrev-table ,abbrev))
; Splice in the body (if any).
,@body
)
***************
*** 220,231 ****
;;; PRIVATE
! (defun derived-mode-make-docstring (parent child &optional docstring)
"Construct a docstring for a new mode if none is provided."
(let ((map (derived-mode-map-name child))
- (syntax (derived-mode-syntax-table-name child))
- (abbrev (derived-mode-abbrev-table-name child))
(hook (derived-mode-hook-name child)))
(unless (stringp docstring)
--- 252,262 ----
;;; PRIVATE
! (defun derived-mode-make-docstring (parent child &optional
! docstring syntax abbrev)
"Construct a docstring for a new mode if none is provided."
(let ((map (derived-mode-map-name child))
(hook (derived-mode-hook-name child)))
(unless (stringp docstring)
***************
*** 244,250 ****
parent map abbrev syntax parent))))
(unless (string-match (regexp-quote (symbol-name hook)) docstring)
! ;; Make sure the docstring mentions the mode's hook
(setq docstring
(concat docstring
(if (null parent)
--- 275,281 ----
parent map abbrev syntax parent))))
(unless (string-match (regexp-quote (symbol-name hook)) docstring)
! ;; Make sure the docstring mentions the mode's hook.
(setq docstring
(concat docstring
(if (null parent)
***************
*** 259,265 ****
", as the final step\nduring initialization.")))
(unless (string-match "\\\\[{[]" docstring)
! ;; And don't forget to put the mode's keymap
(setq docstring (concat docstring "\n\n\\{" (symbol-name map) "}")))
docstring))
--- 290,296 ----
", as the final step\nduring initialization.")))
(unless (string-match "\\\\[{[]" docstring)
! ;; And don't forget to put the mode's keymap.
(setq docstring (concat docstring "\n\n\\{" (symbol-name map) "}")))
docstring))
- [Emacs-diffs] Changes to emacs/lisp/derived.el,
Stefan Monnier <=