Source

cc-mode / cc-mode-19.el

Diff from to

File cc-mode-19.el

 ;;; cc-mode-19.el --- compatibility library for Emacs and XEmacs 19
 
-;; Copyright (C) 1985,1987,1992-2000 Free Software Foundation, Inc.
+;; Copyright (C) 1985,1987,1992-2001 Free Software Foundation, Inc.
 
 ;; Authors:    2000- Martin Stjernholm
 ;;	       1998-1999 Barry A. Warsaw and Martin Stjernholm
 ;; 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., 59 Temple Place - Suite 330,
+;; along with this program; see the file COPYING.  If not, write to
+;; the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
 ;; Boston, MA 02111-1307, USA.
 
 ;;; Commentary:
 
 ;;; Code:
 
-(provide 'cc-mode-19) ; Before loading cc-defs to avoid a file load loop.
 (eval-when-compile
   (let ((load-path
-	 (if (and (boundp 'byte-compile-current-file)
-		  (stringp byte-compile-current-file))
-	     (cons (file-name-directory byte-compile-current-file)
-		   load-path)
+	 (if (and (boundp 'byte-compile-dest-file)
+		  (stringp byte-compile-dest-file))
+	     (cons (file-name-directory byte-compile-dest-file) load-path)
 	   load-path)))
-    (load "cc-defs" nil t)))
+    (require 'cc-bytecomp)))
+
+;; Silence the compiler (in case this file is compiled by other
+;; Emacsen even though it isn't used by them).
+(cc-bytecomp-obsolete-fun byte-code-function-p)
 
 (require 'advice)
 
 
 ;; Emacs 19.34 requires the POS argument to char-after.  Emacs 20
 ;; makes it optional, as it has long been in XEmacs.
-(or (condition-case nil
-	(progn (char-after) t)
-      (error nil))
-    (progn
-      (ad-define-subr-args 'char-after '(pos))
-      (defadvice char-after (before c-char-after-advice
-				    (&optional pos)
-				    activate)
-	"POS is optional and defaults to the position of point."
-	(if (not pos)
-	    (setq pos (point))))))
+(eval-and-compile
+  (condition-case nil
+      (eval '(char-after))		; `eval' avoids argcount warnings
+    (error
+     (ad-define-subr-args 'char-after '(pos))
+     (defadvice char-after (before c-char-after-advice
+				   (&optional pos)
+				   activate preactivate)
+       "POS is optional and defaults to the position of point."
+       (if (not pos)
+	   (setq pos (point))))
+     (if (and (featurep 'cc-bytecomp)
+	      (cc-bytecomp-is-compiling))
+	 (progn
+	   ;; Since char-after is handled specially by the byte
+	   ;; compiler, we need some black magic to make the compiler
+	   ;; warnings go away.
+	   (defun byte-compile-char-after (form)
+	     (if (= (length form) 1)
+		 (byte-compile-one-arg (append form '((point))))
+	       (byte-compile-one-arg form)))
+	   (byte-defop-compiler char-after))))))
 
 (if (fboundp 'char-before)
     ;; (or (condition-case nil
     ;; of this is that the advice below may be activated in those
     ;; versions, which is unnecessary but won't break anything.  It
     ;; only occurs when this file is explicitly loaded; in normal use
-    ;; the test in cc-mode.el will skip it altogether.
+    ;; the test in cc-defs.el will skip it altogether.
 
     ;; MULE based on Emacs 19.34 has a char-before function, but
     ;; it requires a position.  It also has a second optional
       (ad-define-subr-args 'char-before '(pos &optional byte-unit))
       (defadvice char-before (before c-char-before-advice
 				     (&optional pos byte-unit)
-				     activate)
+				     activate preactivate)
 	"POS is optional and defaults to the position of point."
 	(if (not pos)
-	    (setq pos (point)))))
-  ;; Emacs 19.34 doesn't have a char-before function.  Here's it's
-  ;; Emacs 20 definition.
-  (defsubst char-before (&optional pos)
-    (if (not pos)
-	(setq pos (point)))
-    (char-after (1- pos))))
+	    (setq pos (point))))))
 
-;; Emacs 19.34 doesn't have a functionp function.  Here's it's Emacs
+(cc-eval-when-compile
+  (or (fboundp 'char-before)
+      ;; Emacs 19.34 doesn't have a char-before function.
+      (defsubst char-before (&optional pos)
+	(char-after (1- (or pos (point)))))))
+
+;; Emacs 19.34 doesn't have a functionp function.  Here's its Emacs
 ;; 20 definition.
 (or (fboundp 'functionp)
     (defun functionp (object)
 	  (eq (car-safe object) 'lambda)
 	  (and (symbolp object) (fboundp object)))))
 
-;; Emacs 19.34 doesn't have a when macro.  Here's it's Emacs 20
+;; Emacs 19.34 doesn't have a when macro.  Here's its Emacs 20
 ;; definition.
-(or (fboundp 'when)
-    (defmacro when (cond &rest body)
-      "(when COND BODY...): if COND yields non-nil, do BODY, else return nil."
-      (list 'if cond (cons 'progn body))))
+(cc-eval-when-compile
+  (or (fboundp 'when)
+      (defmacro when (cond &rest body)
+	"(when COND BODY...): if COND yields non-nil, "
+	"do BODY, else return nil."
+	(list 'if cond (cons 'progn body)))))
 
-;; Emacs 19.34 doesn't have an unless macro.  Here's it's Emacs 20
+;; Emacs 19.34 doesn't have an unless macro.  Here's its Emacs 20
 ;; definition.
-(or (fboundp 'unless)
-    (defmacro unless (cond &rest body)
-      "(unless COND BODY...): if COND yields nil, do BODY, else return nil."
-      (cons 'if (cons cond (cons nil body)))))
+(cc-eval-when-compile
+  (or (fboundp 'unless)
+      (defmacro unless (cond &rest body)
+	"(unless COND BODY...): if COND yields nil, "
+	"do BODY, else return nil."
+	(cons 'if (cons cond (cons nil body))))))
 
 
+(cc-provide 'cc-mode-19)
 ;;; cc-mode-19.el ends here