Frank Wunderlich:
Roman Hubacek, 02.05.2006 09:51:
Frank Wunderlich:
ok, i see the error must in this function:

function OnChar(c)
  function char_at(p)
    return string.char(editor.CharAt[p])
  end
  local toClose = { ['('] = ')', ['['] = ']', ['"'] = '"', ["'"] = "'" }

  if (toClose[c] ~= nil) then
    local pos = editor.CurrentPos
    local nextchar=char_at(pos+1)
    if ((nextchar == "\n") or (nextchar == "\r")) then
      editor:ReplaceSel(toClose[c])
      editor:SetSel(pos, pos)
    end
  end
  return false
end


Hello, this works for me:

function OnChar(c)
  local toClose = { ['('] = ')', ['['] = ']', ['"'] = '"', ["'"] = "'" }
  if(toClose[c]) then
    local pos = editor.CurrentPos
    editor:SetSel(pos,pos)
    editor:ReplaceSel(toClose[c])
    editor:SetSel(pos,pos)
  end
end

-- Roman

Hi Roman, i've added the nextchar-lines because sometimes i don't want the autocompletion. e.g. adding brackets aroud an existing text:

testfunction() => (testfunction())

to avoid the deletion of the close-brackets i've added the line. but i think the problem is when the cursor is on last char in file. is there a possibility to test the nextchar for e.g. whitespace (\n \r \t \s <eof>) and then exit function?

Hi, you can get next char by using editor:textrange(frompos, topos). But you should test, if you are getting text in current document range. Something like this:

    ...
    local pos = editor.CurrentPos
    local nextchar = "\n"
    if pos<editor.Length then
      nextchar = editor:textrange(pos, pos+1)
    end

    if ((nextchar == "\n") or (nextchar == "\r")) then
    ...

-- Roman

_______________________________________________
Scite-interest mailing list
[email protected]
http://mailman.lyra.org/mailman/listinfo/scite-interest

Reply via email to