Collected tips for Crimson Editor

Posted by Nick Gammon on Wed 04 Jun 2008 09:47 PM — 5 posts, 31,187 views.

Australia Forum Administrator #0
I have been very happy with using Crimson Editor for editing MUSHclient script files, and in general.

It is:

  • Free
  • Fast
  • Does syntax colouring of Lua (and various other languages, like C, HTML)
  • Lets you do FTP editing (load and save from a FTP server), which is handy for grabbing files on another server
  • Can be configured to show MUSHclient help for the word under the cursor (see below)
  • Can be configured to show Lua help for the word under the cursor (see below)
  • Can be configured to test Lua stand-alone by putting the path to lua.exe in its tools configuration, so you can edit/test/fix Lua programs very quickly
  • Can be configured to syntax-colour the MUSHclient functions, so you can immediately see if they are spelt correctly (see below).


Below are links to the various tips I have developed for Crimson Editor over the years:



Amended on Wed 18 Jun 2008 01:05 AM by Nick Gammon
Australia Forum Administrator #1
To simplify syntax colouring MUSHclient keywords, here are the files I used for Crimson Editor:

http://www.gammon.com.au/files/mushclient/lua.key (15 Kb)
http://www.gammon.com.au/files/mushclient/lua.spc (1 Kb)

The first one has all the Lua keywords and functions, as well as the MUSHclient function names.

You can download these files and replace the ones of the same name in the Crimson Editor "spec" subdirectory.

I generated the function names with this script:


pairsbykeys = require "pairsbykeys"

for _, t in ipairs {"math", 
  "io", 
  "debug", 
  "coroutine", 
  "os", 
  "string", 
  "table", 
  "package",
  "world",
  "utils",
  "bit",
  "bc",
  } do

  for k, v in pairsbykeys (_G [t]) do
    if string.sub (k, 1, 1) ~= "_" then
      print (t .. "." .. k)
    end -- not starts with underscore
  end -- each function
  print ""
end -- each major package

-- now global variables

for k, v in pairsbykeys (_G) do
  if type (v) == "function" or type (v) == "string" then
    print (k)
  end -- function or string
end -- each function



Then I copied all the "world.xxx" functions to have a second copy without "world." in front, as MUSHclient does not require the world prefix, for simplicity. (Basically this is done by putting a metatable on the _G table).


Amended on Thu 05 Jun 2008 03:29 AM by Nick Gammon
Australia Forum Administrator #2
A slightly improved version finds for itself all the table names:


require "pairsbykeys"

for a, b in pairsByKeys (_G) do

  if type (b) == "table" and a ~= "_G" then
    for k, v in pairsByKeys (_G [a]) do
      if string.sub (k, 1, 1) ~= "_" and type (v) == "function"  then
        print (a .. "." .. k)
      end -- not starts with underscore
    end -- each function
  end -- each table
  print ""
end -- each major package

-- now global variables

for k, v in pairsByKeys (_G) do
  if type (v) == "function" or type (v) == "string" then
    print (k)
  end -- function or string
end -- each function



After running this a few extra function names cropped up (eg. progress.new) so I have uploaded a more up-to-date lua.key file.
USA #3
using the 'progress.new' function just shows a progress dialog that does not allow you to dismiss it, so use of it is pointless as of yet.

-Onoitsu2
Amended on Thu 05 Jun 2008 03:39 AM by Onoitsu2
Australia Forum Administrator #4
Well, it was designed for use in the spell checker, and it *can* be dismissed, however in version 4.26 or earlier it has a bug which I just noticed, so I wouldn't use it just yet. Here is an example of how it might be used:


dlg = progress.new ("Self-destruct sequence started ...")
  
number_of_things = 100000

dlg:range (0, number_of_things )
dlg:setstep (1)

for i = 1, number_of_things do

  dlg:step ()  
  dlg:status ("Doing item " .. i)

  if dlg:checkcancel () then
    print "Self-destruct sequence cancelled..."
    break
  end -- if

end -- loop

dlg:close ()



This illustrates the general idea of the progress dialog.

  • You create it with progress.new - that gives you a userdatum which is used for subsequent operations.

    With the userdatum (dlg in this example) you can:
  • dlg:range - set a range for the progress bar (assuming you know that you need to do x things)
  • dlg:setstep - set a step amount - when you step it goes up by this much.
  • dlg:status - set the status (which is shown in the progress bar) - this is a piece of text
  • dlg:step - step up to the next item
  • dlg:checkcancel () - check if they clicked "cancel"
  • dlg:close - close and dismiss the dialog


Notice the colon after "dlg", not a period. This is because it is a userdatum.

Thanks to your message I noticed that there is a bug, after you close it, when Lua goes to garbage-collect it (which might be 5 minutes later) it raises an error. Better wait for version 4.27 before you try it.