0

I use clang-format to format my source code. It's really handy, however, I'm facing an issue while working on Emacs. I separate my files into pages to keep them narrow, especially when dealing with large header files, this becomes really handy.

The thing is, in order to specify a page, you need to insert a special character 014 or ^L, but clang-format removes this character everything time I format. Is there any way to alter this behavior?

0x0584
  • 258
  • 1
  • 7
  • 15

1 Answers1

0

At first I thought this was not possible. However, you can do it by enclosing the ^L inside quotes. For example:

#include <stdio.h>
int main()
{
    int i;
    function_call_on_first_page();
    // "^L" <-- use an actual control-L character inside those quotes
    function_call_on_next_page();
    return 0;
}

It's ugly, but it might solve your problem. I tested this with clang-format version 6.0. Either single or double quotes seem to work.

Alternatively, you might try separating your code into "regions", and use one of the methods described at Equivalent of #region for C++. Unfortunately, none of those methods are very portable.

Eric Backus
  • 1,614
  • 1
  • 12
  • 29
  • Ah, it looks like emacs only uses ^L if it is alone on a line. Sorry, I don't see any solution then. – Eric Backus Oct 31 '20 at 04:07
  • Yeah that's the case, I see if I can make some elisp hacking to make it work.. Thanks for your help nonetheless – 0x0584 Oct 31 '20 at 10:24