emacs-pretest-bug
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

cpp use in cc-mode is broken


From: Tim Van Holder
Subject: cpp use in cc-mode is broken
Date: Fri, 29 Apr 2005 16:18:25 +0200

As of a few days ago, the cc-mode in cvs emacs seems to preprocess the
source file in order to determine the C macros present.

There are two things wrong with this:
1) it uses /lib/cpp unconditionally, but the use of the -dM switch
suggests it currently requires gcc (at least, /lib/cpp on neither AIX
nor HP/UX support that switch).  So this should either be
user-configurable, or defaulted to "gcc -E".
2) it does this even for files that don't exist (e.g. when you open a
fresh file); for such cases, either cpp should simply not be run, or a
temp file should be used (containing the buffer contents).

The patches below resolve the immediate problem, just not optimally.

Index: cc-vars.el
===================================================================
RCS file: /cvsroot/emacs/emacs/lisp/progmodes/cc-vars.el,v
retrieving revision 1.37
diff -u -u -p -d -r1.37 cc-vars.el
--- cc-vars.el  31 Dec 2004 14:52:17 -0000      1.37
+++ cc-vars.el  29 Apr 2005 14:11:11 -0000
@@ -330,6 +330,17 @@ better with the \"do { ... } while \(0)\
   :type 'boolean
   :group 'c)
 
+(defcustom c-preprocessor-command "/lib/cpp"
+  "*The program to use for preprocessing C sources.
+
+If set, it will be run when opening source files in order to list all
+C macros in use.  Note that this program must currently support the
+`-dM' flag (which may narrow it down to gcc).
+
+If nil, no preprocessing will be done."
+  :type '(file :must-match t)
+  :group 'c)
+
 (defcustom-c-stylevar c-comment-only-line-offset 0
   "*Extra offset for line which contains only the start of a comment.
 Can contain an integer or a cons cell of the form:
Index: cc-mode.el
===================================================================
RCS file: /cvsroot/emacs/emacs/lisp/progmodes/cc-mode.el,v
retrieving revision 1.34
diff -u -u -p -d -r1.34 cc-mode.el
--- cc-mode.el  27 Apr 2005 21:59:43 -0000      1.34
+++ cc-mode.el  29 Apr 2005 14:11:39 -0000
@@ -642,17 +642,22 @@ Note that the style variables are always
 (defvar cc-define-alist nil "Alist of #define directives for GUD tooltips.")
 
 (defun cc-create-define-alist ()
-  (let* ((file (buffer-file-name))
-        (output
-         (with-output-to-string
-           (with-current-buffer standard-output
-             (call-process "/lib/cpp"
-                           file t nil "-dM"))))
-       (define-list (split-string output "\n" t))
-       (name))
-    (dolist (define define-list)
-      (setq name (nth 1 (split-string define "[( ]")))
-      (push (cons name define) cc-define-alist))))
+  (let ((file (buffer-file-name)))
+    (cond
+     (c-preprocessor-command
+      (and (file-exists-p file) ;; TODO: use a temp file if needed
+          (let*
+              ((output
+                (with-output-to-string
+                  (with-current-buffer standard-output
+                    (call-process c-preprocessor-command
+                                  file t nil "-dM"))))
+               (define-list (split-string output "\n" t))
+               (name))
+            (dolist (define define-list)
+              (setq name (nth 1 (split-string define "[( ]")))
+              (push (cons name define) cc-define-alist)))))
+     (t nil))))
 
 ;;;###autoload
 (defun c-mode ()




reply via email to

[Prev in Thread] Current Thread [Next in Thread]