Mark Paragraph

This forum allows you to share scripts with other Zeus users. Please do not post bug reports, feature requests or questions to this forum, but rather use it exclusively for posting scripts or for the discussion of scripts that have been posted.
Post Reply
jussij
Site Admin
Posts: 2446
Joined: Fri Aug 13, 2004 5:10 pm

Mark Paragraph

Post by jussij » Wed Sep 19, 2012 5:11 am

This is a Python macro that will mark the current paragraph.

To use this macro save the code below to the mark_paragraph.py file in the zScript folder and then run the macro using the Macro, Execute Script menu.

The macro can also be bound to a keyboard key or bound to the menu.

Code: Select all

#
#        Name: Mark Current Paragraph
#
#    Language: Python Macro
#
# Description: This Python macro will select mark the current paragraph.
#

import zeus

def key_macro():
   # reduces screen flicker
   zeus.screen_update_disable()

   # macro only works for documents
   document = zeus.is_document()

   if document > 0 :
      # save the current cursor
      zeus.cursor_save()

      # line variables that will define the paragraph
      line_end = -1
      line_start = -1
      line_number = zeus.get_line_pos()

      # look for the start of paragraph
      while line_number >= 1:
         text = zeus.get_line_text(line_number)

         if len(text) == 0:
            # found the start of paragraph
            line_start = line_number + 1
            break
         elif line_number == 1:
            # found the start of document
            line_start = line_number
            break

         line_number = line_number - 1

      #zeus.message_box(0, line_start)

      if line_start != -1:
         line_number = zeus.get_line_pos()
         line_count  = zeus.get_line_count()

         # look for the end of paragraph
         while line_number < line_count:
            text = zeus.get_line_text(line_number)

            if len(text) == 0:
               # found the end of paragraph
               line_end = line_number - 1
               break

            line_number = line_number + 1

         if line_end == -1:
            line_end = line_count - 1

      # see if we found a paragraph
      if line_end != -1:
         # move to the start of paragraph
         zeus.set_line_pos(line_start, 1)

         # turn on block marking
         zeus.MarkBlockSet()

         text_len = len(zeus.get_line_text(line_end)) + 1

         #zeus.message(text_len)

         # move to the end of paragraph
         zeus.set_line_pos(line_end, text_len)

         # complete the marking
         zeus.MarkBlockReset()

         # ignore the original saved cursor
         zeus.cursor_ignore()
      else:
         # restore the original cursor
         zeus.cursor_restore()

         # feedback to the user
         zeus.message("No paragraph of text was found.")

   else:
      # feedback to the user
      zeus.message("This macro only works for document files.")
      zeus.beep()

   # reduces screen flicker
   zeus.screen_update_enable()
   zeus.screen_update()

key_macro() # run the macro

Post Reply
kuchnie warszawa opinie

Who is online

Users browsing this forum: No registered users and 2 guests