Re: [code] [Textadept]

From: Mitchell <>
Date: Wed, 19 Sep 2018 11:02:35 -0400 (EDT)

Hi Alexander,

On Wed, 19 Sep 2018, Misel Alexander wrote:

> I am using Win7 x64 to run Textadept.
> I started to use Textadept recently and found it a great text editor! So I immediately went to translate the interface into Chinese. See attached file.

Thank you very much!

> Problems I faced:
> 1. As os.getenv('LANG') gets nil, the program cannot automatically decide which language to show. But this could work when I manually set a system variable LANG = zh_CN.UTF8

Yes, the manual states that Textadept uses $LANG to determine language, or a *~/.textadept/locale.conf* file.

> 2. When I swtich the language to zh (Chinese) or ja (Japanese), I cannot get focused in search panel. But this works when the language is set English. Very strange. So I did another hack to set LANG wp_CN.UTF8 and the language file became locale.wp.conf

That is strange indeed. If you move your locale file from Textadept's home directory to your *~/.textadept/locale.conf* (note the simpler filename), do you still see the same problem? I cannot see why changing your $LANG from "zh_CN.UTF8" to "wp_CN.UTF8" would affect being able to change focus to the Find & Replace pane.

> 3. Chinese characters became boxes as our default monospace font (for example, Courier New) doesn't support the CJK characters. Other text editors seem fine, since they will look for the system fallback font for Chinese characters.k

Textadept is not smart enough to go searching for fonts that can display all characters. It relies on you to specify better fonts, as you have done in your attached *init.lua* file.

> 4. I managed to highlight all the TODOs as well as FIXMEs. But I didn't manage to add any lexer rules. Should I do so? I added a handler to LEXER_LOADED and colored al TODOs. But newly typed TODOs won't be colored. Is there a way to color new texts like code highlight?

I would probably connect to the `events.CHAR_ADDED` event and look for a character that comes after one of your markers. For example:

   events.connect(events.CHAR_ADDED, function(ch)
     if ch ~= string.byte(':') then return end
     if buffer:get_cur_line():match('TODO:$') or
        buffer:get_cur_line():match('FIXME:$') then
       -- Perform highlighting of TODO or FIXME just added.

When you type ':', the event handler looks for a preceding "TODO" or "FIXME" and proceeds to highlight it.

> 5. File browser is a very useful plugin but when I closed and reopened Textadept, it couldn't load correctly. I hope this can be fixed.

The file browser module does not persist between sessions. I'm pretty sure it can be extended to do so, but I'll leave it to someone else.

> I'll also share my init.lua in attached files. I'm looking for an option that will fold all fold-points or blocks that are longer than 100 lines.

I suppose you could:

1. Iterate over all buffer lines via `for i = 0, #buffer.line_count do ... end`.
2. For each line, `i`, check the fold level via `buffer.fold_level[i]`.
3. If it's a fold header (`level & buffer.FOLDLEVELHEADERFLAG > 0`), note the line and its level minus the header bit, and start counting from 0.
4. When you find 100 subsequent lines whose fold levels are greater than the noted level in step 3, you can fold the line noted in step 3.
5. Continue looking for header lines after the last folded line.

Note that you will have to handle blank lines `buffer.FOLDLEVELWHITEFLAG`. You will also have to correctly determine the index of the last folded line for step 5 (perhaps `buffer:get_last_child()`[1] may be of help).

I hope this helps.



You are subscribed to
To change subscription settings, send an e-mail to
To unsubscribe, send an e-mail to
Received on Wed 19 Sep 2018 - 11:02:35 EDT

This archive was generated by hypermail 2.2.0 : Thu 20 Sep 2018 - 06:48:53 EDT