При наличии выделения работает именно с ним.
Полезно при написании макросов на Yue-/MoonScript, если что-то работает не так как ожидалось.
Code: Select all
F = far.Flags
toEditor = (name, content, CurLine) ->
name = name\match"[^\\/]+$"
do
local suffix
base = win.JoinPath far.GetCurrentDirectory!, name
while win.GetFileAttr base..(suffix or "")..".lua"
suffix = (suffix or 0)+1
name ..= (suffix or "")..".lua"
mf.postmacro ()->
with actl.GetWindowInfo!
assert .Type==F.WTYPE_EDITOR and string.sub(.Name, -#name-1)=="\\"..name, "oops, editor has not been opened"
mf.print content
if CurLine
with editor.GetInfo!
editor.SetPosition nil,
:CurLine
TopScreenLine: math.max 1, CurLine-.WindowSizeY/2
CP = 65001
curModal = F.WIF_MODAL==bit64.band actl.GetWindowInfo!.Flags, F.WIF_MODAL
flags = F.EF_DISABLEHISTORY +F.EF_OPENMODE_NEWIFOPEN
-- try open nonmodal editor
res = editor.Editor name, nil, nil, nil, nil, nil, flags +F.EF_NONMODAL +F.EF_IMMEDIATERETURN , nil, nil, CP unless curModal
if curModal or res==F.EEC_LOADING_INTERRUPTED
editor.Editor name, nil, nil, nil, nil, nil, flags, nil, nil, CP
getText = () ->
return Editor.SelValue if Object.Selected
with editor.GetInfo!
lines = for i=1,.TotalLines
editor.GetString nil,i,3
return (table.concat lines, "\n"), .CurLine
moon_to_lua = (source, MoonLine)->
import to_lua from require"moonscript"
lua,moon_map = to_lua source
return lua,moon_map if not lua
lines_map = [ln for ln in string.gmatch source, "\n()"]
local LuaLine
for lua_line, moon_pos in pairs moon_map
for moon_line=1,#lines_map
if lines_map[moon_line] > moon_pos
moon_map[lua_line] = moon_line
LuaLine = lua_line if not LuaLine and moon_line==MoonLine
break
curline = 0
lua = lua\gsub "[^\r\n]+", (text) ->
curline += 1
if line = moon_map[curline]
text.." -- "..line
lua, LuaLine
Macro
description:"MoonScript to lua"
area:"Editor"
key:"F6"
filemask:"*.moon.*"
id:"3B5508B4-A0A5-4B74-9573-D2505DBF71D5"
action:()->
lua,CurLine = moon_to_lua getText!
unless lua
return far.Message CurLine, "Error", nil, "wl"
toEditor Editor.FileName, lua, CurLine
Macro
description:"YueScript to lua"
area:"Editor"
key:"F6"
filemask:"*.yue.*"
id:"9CE04C33-A1B3-4F76-AE12-3F60454AE43F"
action:()->
import to_lua from require"yue"
source, srcLine = getText!
lua, err = to_lua source
unless lua
return far.Message err, "Error", nil, "wl"
toEditor Editor.FileName, lua, (->
srcLine = tostring srcLine
CurLine = 0
for line in lua\gmatch " -- (%d+)\n"
CurLine += 1
return CurLine if line==srcLine)!Также в теме обсуждается Исправление номеров строк в сообщениях об ошибках на соответствующие MoonScript-файлам.