Reading the entire file contents into a string in a macro

Get help with the installation and running of the Zeus IDE. Please do not post bug reports or feature requests here. When in doubt post your question here.
Post Reply
nedmunds
Posts: 5
Joined: Mon Nov 28, 2005 9:58 pm

Reading the entire file contents into a string in a macro

Post by nedmunds »

My apologies if this has already been covered, but I could not find any reference in the forum.

Within a macro, how do I read in the contents of the current file into a string? I seem to easily be able to get a single line, but not the entire file.

Thanks in advance,

Neil

PS. I am in day 5 of evaluation and and all of my "required" items have been resolved. Now working on nice to haves.
jussij
Site Admin
Posts: 2650
Joined: Fri Aug 13, 2004 5:10 pm

Post by jussij »

Hi Neil,
Within a macro, how do I read in the contents of the current file into a string?

The Lua macro shown below illustrates at least two methods of achieving this result:

Code: Select all

function get_file_as_string1()
    -- save the cursor details
    cursor_save()

    -- select all the text
    MarkSelectAll()

    -- copy the text to string
    local string result = macro_tag("$WEX")

    -- restore the cursor details
    cursor_restore()

    return result
end

function get_file_as_string2()
    -- save the cursor details
    cursor_save()

    -- copy the text to string
    local string result = ""

    -- total number of lines
    local lines = get_line_count();

    for i = 1, lines, 1 do
      -- append the line to the results buffer
      result = result .. get_line_text(i) .. "\n"
    end

    -- restore the cursor details
    cursor_restore()

    return result
end

function key_macro()
    -- get the file text as a string
    local string text1 = get_file_as_string1()

    -- display the result
    message_box(1, text1, "The Current File - Method 1")

    -- get the file text as a string
    local string text2 = get_file_as_string2()

    -- display the result
    message_box(1, text2, "The Current File - Method 2")
end

key_macro()
To use this macro do the following
  1. Copy the text above to the zScript\marking.lua file located off the Zeus installation directory.
  2. Open any small text file
  3. Select the Macros, Execute Script Menu
  4. Type in marking
  5. Hit the Run button
By running the macro you should see the text of the current file displayed in one of two message boxes. Naturally I would not suggest running this macro on a file that is several mega bytes in size ;)
PS. I am in day 5 of evaluation and and all of my "required" items have been resolved. Now working on nice to haves.
Feel free to post any nice to have requirements to this forum. Zeus is constantly evolving and user feedback is of great value in determining the direction of this evolution.

Cheers Jussi
nedmunds
Posts: 5
Joined: Mon Nov 28, 2005 9:58 pm

Post by nedmunds »

Jussi,

Thanks for the quick response. That works for me!

As requested, here are my nice to haves. Some have already been posted.

(already posted)
1. Triple quoted strings in Python. I use these a lot.
2. Visible bookmarks. Helps me to keep track of where they are.

(no posts that I can find)
1. Syntax Highlighting keywords seem to have an upper limit. I tried to import all Namespaces, classes, methods and properties for C# (around 25000 keywords) Zeus allows the import, but when I restart zeus and load a C# file, the program displays an error message and aborts.

2. I program web applications using ASP.net and C#. For many simple sites, I do not use code behind, but include the C# code in the same file as my Markup. I successfully updated the C# document type to support this, however code folding does not work for these files. (probably confused by the markup)

3. I tried to program some macros in Python, however there are a number of libraries that I commonly use that are not included in the Python built into Zeus. I commonly use the following imports in most of my Python code:
import dbi
import odbc
import win32com.client
import ftplib
import time
import os
import string
from pprint import pprint


I have not yet started looking at Workspace functionality.

Of course none of these are show stoppers for me. I have found the forum to be a wonderful source of information.

Thanks for a great product. I purchased a license for Zeus this morning.

-Neil
jussij
Site Admin
Posts: 2650
Joined: Fri Aug 13, 2004 5:10 pm

Post by jussij »

Hi Neil,
1. Triple quoted strings in Python.

Unfortunately triple quoted strings is definitely a problem for the current Zeus colorizer engine :(
2. Visible bookmarks. Helps me to keep track of where they are.

This feature is on the Zeus todo list.
1. Syntax Highlighting keywords seem to have an upper limit. I tried to import all Namespaces, classes, methods and properties for C# (around 25000 keywords) Zeus allows the import, but when I restart zeus and load a C# file, the program displays an error message and aborts.

This sounds like a bug :(
2. I program web applications using ASP.net and C#. For many simple sites, I do not use code behind, but include the C# code in the same file as my Markup. I successfully updated the C# document type to support this, however code folding does not work for these files. (probably confused by the markup)
What will be going wrong here is the file extension for c# is hard coded into the xFolder.dll file, but when you embed the c# into a html file it has a different file extension and hence the code folding disappears :(

I will look to see if it is possible to maybe add some soft coding into the xFolder.dll to allow some form of user configuration.
3. I tried to program some macros in Python, however there are a number of libraries that I commonly use that are not included in the Python built into Zeus. I commonly use the following imports in most of my Python code:

I am not sure if this is a bug or a suggestion :?

Do you think Zeus should include these libraries by default :?:

Aren't you able to import these libraries from within the Zeus macro or does this not work :?:
I have not yet started looking at Workspace functionality.

If you have not done so already, I would suggest taking a look at the Python Quick Help feature. I suspect a lot of Zeus users don't even know of the Quick Help feature, but for me personally it is one feature I can not live without.
Of course none of these are show stoppers for me. I have found the forum to be a wonderful source of information.
It only because of users like yourself, who take the time to post questions that have helped make the forum such a good source of information.

I thank you.

Cheers Jussi
nedmunds
Posts: 5
Joined: Mon Nov 28, 2005 9:58 pm

Post by nedmunds »

Jussi

Quote

Code: Select all

I am not sure if this is a bug or a suggestion Confused

Do you think Zeus should include these libraries by default Question

Aren't you able to import these libraries from within the Zeus macro or does this not work Question
I am not able to import these libraries from within Zeus. These libraries are pretty critical for allowing Python to automate Zeus.

I did perform some additional research and discovered that Zeus was using a different version of Python than me. (Zeus uses 2.4, I was using 2.3)

I upgraded my version of Python and set some environment variables (to find the libraries) that had not been previously set.

Now most of the imports work. Those imports that are loaded from a .py or .pyc (source files) work fine. Those imports that are loaded from executables (dll) cause Zeus to abort with the following error message:

Code: Select all

Messagebox title is Microsoft Visual C++ Runtime Library

Runtime Error!

Program:  C:\Program Files\Zeus\zeus.exe

This application has requested the Runtime to terminate in an unusual way.  
Please contact the application's support team for more information.
For some reason, the Zeus version of Python seems to have trouble importing dlls that come with my version of Python (ActiveState).

If you have an easy fix or work around, I would appreciate it. However, I can implement just about macro functionality I need using vbscript instead of Python. (But I prefer coding in Python)

-Neil
jussij
Site Admin
Posts: 2650
Joined: Fri Aug 13, 2004 5:10 pm

Post by jussij »

After some testing it appears the Zeus integration with the ActiveState Python is pretty much broken :(

I have created a new thread that summaries the issues as they currently stand. The new thread can be found here.

Jussi
jussij
Site Admin
Posts: 2650
Joined: Fri Aug 13, 2004 5:10 pm

Post by jussij »

The latest Zeus patch now has support for Python triple quotes :)

To enable this features you need to edit the Python document type and in the Keywords section, enable the triple quotes option.

This latest version also provides better macro integration with the official Python release.

Cheers Jussi
nedmunds
Posts: 5
Joined: Mon Nov 28, 2005 9:58 pm

Post by nedmunds »

Awesome!

Thanks!
Post Reply