Блокнот ++ XML Auto Indent + закрытие тегов

4495
funseiki

Я перенес вопрос, который я разместил в stackoverflow, сюда, поскольку он может быть более актуальным.

Вот вопрос:

Я ищу способ кодирования XML (в частности, mxml) в Notepad ++, чтобы он следовал поведению плагина "Indent by Fold" - отступ после нажатия клавиши "enter" после открывающего тега - но также включает автоматическое закрытие тега аналогично к тому, что предусмотрено плагином "XML Tools".

Проблема с включением обоих одновременно заключается в том, что я начинаю с чего-то вроде этого:

<hello| 

(Примечание: символ «|» представляет курсор)

Затем после нажатия клавиши «>» я получаю это:

<hello>|</hello> 

И после нажатия «Enter» я получаю что-то похожее на это:

<hello> |</hello> 

То, что я ищу, выглядит примерно так (после нажатия клавиши «>»):

<hello> | </hello> 

Любая помощь приветствуется.

2

1 ответ на вопрос

2
funseiki

Here's my quick and dirty solution. Really it just involves creating a macro along with enabling a XML tools feature.

First, remove the "Indent By Fold" plugin, if installed.

Then, enable the "Tag auto-close" feature by going to Plugins>XML Tools.

Also, enable Notepad++'s auto indent by going to Settings > Preferences > MISC. Tab

Next, go to Macro > Start Recording.

Now, hit the following keys in this sequence:

>, enter, enter, up, tab.

Then, go to Macro > Stop Recording. Followed by, Macro > Save Current Recorded Macro.

This will create the final '>' as well as the closing tag, but then leave your cursor indented in a new line between the opening and closing tags.

I saved mine as "CTRL + '.'".

The reasoning behind this was that if I was here:

<hello| 

The natural thing to do would be to hit the '>' key. Since I need to hit SHIFT+ '.' on a QWERTY keyboard to get this character, I figure I'd use CTRL+'.' (only one key away) to perform the macro and save SHIFT+'.' for cases where I just want the plain old character (e.g. <hello />).

Here is the result after hitting CTRL + '.'

<hello> | </hello> 

I'll be on the lookout for a more elegant solution, but for now this seems to be pretty good.

Hope this helps!

Похожие вопросы