[utilities/kate] /: formatting: support fish_indent, dfmt, nixfmt, shfmt

Waqar Ahmed null at kde.org
Wed May 15 13:42:58 BST 2024


Git commit 583fea1bb3003948fced657be608f9cec2ad1f10 by Waqar Ahmed.
Committed on 15/05/2024 at 12:42.
Pushed by waqar into branch 'master'.

formatting: support fish_indent, dfmt, nixfmt, shfmt

M  +8    -0    addons/format/FormatterFactory.h
M  +12   -0    addons/format/FormatterSettings.json
M  +11   -0    addons/format/Formatters.h
M  +10   -12   doc/kate/plugins.docbook

https://invent.kde.org/utilities/kate/-/commit/583fea1bb3003948fced657be608f9cec2ad1f10

diff --git a/addons/format/FormatterFactory.h b/addons/format/FormatterFactory.h
index 3dd19dab2d..63b4df6c85 100644
--- a/addons/format/FormatterFactory.h
+++ b/addons/format/FormatterFactory.h
@@ -63,6 +63,14 @@ static AbstractFormatter *formatterForDoc(KTextEditor::Document *doc, const QJso
         }
         Utils::showMessage(i18n("Unknown formatterForPython: %1", configValue), {}, i18n("Format"), MessageType::Error);
         return ruffFormat(config, doc);
+    } else if (is("d")) {
+        return dfmt(config, doc);
+    } else if (is("fish")) {
+        return fishIndent(config, doc);
+    } else if (is("bash")) {
+        return shfmt(config, doc);
+    } else if (is("nixfmt")) {
+        return nixfmt(config, doc);
     }
 
     static QList<QString> alreadyWarned;
diff --git a/addons/format/FormatterSettings.json b/addons/format/FormatterSettings.json
index a92d7dbfdf..4e7bdf76ca 100644
--- a/addons/format/FormatterSettings.json
+++ b/addons/format/FormatterSettings.json
@@ -36,5 +36,17 @@
     },
     "ruff": {
         "command": ["ruff"]
+    },
+    "dfmt": {
+        "command": ["dfmt"]
+    },
+    "fish_indent": {
+        "command": ["fish_indent"]
+    },
+    "shfmt": {
+        "command": ["shfmt"]
+    },
+    "nixfmt": {
+        "command": ["nixfmt"]
     }
 }
diff --git a/addons/format/Formatters.h b/addons/format/Formatters.h
index c231cb0d3f..9aad32c476 100644
--- a/addons/format/Formatters.h
+++ b/addons/format/Formatters.h
@@ -297,6 +297,17 @@ DEFINE_STDIN_FORMATTER(ruffFormat, "ruff", (QStringList{S("format"), S("-q"), S(
 DEFINE_STDIN_FORMATTER(goFormat, "gofmt", (QStringList{}));
 DEFINE_STDIN_FORMATTER(autoPep8Format, "autopep8", (QStringList{S("-")}));
 DEFINE_STDIN_FORMATTER(cMakeFormat, "cmake-format", (QStringList{S("-")}));
+DEFINE_STDIN_FORMATTER(dfmt, "dfmt", (QStringList{}));
+DEFINE_STDIN_FORMATTER(fishIndent, "fish_indent", (QStringList{}));
+DEFINE_STDIN_FORMATTER(nixfmt, "nixfmt", (QStringList{}));
+
+inline AbstractFormatter *shfmt(const QJsonObject &obj, KTextEditor::Document *parent)
+{
+    int width = parent->configValue(QStringLiteral("indent-width")).toInt();
+    width = width == 0 ? 4 : width;
+    bool spaces = parent->configValue(QStringLiteral("replace-tabs")).toBool();
+    return new StdinFormatter(obj, parent, QStringLiteral("shfmt"), QStringList{QStringLiteral("--indent"), QString::number(spaces ? width : 0)});
+}
 
 #undef S
 #undef DEFINE_STDIN_FORMATTER
diff --git a/doc/kate/plugins.docbook b/doc/kate/plugins.docbook
index 7d6b16abaf..2fcf5f71c1 100644
--- a/doc/kate/plugins.docbook
+++ b/doc/kate/plugins.docbook
@@ -4455,18 +4455,16 @@ The current list of supported languages and formatters are as follows:
 </itemizedlist>
 </para></listitem>
 
-<listitem><para>Dart - <command>dartfmt</command>
-</para></listitem>
-<listitem><para>Rust - <command>rustfmt</command>
-</para></listitem>
-<listitem><para>Go - <command>gofmt</command>
-</para></listitem>
-<listitem><para>XML - <command>xmllint</command>
-</para></listitem>
-<listitem><para>Zig - <command>zigfmt</command>
-</para></listitem>
-<listitem><para>CMake - <command>cmake-format</command>
-</para></listitem>
+<listitem><para>Dart - <command>dartfmt</command></para></listitem>
+<listitem><para>Rust - <command>rustfmt</command></para></listitem>
+<listitem><para>Go - <command>gofmt</command></para></listitem>
+<listitem><para>XML - <command>xmllint</command></para></listitem>
+<listitem><para>Zig - <command>zigfmt</command></para></listitem>
+<listitem><para>CMake - <command>cmake-format</command></para></listitem>
+<listitem><para>D - <command>dfmt</command></para></listitem>
+<listitem><para>Fish Shell - <command>fish_indent</command></para></listitem>
+<listitem><para>Bash - <command>shfmt</command></para></listitem>
+<listitem><para>Nix - <command>nixfmt</command></para></listitem>
 
 <listitem><para>Python
 <itemizedlist>


More information about the kde-doc-english mailing list