X-Git-Url: http://git.hcoop.net/bpt/emacs.git/blobdiff_plain/b9345dfd4b5479ec624f1870723a8ea5c9c719e7..ba03d0d932888f687ae9c9fb12e20908c6b0620f:/lisp/emacs-lisp/derived.el diff --git a/lisp/emacs-lisp/derived.el b/lisp/emacs-lisp/derived.el index 1db98ac39c..f4b79eb301 100644 --- a/lisp/emacs-lisp/derived.el +++ b/lisp/emacs-lisp/derived.el @@ -1,7 +1,7 @@ ;;; derived.el --- allow inheritance of major modes ;; (formerly mode-clone.el) -;; Copyright (C) 1993-1994, 1999, 2001-2011 Free Software Foundation, Inc. +;; Copyright (C) 1993-1994, 1999, 2001-2012 Free Software Foundation, Inc. ;; Author: David Megginson (dmeggins@aix1.uottawa.ca) ;; Maintainer: FSF @@ -90,8 +90,6 @@ ;;; Code: -(eval-when-compile (require 'cl)) - ;;; PRIVATE: defsubst must be defined before they are first used (defsubst derived-mode-hook-name (mode) @@ -133,10 +131,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: @@ -183,11 +181,11 @@ See Info node `(elisp)Derived Modes' for more details." ;; 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)) - (t (pop body)))) + (pcase (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)) + (_ (pop body)))) (setq docstring (derived-mode-make-docstring parent child docstring syntax abbrev)) @@ -230,7 +228,7 @@ No problems result if this variable is not bound. ; Run the parent. (delay-mode-hooks - (,(or parent 'fundamental-mode)) + (,(or parent 'kill-all-local-variables)) ; Identify the child mode. (setq major-mode (quote ,child)) (setq mode-name ,name) @@ -253,8 +251,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)) @@ -272,10 +276,10 @@ A mode's class is the first ancestor which is NOT a derived mode. Use the `derived-mode-parent' property of the symbol to trace backwards. Since major-modes might all derive from `fundamental-mode', this function is not very useful." + (declare (obsolete derived-mode-p "22.1")) (while (get mode 'derived-mode-parent) (setq mode (get mode 'derived-mode-parent))) mode) -(make-obsolete 'derived-mode-class 'derived-mode-p "22.1") ;;; PRIVATE @@ -291,16 +295,32 @@ is not very useful." ;; Use a default docstring. (setq docstring (if (null parent) - (format "Major-mode. -Uses keymap `%s', abbrev table `%s' and syntax-table `%s'." map abbrev syntax) + ;; FIXME filling. + (format "Major-mode.\nUses keymap `%s'%s%s." map + (if abbrev (format "%s abbrev table `%s'" + (if syntax "," " and") abbrev) "") + (if syntax (format " and syntax-table `%s'" syntax) "")) (format "Major mode derived from `%s' by `define-derived-mode'. -It inherits all of the parent's attributes, but has its own keymap, -abbrev table and syntax table: - - `%s', `%s' and `%s' - -which more-or-less shadow %s's corresponding tables." - parent map abbrev syntax parent)))) +It inherits all of the parent's attributes, but has its own keymap%s: + + `%s'%s + +which more-or-less shadow%s %s's corresponding table%s." + parent + (cond ((and abbrev syntax) + ",\nabbrev table and syntax table") + (abbrev "\nand abbrev table") + (syntax "\nand syntax table") + (t "")) + map + (cond ((and abbrev syntax) + (format ", `%s' and `%s'" abbrev syntax)) + ((or abbrev syntax) + (format " and `%s'" (or abbrev syntax))) + (t "")) + (if (or abbrev syntax) "" "s") + parent + (if (or abbrev syntax) "s" ""))))) (unless (string-match (regexp-quote (symbol-name hook)) docstring) ;; Make sure the docstring mentions the mode's hook.