X-Git-Url: https://code.delx.au/gnu-emacs/blobdiff_plain/f76840f36cf60feecaf21d55d24ace948800fef7..8350f087efe62e2ce0ded434534629a56cdc4e8c:/lisp/emacs-lisp/derived.el diff --git a/lisp/emacs-lisp/derived.el b/lisp/emacs-lisp/derived.el index acf73d94b3..55ea102ed2 100644 --- a/lisp/emacs-lisp/derived.el +++ b/lisp/emacs-lisp/derived.el @@ -1,19 +1,19 @@ ;;; derived.el --- allow inheritance of major modes ;; (formerly mode-clone.el) -;; Copyright (C) 1993, 1994, 1999, 2001, 2002, 2003, 2004, -;; 2005, 2006, 2007 Free Software Foundation, Inc. +;; Copyright (C) 1993-1994, 1999, 2001-2011 Free Software Foundation, Inc. ;; Author: David Megginson (dmeggins@aix1.uottawa.ca) ;; Maintainer: FSF ;; Keywords: extensions +;; Package: emacs ;; This file is part of GNU Emacs. -;; GNU Emacs is free software; you can redistribute it and/or modify +;; GNU Emacs 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 3, or (at your option) -;; any later version. +;; the Free Software Foundation, either version 3 of the License, or +;; (at your option) any later version. ;; GNU Emacs is distributed in the hope that it will be useful, ;; but WITHOUT ANY WARRANTY; without even the implied warranty of @@ -21,9 +21,7 @@ ;; GNU General Public License for more details. ;; You should have received a copy of the GNU General Public License -;; along with GNU Emacs; see the file COPYING. If not, write to the -;; Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, -;; Boston, MA 02110-1301, USA. +;; along with GNU Emacs. If not, see . ;;; Commentary: @@ -135,10 +133,10 @@ BODY can start with a bunch of keyword arguments. The following keyword Declare the customization group that corresponds to this mode. The command `customize-mode' uses this. :syntax-table TABLE - Use TABLE instead of the default. + Use TABLE instead of the default (CHILD-syntax-table). A nil value means to simply use the same syntax-table as the parent. :abbrev-table TABLE - Use TABLE instead of the default. + Use TABLE instead of the default (CHILD-abbrev-table). 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: @@ -164,7 +162,8 @@ The new mode runs the hook constructed by the function See Info node `(elisp)Derived Modes' for more details." (declare (debug (&define name symbolp sexp [&optional stringp] - [&rest keywordp sexp] def-body))) + [&rest keywordp sexp] def-body)) + (doc-string 4)) (when (and docstring (not (stringp docstring))) ;; Some trickiness, since what appears to be the docstring may really be @@ -194,25 +193,34 @@ See Info node `(elisp)Derived Modes' for more details." parent child docstring syntax abbrev)) `(progn - (unless (get ',hook 'variable-documentation) + (unless (get ',hook 'variable-documentation) (put ',hook 'variable-documentation - ,(format "Hook run when entering %s mode. + (purecopy ,(format "Hook run when entering %s mode. No problems result if this variable is not bound. `add-hook' automatically binds it. (This is true for all hook variables.)" - name))) + name)))) (unless (boundp ',map) (put ',map 'definition-name ',child)) - (defvar ,map (make-sparse-keymap)) + (with-no-warnings (defvar ,map (make-sparse-keymap))) + (unless (get ',map 'variable-documentation) + (put ',map 'variable-documentation + (purecopy ,(format "Keymap for `%s'." child)))) ,(if declare-syntax `(progn (unless (boundp ',syntax) (put ',syntax 'definition-name ',child)) - (defvar ,syntax (make-syntax-table)))) + (defvar ,syntax (make-syntax-table)) + (unless (get ',syntax 'variable-documentation) + (put ',syntax 'variable-documentation + (purecopy ,(format "Syntax table for `%s'." child)))))) ,(if declare-abbrev `(progn (put ',abbrev 'definition-name ',child) (defvar ,abbrev - (progn (define-abbrev-table ',abbrev nil) ,abbrev)))) + (progn (define-abbrev-table ',abbrev nil) ,abbrev)) + (unless (get ',abbrev 'variable-documentation) + (put ',abbrev 'variable-documentation + (purecopy ,(format "Abbrev table for `%s'." child)))))) (put ',child 'derived-mode-parent ',parent) ,(if group `(put ',child 'custom-mode-group ,group)) @@ -245,8 +253,14 @@ No problems result if this variable is not bound. `(let ((parent (char-table-parent ,syntax))) (unless (and parent (not (eq parent (standard-syntax-table)))) - (set-char-table-parent ,syntax (syntax-table))))))) - + (set-char-table-parent ,syntax (syntax-table))))) + ,(when declare-abbrev + `(unless (or (abbrev-table-get ,abbrev :parents) + ;; This can happen if the major mode defines + ;; the abbrev-table to be its parent's. + (eq ,abbrev local-abbrev-table)) + (abbrev-table-put ,abbrev :parents + (list local-abbrev-table)))))) (use-local-map ,map) ,(when syntax `(set-syntax-table ,syntax)) ,(when abbrev `(setq local-abbrev-table ,abbrev)) @@ -448,5 +462,4 @@ Where the new table already has an entry, nothing is copied from the old one." (provide 'derived) -;; arch-tag: 630be248-47d1-4f02-afa0-8207de0ebea0 ;;; derived.el ends here