Running an Editor ScriptThis 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.
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''.
(sg:add-menu "" "LOCAL" 0 #\null #\c '() "local")
(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.
(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.
aahome/scripts/vi.stkor use the file-and-directory browser to locate it. Then click on OK.
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:
aahome/AdaSamples/SPC/examples1
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''.
(sg:add-menu "" "LOCAL" 0 #\null #\c '() "local")
(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.
(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.
aahome/scripts/notepad.stkor use the file-and-directory browser to locate it. Then click on OK.
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:
aahome/AdaSamples/SPC/examples1