How to let Emacs c-mode understand Chromium specific macro like EXPORT?

59 views
Skip to first unread message

Dean Liao

unread,
Oct 8, 2018, 5:36:54 AM10/8/18
to Chromium-dev
Hi all,

I'm a new developer for Chromium codebase. I have set my Emacs to use google-set-c-style , but it doesn't recognize Chromium macro like EXPORT.  So it makes the wrong indentation for header file with class definition with EXPORT macro after class name.

Does anyone have receipt of this issue? I didn't find a document mention about it. Thanks.

Best,
Dean

Sylvain Defresne

unread,
Oct 8, 2018, 5:43:23 AM10/8/18
to dean...@chromium.org, chromi...@chromium.org
I do not use emacs myself, but at https://chromium.googlesource.com/chromium/src/+/master/docs/emacs.md there is documentation on how to set up emacs to use TAB to format current bloc with clang-format. Could this work for you?
-- Sylvain

--
--
Chromium Developers mailing list: chromi...@chromium.org
View archives, change email options, or unsubscribe:
http://groups.google.com/a/chromium.org/group/chromium-dev
---
You received this message because you are subscribed to the Google Groups "Chromium-dev" group.
To view this discussion on the web visit https://groups.google.com/a/chromium.org/d/msgid/chromium-dev/4ead6409-d79b-4351-b4ff-672074ec53dc%40chromium.org.

Yuta Kitamura

unread,
Oct 8, 2018, 9:24:40 PM10/8/18
to dean...@chromium.org, chromium-dev
I managed to get this working for me, but unfortunately that was not easy. Essentially, you need to edit the source code of cc-mode and recompile.

If you want to give it a try, do the following:
  1. Get the latest tarball of cc-mode and expand it.
  2. Run the following shell command (obviously you can change the list of EXPORTs):

    $ patch -p0 -u <<'__EOF__'
    --- cc-langs.el.orig 2018-02-27 16:59:23.978931404 +0900
    +++ cc-langs.el 2018-02-27 17:02:05.409110857 +0900
    @@ -2103,7 +2103,13 @@
       (c c++) '(;; GCC extension.
        "__attribute__"
          ;; MSVC extension.
    -     "__declspec"))
    +     "__declspec"
    +     ;; Custom Chromium/Blink specific keywords.
    +     "BASE_EXPORT"
    +     "CORE_EXPORT" "CONTROLLER_EXPORT" "MODULES_EXPORT"
    +     "PLATFORM_EXPORT" "BLINK_COMMON_EXPORT" "BLINK_EXPORT"
    +     "BLINK_PLATFORM_EXPORT" "WTF_EXPORT"
    +           "BASE_EXPORT" "CONTENT_EXPORT"))
     
     (c-lang-defconst c-decl-hangon-key
       ;; Adorned regexp matching `c-decl-hangon-kwds'.
    __EOF__

  3. Byte-compile the source code as instructed in README.
  4. In your emacs initialization file (typically ~/.emacs), add the following to prepend your modified cc-mode to load-path:

    (add-to-list 'load-path "~/path/to/your/cc-mode")

  5. Restart emacs, and open some source code to see if XXX_EXPORT is highlighted differently, and cc-mode doesn't mis-indent within a class.
    (Alternatively, you can check the version of cc-mode by typing M-x c-version)
YMMV, but hope this helps.

Thanks,
Yuta

--

Dean Liao

unread,
Oct 8, 2018, 10:55:28 PM10/8/18
to Chromium-dev
Thank you Yuta. I saw your internal Site mentioned about this. I tried but it compiled with warning and my emacs failed to identify those EXPORT macros. It said "cc-defs.el:62:1:Warning: cl package required at runtime". Did you encounter this before?

Best,
Dean

~/.emacs.d/cc-mode-5.33 $ emacs -batch -no-site-file -q -f batch-byte-compile cc-*.el

In toplevel form:
cc-defs.el:62:1:Warning: cl package required at runtime
cc-defs.el:1036:22:Warning: Use ‘with-current-buffer’ rather than
    save-excursion+set-buffer
cc-defs.el:1915:20:Warning: Use ‘with-current-buffer’ rather than
    save-excursion+set-buffer
cc-defs.el:1935:26:Warning: Use ‘with-current-buffer’ rather than
    save-excursion+set-buffer

In c-lang-defconst:
cc-defs.el:2208:50:Warning: ‘cl-macroexpand-all’ is an obsolete function (as
    of 24.3); use ‘macroexpand-all’ instead.

In toplevel form:
cc-fix.el:49:1:Warning: assignment to free variable ‘cc-bytecomp-set-vars’

In toplevel form:
cc-fonts.el:147:16:Warning: ‘font-lock-reference-face’ is an obsolete variable
    (as of 20.3); use ‘font-lock-constant-face’ instead.

In toplevel form:
cc-langs.el:132:1:Warning: cl package required at runtime

In c-make-init-lang-vars-fun:
cc-langs.el:3492:40:Warning: ‘cl-macroexpand-all’ is an obsolete function (as
    of 24.3); use ‘macroexpand-all’ instead.

In end of data:
cc-mode.el:2123:1:Warning: the function ‘make-local-hook’ is not known to be
    defined.

In c-make-styles-buffer-local:
cc-styles.el:655:30:Warning: ‘make-variable-buffer-local’ not called at
    toplevel

In end of data:
cc-styles.el:678:1:Warning: the function ‘c-guess-basic-syntax’ might not be
    defined at runtime.
cc-styles.el:678:1:Warning: the function ‘make-local-hook’ is not known to be
    defined.

In toplevel form:
cc-subword.el:164:5:Warning: ‘make-variable-buffer-local’ not called at
    toplevel

Dean Liao

unread,
Oct 8, 2018, 10:57:17 PM10/8/18
to Chromium-dev

Yuta Kitamura

unread,
Oct 8, 2018, 11:20:06 PM10/8/18
to dean...@chromium.org, chromium-dev
I also saw bite-compiling generated a lot of warnings, but it worked anyway. Seems like those warnings are normal for cc-mode.

Reply all
Reply to author
Forward
0 new messages