New plugins to the Kate, utils to: Python, JavaScript, Django and XML

The project plugin in kate.git master now has four new more plugins, with many features in each one: Python (autocomplete, smart snippets, parse checker, pep8 checker and pyflakes checker), Javascript (autocompletes, jquery snippet, pretty JSON, and jslint checker), Django (smart snippets and utils to Django template) and XML (pretty xml). There are also many generic functions and generic classes in these that will be useful to the new plugins developers.

I began to develop these plugins in 2009, this was my first version :-). I wanted to set a shortcut to a snippet, as it was not possible (now it is posible) I started to develop these plugins to Kate.

In November 2011, I created a repository on github to develop new features and share them. I have to thank Alejandro Blanco, Jeroen van Veen, Javier Romero, Martin Borho, Justin Chudgar and Yaco Sistemas for helping me in this project.

In October 2012 Christoph Cullmann (Kate maintainer) sent me an e-mail, in which he asked me if I was interested to contribute with KDE project. I answered: “Of course!”…. finally I have a little time, and I have been able to integrate these plugins in the kate.git

Features to Python Plugin:

  • Python dynamic autocomplete using pyplete, this is in beta… It requires development, but now it is very useful.
  • Smart snippets:
    1. Insert an __init__ method into a class.
    2. Insert a super call into a method.
    3. Insert a call recursive into a method or into a function
  • Simple snippet: Insert the debug instrunctions “import ipdb; ipdb.set_trace()”
  • Checkers: When you save the file it is syntax checked, pep8 checked and pyflakes checked. You can invocate them any other time.


Python auto complete

Features to Javascript Plugin:

  • JavaScript static autocomplete, using a JSON file.
  • JQuery static autocomplete using a JSON file.
  • Pretty JSON: Pretty format of a JSON code selected
  • JSLint checker: When you save the file it is JSLint checked. You can invocate it any other time.
  • JQuery snippet, insert the ready code of the jQuery

JSLint checker

Features to Django Plugin:

  • Smart snippets:
    1. Create a model class
    2. Create a form class
    3. Template to the urls.py file
  • Simple snippet: Insert the typical imports of a views.py file
  • Template Django utils
    1. Insert the tag block/endblock. The name of the block will be the text selected
    2. Close the last templatetag open

Create a form class

Pretty XML:

Pretty format of an XML code selected

Pretty XML

Generic features:

Also I have added many generic functions and generic classes, likely the more outstanding are the autocompletations. Now you can create a code completion model with very few lines:

import kate
from libkatepate.autocomplete import AbstractJSONFileCodeCompletionModel, reset

class MyCodeCompletionModel(AbstractJSONFileCodeCompletionModel):

    MIMETYPES = [] # List of mimetypes E.G.: ['application/javascript', 'text/html']
    TITLE_AUTOCOMPLETION = "My Auto Completion Model"
    FILE_PATH = 'my_autocompletion.json'
    # Operators to separate the instrunctions
    OPERATORS = ["=", " ", "[", "]", "(", ")", "{", "}", ":", ">", "<",
                 "+", "-", "*", "/", "%", " && ", " || ", ","]

@kate.init
@kate.viewCreated
def createSignalAutocompleteJS(view=None, *args, **kwargs):
    view = view or kate.activeView()
    cci = view.codeCompletionInterface()
    cci.registerCompletionModel(my_code_completion_model)

my_code_completion_model = MyCodeCompletionModel(kate.application)
my_code_completion_model.modelReset.connect(reset)

The my_autocompletion.json file should have this format:

  {
    "xxx": {
      "category": "module",
      "children": {
        "www": {
          "category": "class",
          "children": {}
        },
        "yyy": {
          "category": "constant",
          "children": {}
        },
        "zzz": {
          "category": "function",
          "args": "(x1, x2, x3)",
          "children": {}
        }
      }
    }
  }

I encourage you to participate in the KDE project, for me this participation has been very simple because this community is very, very open.

Thanks all,

34 thoughts on “New plugins to the Kate, utils to: Python, JavaScript, Django and XML”

  1. Sounds pretty cool, I’ve been missing a jslint/jshint integration for kate for a long time.

    Unfortunately, js_utils seems to be depending on a non-existing version of pyjslint.

    When I try to install pyjslint with “easy_install pyjslint=0.6.0″ like the error message suggests, easy_install can’t find that version. The newest version is 0.3.3.

    I’m using latest git checkout of kate.git

  2. jslint just got experimental color highlighting:

    https://plus.google.com/118095276221607585885/posts/FzKnHk96m2C

    I have added an experimental context coloring feature to JSLint.
    It is intended to provide context coloring in text editors and
    IDEs. Context coloring gives a different color to each level of
    function nesting. Variables are displayed with the color in
    which they were defined. Context coloring makes it easier to
    see the structure of programs and the closure of variables.

  3. how to get python support in kate 4.10?
    I’m currently using kde 4.10 on ubuntu.. should I wait for 4.11 or it is possible to get plugins via sources?

          1. It works quite well.. unfortunately autocomplete function doesn’t see builtin modules like os. or sys., just the dist-packages modules.

            it doesn’t autocomplete also local variables..

            it probably needs some more love :)

          1. lucazade for this I said: “Python dynamic autocomplete using pyplete, this is in beta… It requires development, but now it is very useful.”.

            I thought that this feature required development… but if you think that this needs love… it’s possible that you had to present something for the Valentine’s day :-)

            Seriously, I you (or someone) want to help me…. I will be happy for it

            https://github.com/goinnn/pyplete

  4. Hello, I’m using Chakra Linux with 4.10 and tried to install those plugins in got this result.

    kate(4763)/Kate (Plugins): “Traceback (most recent call last):
    File “/home/user/.kde4/share/apps/kate/pate/kate_plugins.py”, line 47, in
    from pyte_plugins.check_plugins.pep8_plugins import *
    File “/home/user/.kde4/share/apps/kate/pate/pyte_plugins/check_plugins/pep8_plugins.py”, line 30, in
    class KateReport(pep8.BaseReport):
    AttributeError: ‘module’ object has no attribute ‘BaseReport’
    Could not import kate_plugins”
    kate(4763)/Kate (Plugins): “Traceback (most recent call last):
    File “/home/user/.kde4/share/apps/kate/pate/kate_plugins.py”, line 47, in
    from pyte_plugins.check_plugins.pep8_plugins import *
    File “/home/user/.kde4/share/apps/kate/pate/pyte_plugins/check_plugins/pep8_plugins.py”, line 30, in
    class KateReport(pep8.BaseReport):
    AttributeError: ‘module’ object has no attribute ‘BaseReport’
    Could not import kate_plugins”
    kate(4763)/Kate (Plugins): “Traceback (most recent call last):
    File “/home/user/.kde4/share/apps/kate/pate/kate_plugins.py”, line 47, in
    from pyte_plugins.check_plugins.pep8_plugins import *
    File “/home/user/.kde4/share/apps/kate/pate/pyte_plugins/check_plugins/pep8_plugins.py”, line 30, in
    class KateReport(pep8.BaseReport):
    AttributeError: ‘module’ object has no attribute ‘BaseReport’
    Could not import kate_plugins”
    kate(4763)/Kate (Plugins): “Traceback (most recent call last):
    File “/home/user/.kde4/share/apps/kate/pate/kate_plugins.py”, line 47, in
    from pyte_plugins.check_plugins.pep8_plugins import *
    File “/home/user/.kde4/share/apps/kate/pate/pyte_plugins/check_plugins/pep8_plugins.py”, line 30, in
    class KateReport(pep8.BaseReport):
    AttributeError: ‘module’ object has no attribute ‘BaseReport’
    Could not import kate_plugins”
    kate(4763)/Kate (Plugins): “Traceback (most recent call last):
    File “/home/user/.kde4/share/apps/kate/pate/kate_plugins.py”, line 47, in
    from pyte_plugins.check_plugins.pep8_plugins import *
    File “/home/user/.kde4/share/apps/kate/pate/pyte_plugins/check_plugins/pep8_plugins.py”, line 30, in
    class KateReport(pep8.BaseReport):
    AttributeError: ‘module’ object has no attribute ‘BaseReport’
    Could not import kate_plugins”
    kate(4763)/Kate (Plugins): “Traceback (most recent call last):
    File “/home/user/.kde4/share/apps/kate/pate/kate_plugins.py”, line 47, in
    from pyte_plugins.check_plugins.pep8_plugins import *
    File “/home/user/.kde4/share/apps/kate/pate/pyte_plugins/check_plugins/pep8_plugins.py”, line 30, in
    class KateReport(pep8.BaseReport):
    AttributeError: ‘module’ object has no attribute ‘BaseReport’
    Could not import kate_plugins”
    kate(4763)/Kate (Plugins): “Traceback (most recent call last):
    File “/home/user/.kde4/share/apps/kate/pate/kate_plugins.py”, line 47, in
    from pyte_plugins.check_plugins.pep8_plugins import *
    File “/home/user/.kde4/share/apps/kate/pate/pyte_plugins/check_plugins/pep8_plugins.py”, line 30, in
    class KateReport(pep8.BaseReport):
    AttributeError: ‘module’ object has no attribute ‘BaseReport’
    Could not import kate_plugins”
    Traceback (most recent call last):
    File “/usr/share/apps/kate/plugins/pate/kate/__init__.py”, line 211, in _callAll
    f(*args, **kwargs)
    File “/home/user/.kde4/share/apps/kate/pate/kate_settings_plugins.py”, line 34, in move_menus
    move_menu_submenu(py_menu_slug, dj_menu_slug)
    File “/home/user/.kde4/share/apps/kate/pate/kate_core_plugins.py”, line 124, in move_menu_submenu
    action = QtGui.QAction(action_menubar.text(), submenu)
    AttributeError: ‘NoneType’ object has no attribute ‘text’

    Any ideas to solve this issue?

    Regards.

  5. I’ve installed these plugins and they seem to be working OK but I have a question: How do I configure pep8? I see that there’s a IGNORE_PEP8_ERRORS global in kate_settings_plugins.py but there’s no way that I can see to override this value without editing the kate_settings_plugins.py file. Since the plugins are installed globally it doesn’t seem practical to edit the file directly.

    Another problem with IGNORE_PEP8_ERRORS is that it is defined as an empty list but it should be defined as an empty string. This is because pep8.options.ignore takes a comma-separated string like this:

    pep8.options.ignore = “E226,E261″

    So the default value for that global should be an empty string, not an empty list:

    IGNORE_PEP8_ERRORS = “”

    IMHO it would make a lot more sense to simply use the user’s ~/.config/pep8 as the pep8 configuration like pep8 itself does. I have tested and confirmed that the file is ignored by this package of plugins.

    I can probably add that as a feature to the package but now that the repository has been moved out of Github I have no idea how to contribute. The links from the pypi page (https://pypi.python.org/pypi/Kate-plugins) point to a page that does not exist:

    https://projects.kde.org/projects/kde/applications/kate/repository/revisions/master/show/kate/plugins/pate/src/plugins/python_utils

    How do I pull down the repo and submit a pull request? Where has it been moved to? Even the links in this post don’t work. For example:

    https://projects.kde.org/projects/kde/kde-baseapps/kate/repository/

    Results in a 404.

    Thanks for these plugins!

    1. You are using a old versión of the plugins. How the readme says: This repository is unmaintained, because these plugins have been added to the official repository: Python utils, Javascript utils, Django utils and XML pretty. The generic functions and generic classes have been added to the libkatepate

      https://github.com/goinnn/Kate-plugins#information

      Each problem, that you comment, has been solved. Now you configure it through ui, you can see in this other post:

      http://kate-editor.org/2013/04/23/a-rich-python-console-and-more-in-kate-editor/

      It is true the url now is other (it is the second time). Now the plugins are here:

      https://projects.kde.org/projects/kde/applications/kate/repository/revisions/master/show/addons/kate/pate/src/plugins

      The next week I will change it in the github repository

      If you have other problem tell me please,

      Thanks you!!

        1. When I told you other problem, I didn’t want to say a bug… I want to say a broken link, an install problem etc

          Please if you detect a bug, open an issue at bugs.kde.org

    1. The first thing is that this repo[1] is unmaintained. Because these plugins have been added to the official repository. The next month will be the release of the KDE 4.11 with these plugins…

      It’s possible that you don’t see “Python Plugins” because the name of this plugin in this version was other…. Something with “Pate” or “Pâtè”

      1. https://github.com/goinnn/Kate-plugins#information

  6. I built Kate from source, per the instructions at http://kate-editor.org/get-it/, and there are no Python Plugins. I looked in the apps/kate directory, and there’s no Pate directory. The version included in Fedora doeesn’t have them either, apparently because of circular dependencies. I tried installing them from the unmaintained git repo, and no Plugins show up in Kate. Is there some possible way to get these plugins?

      1. That’s where kate was installed to, but there’s no pate directory. None of the settings inside the orange box in your picture show up in my settings dialog.

        Do I need to install pate separately, or is it installed by default when you build kate from source? Is there a build option I need to use?

        I followed the instructions for installing kate from source exactly, except I put everything in ~/kdelocal, instead of ~/kde. But I changed all the path variables and prefixes accordingly.

        1. If you install Kate from sources you don’t need install Pate.

          You only have to enable the plugin “Python plugins” (Settings > Configure Kate > Plugins).

          Do you have a plugin called “Python Plugins”?

          Do you execute kate like says in the documentation, from konsole?

          ./run.sh kate

          1. Yes, I did all that. There’s no Python Plugin. Everything looks the same as for my system Kate install.

            I tried ./run.sh kate –version, and got this output:
            kbuildsycoca4 running…
            Qt: 4.8.4
            KDE Development Platform: 4.10.5
            Kate: 3.10.5

            I even tried executing ~/kdelocal/usr/bin/kate, after running it with run.sh to set up the environment, to make sure it was running the correct one.

            I also deleted ~/.kde/share/apps/kate to start with a fresh configuration.

            Is there a dependency I’m missing? I installed everything listed on the “Get Kate” page.

          2. I figured it out. The build instructions for Fedora say to install PyKDE4-devel. There’s no such package, so I installed PyKDE-devel. This made sense, because there are a number of old package for kde and qt on RHEL/Fedora that have had the 4 removed from the name, or that have a 4 on other distros, but not on Fedora. The correct name is pykde4-devel. After rebuilding with this installed, I have Python Plugins. Funny that i didn’t get any errors when I built it the first time.

            Thanks for the help.

  7. I have a problem (pclinuxos 2013 32bit, updated, kde) with the shortcuts of kate: does not work.

    Packages installed:
    kate-4.11.3-1pclos2013
    kate-part-4.11.3-1pclos2013
    lib64kate1-0.4.1-1pclos2013
    kate-libs-4.11.3-1pclos2013
    gstreamer0.10-kate-0.10.23-1pclos2013

    Config:
    [duns@localhost ~]$ ls .kde4/share/config/kate*
    .kde4/share/config/katepartpluginsrc .kde4/share/config/kateschemarc .kde4/share/config/katesyntaxhighlightingrc
    .kde4/share/config/katerc .kde4/share/config/katescriptingrc

    Thank you
    Johannes

Leave a Reply