Add 2010 to copyright years.
[bpt/emacs.git] / lisp / emacs-lisp / byte-run.el
index 84a4b39..dbbf057 100644 (file)
@@ -1,7 +1,7 @@
 ;;; byte-run.el --- byte-compiler support for inlining
 
-;; Copyright (C) 1992, 2001, 2002, 2003, 2004, 2005,
-;;   2006, 2007 Free Software Foundation, Inc.
+;; Copyright (C) 1992, 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008,
+;;   2009, 2010  Free Software Foundation, Inc.
 
 ;; Author: Jamie Zawinski <jwz@lucid.com>
 ;;     Hallvard Furuseth <hbf@ulrik.uio.no>
 
 ;; 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 2, 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 <http://www.gnu.org/licenses/>.
 
 ;;; Commentary:
 
@@ -47,14 +45,19 @@ The return value of this function is not used."
     ;; Ignore the first element of `decl' (it's always `declare').
     (while (setq decl (cdr decl))
       (setq d (car decl))
-      (cond ((and (consp d) (eq (car d) 'indent))
-            (put macro 'lisp-indent-function (car (cdr d))))
-           ((and (consp d) (eq (car d) 'debug))
-            (put macro 'edebug-form-spec (car (cdr d))))
-           ((and (consp d) (eq (car d) 'doc-string))
-            (put macro 'doc-string-elt (car (cdr d))))
-           (t
-            (message "Unknown declaration %s" d))))))
+      (if (and (consp d)
+              (listp (cdr d))
+              (null (cdr (cdr d))))
+         (cond ((eq (car d) 'indent)
+                (put macro 'lisp-indent-function (car (cdr d))))
+               ((eq (car d) 'debug)
+                (put macro 'edebug-form-spec (car (cdr d))))
+               ((eq (car d) 'doc-string)
+                (put macro 'doc-string-elt (car (cdr d))))
+               (t
+                (message "Unknown declaration %s" d)))
+       (message "Invalid declaration %s" d)))))
+
 
 (setq macro-declaration-function 'macro-declaration-function)
 
@@ -103,10 +106,20 @@ The return value of this function is not used."
      (eval-and-compile
        (put ',name 'byte-optimizer 'byte-compile-inline-expand))))
 
+(defvar advertised-signature-table (make-hash-table :test 'eq :weakness 'key))
+
+(defun set-advertised-calling-convention (function signature)
+  "Set the advertised SIGNATURE of FUNCTION.
+This will allow the byte-compiler to warn the programmer when she uses
+an obsolete calling convention."
+  (puthash (indirect-function function) signature
+           advertised-signature-table))
+
 (defun make-obsolete (obsolete-name current-name &optional when)
   "Make the byte-compiler warn that OBSOLETE-NAME is obsolete.
 The warning will say that CURRENT-NAME should be used instead.
-If CURRENT-NAME is a string, that is the `use instead' message.
+If CURRENT-NAME is a string, that is the `use instead' message
+\(it should end with a period, and not start with a capital).
 If provided, WHEN should be a string indicating when the function
 was first made obsolete, for example a date or a release number."
   (interactive "aMake function obsolete: \nxObsoletion replacement: ")
@@ -114,8 +127,12 @@ was first made obsolete, for example a date or a release number."
     (if (eq 'byte-compile-obsolete handler)
        (setq handler (nth 1 (get obsolete-name 'byte-obsolete-info)))
       (put obsolete-name 'byte-compile 'byte-compile-obsolete))
-    (put obsolete-name 'byte-obsolete-info (list current-name handler when)))
+    (put obsolete-name 'byte-obsolete-info
+        (list (purecopy current-name) handler (purecopy when))))
   obsolete-name)
+(set-advertised-calling-convention
+ ;; New code should always provide the `when' argument.
+ 'make-obsolete '(obsolete-name current-name when))
 
 (defmacro define-obsolete-function-alias (obsolete-name current-name
                                                   &optional when docstring)
@@ -133,6 +150,10 @@ See the docstrings of `defalias' and `make-obsolete' for more details."
   `(progn
      (defalias ,obsolete-name ,current-name ,docstring)
      (make-obsolete ,obsolete-name ,current-name ,when)))
+(set-advertised-calling-convention
+ ;; New code should always provide the `when' argument.
+ 'define-obsolete-function-alias
+ '(obsolete-name current-name when &optional docstring))
 
 (defun make-obsolete-variable (obsolete-name current-name &optional when)
   "Make the byte-compiler warn that OBSOLETE-NAME is obsolete.
@@ -146,26 +167,64 @@ was first made obsolete, for example a date or a release number."
       (if (equal str "") (error ""))
       (intern str))
     (car (read-from-string (read-string "Obsoletion replacement: ")))))
-  (put obsolete-name 'byte-obsolete-variable (cons current-name when))
+  (put obsolete-name 'byte-obsolete-variable
+       (cons
+       (if (stringp current-name)
+           (purecopy current-name)
+         current-name) (purecopy when)))
   obsolete-name)
+(set-advertised-calling-convention
+ ;; New code should always provide the `when' argument.
+ 'make-obsolete-variable '(obsolete-name current-name when))
 
 (defmacro define-obsolete-variable-alias (obsolete-name current-name
                                                 &optional when docstring)
   "Make OBSOLETE-NAME a variable alias for CURRENT-NAME and mark it obsolete.
-
-\(define-obsolete-variable-alias 'old-var 'new-var \"22.1\" \"old-var's doc.\")
-
-is equivalent to the following two lines of code:
-
-\(defvaralias 'old-var 'new-var \"old-var's doc.\")
-\(make-obsolete-variable 'old-var 'new-var \"22.1\")
-
-See the docstrings of `defvaralias' and `make-obsolete-variable' or
-Info node `(elisp)Variable Aliases' for more details."
+This uses `defvaralias' and `make-obsolete-variable' (which see).
+See the Info node `(elisp)Variable Aliases' for more details.
+
+If CURRENT-NAME is a defcustom (more generally, any variable
+where OBSOLETE-NAME may be set, e.g. in a .emacs file, before the
+alias is defined), then the define-obsolete-variable-alias
+statement should be evaluated before the defcustom, if user
+customizations are to be respected.  The simplest way to achieve
+this is to place the alias statement before the defcustom (this
+is not necessary for aliases that are autoloaded, or in files
+dumped with Emacs).  This is so that any user customizations are
+applied before the defcustom tries to initialize the
+variable (this is due to the way `defvaralias' works).
+
+For the benefit of `custom-set-variables', if OBSOLETE-NAME has
+any of the following properties, they are copied to
+CURRENT-NAME, if it does not already have them:
+'saved-value, 'saved-variable-comment."
   (declare (doc-string 4))
   `(progn
      (defvaralias ,obsolete-name ,current-name ,docstring)
+     ;; See Bug#4706.
+     (dolist (prop '(saved-value saved-variable-comment))
+       (and (get ,obsolete-name prop)
+            (null (get ,current-name prop))
+            (put ,current-name prop (get ,obsolete-name prop))))
      (make-obsolete-variable ,obsolete-name ,current-name ,when)))
+(set-advertised-calling-convention
+ ;; New code should always provide the `when' argument.
+ 'define-obsolete-variable-alias
+ '(obsolete-name current-name when &optional docstring))
+
+;; FIXME This is only defined in this file because the variable- and
+;; function- versions are too.  Unlike those two, this one is not used
+;; by the byte-compiler (would be nice if it could warn about obsolete
+;; faces, but it doesn't really do anything special with faces).
+;; It only really affects M-x describe-face output.
+(defmacro define-obsolete-face-alias (obsolete-face current-face when)
+  "Make OBSOLETE-FACE a face alias for CURRENT-FACE and mark it obsolete.
+The string WHEN gives the Emacs version where OBSOLETE-FACE became
+obsolete."
+  `(progn
+     (put ,obsolete-face 'face-alias ,current-face)
+     ;; Used by M-x describe-face.
+     (put ,obsolete-face 'obsolete-face (or (purecopy ,when) t))))
 
 (defmacro dont-compile (&rest body)
   "Like `progn', but the body always runs interpreted (not compiled).
@@ -221,7 +280,7 @@ In interpreted code, this is entirely equivalent to `progn'."
 ;;   verbose     t, nil                byte-compile-verbose
 ;;   optimize    t, nil, source, byte  byte-compile-optimize
 ;;   warnings    list of warnings      byte-compile-warnings
-;;                   Legal elements: (callargs redefine free-vars unresolved)
+;;                   Valid elements: (callargs redefine free-vars unresolved)
 ;;   file-format         emacs18, emacs19      byte-compile-compatibility
 ;;
 ;; For example, this might appear at the top of a source file: