[education/rkward] /: Code formatting
Thomas Friedrichsmeier
null at kde.org
Mon May 26 15:06:38 BST 2025
Git commit fcfbc1c70d9d91cb951109989f064a40d9074b73 by Thomas Friedrichsmeier.
Committed on 26/05/2025 at 14:06.
Pushed by tfry into branch 'master'.
Code formatting
M +4 -0 .clang-format
M +2 -2 rkward/autotests/rkparsedscript_test.cpp
M +1 -4 rkward/main.cpp
M +2 -2 rkward/misc/rkoutputdirectory.h
M +7 -6 rkward/misc/rkparsedscript.cpp
M +5 -5 rkward/misc/rkparsedscript.h
M +0 -1 rkward/scriptbackends/rkcomponentscripting.cpp
M +5 -3 rkward/windows/rkcommandeditorwindow.cpp
https://invent.kde.org/education/rkward/-/commit/fcfbc1c70d9d91cb951109989f064a40d9074b73
diff --git a/.clang-format b/.clang-format
index 7cd590823..357f2f125 100644
--- a/.clang-format
+++ b/.clang-format
@@ -13,3 +13,7 @@ BinPackArguments: true
AllowAllArgumentsOnNextLine: true
AllowShortIfStatementsOnASingleLine: AllIfsAndElse
IndentPPDirectives: AfterHash
+SpacesInLineCommentPrefix:
+ Maximum: -1
+ Minimum: 0
+SpaceBeforeCpp11BracedList: false
diff --git a/rkward/autotests/rkparsedscript_test.cpp b/rkward/autotests/rkparsedscript_test.cpp
index d9f0e0a15..ae282a439 100644
--- a/rkward/autotests/rkparsedscript_test.cpp
+++ b/rkward/autotests/rkparsedscript_test.cpp
@@ -41,7 +41,7 @@ class RKParsedScriptTest : public QObject {
QString script;
RKParsedScript ps;
- void loadScript(const QString &relname, bool rmd=false) {
+ void loadScript(const QString &relname, bool rmd = false) {
QFile f(QStringLiteral(TEST_DATA_DIR) + relname);
bool ok = f.open(QIODevice::ReadOnly | QIODevice::Text);
QVERIFY(ok);
@@ -244,7 +244,7 @@ class RKParsedScriptTest : public QObject {
void range() {
loadScript(u"script1.R"_s);
auto ctx = ps.contextAtPos(script.indexOf(u"Symbol01"));
- QCOMPARE(script.mid(ps.lastPositionInStatement(ctx)+1, 9), u"\nSymbol19"_s);
+ QCOMPARE(script.mid(ps.lastPositionInStatement(ctx) + 1, 9), u"\nSymbol19"_s);
ctx = ps.contextAtPos(script.indexOf(u"Symbol08"));
QCOMPARE(script.at(ps.lastPositionInStatement(ctx)), u']');
}
diff --git a/rkward/main.cpp b/rkward/main.cpp
index b027d9ad6..e5c7c9a00 100644
--- a/rkward/main.cpp
+++ b/rkward/main.cpp
@@ -212,10 +212,7 @@ int main(int argc, char *argv[]) {
RK_DEBUG(APP, DL_INFO, "Failed to open debug file %s", qPrintable(RK_Debug::debug_file->fileName()));
}
qInstallMessageHandler(RKDebugMessageOutput);
- RK_DO({
- RK_DEBUG(APP, DL_DEBUG, "Basic runtime info (expected to be incomplete at this stage):\n%s", qPrintable(RKSessionVars::frontendSessionInfo().join(u"\n"_s)));
- },
- APP, DL_DEBUG);
+ RK_DO({ RK_DEBUG(APP, DL_DEBUG, "Basic runtime info (expected to be incomplete at this stage):\n%s", qPrintable(RKSessionVars::frontendSessionInfo().join(u"\n"_s))); }, APP, DL_DEBUG);
// MacOS may need some path adjustments, first
#if defined(Q_OS_MACOS)
diff --git a/rkward/misc/rkoutputdirectory.h b/rkward/misc/rkoutputdirectory.h
index 92f5c443a..c61aa6efb 100644
--- a/rkward/misc/rkoutputdirectory.h
+++ b/rkward/misc/rkoutputdirectory.h
@@ -24,8 +24,8 @@ class RKOutputDirectory;
/** Convenience struct to avoid defining separate functions for R API and C++ API in RKOutputDirectory.
* This struct encapsulates the relevant results for both */
struct RKOutputDirectoryCallResult : public GenericRRequestResult {
- RKOutputDirectoryCallResult() : GenericRRequestResult(), _dir(nullptr) {};
- RKOutputDirectoryCallResult(const GenericRRequestResult &other) : GenericRRequestResult(other), _dir(nullptr) {};
+ RKOutputDirectoryCallResult() : GenericRRequestResult(), _dir(nullptr){};
+ RKOutputDirectoryCallResult(const GenericRRequestResult &other) : GenericRRequestResult(other), _dir(nullptr){};
void setDir(RKOutputDirectory *d);
RKOutputDirectory *dir() const { return _dir; }
diff --git a/rkward/misc/rkparsedscript.cpp b/rkward/misc/rkparsedscript.cpp
index a744b742e..71f3dcbfd 100644
--- a/rkward/misc/rkparsedscript.cpp
+++ b/rkward/misc/rkparsedscript.cpp
@@ -62,11 +62,11 @@ int RKParsedScript::addNextMarkdownChunk(int start, const QString &content) {
int chunkend = content.indexOf(chunk_barrier, chunkstart);
if (chunkend < 0) chunkend = content.size();
- context_list.emplace_back(Comment, start, chunkstart-1);
- prevtype = Comment; // causes insertion of a delimiter in the following addContext
- addContext(Top, chunkstart-1, content.left(chunkend)); // in case markdown region has incomplete syntax
- // limit parsing to the actual markdown region
- context_list.emplace_back(Top, chunkend, chunkend); // HACK: Used as a dummy separtor, here...
+ context_list.emplace_back(Comment, start, chunkstart - 1);
+ prevtype = Comment; // causes insertion of a delimiter in the following addContext
+ addContext(Top, chunkstart - 1, content.left(chunkend)); // in case markdown region has incomplete syntax
+ // limit parsing to the actual markdown region
+ context_list.emplace_back(Top, chunkend, chunkend); // HACK: Used as a dummy separtor, here...
return chunkend + chunk_barrier.length();
}
@@ -294,7 +294,8 @@ RKParsedScript::ContextIndex RKParsedScript::nextStatement(const ContextIndex fr
// forward past end of current statement
auto ni = nextContext(lastContextInStatement(from));
// consider advancing from "b" in "a = (b + c) + d; e" -> should be e, not "+ d"
- while (ni.valid() && getContext(ni).type != Delimiter) ni = nextContext(lastContextInStatement(ni));
+ while (ni.valid() && getContext(ni).type != Delimiter)
+ ni = nextContext(lastContextInStatement(ni));
// skip over any following non-interesting contexts
while (ni.valid()) {
auto type = getContext(ni).type;
diff --git a/rkward/misc/rkparsedscript.h b/rkward/misc/rkparsedscript.h
index d25c1c6ca..6c2ecbefe 100644
--- a/rkward/misc/rkparsedscript.h
+++ b/rkward/misc/rkparsedscript.h
@@ -43,15 +43,15 @@ class RKParsedScript {
};
struct Context {
- Context(ContextType type, int start) : type(type), start(start) {};
- Context(ContextType type, int start, int end) : type(type), start(start), end(end) {};
+ Context(ContextType type, int start) : type(type), start(start){};
+ Context(ContextType type, int start, int end) : type(type), start(start), end(end){};
bool maybeNesting() const { return (type == Parenthesis || type == Brace || type == Bracket || type == Top); };
ContextType type;
int start;
int end;
};
- explicit RKParsedScript(const QString &content = QString(), bool rmd=false);
+ explicit RKParsedScript(const QString &content = QString(), bool rmd = false);
enum SearchFlags {
NoFlags,
@@ -61,8 +61,8 @@ class RKParsedScript {
/** Helper struct to enforce strict type checking between character position, and index of context */
struct ContextIndex {
- ContextIndex() : index(-1) {};
- explicit ContextIndex(int index) : index(index) {};
+ ContextIndex() : index(-1){};
+ explicit ContextIndex(int index) : index(index){};
bool valid() const { return index >= 0; };
bool operator==(const ContextIndex &other) const { return index == other.index; };
bool operator!=(const ContextIndex &other) const { return index != other.index; };
diff --git a/rkward/scriptbackends/rkcomponentscripting.cpp b/rkward/scriptbackends/rkcomponentscripting.cpp
index 57af6dd3b..a4fe33683 100644
--- a/rkward/scriptbackends/rkcomponentscripting.cpp
+++ b/rkward/scriptbackends/rkcomponentscripting.cpp
@@ -112,7 +112,6 @@ void RKComponentScriptingProxy::addChangeCommand(const QStringList &changed_ids,
return;
}
-
if (base->isComponent()) {
connect(static_cast<RKComponent *>(base), &RKComponent::componentChanged, this, callback);
} else {
diff --git a/rkward/windows/rkcommandeditorwindow.cpp b/rkward/windows/rkcommandeditorwindow.cpp
index 5d4edb1e6..33f4472bb 100644
--- a/rkward/windows/rkcommandeditorwindow.cpp
+++ b/rkward/windows/rkcommandeditorwindow.cpp
@@ -30,12 +30,12 @@ SPDX-License-Identifier: GPL-2.0-or-later
#include <QTemporaryFile>
#include <QTimer>
+#include <KColorScheme>
#include <KIO/DeleteJob>
#include <KIO/FileCopyJob>
#include <KLocalizedString>
#include <kactioncollection.h>
#include <kactionmenu.h>
-#include <KColorScheme>
#include <kconfiggroup.h>
#include <kmessagebox.h>
#include <krandom.h>
@@ -105,7 +105,7 @@ class RKCodeNavigation : public QWidget {
int cursorToPosition(const KTextEditor::Cursor &cursor) {
int pos = cursor.column();
for (int l = 0; l < cursor.line(); ++l) {
- pos += doc->lineLength(l) + 1;
+ pos += doc->lineLength(l) + 1;
}
return pos;
}
@@ -157,7 +157,7 @@ class RKCodeNavigation : public QWidget {
} else if (command == u's') {
auto posa = ps.getContext(ps.firstContextInStatement(ci)).start;
auto posb = ps.lastPositionInStatement(ci);
- newpos.selection = KTextEditor::Range(positionToCursor(posa), positionToCursor(posb+1));
+ newpos.selection = KTextEditor::Range(positionToCursor(posa), positionToCursor(posb + 1));
} else {
RK_DEBUG(COMMANDEDITOR, DL_WARNING, "unknown navigation commmand");
// TODO: show error
@@ -182,6 +182,7 @@ class RKCodeNavigation : public QWidget {
}
return false;
}
+
public:
static void doNavigation(KTextEditor::View *view) {
auto w = new RKCodeNavigation(view);
@@ -189,6 +190,7 @@ class RKCodeNavigation : public QWidget {
w->updatePos();
w->input->setFocus();
}
+
private:
KTextEditor::View *view;
KTextEditor::Document *doc;
More information about the rkward-tracker
mailing list