Skip to content

[feature-request] [clang-format] Preserve the form feed character (^L, 0xC, \f) #113170

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
Gleefre opened this issue Oct 21, 2024 · 2 comments · Fixed by #113268
Closed

[feature-request] [clang-format] Preserve the form feed character (^L, 0xC, \f) #113170

Gleefre opened this issue Oct 21, 2024 · 2 comments · Fixed by #113268
Assignees
Labels
clang-format enhancement Improving things as opposed to bug fixing, e.g. new or missing feature

Comments

@Gleefre
Copy link

Gleefre commented Oct 21, 2024

The form feed character is often used to divide programs into logical blocks. When placed alone on a line, it acts as a logical page break, which can be used by text editors for efficient navigation and various display features. For example, Emacs has commands like narrow-to-page and forward-page / backward-page, and Vim also recognizes the ^L markers for navigation. Additionally, various IDE extensions provide similar functionality.

Although formfeeds are mostly used in lisp code, they also can be found in C/C++ code. Here's a quote from the GNU coding standards (gcc's code style):

Please use formfeed characters (control-L) to divide the program into pages at logical places (but not within a function). It does not matter just how long the pages are, since they do not have to fit on a printed page. The formfeeds should appear alone on lines by themselves.

Currently, clang-format removes form feed characters that appear alone on a line, and to my knowledge there is no option to disable this behavior. It would be great either if formfeeds were always preserved or if there was an configuration option to control that.

@EugeneZelenko EugeneZelenko added the enhancement Improving things as opposed to bug fixing, e.g. new or missing feature label Oct 21, 2024
@owenca owenca self-assigned this Oct 22, 2024
@owenca
Copy link
Contributor

owenca commented Oct 22, 2024

Here is what the new option would do:

--- a/clang/include/clang/Format/Format.h
+++ b/clang/include/clang/Format/Format.h
@@ -3207,6 +3207,13 @@ struct FormatStyle {
   /// \version 3.7
   // bool KeepEmptyLinesAtTheStartOfBlocks;
 
+  /// Keep the form feed character if it's immediately preceded and followed by
+  /// a newline. Multiple form feeds and newlines within a whitespace range are
+  /// replaced with a single newline and form feed followed by the remaining
+  /// newlines.
+  /// \version 20
+  bool KeepFormFeed;
+
   /// Indentation logic for lambda bodies.
   enum LambdaBodyIndentationKind : int8_t {
     /// Align lambda body relative to the lambda signature. This is the default.

owenca added a commit to owenca/llvm-project that referenced this issue Oct 22, 2024
@Gleefre
Copy link
Author

Gleefre commented Oct 22, 2024

That would be great, thanks!

owenca added a commit that referenced this issue Oct 24, 2024
NoumanAmir657 pushed a commit to NoumanAmir657/llvm-project that referenced this issue Nov 4, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
clang-format enhancement Improving things as opposed to bug fixing, e.g. new or missing feature
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants