• a great tool for automatically formating your code!


    1. make your own format file at your project's root or file's folder. (The clang-format will automatically use the latest format file to format your code)

    vim .clang-format

    IndentWidth: 8

    UseTab: Always

    BreakBeforeBraces: Linux

    AllowShortIfStatementsOnASingleLine: false

    IndentCaseLabels: false

    2. Then use the clang-format plug-in to automatically format your code.

    Edit-->Clang-format-->Format File in Focus

    Most likely, you'll have a .clang-format file at the root of your project.

    So easy! so neat!

    ClangFormat-Xcode

    An Xcode plug-in to format your code using Clang's format tools, by @travisjeffery.

    With clang-format you can use Clang to format your code to styles such as LLVM, Google, Chromium, Mozilla, WebKit, or your own configuration.

    usage

    demo

    Installation:

    Install via Alcatraz.

    OR

    Clone this repo, build and run ClangFormat, restart Xcode.

    Usage:

    Format on save

    I.e., you press command-s and the file is formatted and wrote to disk.

    In the menu, open Edit > Clang Format > Click Format on save (a checkmark appears in this menu item indicicating that the feature is active.)

    Assign keyboard shortcuts

    You can assign your own keyboard shortcuts like so:

    • Open the System Preferences > Keyboard > Shortcuts > App Shortcuts > Click +
    • Set the application to be Xcode
    • Set the menu title to an action title, e.g. "Format File in Focus"
    • Set your shortcut

    In this example, we'll format the active file when control-i is pressed.

    assign keyboard shortcut

    Using your own style configuration

    By using Clang Format > File in the plug-in menu, Clang will look for the nearest .clang-format file from the input file. Most likely, you'll have a .clang-format file at the root of your project.

    Here are the options for .clang-format and how they're configured.

    If one of the built-in styles is close to what you want, you can bootstrap your own configuration with:

    ./bin/clang-format -style=llvm -dump-config > .clang-format

    For example, this .clang-format is similar to the Linux Kernel style:

    BasedOnStyle: LLVM
    IndentWidth: 8
    UseTab: Always
    BreakBeforeBraces: Linux
    AllowShortIfStatementsOnASingleLine: false
    IndentCaseLabels: false
    

    And this is similar to Visual Studio's style:

    UseTab: Never
    IndentWidth: 4
    BreakBeforeBraces: Allman
    AllowShortIfStatementsOnASingleLine: false
    IndentCaseLabels: false
    ColumnLimit: 0
  • 相关阅读:
    【学习笔记】Hibernate关联映射(Y2-1-6)
    百度搜索排名API接口返回JSON数据格式
    HtmlAgilityPack 属性获取
    HtmlAgilityPack
    HighCharts实现双Y轴
    QQ在线客服配置
    项目管理者必知:适用于仪表盘项目的7个优秀JavaScript库
    极简Node教程-七天从小白变大神(二:中间件是核心)
    极简Node教程-七天从小白变大神(一:你需要Express)
    CSS滚动插件
  • 原文地址:https://www.cnblogs.com/airwindow/p/4051259.html
Copyright © 2020-2023  润新知