Cannot properly require c-common-init and other c-mode functions

110 views Asked by At

This must've happened during the last month or two. I'm not sure who's to blame for it, but now when I'm trying to byte-compile a mode derived from c-mode, Emacs can't find any of c-mode functions referenced in the derived mode. I've looked into cc-bytecom.el and (I'm not sure if it is new, but looks like it is) it defines two macros: cc-requre and cc-provide. I can't really understand what they are doing, but they seem to prevent Emacs from finding out that these functions must be available. If, in my code, I try to substitute (requre 'cc-mode) to (cc-requre 'cc-mode) nothing changes.

The said macros only seem to apply to the compilation time, but I can't tell for sure, they also call (eval-when-compile (cc-bytecomp-restore-environment)) and (eval-when-compile (cc-bytecomp-load (symbol-name ,cc-part))). I'm having hard time figuring what does it do.

1

There are 1 answers

0
Stefan On BEST ANSWER

I don't see the problem you describe: when I compile the haxe-mode files, I just see a warning about several c-mode functions, saying that they may be undefined at runtime, because haxe-mode.el calls those functions but only loads the correspond files inside an eval-when-compile.

BTW, those warnings seem to be due to some weird code, probably copied from the infamous cc-bytecomp. The patch below seem to result in a clean compilation:

=== modified file 'haxe-help.el'
--- haxe-help.el    2012-10-16 14:41:06 +0000
+++ haxe-help.el    2012-10-16 15:11:37 +0000
@@ -33,7 +33,6 @@

 ;;; Code:

-(eval-when-compile (require 'cl))
 (require 'cl)

 (defcustom haxe-help-location

=== modified file 'haxe-mode.el'
--- haxe-mode.el    2012-10-16 14:41:06 +0000
+++ haxe-mode.el    2012-10-16 15:21:23 +0000
@@ -77,7 +77,6 @@
 (require 'cc-bytecomp)
 (require 'cc-mode)
 (require 'cc-fonts)
-;; (cc-require-when-compile 'cc-langs)
 (require 'cc-langs)

 (require 'compile)
@@ -91,18 +90,6 @@
 (require 'haxe-log)
 ;; ------------------- my change -------------------------------------

-;; The language constants are needed when compiling.
-(eval-when-compile
-  (let ((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-mode" nil t)
-    (load "cc-fonts" nil t)
-    (load "cc-langs" nil t)
-    (load "cc-bytecomp" nil t)))
-
 (eval-and-compile
   ;; Tell the language constant system about haXe and base it on Java.
   (c-add-language 'haxe-mode 'java-mode))
@@ -387,7 +374,7 @@
                   (c-fontify-types-and-refs
                       ((c-promote-possible-types t)
                        (parse-sexp-lookup-properties
-                        (cc-eval-when-compile
+                        (eval-when-compile
                           (boundp 'parse-sexp-lookup-properties))))
                     (save-restriction
                       (narrow-to-region (point) limit)