]> code.delx.au - gnu-emacs/blobdiff - lisp/emacs-lisp/derived.el
Don’t create unnecessary marker in ‘delete-trailing-whitespace’
[gnu-emacs] / lisp / emacs-lisp / derived.el
index 52da4c99eafc862bb5b0dac04112a1d19b02f92e..0f7691af0f400a762ca5d661da1e54d80c15f73a 100644 (file)
@@ -1,7 +1,7 @@
 ;;; derived.el --- allow inheritance of major modes
 ;; (formerly mode-clone.el)
 
-;; Copyright (C) 1993-1994, 1999, 2001-2015 Free Software Foundation,
+;; Copyright (C) 1993-1994, 1999, 2001-2016 Free Software Foundation,
 ;; Inc.
 
 ;; Author: David Megginson (dmeggins@aix1.uottawa.ca)
@@ -137,6 +137,9 @@ BODY can start with a bunch of keyword arguments.  The following keyword
 :abbrev-table TABLE
        Use TABLE instead of the default (CHILD-abbrev-table).
        A nil value means to simply use the same abbrev-table as the parent.
+:after-hook FORM
+       A single lisp form which is evaluated after the mode hooks have been
+       run.  It should not be quoted.
 
 Here is how you could define LaTeX-Thesis mode as a variant of LaTeX mode:
 
@@ -163,7 +166,12 @@ See Info node `(elisp)Derived Modes' for more details."
   (declare (debug (&define name symbolp sexp [&optional stringp]
                           [&rest keywordp sexp] def-body))
           (doc-string 4)
-           (indent 3))
+          ;; Ask not what
+          ;;(indent 3)
+          ;; can do for you, ask what it can do to others. IOW, the
+          ;; missing of indentation setting here is the indentation
+          ;; setting and not an oversight.
+          )
 
   (when (and docstring (not (stringp docstring)))
     ;; Some trickiness, since what appears to be the docstring may really be
@@ -179,7 +187,8 @@ See Info node `(elisp)Derived Modes' for more details."
        (declare-abbrev t)
        (declare-syntax t)
        (hook (derived-mode-hook-name child))
-       (group nil))
+       (group nil)
+        (after-hook nil))
 
     ;; Process the keyword args.
     (while (keywordp (car body))
@@ -187,6 +196,7 @@ See Info node `(elisp)Derived Modes' for more details."
        (`: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))
+        (`:after-hook (setq after-hook (pop body)))
        (_ (pop body))))
 
     (setq docstring (derived-mode-make-docstring
@@ -267,7 +277,11 @@ No problems result if this variable is not bound.
          ,@body
          )
         ;; Run the hooks, if any.
-         (run-mode-hooks ',hook)))))
+         (run-mode-hooks ',hook)
+         ,@(when after-hook
+             `((if delay-mode-hooks
+                   (push ',after-hook delayed-after-hook-forms)
+                 ,after-hook)))))))
 
 ;; PUBLIC: find the ultimate class of a derived mode.
 
@@ -331,12 +345,15 @@ which more-or-less shadow%s %s's corresponding table%s."
                        "\n\nThis mode "
                      (concat
                       "\n\nIn addition to any hooks its parent mode "
-                      (if (string-match (regexp-quote (format "`%s'" parent))
-                                        docstring) nil
+                      (if (string-match (format "[`‘]%s['’]"
+                                                 (regexp-quote
+                                                 (symbol-name parent)))
+                                        docstring)
+                           nil
                         (format "`%s' " parent))
                       "might have run,\nthis mode "))
                    (format "runs the hook `%s'" hook)
-                   ", as the final step\nduring initialization.")))
+                   ", as the final or penultimate step\nduring initialization.")))
 
     (unless (string-match "\\\\[{[]" docstring)
       ;; And don't forget to put the mode's keymap.