]> code.delx.au - gnu-emacs/blobdiff - lisp/progmodes/cc-bytecomp.el
Merge branch 'emacs-25-merge'
[gnu-emacs] / lisp / progmodes / cc-bytecomp.el
index b63eeb4c7a6a76b6b2290f99ba76699c956bd30d..d3b4db74c160b917171b5bb1ab3d128e95fbc31e 100644 (file)
@@ -252,6 +252,11 @@ perhaps a `cc-bytecomp-restore-environment' is forgotten somewhere"))
        (cc-bytecomp-debug-msg
         "cc-bytecomp-restore-environment: Done"))))
 
+(defun cc-bytecomp-load (cc-part)
+  ;; A dummy function which will immediately be overwritten by the
+  ;; following at load time.  This should suppress the byte compiler
+  ;; error that the function is "not known to be defined".
+)
 (eval
  ;; This eval is to avoid byte compilation of the function below.
  ;; There's some bug in XEmacs 21.4.6 that can cause it to dump core
@@ -284,9 +289,6 @@ perhaps a `cc-bytecomp-restore-environment' is forgotten somewhere"))
          (cc-bytecomp-setup-environment)
          t))))
 
-(defvar cc-bytecomp-noruntime-functions nil
-  "Saved value of `byte-compile-noruntime-functions'.")
-
 (defmacro cc-require (cc-part)
   "Force loading of the corresponding .el file in the current directory
 during compilation, but compile in a `require'.  Don't use within
@@ -296,19 +298,37 @@ Having cyclic cc-require's will result in infinite recursion.  That's
 somewhat intentional."
   `(progn
      (eval-when-compile
-       (if (boundp 'byte-compile-noruntime-functions) ; in case load uncompiled
-          (setq cc-bytecomp-noruntime-functions
-                byte-compile-noruntime-functions))
        (cc-bytecomp-load (symbol-name ,cc-part)))
-     ;; Hack to suppress spurious "might not be defined at runtime" warnings.
-     ;; The basic issue is that
-     ;;   (eval-when-compile (require 'foo))
-     ;;   (require 'foo)
-     ;; produces bogus noruntime warnings about functions from foo.
-     (eval-when-compile
-       (setq byte-compile-noruntime-functions cc-bytecomp-noruntime-functions))
      (require ,cc-part)))
 
+(defmacro cc-conditional-require (cc-part condition)
+  "If the CONDITION is satisfied at compile time, (i) force the
+file CC-PART.el in the current directory to be loaded at compile
+time, (ii) generate code to load the file at load time.
+
+CC-PART will normally be a quoted name such as 'cc-fix.
+CONDITION should not be quoted."
+  (if (eval condition)
+      (progn
+       (cc-bytecomp-load (symbol-name (eval cc-part)))
+       `(require ,cc-part))
+    '(progn)))
+
+(defmacro cc-conditional-require-after-load (cc-part file condition)
+  "If the CONDITION is satisfied at compile time, (i) force the
+file CC-PART.el in the current directory to be loaded at compile
+time, (ii) generate an `eval-after-load' form to load CC-PART.el
+after the loading of FILE.
+
+CC-PART will normally be a quoted name such as 'cc-fix.  FILE
+should be a string.  CONDITION should not be quoted."
+  (if (eval condition)
+      (progn
+       (cc-bytecomp-load (symbol-name (eval cc-part)))
+       `(eval-after-load ,file
+          '(require ,cc-part)))
+    '(progn)))
+
 (defmacro cc-provide (feature)
   "A replacement for the `provide' form that restores the environment
 after the compilation.  Don't use within `eval-when-compile'."
@@ -439,8 +459,8 @@ exclude any functions that have been bound during compilation with
 \f
 (provide 'cc-bytecomp)
 
-;;; Local Variables:
-;;; indent-tabs-mode: t
-;;; tab-width: 8
-;;; End:
+;; Local Variables:
+;; indent-tabs-mode: t
+;; tab-width: 8
+;; End:
 ;;; cc-bytecomp.el ends here