Merge from emacs-24; up to 2012-11-15T23:31:37Z!dancol@dancol.org
[bpt/emacs.git] / lisp / emacs-lisp / cl-lib.el
index b9a5d4b..d5e5f4b 100644 (file)
@@ -3,7 +3,7 @@
 ;; Copyright (C) 1993, 2001-2012  Free Software Foundation, Inc.
 
 ;; Author: Dave Gillespie <daveg@synaptics.com>
-;; Version: 2.02
+;; Version: 1.0
 ;; Keywords: extensions
 
 ;; This file is part of GNU Emacs.
@@ -99,8 +99,8 @@
 ;;;###autoload
 (define-obsolete-variable-alias
   ;; This alias is needed for compatibility with .elc files that use defstruct
-  ;; and were compiled with Emacs<24.2.
-  'custom-print-functions 'cl-custom-print-functions "24.2")
+  ;; and were compiled with Emacs<24.3.
+  'custom-print-functions 'cl-custom-print-functions "24.3")
 
 ;;;###autoload
 (defvar cl-custom-print-functions nil
@@ -121,7 +121,7 @@ a future Emacs interpreter will be able to use it.")
 
 ;;; Generalized variables.
 ;; These macros are defined here so that they
-;; can safely be used in .emacs files.
+;; can safely be used in init files.
 
 (defmacro cl-incf (place &optional x)
   "Increment PLACE by X (1 by default).
@@ -230,12 +230,13 @@ one value."
   "Apply FUNCTION to ARGUMENTS, taking multiple values into account.
 This implementation only handles the case where there is only one argument.")
 
-(defsubst cl-nth-value (n expression)
+(cl--defalias 'cl-nth-value #'nth
   "Evaluate EXPRESSION to get multiple values and return the Nth one.
 This handles multiple values in Common Lisp style, but it does not work
 right when EXPRESSION calls an ordinary Emacs Lisp function that returns just
-one value."
-  (nth n expression))
+one value.
+
+\(fn N EXPRESSION)")
 
 ;;; Declarations.
 
@@ -250,12 +251,17 @@ one value."
 (defvar cl-proclaims-deferred nil)
 
 (defun cl-proclaim (spec)
+  "Record a global declaration specified by SPEC."
   (if (fboundp 'cl-do-proclaim) (cl-do-proclaim spec t)
     (push spec cl-proclaims-deferred))
   nil)
 
 (defmacro cl-declaim (&rest specs)
-  (let ((body (mapcar (function (lambda (x) (list 'cl-proclaim (list 'quote x))))
+  "Like `cl-proclaim', but takes any number of unevaluated, unquoted arguments.
+Puts `(cl-eval-when (compile load eval) ...)' around the declarations
+so that they are registered at compile-time as well as run-time."
+  (let ((body (mapcar (function (lambda (x)
+                                  (list 'cl-proclaim (list 'quote x))))
                      specs)))
     (if (cl--compiling-file) (cl-list* 'cl-eval-when '(compile load eval) body)
       (cons 'progn body))))   ; avoid loading cl-macs.el for cl-eval-when
@@ -263,12 +269,12 @@ one value."
 
 ;;; Symbols.
 
-(defun cl-random-time ()
+(defun cl--random-time ()
   (let* ((time (copy-sequence (current-time-string))) (i (length time)) (v 0))
     (while (>= (cl-decf i) 0) (setq v (+ (* v 3) (aref time i))))
     v))
 
-(defvar cl--gensym-counter (* (logand (cl-random-time) 1023) 100))
+(defvar cl--gensym-counter (* (logand (cl--random-time) 1023) 100))
 
 
 ;;; Numbers.
@@ -295,7 +301,7 @@ always returns nil."
   "Return t if INTEGER is even."
   (eq (logand integer 1) 0))
 
-(defvar cl--random-state (vector 'cl-random-state-tag -1 30 (cl-random-time)))
+(defvar cl--random-state (vector 'cl-random-state-tag -1 30 (cl--random-time)))
 
 (defconst cl-most-positive-float nil
   "The largest value that a Lisp float can hold.
@@ -634,7 +640,7 @@ If ALIST is non-nil, the new pairs are prepended to it."
      (set-buffer-modified-p ,flag)))
 (gv-define-simple-setter buffer-name rename-buffer t)
 (gv-define-setter buffer-string (store)
-  `(progn (erase-buffer) (insert ,store)))
+  `(insert (prog1 ,store (erase-buffer))))
 (gv-define-simple-setter buffer-substring cl--set-buffer-substring)
 (gv-define-simple-setter current-buffer set-buffer)
 (gv-define-simple-setter current-case-table set-case-table)
@@ -655,7 +661,7 @@ If ALIST is non-nil, the new pairs are prepended to it."
 (gv-define-setter face-foreground (x f &optional s)
   `(set-face-foreground ,f ,x ,s))
 (gv-define-setter face-underline-p (x f &optional s)
-  `(set-face-underline-p ,f ,x ,s))
+  `(set-face-underline ,f ,x ,s))
 (gv-define-simple-setter file-modes set-file-modes t)
 (gv-define-simple-setter frame-height set-screen-height t)
 (gv-define-simple-setter frame-parameters modify-frame-parameters t)
@@ -727,7 +733,8 @@ If ALIST is non-nil, the new pairs are prepended to it."
 ;;;###autoload
 (progn
   ;; Make sure functions defined with cl-defsubst can be inlined even in
-  ;; packages which do not require CL.
+  ;; packages which do not require CL.  We don't put an autoload cookie
+  ;; directly on that function, since those cookies only go to cl-loaddefs.
   (autoload 'cl--defsubst-expand "cl-macs")
   ;; Autoload, so autoload.el and font-lock can use it even when CL
   ;; is not loaded.
@@ -744,7 +751,6 @@ If ALIST is non-nil, the new pairs are prepended to it."
 
 ;; Local variables:
 ;; byte-compile-dynamic: t
-;; byte-compile-warnings: (not cl-functions)
 ;; End:
 
 ;;; cl-lib.el ends here