📜 ⬆️ ⬇️

Meet the new plugin for Geany IDE - PairTagHighlighter

Hello!

Unexpectedly, I learned that the Geany IDE cannot highlight paired HTML / XML tags. Those. Put the cursor in the middle of the tag, this tag and its pair (opening or closing) should be highlighted. Googling showed that there are really no features, and it is present on the wish list.

Without hesitation, I decided to add this opportunity. If you are interested to know the details, discuss / criticize the result, take part in the survey, and also advise what to add, until Geany 1.24 is released, welcome to the cat!
')
image


At once I will make a reservation that this article is not a manual for writing plug-ins for Geany. All this is clearly and thoroughly described in the official documentation.

First steps to implement


After making sure that the “Hello World” plugin, which is described in the official manual, works as expected and performs all its useful functions, I began to think about the algorithm. I decided to peep the implementation of this feature in Notepad ++. In the process I made an interesting discovery for myself: In Geany and Notepad ++, one engine is used - Scintilla. From this, it seemed that Notepad ++ fits even more: not only does it have the necessary feature, it is also implemented on the necessary engine.

As a result, Notepad ++ did not suit me for several reasons:
  1. Notepad ++ code is distributed under the GPL, but I wanted to open my plugin under BSD.
  2. In Notepad ++, the xmlMatchedTagsHighlighter component, written in C ++ using STL, is responsible for tagging. I wanted to do the implementation in C, and in the Geany project this language is preferred. About this in the mailing lists are active discussions, but so far.
  3. The implementation of the features in Notepad ++ seemed to me cumbersome and ugly. And the desire to develop prevailed over the desire to port.


A few words about the algorithm


... It was the words, the flowchart to draw the desire was not there. The algorithm for finding the closing tag is described below. The search for the opener works similarly, just up the document.
  1. Check whether the cursor is in the middle of the tag.
  2. If so, determine the tag name.
  3. Check the type of the tag: opening or closing.
  4. For example, the opening. So we move forward relative to the closing bracket and check whether the position is in the middle of the tag or not.
  5. If the position has hit the tag and it is the opening one, and the name matches the name specified in step two, increase the counter of the opening tags.
  6. If the tag is closing, and the name matches the name specified in step two, increase the counter of closing tags.
  7. If the counters of the opening and closing tags match, the pair is found.
  8. Highlight the desired position.


What does the implementation look like?


The source code is already in the master Geany branch. You can see on the githaba .

For those who want to try in business, who wrote to me in the mail, I posted the assembled plugin in the blog (64-bit build for Linux).

Earlier on the official site only plugins were published that are in the release. After consulting with the community in IRC, I corrected this case, after which PairTagHihlighter appeared on the site before the release of Geany 1.24.

What to do



It is also interesting to know what priority users are. I do not promise that I will do everything, but from time to time I want to look for for fun. I wrote the plug-in's code back in April, and now I returned to it again.

Update
If in the survey you choose “Change backlight style” or “Other”, it is advisable to inform in the comments what was meant. It's hard for me to translate :)

Source: https://habr.com/ru/post/193490/


All Articles