Skip to content

Commit

Permalink
Teal: Ctrl+N means next error, Alt+L switch to .lua
Browse files Browse the repository at this point in the history
Word wrap moves to Alt+N
  • Loading branch information
hishamhm committed Jan 18, 2024
1 parent f18a0a7 commit 9a42f7d
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 14 deletions.
2 changes: 1 addition & 1 deletion bindings/default
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ CTRL_G Dit_goto
CTRL_J Dit_previousTabPage
CTRL_K Dit_nextTabPage
CTRL_L Dit_refresh
CTRL_N Dit_wordWrap
CTRL_Q Dit_quit
CTRL_S Dit_save
CTRL_T Buffer_toggleTabCharacters
Expand Down Expand Up @@ -74,6 +73,7 @@ ALT_A Dit_selectUpLine
ALT_B Dit_selectDownLine
ALT_C Dit_selectForwardChar
ALT_D Dit_selectBackwardChar
ALT_N Dit_wordWrap
WHEELUP Dit_scrollDown
WHEELDOWN Dit_scrollUp
ESC Dit_cancelSelection
1 change: 1 addition & 0 deletions highlight/teal.dithl
Original file line number Diff line number Diff line change
Expand Up @@ -44,3 +44,4 @@ context enum `$ bright bright brightdiff

rule as bright
rule is bright
rule where bright
10 changes: 10 additions & 0 deletions scripts/lua.lua
Original file line number Diff line number Diff line change
Expand Up @@ -345,3 +345,13 @@ function on_key(code)
end
return tab_handled or handled
end

function on_alt(key)
if key == 'L' then
local filename = buffer:filename()
local x, y = buffer:xy()
local page = tabs:open(filename:gsub("%.lua$", ".tl"))
tabs:set_page(page)
tabs:get_buffer(page):go_to(x, y)
end
end
47 changes: 34 additions & 13 deletions scripts/teal.lua
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ local mobdebug = require("dit.lua.mobdebug")
local json = require("cjson")

local lines
local last_line = 0
local commented_lines = {}
local controlled_change = false
local type_report
Expand Down Expand Up @@ -79,6 +80,7 @@ function on_save(filename)
lines = {}
local state = "start"
local buf = {}
last_line = 0
for line in pd:lines() do
if state == "start" then
if line == "" then
Expand Down Expand Up @@ -117,6 +119,9 @@ function on_save(filename)
text = err,
what = state,
})
if y > last_line then
last_line = y
end
end
end
end
Expand Down Expand Up @@ -161,24 +166,40 @@ local function type_at(px, py)
end
end

function on_alt(key)
if key == 'L' then
local filename = buffer:filename()
local x, y = buffer:xy()
local page = tabs:open(filename:gsub("%.tl$", ".lua"))
tabs:set_page(page)
tabs:get_buffer(page):go_to(x, y)
end
end

function on_ctrl(key)
if key == '_' then
controlled_change = true
code.comment_block("--", "%-%-", lines, commented_lines)
controlled_change = false
elseif key == "O" then
-- local str = buffer:selection()
-- if str == "" then
-- str = buffer:token()
-- end
-- if str and str ~= "" then
-- local out = mobdebug.command("eval " .. str)
-- if type(out) == "table" then
-- buffer:draw_popup(out)
-- end
-- else
-- buffer:draw_popup({ "Select a token to evaluate" })
-- end
elseif key == "N" then
if not lines then
return
end
local x, y = buffer:xy()
if lines[y] then
for _, note in ipairs(lines[y]) do
if note.column > x then
buffer:go_to(note.column, y)
return
end
end
end
for line = y+1, last_line do
if lines[line] then
buffer:go_to(lines[line][1].column, line)
return
end
end
elseif key == "D" then
local x, y = buffer:xy()
local t = type_at(x, y)
Expand Down

0 comments on commit 9a42f7d

Please sign in to comment.