ScriptPlugin for CodeLite 6.0

Script Plugin (LUA) development forum
jfouche
CodeLite Guru
Posts: 351
Joined: Mon Oct 20, 2008 7:26 pm
Genuine User: Yes
IDE Question: C++
Location: France
Contact:

ScriptPlugin for CodeLite 6.0

Post by jfouche »

Hi,

I provide you the ScriptPlugin for CodeLite 6.0.As I only have a Windows machine, I can only provide you the Windows version (I tried using VirtualBox, but I got a very slow ubuntu virtual machine, with a low definition screen :().

To install it, you must extract the 7z content to your plugins directory.

This plugin provides a toolbar with 2 buttons :

  • Show scripts : shows / hide a miniframe which contains all "on demand" script. Double clicking on a script runs it.
  • Scripts settings : it show a dialog that allow you to add / remove scripts (on demand script or hooks scripts).

All scripts embed a global "codelite" variable, you can use to interract with codelite.
Here is the API :

codelite

  • codelite.manager : gives you acces to the IManager

  • codelite.Trace(str) : add a trace in the trace tab

  • codelite:Bind(eventId, function) : This function is only usefull when creating a hook script. It binds the function to the current event. Currently, only the wxEVT_FILE_SAVED has been implemented.

IManager

  • manager:GetActiveEditor() : return the current editor or nil

  • manager:NewEditor() : Create a new editor, and returns it

  • manager:GetWorkspace() : return the workspace or nil

IEditor

  • editor:GetEditorText() : return the text of the editor

  • editor:SetEditorText(str) : set the content of the editor

  • editor:GetSelection() : return the current selection

  • editor:ReplaceSelection(str) : replace the current selection with the given string

  • editor:AppendText(str) : Append the given string at the end of the editor

  • editor:GetCurrentPosition() : return the position of the caret

  • editor:InsertText(int, str) : Insert text at the given position

Workspace

  • workspace:GetActiveProjectName() : return the name of the active project

  • workspace:GetProjectList() : return a table containing all project names

  • worspace:FindProjectByName(str) : return the project named with the given string, or nil

Project

  • project:GetName() : return the project name

  • project:GetFiles() : return a table containing all file paths

wxCommandEvent

  • event:GetString() : return the string, depending on the event context

clCommandEvent (inherit wxCommandEvent)

  • event:GetString() : return the string, depending on the event context

  • event:GetFileName() : return the filename, depending on the event context

Here is a "on demand" script which allow you to comment the current selection :

Code: Select all

editor = codelite.manager:GetActiveEditor()
if editor then
	sel = editor:GetSelection()
	if #sel > 0 then
		text = "/* " .. sel .. " */"
		editor:ReplaceSelection(text)
	end
end

Here is a "on demand" script which trim line ending of the current editor :

Code: Select all

function rtrim(s)
  local n = #s
  while n > 0 and s:find("^%s", n) do n = n - 1 end
  return s:sub(1, n)
end

function lines(str)
  local t = {}
  local function helper(line) table.insert(t, line) return "" end
  helper((str:gsub("(.-)\r?\n", helper)))
  return t
end

editor = codelite.manager:GetActiveEditor()
if editor then
	text = editor:GetEditorText()
	if #text ~= 0 then
		l = lines(text)
		for i, line in ipairs(l) do
			l[i] = rtrim(line)
		end
		newText = table.concat(l, "\n")
		editor:SetEditorText(newText)
	end
end

And here a hook script which trace each saved files

Code: Select all

local f = function(event)
	codelite.Trace("FILE SAVED : " .. event:GetString())
end

codelite:Bind(wxEVT_FILE_SAVED, f)
You do not have the required permissions to view the files attached to this post.
Jérémie
petah
CodeLite Expert
Posts: 231
Joined: Sat Nov 24, 2012 8:04 pm
Genuine User: Yes
IDE Question: c++
Location: Los Angeles
Contact:

Re: ScriptPlugin for CodeLite 6.0

Post by petah »

Nom d'une pipe, t'es de retour?!!! j'ai failli pas voir ton msg. Je teste illico presto ;)

a+

-- p
main: Debian Jessie x64 + custom wxTrunk
Post Reply