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.
Reading the entire file contents into a string in a macro
Hi Neil,
The Lua macro shown below illustrates at least two methods of achieving this result:
To use this macro do the following
Cheers Jussi
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()
- Copy the text above to the zScript\marking.lua file located off the Zeus installation directory.
- Open any small text file
- Select the Macros, Execute Script Menu
- Type in marking
- Hit the Run button

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.PS. I am in day 5 of evaluation and and all of my "required" items have been resolved. Now working on nice to haves.
Cheers Jussi
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
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
Hi Neil,
Unfortunately triple quoted strings is definitely a problem for the current Zeus colorizer engine
This feature is on the Zeus todo list.
This sounds like a bug

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.
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
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.
I thank you.
Cheers Jussi
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

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 disappears2. 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)

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.
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.Of course none of these are show stoppers for me. I have found the forum to be a wonderful source of information.
I thank you.
Cheers Jussi
Jussi
Quote
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:
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
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 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.
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
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

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