Hacktoberfest 2026:维护者为十月标记出来的 issue,仍然开放、适合新手。 浏览 Hacktoberfest issue

Format On Save with Xcode behaviors.

未关闭
#57 0 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

还没有人认领这个 Issue。

评估

难度
5/5
预计耗时
一周以上
新手友好度
25/100
Issue 类型
功能
描述清晰度
需要澄清
活跃度
停滞
技术栈
cpp, shell
领域
tooling

调研方向

首先,根据 issue 中的 Command+S 脚本复现 Xcode 的行为,包括对 .cpp 文件执行 clang-format -i 和 touch 命令。调查 plugin 是否可以在 Xcode 内调用格式化,而不是在外部修改文件。完成的标准是在保存时进行格式化,不显示外部修改对话框,同时保留磁盘上较新的版本。

由索引模型根据 Issue 内容生成。

描述

Hi, in order to allow "Format on Save" I avoid using extensions, but rather set new Xcode behavior hat run the following script upon "Command+S" (which replace the original file save):

My script extract the current file name presented by xcode, and perform clang-format on this file (see below), and it works just fine.

However, when the file is modified, I sometimes get the following message from xcode.

the file for the document at “/Users/me/file.cpp” has been modified by another application. There are also unsaved changes in Xcode. Do you want to keep the Xcode version or revert to the version on disk?

This happens because the file changed outside xcode ... and xcode probably cache the currently file being edited, so I'd like to avoid this message box and always take the newer file version from disk (select the "Revert" option instead of the other option of "Keep Xcode Version") . is it possible to avoid this message box ?

Thanks

#!/bin/sh

CDP=$(osascript -e 'tell application "Xcode"
    activate
    set current_document to last source document
    set current_document_path to path of current_document
end tell ' )

if [[ $CDP == *.cpp ]]
then
    /usr/local/bin/clang-format -i ${CDP}
    touch ${CDP}
fi

P.S I'm aware this option doesn't related directly to the plugin, but if the plugin can somehow run clang-format from within the xcode, it may solve my problem and avoid this messagebox...

主要语言
Objective-C++
星标
807
派生
102
PR 合并指标
30 天内没有已合并 PR

贡献指南

打开贡献指南

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

mapbox/XcodeClangFormat 的其他 Issue

查看 mapbox/XcodeClangFormat 的全部 Issue

相似的 Issue

更多 DevTools Issue

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。