如何根据Eclipse中的文件类型设置不同的代码样式?

时间:2022-09-22 19:02:54

We are using CMake to manage our builds and have a rather large project consisting of pretty much everything that is needed to build the software base for our embedded platforms save for the toolchain. When building a CDT project with CMake it puts everything into one large project rather than splitting it into individual projects based on the CMake specification.

我们正在使用CMake来管理我们的构建,并且有一个相当大的项目,包括为我们的嵌入式平台构建软件库所需的几乎所有东西,除了工具链。在使用CMake构建CDT项目时,它将所有内容放入一个大型项目中,而不是根据CMake规范将其拆分为单个项目。

Our problem is that we have both C and C++ code in the project and we have different code styles for these languages. I have not been able to find out how to tell Eclipse to select a code style based on the file type rather than the project and this makes it very hard to use Eclipse for us since you have to remember to manually switch the style for the entire project if you want to switch from working on a C- to a C++-project or vice versa.

我们的问题是我们在项目中有C和C ++代码,并且我们对这些语言有不同的代码样式。我无法找到如何告诉Eclipse根据文件类型而不是项目选择代码样式,这使得我们很难使用Eclipse,因为你必须记住手动切换整个样式项目,如果你想从C-切换到C ++项目,反之亦然。

Is it at all possible to set the code style based on the file type rather than just for an entire project?

是否可以根据文件类型设置代码样式,而不仅仅是整个项目?

1 个解决方案

#1


1  

You can make use of the "link to folder in the file system" advanced option of the new folder dialog box.

您可以使用新文件夹对话框中的“文件系统中的文件夹链接”高级选项。

Basically create a project build-c, and then create a new folder inside there called build and link to the build source files located elsewhere. Then for the build-c project you can change the code style to something else than the build project.

基本上创建一个项目build-c,然后在其中创建一个名为build的新文件夹,并链接到位于其他地方的构建源文件。然后,对于build-c项目,您可以将代码样式更改为除构建项目之外的其他内容。

If this gets confusing, you can create another project called build-cpp and do the same thing (create a folder called build and link to the actual location of the build source files). Then you can make use of filtering projects by working sets (one working set including the build-c project, and another working set called build-cpp).

如果这让人感到困惑,你可以创建另一个名为build-cpp的项目并执行相同的操作(创建一个名为build的文件夹并链接到构建源文件的实际位置)。然后,您可以使用工作集过滤项目(一个工作集包括build-c项目,另一个工作集名为build-cpp)。

Since the folders in both projects just link to the original location of the build files you don't have to worry about multiple copies between projects. You would still only be able to check files in from the main build project however. It also still requires the user to manual switch working sets from c to cpp depending on what they're interested in changing.

由于两个项目中的文件夹只链接到构建文件的原始位置,因此您不必担心项目之间的多个副本。但是,您仍然只能从主构建项目中检入文件。它还需要用户手动将工作集从c切换到cpp,具体取决于他们对更改感兴趣的内容。

#1


1  

You can make use of the "link to folder in the file system" advanced option of the new folder dialog box.

您可以使用新文件夹对话框中的“文件系统中的文件夹链接”高级选项。

Basically create a project build-c, and then create a new folder inside there called build and link to the build source files located elsewhere. Then for the build-c project you can change the code style to something else than the build project.

基本上创建一个项目build-c,然后在其中创建一个名为build的新文件夹,并链接到位于其他地方的构建源文件。然后,对于build-c项目,您可以将代码样式更改为除构建项目之外的其他内容。

If this gets confusing, you can create another project called build-cpp and do the same thing (create a folder called build and link to the actual location of the build source files). Then you can make use of filtering projects by working sets (one working set including the build-c project, and another working set called build-cpp).

如果这让人感到困惑,你可以创建另一个名为build-cpp的项目并执行相同的操作(创建一个名为build的文件夹并链接到构建源文件的实际位置)。然后,您可以使用工作集过滤项目(一个工作集包括build-c项目,另一个工作集名为build-cpp)。

Since the folders in both projects just link to the original location of the build files you don't have to worry about multiple copies between projects. You would still only be able to check files in from the main build project however. It also still requires the user to manual switch working sets from c to cpp depending on what they're interested in changing.

由于两个项目中的文件夹只链接到构建文件的原始位置,因此您不必担心项目之间的多个副本。但是,您仍然只能从主构建项目中检入文件。它还需要用户手动将工作集从c切换到cpp,具体取决于他们对更改感兴趣的内容。