clang-format

Xcode 8 extension executing NSTask

故事扮演 提交于 2019-12-08 16:09:45
问题 My goal is to create an extension that executes clang-format. My code looks something like this: - (void)performCommandWithInvocation:(XCSourceEditorCommandInvocation *)invocation completionHandler:(void (^)(NSError * _Nullable nilOrError))completionHandler { NSError *error = nil; NSURL *executableURL = [[self class] executableURL]; if (!executableURL) { NSString *errorDescription = [NSString stringWithFormat:@"Failed to find clang-format. Ensure it is installed at any of these locations\n%@"

How can I tell clang-format to indent visibility modifiers?

孤街浪徒 提交于 2019-12-08 15:56:01
问题 I want my visibility modifiers ( public , protected and private ) to be indented by clang-format who currently leaves them at the same level as the class declaration. I've looked for indent and visibility on a dump of the default format options but couldn't find anything. 回答1: From the Clang-Format Style Options documentation: AccessModifierOffset (int) The extra indent or outdent of access modifiers, e.g. public:. So, add the appropriate entry to your .clang-format . For example,

clang-format breaks lint annotations

蹲街弑〆低调 提交于 2019-12-08 15:07:23
问题 We use lint in our codebase at work for C/C++, I'm trying to start integrating clang-format in my workflow as well. Unfortunately, lint occasionally requires annotations to ignore a specific check, either of the format: /*lint -[annotation] */ or //lint -[annotation] Specifically, if there's a space between the opening token for the comment and 'lint', it doesn't recognize it as an annotation directive. Unfortunately, the default settings I have for clang-format see that as an error and

Can Clang formatting be used in Netbeans

允我心安 提交于 2019-12-07 09:53:27
问题 Is there a way to use the clang formatter with NetBeans 8.1? I'm running NetBeans on Arch Linux, if it matters. 回答1: At the time you posted your question the answer was no, but now (over a year later!) you can use the clang formatter in NetBeans, subject to the following constraints: You must use version 8.2 of NetBeans rather than version 8.1. You must install from a recent nightly development build of NetBeans 8.2 rather than using the standard release. That's because this functionality was

How to make clang-format skip sections of c++ code

假装没事ソ 提交于 2019-12-07 03:52:10
问题 Is there any way to configure the clang-format tool to skip my Qt::connect function calls ? There are several connects in my constructors which looks like these: connect( m_Job, SIGNAL( error( const QString&, const QString& ) ), this, SLOT( onError( const QString&, const QString& ) ) ); connect( m_Job, SIGNAL( message( const QString& ) ), this, SLOT( onMessage( const QString& ) ) ); connect( m_Job, SIGNAL( progress( int, int ) ), this, SLOT( onProgress( int, int ) ) ); but after I run the

Git 'pre-receive' hook and 'git-clang-format' script to reliably reject pushes that violate code style conventions

可紊 提交于 2019-12-05 16:14:45
问题 Let's immediately start with a scrap of the pre-receive hook that I've already written: #!/bin/sh ## format_bold='\033[1m' format_red='\033[31m' format_yellow='\033[33m' format_normal='\033[0m' ## format_error="${format_bold}${format_red}%s${format_normal}" format_warning="${format_bold}${format_yellow}%s${format_normal}" ## stdout() { format="${1}" shift printf "${format}" "${@}" } ## stderr() { stdout "${@}" 1>&2 } ## output() { format="${1}" shift stdout "${format}\n" "${@}" } ## error() {

Can Clang formatting be used in Netbeans

谁都会走 提交于 2019-12-05 14:11:50
Is there a way to use the clang formatter with NetBeans 8.1? I'm running NetBeans on Arch Linux, if it matters. At the time you posted your question the answer was no, but now (over a year later!) you can use the clang formatter in NetBeans, subject to the following constraints: You must use version 8.2 of NetBeans rather than version 8.1. You must install from a recent nightly development build of NetBeans 8.2 rather than using the standard release. That's because this functionality was only added recently. See NetBeans bug 270882 . To use the clang formatter in NetBeans: Create a trivial C++

How to make clang-format skip sections of c++ code

会有一股神秘感。 提交于 2019-12-05 06:14:50
Is there any way to configure the clang-format tool to skip my Qt::connect function calls ? There are several connects in my constructors which looks like these: connect( m_Job, SIGNAL( error( const QString&, const QString& ) ), this, SLOT( onError( const QString&, const QString& ) ) ); connect( m_Job, SIGNAL( message( const QString& ) ), this, SLOT( onMessage( const QString& ) ) ); connect( m_Job, SIGNAL( progress( int, int ) ), this, SLOT( onProgress( int, int ) ) ); but after I run the formatting tool it makes it less readable: connect( m_Job, SIGNAL( error(const QString&, const QString&)),

Where are clang-format and clang-format.py in Mac OS X with Xcode Command Line Tools installed?

蓝咒 提交于 2019-12-04 14:57:53
问题 I am having a hard time finding clang-format and clang-format.py on my Mac OS 10.8.5 with Xcode 5 and its Command Line Tools. I tried find / -name "clang-format.py" without luck. Are they already here somewhere hiding, or how would I get this toolchain? (I'm surprised it doesn't seem readily available since clang is Apple's compiler---in that Apple uses it.) 回答1: Seems like Apple doesn't ship clang-format with the Command Line Tools. Right now you have at least three options: Using Homebrew (

How to auto indent a C++ class with 4 spaces using clang-format?

那年仲夏 提交于 2019-12-04 08:03:43
问题 I got the next .clang-format file in my project's root directory: --- AlignTrailingComments: true AllowShortFunctionsOnASingleLine: false AllowShortIfStatementsOnASingleLine: true AllowShortLoopsOnASingleLine: true BreakBeforeBinaryOperators: false IndentWidth: 4 SortIncludes: false NamespaceIndentation: All ... Problem comes when I run clang-format on my c++ headers, the classes become autoindented like this: As you can see, labels public & private are indented only with 2 spaces. But what I