home *** CD-ROM | disk | FTP | other *** search
/ Gold Fish 3 / goldfish_volume_3.bin / files / text / edit / macro / augfl / stylespot.ged < prev    next >
Text File  |  1994-08-24  |  13KB  |  317 lines

  1. /*
  2.  
  3.    $HISTORY:
  4.    26 Apr 1994,   1.06: The fact that Dietmar included the possibility to detect
  5.                         whitespaces confused me a lot. ;-) Everything appeared
  6.                         to be broken, but in fact it was not. I went over the
  7.                         code once more to detect minor changes and tried to
  8.                         avoid the whitespaces-problem for any configuration.<LL>
  9.                         Just leave :;,. and () out of your GUI-config.
  10.    31 Dec 1993,   1.05: The code aimed at toggling word-wrap mode off/on has 
  11.                         been moved from the style_block routine to the main 
  12.                         routine. No more undesired word-wrap in `word'
  13.                         styling mode. Fix another potential bug (an end was
  14.                         missing at the end of the else part of the main routine
  15.                         this went unseen 'cause the script exited right at the
  16.                         missing end position.
  17.  
  18.    23 Dec 1993,   1.04: changes to fix a bug which occured when style4Spot was
  19.                         called while the cursor was in a `word' composed of
  20.                         blanks and no block was selected (ie in word mode),
  21.                         and another one wich occured when `styling' a word 
  22.                         (while in word mode) which was the last of the line.
  23.                         There's now a new procedure called: "word_style".
  24.                         It's worth (funny?) noticing that we corrected bugs 
  25.                         wich are the exact equivalent at word level of the
  26.                         bugs we fixed previously which occured at a `line level'
  27.                         (cfr version 1.03). Which should draw our attention on
  28.                         dealing with `special case' (e.g. boundery-case). <TM>
  29.  
  30.    13 Dec 1993,   1.03: fixed a bug which occured when the `styled' line was the
  31.                         last of the file. Minor change to enable handling of
  32.                         blocks wich include `empty' lines :).
  33.                         Added mome comments :). <TM>
  34.  
  35.    27 Nov 1993,   1.02: fixed (?) a bug related with the wordwrap mode.
  36.                         Minor code cleanup <TM>.
  37.  
  38.    24 Oct 1993,   1.01: fixed some bugs, minor (?)changes and cleaned 
  39.                         up the code <TM>.
  40.  
  41. */
  42.  
  43. /* ©1993 Tattoo Mabonzo/Lieven Lema. TEXTSTYLES FOR SPOT!              */
  44. /* INCLUDE <standard_disclaimer.h>  ;-)                                */
  45.  
  46. /* Thanks to Phillipe Van Der Gucht for some nice suggestions.         */
  47.  
  48. /* HOW TO USE IT?                                                      */
  49. /* -------------                                                       */
  50.  
  51. /* Just put the cursor on the word (or right next to the word ) you    */
  52. /* want to apply textstyle to, or select a block and invoke the        */
  53. /* script.  It's that easy :-)                                         */
  54. /* You can of course bind the script to a key or a menu in GOLDED.     */
  55. /* This is netware, if you like it, send us a netmail.                 */
  56. /* Please also report any bugs, qwirks... you might discover.          */
  57. /* Suggestion on improvements welcome too!                             */
  58. /* Tattoo Mabonzo 2:291/715.8  Lema 2:292/603.11                       */
  59.  
  60.  
  61. OPTIONS RESULTS                             /* enable return codes     */
  62.  
  63. if (LEFT(ADDRESS(), 6) ~= "GOLDED") then    /* not started by GoldEd ? */
  64.     address 'GOLDED.1'
  65.  
  66. 'LOCK CURRENT'        /* lock GUI, gain access         */
  67. OPTIONS FAILAT 6      /* ignore warnings               */
  68. SIGNAL ON SYNTAX      /* ensure clean exit             */
  69.  
  70.  
  71. /* ------------------------- INSERT YOUR CODE HERE: ------------------ */
  72.  
  73.  
  74. 'REQUEST STATUS "/// applying text style..."'
  75. 'REQUEST TITLE="Text Styles" BODY="Please choose a textstyle for word or block application." BUTTON="I|B|U|IB|IU|BU|IBU|CANCEL"'
  76.  
  77. number = RESULT            /* get the user choice (a textstyle or `cancel' */
  78.  
  79. if number = 0 then do      /* user selected cancel */
  80.     'UNLOCK'               /* clean exit           */
  81.     exit
  82.     end
  83.  
  84. else do                             /* user actually selected a textstyle */
  85.  
  86.     'QUERY SPC VAR SPACE'           /* remember white space settings */
  87.     'GUI SPC=32'                    /* set word separator            */
  88.  
  89.     'QUERY WRAP VAR WORDWRAP'       /* let's store current word wrap mode */
  90.     'LAYOUT WRAP=FALSE'             /* we disable wordwrap (ie REFORMAT mode is also disabled) in any case */
  91.     call head_tail_symbols(number)  /* let's get the appropriate text style symbols */
  92.     'QUERY MARKED'                  /* Do we deal with a block or a single word ? */
  93.  
  94.     if (RESULT = 'TRUE') then do    /* we've got a block... */
  95.         'PING SLOT 0'               /* let's remember current cursor position */
  96.         call block_style()          /* There exists a marked block, so let's apply textstyle to it */
  97.         'PONG SLOT 0'               /* we reset cursor position */
  98.         end
  99.     else do                         /* No block marked, we apply textstyle to a single word */
  100.         'PING SLOT 0'               /* let's remember current cursor position */
  101.         call word_style()
  102.         'PONG SLOT 0'               /* we reset cursor position */
  103.         end
  104.  
  105.     'LAYOUT WRAP=' || WORDWRAP      /* we restore the original wordwrap mode*/
  106.  
  107.     'FIX VAR=SPACE'                 /* might contain '*' */
  108.     'GUI SPC="' || SPACE || '"'     /* we restore white space settings */
  109.  
  110.     end
  111.  
  112. 'UNLOCK'                            /* clean exit */
  113. exit
  114.  
  115. /*--------------------------------------------------------------------*/
  116.  
  117. head_tail_symbols:
  118.  
  119. /* Initializes a compound variable with the text styles symbols */
  120. /* takes a number as it's arguments and returns (as a side effect */
  121. /* the so called `head' and `tail' text style symbols  */
  122.  
  123. parse arg S                        /* we get the number corresponding to the */
  124.                                    /* the user chose.                        */
  125. styles.1.head = "/"
  126. styles.1.tail = "/"
  127. styles.2.head = "*"
  128. styles.2.tail = "*"
  129. styles.3.head = "_"
  130. styles.3.tail = "_"
  131. styles.4.head = "/*"
  132. styles.4.tail = "*/"
  133. styles.5.head = "/_"
  134. styles.5.tail = "_/"
  135. styles.6.head = "*_"
  136. styles.6.tail = "_*"
  137. styles.7.head = "/*_"
  138. styles.7.tail = "_*/"
  139.  
  140. head_symbol = styles.S.head        /* we initialize the textstyle symbol variables */
  141. tail_symbol = styles.S.tail        /* with the appropriate symbols                 */
  142.  
  143. return
  144.  
  145. /*--------------------------------------------------------------------*/
  146.  
  147. block_style:
  148.  
  149. /* This routine applies the chosen text style to the selected block of text */
  150. /* It actually only manages the `block' size of the thing. The actual styling */
  151. /* is taken care of by the apply_style routine.                               */
  152.  
  153. 'QUERY BLAST VAR BLAST'             /* let's query for and store important parameters */
  154.  
  155. 'GOTO BFIRST'
  156. 'QUERY LINE VAR LINE'               /* what's the block first line number? */
  157. OLDLINE = -1                        /* we initialize a variable which will */
  158.                                     /* remember the number of the line we've */
  159.                                     /* just treated. It'll help us make sure */
  160.                                     /* we don't treat the same line more than */
  161.                                     /* once, which would occur when line */
  162.                                     /* being treated is the last one in the file */
  163.  
  164. do while ((LINE <= BLAST) & (OLDLINE ~= LINE)) /* while we still have a line to treat... */
  165.     charcode = first_word()                    /* which has NOT yet been treated ... */
  166.  
  167.     do while (charcode ~= _EOL)     /* while we still have a word to treat...*/
  168.         charcode = apply_style()
  169.         end
  170.  
  171.     if EmptyLine then do        /* in case of a empty line ... */
  172.         'FIRST'
  173.         'RIGHT'                 /* we go to the BOL ... */
  174.         'DELETE EOL'            /* and delete everything passed to it */
  175.         end
  176.     else do                     /* our line was NOT empty ... */
  177.         'PREVEND'               /* from our '_EOL' char, back to end of the last word */
  178.         'RIGHT'                 /* We're now just right next to the last word... */
  179.         'DELETE EOL'            /* ...We can (should!) delete anything we added... */
  180.         end
  181.  
  182.         OLDLINE = LINE          /* we store the line number of the line we've just */
  183.         'DOWN'                  /* treated and step down to the next line ... */
  184.         'QUERY LINE VAR LINE'   /* ... and get the new line number */
  185. end
  186.  
  187.  
  188. return
  189.  
  190. /*--------------------------------------------------------------------*/
  191.  
  192. first_word:
  193.  
  194. /* This procedure first sets a special marker for easy locating of the EOL */
  195. /* and returns the first `printable' (cfr code) of the the sentence or the */
  196. /* special marker code if the line does not include any `printable' character */
  197. /* As a side effect it also sets a boolean indicator `EmptyLIne' to `1' in */
  198. /* in the later case (else EmptyLine = 0)*/
  199.  
  200. _EOL = 10               /* we define a End Of Line `constant' */
  201. EmptyLine = 0           /* a priori we consider the line NOT being empty */
  202. 'GOTO EOL'              /* we're after the last char of the last word on the sentence */
  203. 'RIGHT'                 /* we insert a blank... */
  204. 'CODE SET=' || _EOL     /* ... and set our '_EOL' marker */
  205.  
  206. /* ***  Now the last *WORD* of our sentence is actually  */
  207. /* ***  a *ONE-character* word which ASCII value equals  */
  208. /* ***  that of our '_EOL' `constant' */
  209.  
  210.  
  211.  
  212. 'FIRST'                 /* to 'BOL'... */
  213. 'QUERY CODE VAR CODE'
  214.                         /* let's find the first printable char (or the '_EOL')... */
  215.  
  216. do while (((CODE < 33) ^ ((CODE > 127) & (CODE < 160))) & (CODE ~= _EOL))
  217.   'RIGHT'
  218.   'QUERY CODE VAR CODE'
  219.   end
  220.  
  221. if CODE = _EOL then     /* our line doesn't include any `printable' chararcter */
  222.     EmptyLine = 1
  223.  
  224. return CODE             /* ... we return the first `printable' char (or _EOL) */ 
  225.                         /* as the result of the function call */
  226.  
  227. /*--------------------------------------------------------------------*/
  228.  
  229. word_style:
  230.  
  231. /* The purpose of this routine is to handle some special case of one-word style   */
  232. /* application. Namely when the single word we want to apply style to is the last */
  233. /* in the sentence. In that case the delete word function will also delete the    */
  234. /* linefeed char and thus cause the next sentence to jump backward to the end of  */
  235. /* the current line. Which we want to avoid. It also handle the case where the    */
  236. /* script is called while the cursor in the middle of `blanks' and there's no     */
  237. /* selected. This should contribute to making this script a little bit more       */
  238. /* `idiot-proof' ;-)...  */
  239.  
  240. 'QUERY WORD VAR CUR_WORD'           /* let's get the word the cursor on or next to */
  241.  
  242. CW_LEN = wordlength(CUR_WORD,1)     /* what's the length of that word? (if any...) */
  243.  
  244. if (CW_LEN ~= 0) then do
  245.  
  246.     'PING SLOT=1'           /* we store current cursor position */
  247.  
  248.      _EOL = 10              /* we define a End Of Line `constant' */
  249.     'GOTO EOL'              /* we're on blank after the last char of the last word on the sentence */
  250.     'RIGHT'                 /* we insert a blank... */
  251.     'CODE SET=' || _EOL     /* ... and set our '_EOL' marker */
  252.  
  253.     'PONG SLOT=1'           /* we restore cursor position */
  254.  
  255.     call apply_style()
  256.  
  257.     'GOTO EOL'              
  258.     'LEFT'                  /* we 're now 'on' our EOL char...*/
  259.     
  260.     'PREVEND'               /* ... */
  261.     'RIGHT'
  262.     'DELETE EOL'            /* we delete what we've added */
  263. end
  264.  
  265. return 1
  266.  
  267. /*--------------------------------------------------------------------*/
  268.  
  269. apply_style:
  270.  
  271. /* This is the actual `styling' routine. It's word oriented. It applies a text */
  272. /* style to the word the cursor is on or right next to. */
  273. /* Returns the first character ASCII code of the next word in the line */
  274.  
  275. 'QUERY WORD VAR CURWORD'               /* let's get the word the cursor on or next to */
  276.  
  277. CW_LEN = length(CURWORD)               /* what's the length the current word? */
  278.  
  279. LWC = C2D(substr(CURWORD,CW_LEN))      /* we store our current word last char ASCII code */
  280.  
  281.                                         /* is last char one of <;:,.()> ? */
  282. if ((LWC=058)^(LWC=059)^(LWC=044)^(LWC=046)^(LWC=047)^(LWC=061)) then  
  283.  
  284.         /* thus the textstyle symbol should come before the punctuation sign */
  285.  
  286.     CURBWORD = head_symbol || substr(CURWORD,1,(CW_LEN - 1)) || tail_symbol || D2C(LWC) 
  287.  
  288. else
  289.  
  290.      CURBWORD = head_symbol || CURWORD || tail_symbol    /* ditto */
  291.  
  292.     'DELETE WORD'                   /* we now can safely erase the current word... */
  293.     
  294.     'FIX VAR=CURBWORD'              /* consider '*' & '"' */
  295.  
  296.     'TEXT T="' || CURBWORD || ' "'  /* post-insert the `styled' form */
  297.     
  298.     'QUERY CODE VAR CODE'           /* we now should be on the first char of the word */
  299.                                     /* next to the one we just replaced. Let's get */
  300.                                     /* its ASCII code...*/
  301.  
  302. return CODE                     /* ...which we return as our function result */
  303.  
  304.  
  305. /* --- ------- ------ ------------ */
  306. /*END OF YOUR CODE*/
  307. /*----- ---- --- */
  308. /*------ -- --- */
  309.  
  310. SYNTAX:
  311.  
  312. SAY "Sorry, error line" SIGL ":" ERRORTEXT(RC) ":-(" 
  313.  
  314. 'UNLOCK'
  315. EXIT
  316.  
  317.