Appendix B. Sample Macro to Create a Popup Window
/***************************************************************************/
/* */
/* Create and manage a popup window to enter bookmaster tags into a file. */
/* The WINLINE command requires that the window text be separated from the */
/* resulting command by the text "\n". This macro is a sample to show how */
/* to use the editor's popup window interface. */
/* */
/* Requires version 1.61 or later of the editor. */
/* */
/* Written by B. Thompson, June 7, 1995 */
/* Fix problem inserting bookie tag at beginning of line, April 29, 1996 */
/* Insert tag around block mark, April 29, 1996 */
/* Updated to illustrate bold and emphasised attributes, August 30, 1996 */
/* */
/***************************************************************************/
Parse source . . macroname '.' . /* Who are we?*/
Parse Arg parm .
Select
When parm = 'HP1' | parm = 'HP2'
Then Do /* Italics*/
gml_tag = 'hp' || substr(parm,3) || '.'
'EXTRACT /CURLINE/'
'EXTRACT /CURSOR/'
'EXTRACT /MARK/'
wordlen = 0
If (mark.0 > 0) & (mark.2 = mark.3) & (mark.4 > 0)
Then Do /* Tag the marked block*/
cursor.2 = mark.4 - 1
wordlen = mark.5 - mark.4 + 1
End
Else Do While Substr(curline.1,cursor.2,1) <> ' '
cursor.2 = cursor.2 - 1
If cursor.2 = 0
Then Leave /* We hit the beginning of the line*/
End /* End do*/
If cursor.2 > 0
Then Do
beginning = Substr(curline.1,1,cursor.2)
ending = Substr(curline.1,cursor.2+1)
End
Else Do
beginning = ''
ending = curline.1
End
If wordlen > 0
Then Do /* Parse over the mark*/
word = Substr(ending,1,wordlen)
ending = Substr(ending,wordlen+1)
End
Else Do
Parse Var ending word ending
ending = ' 'ending /* Put the blank back in*/
End
'REPLACE' beginning':'gml_tag || word || ':e'gml_tag || ending
If wordlen > 0
Then Do /* Move the mark*/
'CURSOR' mark.2 mark.4 + length(gml_tag) + 1
'MARK BLOCK'
'CURSOR +0 +'wordlen - 1
'MARK BLOCK'
End
End
Otherwise Do /* Create the window*/
'EXTRACT /ESCAPE/'
'WINDOW 6 50 6 Bookmaster Tags'
'WINLINE Head level 0 (h0)\nKEYIN :h0.'
'WINLINE Head level 1 (h1)\nKEYIN :h1.'
'WINLINE Head level 2 (h2)\nKEYIN :h2.'
'WINLINE Head level 3 (h3)\nKEYIN :h3.'
'WINLINE' escape.1'EItalics' escape.1'T(hp1)\nMACRO' macroname 'HP1'
'WINLINE' escape.1'BBold' escape.1'T(hp2) \nMACRO' macroname 'HP2'
End
End /* End select*/
Exit