logo

oasis-root

Compiled tree of Oasis Linux based on own branch at <https://hacktivis.me/git/oasis/> git clone https://anongit.hacktivis.me/git/oasis-root.git

textobject-lexer.lua (697B)


  1. -- text object matching a lexer token
  2. local MAX_CONTEXT = 32768
  3. vis:textobject_new("ii", function(win, pos)
  4. if not win.syntax or not vis.lexers.load then
  5. return nil
  6. end
  7. local before, after = pos - MAX_CONTEXT, pos + MAX_CONTEXT
  8. if before < 0 then
  9. before = 0
  10. end
  11. -- TODO make sure we start at a line boundary?
  12. local lexer = vis.lexers.load(win.syntax, nil, true)
  13. local data = win.file:content(before, after - before)
  14. local tokens = lexer:lex(data)
  15. local cur = before
  16. for i = 1, #tokens, 2 do
  17. local token_next = before + tokens[i+1] - 1
  18. if cur <= pos and pos < token_next then
  19. return cur, token_next
  20. end
  21. cur = token_next
  22. end
  23. return nil
  24. end, "Current lexer token")