XML: Allowing dashes in words

It seems that IntelliJ has a notion of what characters are used as word separators, and this has a impact on things like "Select Word at Caret", selecting text word-by-word with the keyboard, or double-clicking on a piece of text.

Say you have `foo-bar` in Java. It means `foo` minus `bar`. So `foo` is a word and `bar` is a word. If you double click on a letter of `foo` it selects just `foo`. But if you have `foo_bar`, the whole thing is a word. Double click on a letter of `foo` and it will select `foo_bar`. This is reasonable for Java.

But it isn't for XML: in XML `foo-bar` as a whole should be considered as word, just like `foo_bar` is in Java. Because in XML, `foo-bar` can be a valid id, or in XPath it points to the element `<foo-bar>`. As far as I know it never means `foo` minus `bar`. The problem is that in XML, you often go for a "lowercase with dashes" convention, which makes it harder to select those ids in IntelliJ.

Let me get to the point: is there a way to setup IntelliJ so, for XML files, `-` is not considered as a word separator, similarly to `_`?

Alex

0
3 comments

Hello Alessandro,

The behavior of Ctrl-W for different file types is hard-coded in IntelliJ
IDEA and is not user configurable. Requests for improving the existing behavior
are welcome.

It seems that IntelliJ has a notion of what characters are used as
word separators, and this has a impact on things like "Select Word at
Caret", selecting text word-by-word with the keyboard, or
double-clicking on a piece of text.

Say you have `foo-bar` in Java. It means `foo` minus `bar`. So `foo`
is a word and `bar` is a word. If you double click on a letter of
`foo` it selects just `foo`. But if you have `foo_bar`, the whole
thing is a word. Double click on a letter of `foo` and it will select
`foo_bar`. This is reasonable for Java.

But it isn't for XML: in XML `foo-bar` as a whole should be considered
as word, just like `foo_bar` is in Java. Because in XML, `foo-bar` can
be a valid id, or in XPath it points to the element `<foo-bar>`. As
far as I know it never means `foo` minus `bar`. The problem is that in
XML, you often go for a "lowercase with dashes" convention, which
makes it harder to select those ids in IntelliJ.

Let me get to the point: is there a way to setup IntelliJ so, for XML
files, `-` is not considered as a word separator, similarly to `_`?


--
Dmitry Jemerov
Development Lead
JetBrains, Inc.
http://www.jetbrains.com/
"Develop with Pleasure!"


0

Hi Dmitry,

Thank you for taking the time to respond. Got it: the behavior of Ctrl-W is hard coded per language. Now, I imagine that the thinking behind deciding what characters can separate words in different languages is based on what characters can be part of identifiers in that language. So if I'm in Java, `_` can be part of an identifier, when I Ctrl-W on `foo_bar`, IntelliJ selects the whole thing.

In XML languages, `-` can be part of "identifiers" (element names, XPath variables, XSLT template names…), I would say that it is fine to hard code that `-` can be part of a word, just like in Java you allow `_` to be part of a word. You could imagine a preference for this, but I personally don't think it is really needed.

Does this make sense?

Alex

0

Dmitry & all,

Do you think it would make sense to treat dashes in XML as underscores in other language, as I was arguing for earlier (i.e. as a character which can be part of an identifier)? If it does, would you suggest that I add and RFE in YouTrack for this?

Alex

0

Please sign in to leave a comment.