Author Topic: auto-completing current XML element  (Read 6794 times)

ronburk

  • Community Member
  • Posts: 22
  • Hero Points: 3
auto-completing current XML element
« on: July 11, 2006, 10:03:56 pm »
I increasingly find myself typing custom XML documents with lengthy element names like <SectionHeading>, and I would sure like to find a keystroke that just automatically supplies the end tag for the element I'm in the midst of. In other words, if the nearest unclosed element to the left of my cursor is "<SectionHeading>", I would like to hit a key that automatically inserts a "</SectionHeading>".

I'm guessing that functionality is in VS 11.0 already and I just haven't found it. Is there such a function already, or would that require some custom coding?

Matthew

  • SlickEdit Team Member
  • Senior Community Member
  • *
  • Posts: 990
  • Hero Points: 44
Re: auto-completing current XML element
« Reply #1 on: July 12, 2006, 12:30:42 am »
Yes, this feature is in v11. You have to make sure the file extension you're working with is mapped as XML. Go to Tools | Options | File Extension Setup, and create a new extension. Then just have that extension refer to XML.
Now, there isn't a hotkey per-se. Just enter the first part of the closing tag (ie - type </), and it'll take it from there. I edit a heck of a lot of NAnt buildfiles in SE, and this autocomplete feature is must-have.

ronburk

  • Community Member
  • Posts: 22
  • Hero Points: 3
Re: auto-completing current XML element
« Reply #2 on: July 12, 2006, 04:41:16 am »
Well, I'm using v11 to edit a .xml file, and typing the "</" seems to do nothing for me at all.

At that point, the little listbox in the rebar area says "no current context" (not sure what that means).

If you're getting something useful to happen, then I would have guessed we have different options set in the "Auto-Complete" tab of the "Extension Options" for ".xml". But, staring at and tinkering with those options brings me no change in this behavior.

I have checked "Enable auto-completion" and "Keywords" and "Alias expansion" and "Symbols" and "Word completion".

If I type a character after the "</", then it does try to do some kind of auto-completion, but it seems to have no concept that there's only one possible legal tag it can be at that point. It offers me choices that include most any word of text with the same prefix that appears in the file.

Anything else I might try to get this feature enabled? Is it possible this just doesn't work on well-formed XML, and requires a DTD or some other aspect of "valid" (as opposed to "well-formed", as defined by the standard) XML?

gavink

  • Community Member
  • Posts: 14
  • Hero Points: 0
Re: auto-completing current XML element
« Reply #3 on: July 13, 2006, 08:38:37 pm »
Anything else I might try to get this feature enabled? Is it possible this just doesn't work on well-formed XML, and requires a DTD or some other aspect of "valid" (as opposed to "well-formed", as defined by the standard) XML?

Well, I am confused. I have been using SlickEdit to edit XML files since about version 9 and typing </ has always been enough for me. AFAIK they only criteria is having well formed XML (in fact, it does not have to be well formed since by definition you do not have a closing tag for your element yet). No DTD or schema is required. Sorry I cannot help.

ronburk

  • Community Member
  • Posts: 22
  • Hero Points: 3
Re: auto-completing current XML element
« Reply #4 on: July 15, 2006, 02:04:14 am »
Thanks guys. Just knowing it's supposed to work gives me the energy to try to figure this out. I'll start by getting the latest patch, then start trying to understand where the magic code lies and why it's not getting invoked. Maybe it's some forgotten self-inflicted tweak that I did to myself ages ago.

ronburk

  • Community Member
  • Posts: 22
  • Hero Points: 3
Resolution: Indent Style (confusingly) affects syntax expansion.
« Reply #5 on: July 15, 2006, 03:58:42 am »
Got it! For my future edification, when I'll note doubt stumble over this or something similar again:

a) I found that xml.e has the code for special XML handling.

b) I found that xml_slash() is the guy who has the smarts.

c) Debugging statements tracked it down to not getting past this statement:


   if (p_window_state:=='I' ||
      p_SyntaxIndent<0 || p_indent_style!=INDENT_SMART||
       _prev_char()!='<') {
      keyin(key);
      return;
   }

So, getting the auto closing tag completion requires having, not completion options, but syntax indenting options set just so. Tracing those variables back to dialog boxes showed me that I needed to go to Tools|Options|File Extension Setup...

and go to the Indent tab, and set "Indent Style" to "Syntax indent", and make sure the "Syntax expansion" box was checked.

It will not work to have "Indent Style" set to "Auto". This was and remains unintuitive to me. In fact, I don't really see what "Indent Style" has to do with auto-completing a closing XML tag.

In any case, I'm very happy to have the auto-completion for end tags working, and will remain so until I rediscover what it was that made me unwilling to have "Indent Style" set to "Syntax indent" for XML files :-)