The Zeus macro shown below wraps the Zen Coding plug-in allowing the package to be used from within the Zeus editor.
Installation Procedure
Step 1: Download the Zen Coding plug-in.
Step 2: Copy the following files found in this package:
Code: Select all
__init__.py
settings.py
zen_core.py
Code: Select all
C:\Program Files\Zeus\zScript\zencoding
Code: Select all
C:\Program Files\Zeus\zScript\zeus_zen.py
To test the installation do the following:
Step 1: Use the Zeus Macros, Load menu to load the zeus_zen.py macro script created above.
Step 2: Create a new file inside of Zeus and type in the following Zen command.
Code: Select all
html>table>tr*5
Code: Select all
<html>
<table>
<tr></tr>
<tr></tr>
<tr></tr>
<tr></tr>
<tr></tr>
</table>
</html>
Here are some more Zen HTML and CSS examples.
Further Configuration - Bind Macro to the Keyboard
In the example above the macro was loaded and executed using the Macros menu. It is also possible to bind this macro to the keyboard by using the Zeus Options, Editor Options menu, making it much easier to execute.
Macro Code
Code: Select all
#
# Name: Zen Coding Macro
# Author: Jussi Jumppanen
# Language: Python
# Description:
#
# This is Zeus Python macro that wraps around the Zen Coding
# package found here:
#
# http://code.google.com/p/zen-coding/source/checkout
#
# For this macro to run the Zen Coding package needs to have been
# correctly installed.
#
# This package consists of the following files:
#
# __init__.py
# settings.py
# zen_core.py
#
# To install the Zen Coding package create the 'zencoding' folder in
# the 'C:\Program Files\Zeus\zScript' folder and copy the three
# files listed above to this new folder.
#
# Zen HTML Examples:
# http://code.google.com/p/zen-coding/wiki/ZenHTMLElementsEn
#
# Zen CSS Examples:
# http://code.google.com/p/zen-coding/wiki/ZenCSSPropertiesEn
#
import os
import re
import zeus
from zencoding import zen_core as zen
from zencoding.settings import zen_settings
def key_macro():
locked = zeus.is_read_only()
document = zeus.is_document()
# macro only works for read/write documents.
if (document == 1) and (locked == 0):
zeus.screen_update_disable()
zen.newline = '\n'
zen.insertion_point = '##IP##'
# get the current line details
cur_line = zeus.get_line_text()
cur_index = zeus.cursor_to_index(zeus.get_line_pos(), zeus.get_cursor_pos())
# check for the end of line case
cur_index = min(cur_index, len(cur_line))
# make sure we are not past the EOL
if zeus.is_cursor_online() == 0:
zeus.MoveLineEnd()
# no end of line text
end_line = ""
else:
# get the end of line text
end_line = cur_line[cur_index:len(cur_line)]
# Help with bebugging
#zeus.message_box(1, "line: " + cur_line + " index: " + str(cur_index))
if cur_index > 0:
# look for a Zen abbreviation
abbr, start_index = zen.find_abbr_in_line(cur_line, cur_index)
if abbr:
# Help with bebugging
#zeus.message_box(1, "abbr : " + abbr + " start: " + str(start_index))
# get the current file extensions
extension = zeus.macro_tag("$Ext")
# set the document type based on the extension
if (extension.lower() == ".css" ):
doc_type = 'xsl'
else:
doc_type = 'html'
# build up a new line by expanding out the Zen abbreviation
result = zen.expand_abbr(abbr, doc_type)
# Help with debugging
#zeus.message_box(1, "result: " + result + "(" + abbr + ")")
if result:
# the complete new line
result = cur_line[0:start_index] + result
# see if the current line had any padding
cur_line_pad = re.match(r'^(\s+)', cur_line)
if cur_line_pad:
# add the padding to the new line
result = zen.pad_string(result, cur_line_pad.group(1))
# see if spaces are being used for tabs
if zeus.macro_tag("$UseTabs") == 'false':
# get the tab size for the current document
tab_size = zeus.macro_tag("$TabSize")
# expand the tab characters into spaces
result = result.expandtabs(int(tab_size))
# remove the current line
zeus.MoveLineHome()
zeus.LineDeleteEnd()
# add in the end of line text
result = result + end_line
# write out the new line including the abbreviation
zeus.write(result, 0)
# try to look for an insertion point
if (result.find(zen.insertion_point) <> -1):
# save the current search options
zeus.search_options_save()
zeus.set_search_option("Scope" , 0)
zeus.set_search_option("WholeWord" , 0)
zeus.set_search_option("UseCase" , 0)
zeus.set_search_option("RegExpress", 0)
# find the insertion point
zeus.set_find_text(zen.insertion_point)
# put the cursor at the insertion point
zeus.set_cursor_pos(start_index + 1)
# locate insertion point
zeus.SearchPrevious()
# remove the insertion point text
zeus.MarkDelete()
# restore the saved search options
zeus.search_options_restore()
else:
# give some feedback
zeus.message("The current line does not contain a valid Zen Code abbreviation.")
zeus.beep()
else:
# give some feedback
zeus.message("The current line does not contain a valid Zen Code abbreviation.")
zeus.beep()
zeus.screen_update_enable()
else:
zeus.message("This macro only works for writable document files!")
zeus.beep()
key_macro() # run the macro