git/list[1] front-page[2] threads[3] people[4] search[5] about
 

[PATCH] clang-format: use git grep to generate the ForEachMacros list

From
MOMiguel Ojeda <miguel.ojeda.sandonis@gmail.com>
Date
Jun 3, 2019, 22:48 UTC
Message-ID
<20190603224814.GA15851@gmail.com>

The ForEachMacros list can reasonably be generated grepping the C source code for macros with 'for_each' in their name.

Taken almost verbatim from the .clang-format file in the Linux kernel.
Signed-off-by: Miguel Ojeda <miguel.ojeda.sandonis@gmail.com>
---
We wrote this for the Linux kernel a while ago, and it has been working
fine there, so I thought it would be nice to use the same approach here.
There are fancier ways of approaching this, of course.
 .clang-format | 17 +++++++++++++++--
 1 file changed, 15 insertions(+), 2 deletions(-)
diff --git a/.clang-format b/.clang-format
index 41d4cd23fd..c592dda681 100644
--- a/.clang-format
+++ b/.clang-format
@@ -148,8 +148,21 @@ SpacesInSquareBrackets: false
 Cpp11BracedListStyle: false
 
 # A list of macros that should be interpreted as foreach loops instead of as
-# function calls.
-ForEachMacros: ['for_each_string_list_item', 'for_each_wanted_builtin', 'for_each_builtin', 'for_each_ut']
+# function calls. Taken from:
+#   git grep -h '^#define [^[:space:]]*for_each[^[:space:]]*(' \
+#   | sed "s,^#define \([^[:space:]]*for_each[^[:space:]]*\)(.*$,  - '\1'," \
+#   | sort | uniq
+ForEachMacros:
+  - 'for_each_abbrev'
+  - 'for_each_builtin'
+  - 'for_each_string_list_item'
+  - 'for_each_ut'
+  - 'for_each_wanted_builtin'
+  - 'list_for_each'
+  - 'list_for_each_dir'
+  - 'list_for_each_prev'
+  - 'list_for_each_prev_safe'
+  - 'list_for_each_safe'
 
 # The maximum number of consecutive empty lines to keep.
 MaxEmptyLinesToKeep: 1
-- 
2.17.1
Next: Johannes Schindelin
Message 1 of 4 in “clang-format: use git grep to generate the ForEachMacros list”
  1. clang-format: use git grep to generate the ForEachMacros listMiguel Ojeda, Jun 3, 2019
  2. Johannes SchindelinJun 4, 2019
  3. Taylor BlauJun 5, 2019
  4. Miguel OjedaJun 6, 2019

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.