TutorialRunning an Editor Script




Prev | Up | Next | Back | Forward | Online Documentation Home Page

Running an Editor Script

This chapter illustrates Ada-ASSURED's scripting language. Scripts can be used to (a) customize and extend the Ada-ASSURED's functionality, (b) integrate Ada-ASSURED with other tools, and (c) implement batch or interactive program analyzers. The chapter contains only toy examples, to suggest what is possible. Chapter Scripting Language describes the scripting language in detail.

Scripts under X Windows

Typically, scripts are stored in a text file that is loaded and executed. However, here you execute script statements one at a time in the *transcript* buffer so you can see the immediate effect of each statement:

Customization and Extension under X Windows

In this section, you define a new Ada-ASSURED command and add a new menu item for it. For now, the command will be stubbed, just printing the message ``Call vi''.
  1. Type the following statement in the *transcript* window. When you strike Enter, a new menu labeled LOCAL should appear at the left end of the menu bar:

    	(sg:add-menu "" "LOCAL" 0 #\null #\c '() "local")
    	

  2. Type the following script statement in the *transcript* window. When you strike Enter, a new item labeled My Editor should appear in the LOCAL menu:

    	(sg:add-menu "local" "My Editor" 0 #\null #\b '() "vi")
    	

    If you select item My Editor from the LOCAL menu, you will get the message ``Bad command "vi" in menu'' because no command named vi is yet defined to carry out the action for the menu item.

  3. Type the following script statement in the *transcript* window, and then strike Enter:
    	(sg:add-command "vi" (lambda() (sg:write-message "Call vi")))
    	
    Now, when you select item My Editor from the LOCAL menu, the message ``Call vi'' is displayed in the status pane.

Integration under X Windows

In this section, you redefine the vi command so that it actually invokes a text editor on the current structural selection. Rather than typing the new definition, load it from a file as described below.

The new definition of command myeditor is:

(sg:add-command "vi" (lambda()
   (sg:save-selection-to-file "Text" "/tmp/ssel" "BASEVIEW")
   (system "xterm -e /usr/ucb/vi /tmp/ssel")
   (sg:cut-structure)
   (sg:insert-file-structure "/tmp/ssel")))
which first saves the structural selection to file /tmp/ssel, and then invokes vi on the file running in a separate shell. When vi exits, the structural selection is replaced by the contents of /tmp/ssel, as edited in vi.

Try out the new vi command on an Ada file:

  1. Open an Ada file from directory
    aahome/AdaSamples/SPC/examples1

  2. Make the buffer modifiable by toggling Write Permission in menu Options.

  3. Select a small group of statements, or a single procedure.

  4. Invoke command myeditor from the LOCAL menu, so as to run vi.

  5. If you know vi, modify the code fragment slightly.

  6. Exit vi by typing :wq and then strike Enter.

Scripts under Microsoft® Windows®

Typically, scripts are stored in a text file that is loaded and executed. However, here you execute script statements one at a time in the *transcript* buffer so you can see the immediate effect of each statement:

Customization and Extension under Microsoft® Windows®

In this section, you define a new Ada-ASSURED command and add a new menu item for it. For now, the command will be stubbed, just printing the message ``Call notepad''.
  1. Type the following statement in the *transcript* window. When you strike Enter, a new menu labeled LOCAL should appear at the left end of the menu bar:

    	(sg:add-menu "" "LOCAL" 0 #\null #\c '() "local")
    	

  2. Type the following script statement in the *transcript* window. When you strike Enter, a new item labeled My Editor should appear in the LOCAL menu:

    	(sg:add-menu "local" "My Editor" 0 #\null #\b '() "notepad")
    	

    If you select item My Editor from the LOCAL menu, you will get the message ``Bad command "notepad" in menu'' because no command named notepad is yet defined to carry out the action for the menu item.

  3. Type the following script statement in the *transcript* window, and then strike Enter:
    	(sg:add-command "notepad" (lambda() (sg:write-message "Call notepad")))
    	
    Now, when you select item My Editor from the LOCAL menu, the message ``Call notepad'' is displayed in the status pane.

Integration under Microsoft® Windows®

In this section, you redefine the notepad command so that it actually invokes a text editor on the current structural selection. Rather than typing the new definition, load it from a file as described below. You should read the description that applies to your windowing system.

The new definition of command notepad is:

(sg:add-command 
   "notepad" 
   (lambda()
     (sg:save-selection-to-file "Text" "C:\\temp\\ssel" "BASEVIEW")
     (system "notepad C:\\temp\\ssel")
     (sg:cut-structure)
     (sg:insert-file-structure "C:\\temp\\ssel")))
which first saves the structural selection to file C:\temp\ssel, and then invokes notepad on the file running in a separate shell. When notepad exits, the structural selection is replaced by the contents of C:\temp\ssel, as edited in notepad.

Try out the new notepad command on an Ada file:

  1. Open an Ada file from directory
    aahome/AdaSamples/SPC/examples1

  2. Make the buffer modifiable by toggling Write Permission in menu Options.

  3. Select a small group of statements, or a single procedure.

  4. Invoke command notepad from the LOCAL menu, so as to run notepad.

  5. If you know notepad, modify the code fragment slightly.

  6. Exit notepad by selecting Exit from the notepad window File menu.


Forward