# Regular Expression in countColumn method

**URL:** <https://discuss.codemirror.net/t/regular-expression-in-countcolumn-method/2282>\
**Category:** Uncategorized\
**Created:** [February 1, 2020, 5:24pm UTC](https://discuss.codemirror.net/t/regular-expression-in-countcolumn-method/2282 "2020-02-01T17:24:25Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![suino](https://discuss.codemirror.net/user_avatar/discuss.codemirror.net/suino/32/706_2.png) [@suino](https://discuss.codemirror.net/u/suino)\
**Post date:** [February 1, 2020, 5:24pm UTC](https://discuss.codemirror.net/t/regular-expression-in-countcolumn-method/2282/1 "2020-02-01T17:24:25Z")

</div>

`CountColumn()` method is mainly used to count number of text for indentation.  
Then indentation is only created by half-width space or tab.  
But regular expression in `countColumn()` method also counts _spaces_ other than half-width space or tab.

> <https://github.com/codemirror/CodeMirror/blob/master/src/util/misc.js#L18>

In my case:

I want to write `\u3000`（full-width space） on head of all lines when writing Japanese text.  
`\u3000` is included in `\s`.  
For the reason, CodeMirror indents next line for half-width space.  
However that I need is No-indent or Full-width space indent.

I suppose that appropriate regular expression is `/[^\u0020\u00a0\t]/`…

Is there any other way?

Thank you.

---

<div class="post-metadata">

**Author:** ![marijn](https://discuss.codemirror.net/user_avatar/discuss.codemirror.net/marijn/32/136_2.png) [@marijn](https://discuss.codemirror.net/u/marijn)\
**Post date:** [February 1, 2020, 8:48pm UTC](https://discuss.codemirror.net/t/regular-expression-in-countcolumn-method/2282/2 "2020-02-01T20:48:46Z")

</div>

CodeMirror’s indentation system is written with only (Latin) spaces and tabs in mind. I suspect adjusting it to do something sensible with Japanese spacing would require a lot more than just adjusting this regexp. So I’d advise you to avoid using the built-in indentation handling and write your own command to bind to `Enter`.

---

<div class="post-metadata">

**Author:** ![suino](https://discuss.codemirror.net/user_avatar/discuss.codemirror.net/suino/32/706_2.png) [@suino](https://discuss.codemirror.net/u/suino)\
**Post date:** [February 9, 2020, 2:58pm UTC](https://discuss.codemirror.net/t/regular-expression-in-countcolumn-method/2282/3 "2020-02-09T14:58:04Z")

</div>

Thanks for your reply.  
Following your advice, I built my own indentation handling and bind it to `Enter`. It’s just ok.  
Although I had a little difficulty writing because most methods were private.

I have another idea.  
When user uses `prev` mode, indentation should be calculated like belows:  
`if (pos < indentation) indentString += getLine(doc, n-1).text.match(/^\s*/)[0]`  
Because spaces is got like belows:  
`var curSpaceString = line.text.match(/^\s*/)[0], indentation;`  
I think these sentense should use same regexp.

Sorry for ranting.  
I understand what you mean.  
I’m glad if you consider not-Latin languages someday!

Thanks.
