Page 1 of 1

Simple Script question: Newbie alert

Posted: Thu Dec 16, 2004 7:10 am
by John
Hi

I'm trying to write a script and have run into a problem on the first step :-)

The cursor can start anywhere on a line, so I move the cursor to the start of the line, easy.

Now I' m wondering if there is a zeus way of determining if there is a word at the start of the line, as opposed to a comment marker or white space. One doesn't jump out of the documentation at me, and I can think of a way to hack it but thought I'd ask if there were an elegant way of doing it.

Or is the general philosophy to import things like standard libraries for the scripting language, python in my case, and use them. I know Python has routines to do this sort of thing.

Thanks

john

Posted: Thu Dec 16, 2004 11:36 am
by jussij
Hi John,
I'm trying to write a script and have run into a problem on the first step
At first macros can be a little difficult but with a bit of practise they do get easier :)
Now I' m wondering if there is a zeus way of determining if there is a word at the start of the line
This Lua macro will test the current line for a space or a word and display the result in the status bar.

Code: Select all

function key_macro()
  screen_update_disable()

  -- get a copy of the current line
  local text = get_line_text()

  if (string.find (text, " ", 1, 1) == 1) then
    message("Line starts with a space.")
  else
    message("Line starts with a word.")
  end

  screen_update_enable()
  screen_update()
end

key_macro() -- run the macro
Or is the general philosophy to import things like standard libraries for the scripting language, python in my case, and use them. I know Python has routines to do this sort of thing.

This is definitely the Zeus philosophy. The Zeus scripting model provides a handfull of scripting interface functions to allow the language to interface with the current document. The real processing should be done using the scripting language. In the Zeus online help, use the index and search for Macro, Builtin Functions. This section describes these scripting interface functions.

One of these interface functions is the get_line_text function. The macro above is written in Lua but it could easily be re-written in any one of the other Python, JavaScript etc scripting languages.

Cheers Jussi.