[code] [textadept] 'Find' with Lua patterns does not support UTF-8

From: Constantine Bytensky <kostya3.att.gmail.com>
Date: Thu, 7 Jan 2016 03:36:40 +0200

Hello,

I figured out that Lua patterns in find dialog does not support UTF-8
symbols (I use Cyrillic).

I tried to fix this and found this project: https://github.com/starwing/luautf8

So I replaced src/lua/src/lutf8lib.c and added src/lua/src/unidata.h
using files obtained from project. Also I modified
modules/textadept/find.lua as in patch below.

After that I got Cyrillic Lua patterns in find dialog working.

I'm new on Textadept and Lua. Is there better way to add UTF-8 support
to Find with Lua patterns?

diff --git modules/textadept/find.lua modules/textadept/find.lua
index 4c89ce7..11846ce 100644
--- modules/textadept/find.lua
+++ modules/textadept/find.lua
@@ -157,10 +157,12 @@ local function find_(text, next, flags, no_wrap, wrapped)
     local patt = text:gsub('\\[abfnrtv\\]', escapes)
     local s = next and buffer.current_pos or 0
     local e = next and buffer.length or buffer.current_pos
- local caps = {buffer:text_range(s, e):find(next and patt or '^.*()'..patt)}
+ local range = buffer:text_range(s, e)
+ local caps = {utf8.find(range, next and patt or '^.*()'..patt)}
     M.captures = {table.unpack(caps, next and 3 or 4)}
     if #caps > 0 and caps[2] >= caps[1] then
- pos, e = s + caps[next and 1 or 3] - 1, s + caps[2]
+ pos = s + utf8.charpos(range, caps[next and 1 or 3]) - 1
+ e = s + utf8.charpos(range, caps[2] + 1) - 1
       M.captures[0] = buffer:text_range(pos, e)
       buffer:set_sel(e, pos)
     end

-- 
You are subscribed to code.att.foicica.com.
To change subscription settings, send an e-mail to code+help.att.foicica.com.
To unsubscribe, send an e-mail to code+unsubscribe.att.foicica.com.
Received on Wed 06 Jan 2016 - 20:36:40 EST

This archive was generated by hypermail 2.2.0 : Thu 07 Jan 2016 - 06:29:02 EST