kate: templates rewrite and implement cursor

I guess selection was something unfinished/experimental

Signed-off-by: Ivailo Monev <xakepa10@gmail.com>
This commit is contained in:
Ivailo Monev 2023-05-23 03:42:49 +03:00
parent b117de749a
commit 74a63ed2fe
10 changed files with 100 additions and 184 deletions

View file

@ -2,11 +2,9 @@
install( install(
FILES FILES
html.katetemplate
cpplgpl.cpp.katetemplate cpplgpl.cpp.katetemplate
cpplgpl.hh.katetemplate cpplgpl.h.katetemplate
cppgpl.cpp.katetemplate cppgpl.cpp.katetemplate
cppgpl.hh.katetemplate cppgpl.h.katetemplate
language.xml.katetemplate
DESTINATION ${KDE4_DATA_INSTALL_DIR}/kate/plugins/katefiletemplates/templates DESTINATION ${KDE4_DATA_INSTALL_DIR}/kate/plugins/katefiletemplates/templates
) )

View file

@ -1,24 +1,23 @@
katetemplate: template=C++ Source File (GPL) group=Source Code documentname=New%N.cpp highlight=C++ katetemplate: template=C++ Source File (GPL) group=Source Code documentname=New%N.cpp highlight=C++
katetemplate: description=A very simple GPL C++ source file katetemplate: description=A very simple GPL C++ source file
katetemplate: author= Anders Lund <anders@alweb.dk> katetemplate: author=Ivailo Monev <xakepa10@gmail.com>
/* /* This file is part of the KDE project
This program is free software; you can redistribute it and/or Copyright (C) %{year} %{fullname} <%{email}>
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful, This library is free software; you can redistribute it and/or
but WITHOUT ANY WARRANTY; without even the implied warranty of modify it under the terms of the GNU Library General Public
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the License as published by the Free Software Foundation; either
GNU General Public License for more details. version 2 of the License, or (at your option) any later version.
You should have received a copy of the GNU General Public License This library is distributed in the hope that it will be useful,
along with this program; if not, write to the Free Software but WITHOUT ANY WARRANTY; without even the implied warranty of
Foundation, Inc., 51 Franklin Street, Fifth Floor, MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Boston, MA 02110-1301, USA. Library General Public License for more details.
--- You should have received a copy of the GNU Library General Public License
Copyright (C) %{year}, %{fullname} <%{email}> along with this library; see the file COPYING.LIB. If not, write to
*/ the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
Boston, MA 02110-1301, USA.
*/
${cursor} %{cursor}

View file

@ -0,0 +1,24 @@
katetemplate: template=C++ Header (GPL) group=Source Code documentname=New%N.h highlight=C++
katetemplate: description=A very simple GPL C++ header file
katetemplate: author=Ivailo Monev <xakepa10@gmail.com>
/* This file is part of the KDE project
Copyright (C) %{year} %{fullname} <%{email}>
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Library General Public
License as published by the Free Software Foundation; either
version 2 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Library General Public License for more details.
You should have received a copy of the GNU Library General Public License
along with this library; see the file COPYING.LIB. If not, write to
the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
Boston, MA 02110-1301, USA.
*/
%{cursor}

View file

@ -1,34 +0,0 @@
katetemplate: template=C++ Header (GPL) group=Source Code documentname=New%N.hh highlight=C++
katetemplate: description=A very simple GPL C++ header file
katetemplate: author= Anders Lund <anders@alweb.dk>
/*
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor,
Boston, MA 02110-1301, USA.
---
Copyright (C) %{year}, %{fullname} <%{email}>
*/
#ifndef _${ClassName}_h_
#define _${ClassName}_h_
class ${ClassName} : public ${Super} {
public:
${ClassName}( ${cursor} );
~${ClassName}();
}
#endif // _${ClassName}_h_

View file

@ -1,23 +1,23 @@
katetemplate: template=C++ Source File (LGPL) group=Source Code documentname=New%N.cpp highlight=C++ katetemplate: template=C++ Source File (LGPL) group=Source Code documentname=New%N.cpp highlight=C++
katetemplate: description=A very simple LGPL C++ source file katetemplate: description=A very simple LGPL C++ source file
katetemplate: author= Anders Lund <anders@alweb.dk> katetemplate: author=Ivailo Monev <xakepa10@gmail.com>
/* /* This file is part of the KDE project
This library is free software; you can redistribute it and/or Copyright (C) %{year} %{fullname} <%{email}>
modify it under the terms of the GNU Library General Public
License version 2 as published by the Free Software Foundation.
This library is distributed in the hope that it will be useful, This library is free software; you can redistribute it and/or
but WITHOUT ANY WARRANTY; without even the implied warranty of modify it under the terms of the GNU Library General Public
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU License as published by the Free Software Foundation; either
Library General Public License for more details. version 2 of the License, or (at your option) any later version.
You should have received a copy of the GNU Library General Public License This library is distributed in the hope that it will be useful,
along with this library; see the file COPYING.LIB. If not, write to but WITHOUT ANY WARRANTY; without even the implied warranty of
the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Boston, MA 02110-1301, USA. Library General Public License for more details.
--- You should have received a copy of the GNU Library General Public License
Copyright (C) %{year}, %{fullname} <%{email}> along with this library; see the file COPYING.LIB. If not, write to
the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
Boston, MA 02110-1301, USA.
*/ */
${cursor} %{cursor}

View file

@ -0,0 +1,23 @@
katetemplate: template=C++ Header (LGPL) group=Source Code documentname=New%N.h highlight=C++
katetemplate: description=A very simple LGPL C++ header file
katetemplate: author=Ivailo Monev <xakepa10@gmail.com>
/* This file is part of the KDE project
Copyright (C) %{year} %{fullname} <%{email}>
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Library General Public
License as published by the Free Software Foundation; either
version 2 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Library General Public License for more details.
You should have received a copy of the GNU Library General Public License
along with this library; see the file COPYING.LIB. If not, write to
the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
Boston, MA 02110-1301, USA.
*/
%{cursor}

View file

@ -1,32 +0,0 @@
katetemplate: template=C++ Header (LGPL) group=Source Code documentname=New%N.hh highlight=C++
katetemplate: description=A very simple LGPL C++ header file
katetemplate: author= Anders Lund <anders@alweb.dk>
/*
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Library General Public
License version 2 as published by the Free Software Foundation.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Library General Public License for more details.
You should have received a copy of the GNU Library General Public License
along with this library; see the file COPYING.LIB. If not, write to
the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
Boston, MA 02110-1301, USA.
---
Copyright (C) %{year}, %{fullname} <%{email}>
*/
#ifndef _${ClassName}_h_
#define _${ClassName}_h_
class ${ClassName} : public ${Super} {
public:
${ClassName}( ${cursor} );
~${ClassName}();
}
#endif // _${ClassName}_h_

View file

@ -1,18 +0,0 @@
katetemplate: template=HTML 4.01 Strict Document documentname=New%N.html
katetemplate: highlight=HTML group=Internet icon=www
katetemplate: description=This will create a very basic HTML file with the HTML 4.01 strict DTD.
katetemplate: author=Anders Lund <anders@alweb.dk>
katetemplate: this text is supposedly thrown away.
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
"http://www.w3.org/TR/html4/strict.dtd">
<html>
<!-- Copyright (C) %{year} %{fullname} <%{email}> -->
<head>
<title>${title}</title>
<link rel="author" title="%{fullname}" href="mailto: (%{author}) %{email}">
</head>
<body>
<h1>${title}</h1>
${cursor}
</body>
</html>

View file

@ -1,60 +0,0 @@
katetemplate: Documentname=New language.xml (%N) Template=Kate Highlight Definition highlight=XML
katetemplate: Author=Dominik Haumann <dhdev@gmx.de>
katetemplate: Description=This template will create the basics of a kate highlight definition file.
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE language SYSTEM "language.dtd">
<!--
This file is part of KDE's kate project.
copyright : (C) %{year} by %{fullname}
email : %{email}
This file is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
-->
<!--
You'll find the "Writing a Kate Highlighting XML File HOWTO" at
http://kate.kde.org/doc/hlhowto.php
This is a template for the XML format used for syntax highlight descriptions
for the Kate text editor (http://kate.kde.org), which is part of the KDE
desktop environment (http://www.kde.org).
Use it as the base for your own syntax files.
Look at language.dtd for some documentation of the allowed elements and their attributes.
There is also a description of how to validate your syntax file.
You'll find the "Writing a Kate Highlighting XML File HOWTO" at
http://kate.kde.org/doc/hlhowto.php
-->
<language version="1.00" kateversion="2.4" name="${cursor}" section="${section}" extensions="${extensions}" mimetype="${mimetypes}" author="%{fullname}" licence="GPL">
<highlighting>
<!--
<list name="aList">
<item></item>
</list>
-->
<contexts>
<context attribute="Normal Text" lineEndContext="#pop" name="Normal Text" >
<!-- <keyword attribute="Normal Text" context="#stay" String="aList" />
-->
</context>
</contexts>
<itemDatas>
<itemData name="Normal Text" defStyleNum="dsNormal"/>
</itemDatas>
</highlighting>
<general>
<keywords casesensitive="1" />
<!--
<comments>
<comment name="singleLine" start="" />
<comment name="multiLine" start="" end="" />
</comments>
-->
</general>
</language>
<!-- kate: space-indent on; indent-width 2; replace-tabs on; indent-mode xml; -->

View file

@ -2133,11 +2133,27 @@ bool KateView::insertTemplateTextImplementation ( const KTextEditor::Cursor& c,
docText.replace(toreplace, it.value()); docText.replace(toreplace, it.value());
it++; it++;
} }
// TODO: handle %{cursor} and %{selection}
// TODO: ${foo} references in templates could be Shell variable - what now?
KTextEditor::Cursor viewCursor = cursorPosition();
m_doc->insertText( c, docText ); m_doc->insertText( c, docText );
const QStringList docLines = docText.split(QLatin1Char('\n'));
for (int i = 0; i < docLines.size(); i++) {
const int cursorIndex = docLines.at(i).indexOf(QLatin1String("%{cursor}"));
if (cursorIndex != -1) {
m_doc->editRemoveText(i, cursorIndex, 9);
const int viewLine = viewCursor.line();
viewCursor.setLine(viewLine + i);
viewCursor.setColumn(cursorIndex);
setCursorPosition(viewCursor);
break;
}
}
// TODO: handle %{selection}, selection begin and end?
return true; return true;
} }