gpt4 book ai didi

c++ - 在 Xcode 上打开用 emacs 编写的代码出现严重缩进

转载 作者:行者123 更新时间:2023-11-28 01:58:33 25 4
gpt4 key购买 nike

这是我关于堆栈溢出的第一篇文章,所以请原谅我的任何错误。

我通过 Xcode 学习了 C++,最近开始与一个使用 Emacs 的团队合作。这个小组有大量的 c++ 代码,所以我做了一个 CMake 接口(interface)来在 Xcode 中生成一个项目。发生的事情是代码在 Xcode 中出现严重缩进。例如,emacs 中的这些行:

if ( argc > 4 ) {
std::string argument( argv[arg_index++] );
// NOTE: file_name should NOT be "aboveCrack" or "belowCrack"
if ( argument == "aboveCrack" ) {
surf_to_draw = CrackMn3DGraphDX2::EAboveSurface;
}
else if ( argument == "belowCrack" ) {
surf_to_draw = CrackMn3DGraphDX2::EBelowSurface;
}
else {
// argument 4 is comp. crack surface output name
got_file_name = true;
postCompSurface_file_name = argument;
}
}
if ( !got_file_name && argc > 5 ) {
got_file_name = true;
postCompSurface_file_name = argv[arg_index++];

if ( argc > 6 ) {
// get comp. crack surface output style
postCompSurface_style = argv[arg_index++];
}
}

在 Xcode 中看起来像这样:

if ( argc > 4 ) {
std::string argument( argv[arg_index++] );
// NOTE: file_name should NOT be "aboveCrack" or "belowCrack"
if ( argument == "aboveCrack" ) {
surf_to_draw = CrackMn3DGraphDX2::EAboveSurface;
}
else if ( argument == "belowCrack" ) {
surf_to_draw = CrackMn3DGraphDX2::EBelowSurface;
}
else {
// argument 4 is comp. crack surface output name
got_file_name = true;
postCompSurface_file_name = argument;
}
}
if ( !got_file_name && argc > 5 ) {
got_file_name = true;
postCompSurface_file_name = argv[arg_index++];

if ( argc > 6 ) {
// get comp. crack surface output style
postCompSurface_style = argv[arg_index++];
}
}

这是无法编程的。

我搜索了一下,显然它与 Emacs 中的选项卡有关。基于此,我找到的一个修复方法是在 Emacs 中打开每个文件并执行 C-x h(标记所有),然后执行 M-x untabify。这会转换空格中的选项卡,并且在 Xcode 中一切看起来都很好。

这个想法的问题在于,它需要一个一个地更改文件,并且不会阻止这种情况在未来再次发生。

因此,我的问题是:有没有办法在 Xcode 中打开 Emacs 缩进文件并保留缩进?

非常感谢!

内森·肖尔

最佳答案

您需要放入 .emacs 的第一个设置是:(setq-default indent-tabs-mode nil)。这将确保 emacs 使用空格而不是制表符进行缩进。另外,我创建了一个小函数:

(defun rag/untabify-buffer ()
;; get rid of all the tabs in a buffer
(interactive)
(untabify (point-min) (point-max))
nil)

将此添加到 before-save-hook,这将确保在您进行更改并保存文件时,所有文件都将untabified。取消标记所有文件后,您可以删除 Hook

关于c++ - 在 Xcode 上打开用 emacs 编写的代码出现严重缩进,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40353119/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com