Crest replacement

Here you can discuss about your favorite plug-in.
Post Reply
kamil
Posts: 20
Joined: Fri 13 Apr, 2012 19:19

Crest replacement

Post by kamil » Sat 19 Mar, 2016 11:11

I have this old simple plugin called "crest".

When I am in Editor and hold down Shift+Ctrl, it highlights for me the line and column that the cursor is currently at.
I got used to this feature so much that this plugin (it's binary I have) is the only reason I use 32 bit Far with 64 bit Windows.

Is there any other plugin which can do that?
Or perhaps some simple lua code could implement that functionality for me?

I know Visualiser can highlight the cursor's line and column, but I need to it be done only while I'm holding Shift+Ctrl, not all the time.

Shmuel
Posts: 5041
Joined: Thu 23 Mar, 2006 21:36
Location: Israel
Has thanked: 11 times
Been thanked: 133 times

Crest replacement

Post by Shmuel » Sat 19 Mar, 2016 15:20

1. I'm not using plugin Colorer but I vaguely recall it had one. Check its options.
2. There is a Lua script by zg for LF4Ed plugin. It must be easy to convert it for LuaMacro.

kamil
Posts: 20
Joined: Fri 13 Apr, 2012 19:19

Crest replacement

Post by kamil » Sat 19 Mar, 2016 15:29

Shmuel wrote:1. I'm not using plugin Colorer but I vaguely recall it had one. Check its options.
You're right.
But its like with the one from Visualizer - its always on.
Shmuel wrote:2. There is a Lua script by zg for LF4Ed plugin. It must be easy to convert it for LuaMacro.
I will have a look at it.

Thanks.

User avatar
sToLp
Posts: 691
Joined: Thu 23 Jul, 2009 10:16
Has thanked: 31 times
Been thanked: 5 times

Crest replacement

Post by sToLp » Sat 19 Mar, 2016 17:28

I use it.
Attachments
ScrollLock_cross_modGrey_(zg)editor.lua
(5.18 KiB) Downloaded 36 times

kamil
Posts: 20
Joined: Fri 13 Apr, 2012 19:19

Crest replacement

Post by kamil » Sun 20 Mar, 2016 13:01

Thank you guys!
I managed to replicate my old CRest behaviour with LUA macro - it works exactly the same.

User avatar
HaRT
Moderator
Posts: 7985
Joined: Tue 30 Aug, 2005 17:21
Location: Санкт-Петербург
Has thanked: 66 times
Been thanked: 98 times

Crest replacement

Post by HaRT » Sun 20 Mar, 2016 13:58

kamil, can you please publish your macro here for others to be able to use it too?
Фар есть инструмент, а не нянька. © 2009 DrKnS

kamil
Posts: 20
Joined: Fri 13 Apr, 2012 19:19

Crest replacement

Post by kamil » Sun 20 Mar, 2016 14:02

Sure.
Sorry that I stripped all the comments, but I like my code clean:

Code: Select all

local F=far.Flags
local editors={}

local color = 0x5e
local color1 = 0x5e

local scrolllock=false

function GetData(id)
  local data=editors[id]
  if not data then
    editors[id]={start=1,finish=1}
    data=editors[id]
  end
  return data
end

function RemoveCrest(id,data)
  for ii=data.start,data.finish do
    editor.DelColor(id,ii,nil)
  end
end

function ProcessCrest(id,update)
  local data=GetData(id)
  RemoveCrest(id,data)
  update(data)
end

function ProcessEditorInput(rec)
  if F.KEY_EVENT==rec.EventType and 0~=rec.VirtualKeyCode then
    if 0==bit64.band(rec.ControlKeyState,F.LEFT_CTRL_PRESSED) or 0==bit64.band(rec.ControlKeyState,F.SHIFT_PRESSED) then
      if scrolllock then
        ProcessCrest(editor.GetInfo(-1).EditorID,
          function(data)
            data.start=1
            data.finish=1
          end
        )
        scrolllock=false
        editor.Redraw(-1)
      end
    else
      if not scrolllock then
        scrolllock=true
        editor.Redraw(-1)
      end
    end
  end
  return false
end

function ProcessEditorEvent(id,event,param)
  if event==F.EE_READ then
    editors[id]={start=1,finish=1}
  end
  if event==F.EE_CLOSE then
    editors[id]=nil
  end
  if event==F.EE_REDRAW then
    if scrolllock then
      local ei=editor.GetInfo(id) --- вместо 'local ei=editor.GetInfo(-1)' - zg Fri 09 Jan, 2015 18:04 http://forum.farmanager.com/viewtopic.php?p=127200#p127200
      ProcessCrest(ei.EditorID,
        function(data)
          data.start=ei.TopScreenLine
          data.finish=math.min(ei.TopScreenLine+ei.WindowSizeY,ei.TotalLines)
          for ii=data.start,data.finish do
            local toreal=function(pos) return editor.TabToReal(ei.EditorID,ii,pos) end
            if ei.CurLine==ii then
              editor.AddColor(ei.EditorID,ii,toreal(ei.LeftPos),toreal(ei.LeftPos+ei.WindowSizeX),F.ECF_TABMARKCURRENT,color,200)
            end
            local column=toreal(ei.CurTabPos)
            editor.AddColor(ei.EditorID,ii,column,column,F.ECF_TABMARKCURRENT,ii==ei.CurLine and color1 or color,201)
          end
        end
      )
    end
  end
end

function ExitScript()
  local wincount=far.AdvControl(F.ACTL_GETWINDOWCOUNT,0,0)
  for ii=1,wincount do
    local info=far.AdvControl(F.ACTL_GETWINDOWINFO,ii,0)
    if info and F.WTYPE_EDITOR==info.Type then
      ProcessCrest(info.Id,
        function(data)
          data.start=1
          data.finish=1
        end
      )
    end
  end
end

Event { group="EditorEvent"; flags="EnableOutput"; description=""; action=ProcessEditorEvent; }
Event { group="EditorInput"; flags="EnableOutput"; description=""; action=ProcessEditorInput; }
Event { group="ExitFAR"; description=""; action=ExitScript; }
Place the above code in a .lua file (inside your far's macros folder) and then every time you hold SHIFT+LCTRL inside the editor, it will paint a cross where the cursor is.

jazz albert
Posts: 1
Joined: Tue 25 Oct, 2016 00:45

Crest replacement

Post by jazz albert » Tue 25 Oct, 2016 00:50

kamil wrote: ure.
Sorry that I stripped all the comments, but I like my code clean:

Code: Select all

local F=far.Flags
local editors={}

local color = 0x5e
local color1 = 0x5e

local scrolllock=false

function GetData(id)
  local data=editors[id]
  if not data then
    editors[id]={start=1,finish=1}
    data=editors[id]
  end
  return data
end

function RemoveCrest(id,data)
  for ii=data.start,data.finish do
    editor.DelColor(id,ii,nil)
  end
end

function ProcessCrest(id,update)
  local data=GetData(id)
  RemoveCrest(id,data)
  update(data)
end

function ProcessEditorInput(rec)
  if F.KEY_EVENT==rec.EventType and 0~=rec.VirtualKeyCode then
    if 0==bit64.band(rec.ControlKeyState,F.LEFT_CTRL_PRESSED) or 0==bit64.band(rec.ControlKeyState,F.SHIFT_PRESSED) then
      if scrolllock then
        ProcessCrest(editor.GetInfo(-1).EditorID,
          function(data)
            data.start=1
            data.finish=1
          end
        )
        scrolllock=false
        editor.Redraw(-1)
      end
    else
      if not scrolllock then
        scrolllock=true
        editor.Redraw(-1)
      end
    end
  end
  return false
end

function ProcessEditorEvent(id,event,param)
  if event==F.EE_READ then
    editors[id]={start=1,finish=1}
  end
  if event==F.EE_CLOSE then
    editors[id]=nil
  end
  if event==F.EE_REDRAW then
    if scrolllock then
      local ei=editor.GetInfo(id) --- вместо 'local ei=editor.GetInfo(-1)' - zg Fri 09 Jan, 2015 18:04 http://forum.farmanager.com/viewtopic.php?p=127200#p127200
      ProcessCrest(ei.EditorID,
        function(data)
          data.start=ei.TopScreenLine
          data.finish=math.min(ei.TopScreenLine+ei.WindowSizeY,ei.TotalLines)
          for ii=data.start,data.finish do
            local toreal=function(pos) return editor.TabToReal(ei.EditorID,ii,pos) end
            if ei.CurLine==ii then
              editor.AddColor(ei.EditorID,ii,toreal(ei.LeftPos),toreal(ei.LeftPos+ei.WindowSizeX),F.ECF_TABMARKCURRENT,color,200)
            end
            local column=toreal(ei.CurTabPos)
            editor.AddColor(ei.EditorID,ii,column,column,F.ECF_TABMARKCURRENT,ii==ei.CurLine and color1 or color,201)
          end
        end
      )
    end
  end
end

function ExitScript()
  local wincount=far.AdvControl(F.ACTL_GETWINDOWCOUNT,0,0)
  for ii=1,wincount do
    local info=far.AdvControl(F.ACTL_GETWINDOWINFO,ii,0)
    if info and F.WTYPE_EDITOR==info.Type then
      ProcessCrest(info.Id,
        function(data)
          data.start=1
          data.finish=1
        end
      )
    end
  end
end

Event { group="EditorEvent"; flags="EnableOutput"; description=""; action=ProcessEditorEvent; }
Event { group="EditorInput"; flags="EnableOutput"; description=""; action=ProcessEditorInput; }
Event { group="ExitFAR"; description=""; action=ExitScript; }
Place the above code in a .lua file (inside your far's macros folder) and then every time you hold SHIFT+LCTRL inside the editor, it will paint a cross where the cursor is.
I messed with this script is there any other way to do so?
Last edited by jazz albert on Thu 01 Jan, 1970 01:00, edited 0 times in total.
Reason: [code]

Post Reply

Return to “General Plug-In Discussions”

Who is online

Users browsing this forum: No registered users and 1 guest