local M = {} local function is_word_char(ch) if ch == "" then return false end local byte = string.byte(ch) if not byte then return false end if byte >= string.byte("a") and byte <= string.byte("z") then return true end if byte >= string.byte("A") and byte <= string.byte("Z") then return true end if byte >= string.byte("0") and byte <= string.byte("9") then return true end return ch == "_" end function M.forward_word() local len = editor.buffer_length() local point = editor.point() if point >= len then return end local ch = editor.char_at(point) if is_word_char(ch) then while point < len and is_word_char(editor.char_at(point)) do point = point + 1 end else while point < len and not is_word_char(editor.char_at(point)) do point = point + 1 end while point < len and is_word_char(editor.char_at(point)) do point = point + 1 end end editor.set_point(point) end function M.backward_word() local point = editor.point() if point <= 0 then return end point = point - 1 while point >= 0 and not is_word_char(editor.char_at(point)) do point = point - 1 end while point >= 0 and is_word_char(editor.char_at(point)) do point = point - 1 end editor.set_point(point + 1) end return M