Commit e48e411e authored by Christoph Cullmann's avatar Christoph Cullmann 🐮
Browse files

use ECM provided clang-format target, guard for older ECM versions

parent b77babcf
---
# SPDX-License-Identifier: MIT
#
# Copyright (C) 2019 Christoph Cullmann <cullmann@kde.org>
# Copyright (C) 2019 Gernot Gebhard <gebhard@absint.com>
#
# Permission is hereby granted, free of charge, to any person obtaining
# a copy of this software and associated documentation files (the
# "Software"), to deal in the Software without restriction, including
# without limitation the rights to use, copy, modify, merge, publish,
# distribute, sublicense, and/or sell copies of the Software, and to
# permit persons to whom the Software is furnished to do so, subject to
# the following conditions:
#
# The above copyright notice and this permission notice shall be included
# in all copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
# IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
# CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
# TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
# SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
# Style for C++
Language: Cpp
# base is WebKit coding style: http://www.webkit.org/coding/coding-style.html
# below are only things set that diverge from this style!
BasedOnStyle: WebKit
# enforce C++11 (e.g. for std::vector<std::vector<lala>>
Standard: Cpp11
# 4 spaces indent
TabWidth: 4
# 3 * 80 wide lines
ColumnLimit: 240
# sematics shall be grouped via empty lines
SortIncludes: true
# break before braces on function, namespace and class definitions.
BreakBeforeBraces: Linux
# CrlInstruction *a;
PointerAlignment: Right
# horizontally aligns arguments after an open bracket.
AlignAfterOpenBracket: Align
# align trailing comments
AlignTrailingComments: true
# don't move all parameters to new line
AllowAllParametersOfDeclarationOnNextLine: false
# no single line functions
AllowShortFunctionsOnASingleLine: None
# always break before you encounter multi line strings
AlwaysBreakBeforeMultilineStrings: true
# don't move arguments to own lines if they are not all on the same
BinPackArguments: false
# don't move parameters to own lines if they are not all on the same
BinPackParameters: false
# don't break binary ops
BreakBeforeBinaryOperators: None
# don't break tenary ops
BreakBeforeTernaryOperators: false
# format C++11 braced lists like function calls
Cpp11BracedListStyle: true
# indent case labels one level
IndentCaseLabels: true
# remove empty lines
KeepEmptyLinesAtTheStartOfBlocks: false
# no namespace indentation to keep indent level low
NamespaceIndentation: None
......@@ -4,6 +4,7 @@
*.orig
*.out
CMakeLists.txt.user*
.clang-format
# kate
*~
......
......@@ -46,3 +46,12 @@ ecm_optional_add_subdirectory(kate)
ecm_optional_add_subdirectory(doc)
feature_summary(INCLUDE_QUIET_PACKAGES WHAT ALL FATAL_ON_MISSING_REQUIRED_PACKAGES)
# this needs at least ECM 5.64...
if(${ECM_VERSION} VERSION_GREATER "5.63.0")
include(KDEClangFormat)
# add clang-format target for all our real source files
file(GLOB_RECURSE ALL_CLANG_FORMAT_SOURCE_FILES *.cpp *.h)
kde_clang_format(${ALL_CLANG_FORMAT_SOURCE_FILES})
endif()
......@@ -211,41 +211,41 @@ void KateExternalToolsPlugin::handleToolFinished(KateToolRunner *runner, int exi
auto view = runner->view();
if (view && !runner->outputData().isEmpty()) {
switch (runner->tool()->outputMode) {
case KateExternalTool::OutputMode::InsertAtCursor: {
KTextEditor::Document::EditingTransaction transaction(view->document());
view->removeSelection();
view->insertText(runner->outputData());
break;
}
case KateExternalTool::OutputMode::ReplaceSelectedText: {
KTextEditor::Document::EditingTransaction transaction(view->document());
view->removeSelectionText();
view->insertText(runner->outputData());
break;
}
case KateExternalTool::OutputMode::ReplaceCurrentDocument: {
KTextEditor::Document::EditingTransaction transaction(view->document());
view->document()->clear();
view->insertText(runner->outputData());
break;
}
case KateExternalTool::OutputMode::AppendToCurrentDocument: {
view->document()->insertText(view->document()->documentEnd(), runner->outputData());
break;
}
case KateExternalTool::OutputMode::InsertInNewDocument: {
auto mainWindow = view->mainWindow();
auto newView = mainWindow->openUrl({});
newView->insertText(runner->outputData());
mainWindow->activateView(newView->document());
break;
}
case KateExternalTool::OutputMode::CopyToClipboard: {
QGuiApplication::clipboard()->setText(runner->outputData());
break;
}
default:
break;
case KateExternalTool::OutputMode::InsertAtCursor: {
KTextEditor::Document::EditingTransaction transaction(view->document());
view->removeSelection();
view->insertText(runner->outputData());
break;
}
case KateExternalTool::OutputMode::ReplaceSelectedText: {
KTextEditor::Document::EditingTransaction transaction(view->document());
view->removeSelectionText();
view->insertText(runner->outputData());
break;
}
case KateExternalTool::OutputMode::ReplaceCurrentDocument: {
KTextEditor::Document::EditingTransaction transaction(view->document());
view->document()->clear();
view->insertText(runner->outputData());
break;
}
case KateExternalTool::OutputMode::AppendToCurrentDocument: {
view->document()->insertText(view->document()->documentEnd(), runner->outputData());
break;
}
case KateExternalTool::OutputMode::InsertInNewDocument: {
auto mainWindow = view->mainWindow();
auto newView = mainWindow->openUrl({});
newView->insertText(runner->outputData());
mainWindow->activateView(newView->document());
break;
}
case KateExternalTool::OutputMode::CopyToClipboard: {
QGuiApplication::clipboard()->setText(runner->outputData());
break;
}
default:
break;
}
}
......
......@@ -28,12 +28,12 @@ namespace
QString toString(KateExternalTool::SaveMode saveMode)
{
switch (saveMode) {
case KateExternalTool::SaveMode::None:
return QStringLiteral("None");
case KateExternalTool::SaveMode::CurrentDocument:
return QStringLiteral("CurrentDocument");
case KateExternalTool::SaveMode::AllDocuments:
return QStringLiteral("AllDocuments");
case KateExternalTool::SaveMode::None:
return QStringLiteral("None");
case KateExternalTool::SaveMode::CurrentDocument:
return QStringLiteral("CurrentDocument");
case KateExternalTool::SaveMode::AllDocuments:
return QStringLiteral("AllDocuments");
}
Q_ASSERT(false); // yout forgot a case above
return QStringLiteral("None");
......@@ -53,22 +53,22 @@ KateExternalTool::SaveMode toSaveMode(const QString &mode)
QString toString(KateExternalTool::OutputMode outputMode)
{
switch (outputMode) {
case KateExternalTool::OutputMode::Ignore:
return QStringLiteral("Ignore");
case KateExternalTool::OutputMode::InsertAtCursor:
return QStringLiteral("InsertAtCursor");
case KateExternalTool::OutputMode::ReplaceSelectedText:
return QStringLiteral("ReplaceSelectedText");
case KateExternalTool::OutputMode::ReplaceCurrentDocument:
return QStringLiteral("ReplaceCurrentDocument");
case KateExternalTool::OutputMode::AppendToCurrentDocument:
return QStringLiteral("AppendToCurrentDocument");
case KateExternalTool::OutputMode::InsertInNewDocument:
return QStringLiteral("InsertInNewDocument");
case KateExternalTool::OutputMode::CopyToClipboard:
return QStringLiteral("CopyToClipboard");
case KateExternalTool::OutputMode::DisplayInPane:
return QStringLiteral("DisplayInPane");
case KateExternalTool::OutputMode::Ignore:
return QStringLiteral("Ignore");
case KateExternalTool::OutputMode::InsertAtCursor:
return QStringLiteral("InsertAtCursor");
case KateExternalTool::OutputMode::ReplaceSelectedText:
return QStringLiteral("ReplaceSelectedText");
case KateExternalTool::OutputMode::ReplaceCurrentDocument:
return QStringLiteral("ReplaceCurrentDocument");
case KateExternalTool::OutputMode::AppendToCurrentDocument:
return QStringLiteral("AppendToCurrentDocument");
case KateExternalTool::OutputMode::InsertInNewDocument:
return QStringLiteral("InsertInNewDocument");
case KateExternalTool::OutputMode::CopyToClipboard:
return QStringLiteral("CopyToClipboard");
case KateExternalTool::OutputMode::DisplayInPane:
return QStringLiteral("DisplayInPane");
}
Q_ASSERT(false); // yout forgot a case above
return QStringLiteral("Ignore");
......
......@@ -526,52 +526,52 @@ QVariant KateFileTreeModel::data(const QModelIndex &index, int role) const
}
switch (role) {
case KateFileTreeModel::PathRole:
// allow to sort with hostname + path, bug 271488
return (item->doc() && !item->doc()->url().isEmpty()) ? item->doc()->url().toString() : item->path();
case KateFileTreeModel::PathRole:
// allow to sort with hostname + path, bug 271488
return (item->doc() && !item->doc()->url().isEmpty()) ? item->doc()->url().toString() : item->path();
case KateFileTreeModel::DocumentRole:
return QVariant::fromValue(item->doc());
case KateFileTreeModel::DocumentRole:
return QVariant::fromValue(item->doc());
case KateFileTreeModel::OpeningOrderRole:
return item->row();
case KateFileTreeModel::OpeningOrderRole:
return item->row();
case KateFileTreeModel::DocumentTreeRole:
return QVariant::fromValue(item->docTree());
case KateFileTreeModel::DocumentTreeRole:
return QVariant::fromValue(item->docTree());
case Qt::DisplayRole:
// in list mode we want to use kate's fancy names.
if (m_listMode) {
return item->documentName();
} else {
return item->display();
}
case Qt::DecorationRole:
return item->icon();
case Qt::DisplayRole:
// in list mode we want to use kate's fancy names.
if (m_listMode) {
return item->documentName();
} else {
return item->display();
}
case Qt::ToolTipRole: {
QString tooltip = item->path();
if (item->flag(ProxyItem::DeletedExternally) || item->flag(ProxyItem::ModifiedExternally)) {
tooltip = i18nc("%1 is the full path", "<p><b>%1</b></p><p>The document has been modified by another application.</p>", item->path());
}
case Qt::DecorationRole:
return item->icon();
return tooltip;
case Qt::ToolTipRole: {
QString tooltip = item->path();
if (item->flag(ProxyItem::DeletedExternally) || item->flag(ProxyItem::ModifiedExternally)) {
tooltip = i18nc("%1 is the full path", "<p><b>%1</b></p><p>The document has been modified by another application.</p>", item->path());
}
case Qt::ForegroundRole: {
const KColorScheme colors(QPalette::Active);
if (!item->flag(ProxyItem::Dir) && (!item->doc() || item->doc()->openingError())) {
return colors.foreground(KColorScheme::InactiveText).color();
}
} break;
return tooltip;
}
case Qt::BackgroundRole:
// TODO: do that funky shading the file list does...
if (m_shadingEnabled && m_brushes.contains(item)) {
return m_brushes[item];
}
break;
case Qt::ForegroundRole: {
const KColorScheme colors(QPalette::Active);
if (!item->flag(ProxyItem::Dir) && (!item->doc() || item->doc()->openingError())) {
return colors.foreground(KColorScheme::InactiveText).color();
}
} break;
case Qt::BackgroundRole:
// TODO: do that funky shading the file list does...
if (m_shadingEnabled && m_brushes.contains(item)) {
return m_brushes[item];
}
break;
}
return QVariant();
......
......@@ -52,20 +52,20 @@ bool KateFileTreeProxyModel::lessThan(const QModelIndex &left, const QModelIndex
collate.setNumericMode(true);
switch (sortRole()) {
case Qt::DisplayRole: {
const QString left_name = model->data(left).toString();
const QString right_name = model->data(right).toString();
return collate.compare(left_name, right_name) < 0;
}
case KateFileTreeModel::PathRole: {
const QString left_name = model->data(left, KateFileTreeModel::PathRole).toString();
const QString right_name = model->data(right, KateFileTreeModel::PathRole).toString();
return collate.compare(left_name, right_name) < 0;
}
case KateFileTreeModel::OpeningOrderRole:
return (left.row() - right.row()) < 0;
case Qt::DisplayRole: {
const QString left_name = model->data(left).toString();
const QString right_name = model->data(right).toString();
return collate.compare(left_name, right_name) < 0;
}
case KateFileTreeModel::PathRole: {
const QString left_name = model->data(left, KateFileTreeModel::PathRole).toString();
const QString right_name = model->data(right, KateFileTreeModel::PathRole).toString();
return collate.compare(left_name, right_name) < 0;
}
case KateFileTreeModel::OpeningOrderRole:
return (left.row() - right.row()) < 0;
}
return false;
......
......@@ -63,17 +63,17 @@ const QStringList AdvancedGDBSettings::configs() const
tmp << u_gdbCmd->text();
switch (u_localRemote->currentIndex()) {
case 1:
tmp << QStringLiteral("target remote %1:%2").arg(u_tcpHost->text(), u_tcpPort->text());
tmp << QString();
break;
case 2:
tmp << QStringLiteral("target remote %1").arg(u_ttyPort->text());
tmp << QStringLiteral("set remotebaud %1").arg(u_baudCombo->currentText());
break;
default:
tmp << QString();
tmp << QString();
case 1:
tmp << QStringLiteral("target remote %1:%2").arg(u_tcpHost->text(), u_tcpPort->text());
tmp << QString();
break;
case 2:
tmp << QStringLiteral("target remote %1").arg(u_ttyPort->text());
tmp << QStringLiteral("set remotebaud %1").arg(u_baudCombo->currentText());
break;
default:
tmp << QString();
tmp << QString();
}
if (!u_soAbsPrefix->text().isEmpty()) {
tmp << QStringLiteral("set solib-absolute-prefix %1").arg(u_soAbsPrefix->text());
......
......@@ -280,155 +280,155 @@ void DebugView::processLine(QString line)
return;
switch (m_state) {
case none:
case ready:
if (PromptStr == line) {
// we get here after initialization
QTimer::singleShot(0, this, &DebugView::issueNextCommand);
}
break;
case executingCmd:
if (breakpointList.exactMatch(line)) {
m_state = listingBreakpoints;
emit clearBreakpointMarks();
m_breakPointList.clear();
} else if (line.contains(QLatin1String("No breakpoints or watchpoints."))) {
emit clearBreakpointMarks();
m_breakPointList.clear();
} else if (stackFrameAny.exactMatch(line)) {
if (m_lastCommand.contains(QLatin1String("info stack"))) {
emit stackFrameInfo(stackFrameAny.cap(1), stackFrameAny.cap(2));
} else {
m_subState = (m_subState == normal) ? stackFrameSeen : stackTraceSeen;
m_newFrameLevel = stackFrameAny.cap(1).toInt();
if (stackFrameFile.exactMatch(line)) {
m_newFrameFile = stackFrameFile.cap(4);
}
}
} else if (changeFile.exactMatch(line)) {
m_currentFile = changeFile.cap(1).trimmed();
int lineNum = changeFile.cap(2).toInt();
case none:
case ready:
if (PromptStr == line) {
// we get here after initialization
QTimer::singleShot(0, this, &DebugView::issueNextCommand);
}
break;
case executingCmd:
if (breakpointList.exactMatch(line)) {
m_state = listingBreakpoints;
emit clearBreakpointMarks();
m_breakPointList.clear();
} else if (line.contains(QLatin1String("No breakpoints or watchpoints."))) {
emit clearBreakpointMarks();
m_breakPointList.clear();
} else if (stackFrameAny.exactMatch(line)) {
if (m_lastCommand.contains(QLatin1String("info stack"))) {
emit stackFrameInfo(stackFrameAny.cap(1), stackFrameAny.cap(2));
} else {
m_subState = (m_subState == normal) ? stackFrameSeen : stackTraceSeen;
if (!m_nextCommands.contains(QLatin1String("continue"))) {
// GDB uses 1 based line numbers, kate uses 0 based...
emit debugLocationChanged(resolveFileName(m_currentFile), lineNum - 1);
}
m_debugLocationChanged = true;
} else if (changeLine.exactMatch(line)) {
int lineNum = changeLine.cap(1).toInt();
m_newFrameLevel = stackFrameAny.cap(1).toInt();
if (m_subState == stackFrameSeen) {
m_currentFile = m_newFrameFile;
}
if (!m_nextCommands.contains(QLatin1String("continue"))) {
// GDB uses 1 based line numbers, kate uses 0 based...
emit debugLocationChanged(resolveFileName(m_currentFile), lineNum - 1);
}
m_debugLocationChanged = true;
} else if (breakPointReg.exactMatch(line)) {
BreakPoint breakPoint;
breakPoint.number = breakPointReg.cap(1).toInt();
breakPoint.file = resolveFileName(breakPointReg.cap(2));
breakPoint.line = breakPointReg.cap(3).toInt();
m_breakPointList << breakPoint;
emit breakPointSet(breakPoint.file, breakPoint.line - 1);
} else if (breakPointMultiReg.exactMatch(line)) {
BreakPoint breakPoint;
breakPoint.number = breakPointMultiReg.cap(1).toInt();
breakPoint.file = resolveFileName(breakPointMultiReg.cap(2));
breakPoint.line = breakPointMultiReg.cap(3).toInt();
m_breakPointList << breakPoint;
emit breakPointSet(breakPoint.file, breakPoint.line - 1);
} else if (breakPointDel.exactMatch(line)) {
line.remove(QStringLiteral("Deleted breakpoint"));
line.remove(QLatin1Char('s')); // in case of multiple breakpoints
QStringList numbers = line.split(QLatin1Char(' '), QString::SkipEmptyParts);
for (int i = 0; i < numbers.size(); i++) {
for (int j = 0; j < m_breakPointList.size(); j++) {
if (numbers[i].toInt() == m_breakPointList[j].number) {
emit breakPointCleared(m_breakPointList[j].file, m_breakPointList[j].line - 1);
m_breakPointList.removeAt(j);
break;
}
}
}
} else if (exitProgram.exactMatch(line) || line.contains(QLatin1String("The program no longer exists")) || line.contains(QLatin1String("Kill the program being debugged"))) {
// if there are still commands to execute remove them to remove unneeded output
// except if the "kill was for "re-run"
if ((!m_nextCommands.empty()) && !m_nextCommands[0].contains(QLatin1String("file"))) {
m_nextCommands.clear();
if (stackFrameFile.exactMatch(line)) {
m_newFrameFile = stackFrameFile.cap(4);
}
m_debugLocationChanged = false; // do not insert (Q) commands
emit programEnded();
} else if (PromptStr == line) {
if (m_subState == stackFrameSeen) {
emit stackFrameChanged(m_newFrameLevel);
}
m_state = ready;
// Give the error a possibility get noticed since stderr and stdout are not in sync
QTimer::singleShot(0, this, &DebugView::issueNextCommand);
}
break;
} else if (changeFile.exactMatch(line)) {
m_currentFile = changeFile.cap(1).trimmed();
int lineNum = changeFile.cap(2).toInt();
case listingBreakpoints:
if (breakpointListed.exactMatch(line)) {
BreakPoint breakPoint;
breakPoint.number = breakpointListed.cap(1).toInt();
breakPoint.file = resolveFileName(breakpointListed.cap(2));
breakPoint.line = breakpointListed.cap(3).toInt();
m_breakPointList << breakPoint;
emit breakPointSet(breakPoint.file, breakPoint.line - 1);
} else if (PromptStr == line) {
m_state = ready;
QTimer::singleShot(0, this, &DebugView::issueNextCommand);
if (!m_nextCommands.contains(QLatin1String("continue"))) {
// GDB uses 1 based line numbers, kate uses 0 based...
emit debugLocationChanged(resolveFileName(m_currentFile), lineNum - 1);
}
break;
case infoArgs:
if (PromptStr == line) {
m_state = ready;
QTimer::singleShot(0, this, &DebugView::issueNextCommand);
} else {
emit infoLocal(line);
m_debugLocationChanged = true;
} else if (changeLine.exactMatch(line)) {
int lineNum = changeLine.cap(1).toInt();
if (m_subState == stackFrameSeen) {
m_currentFile = m_newFrameFile;
}
break;
case printThis:
if (PromptStr == line) {
m_state = ready;
QTimer::singleShot(0, this, &DebugView::issueNextCommand);
} else {
emit infoLocal(line);
if (!m_nextCommands.contains(QLatin1String("continue"))) {
// GDB uses 1 based line numbers, kate uses 0 based...
emit debugLocationChanged(resolveFileName(m_currentFile), lineNum - 1);
}
break;
case infoLocals:
if (PromptStr == line) {
m_state = ready;
emit infoLocal(QString());
QTimer::singleShot(0, this, &DebugView::issueNextCommand);
} else {
emit infoLocal(line);
m_debugLocationChanged = true;
} else if (breakPointReg.exactMatch(line)) {
BreakPoint breakPoint;
breakPoint.number = breakPointReg.cap(1).toInt();
breakPoint.file = resolveFileName(breakPointReg.cap(2));
breakPoint.line = breakPointReg.cap(3).toInt();
m_breakPointList << breakPoint;
emit breakPointSet(breakPoint.file, breakPoint.line - 1);
} else if (breakPointMultiReg.exactMatch(line)) {
BreakPoint breakPoint;
breakPoint.number = breakPointMultiReg