home *** CD-ROM | disk | FTP | other *** search
/ Fish 'n' More 2 / fishmore-publicdomainlibraryvol.ii1991xetec.iso / dirs / uedit-stuff_429.lzh / Uedit-Stuff / Abbrev < prev    next >
Text File  |  1991-01-10  |  10KB  |  208 lines

  1.  
  2.                          WORD ABBREV MODE FOR UEDIT
  3.  
  4. This here is a set of commands that implements what Emacs users call "word
  5. abbrev mode".  What it does is it looks at all the words you type in, and if
  6. any of them is on its list of abbreviations, it replaces it with something
  7. else that it's an abbreviation for.  For instance, you can set it up so that
  8. whenever you type the word "gork", it automatically turns into "Good Old
  9. Raisins and Kumquats" as soon as you press the space bar or a punctuation
  10. character.  This is useful to save typing.  It is especially useful when
  11. programming in Modula-2, to ease the burden of typing stuff like
  12. "IMPLEMENTATION MODULE" over and over.  It can also be used to automatically
  13. capitalize standard identifiers when you type them in lowercase.  The
  14. commands are:
  15.  
  16.     A-x:     Turns the abbreviation expander on or off.
  17.     SA-x:    Add an abbreviation (and what it expands to) to the list.
  18.     SAC-x:   Remove an abbreviation from the list.
  19.     L-x:     Load a set of word abbreviations from a file.
  20.     R-x:     Save the word abbreviation list in a file.
  21.  
  22. The command lAmiga-x which loads the list from a file prompts you to tell it
  23. whether to add the file to the existing list or to replace the old list with
  24. the file.  The rAmiga-x command prompts for a file name.  SAC-x asks for the
  25. abbreviation and removes it and its expanded form, or says "Not found" if
  26. what you typed isn't on the list.  SA-x prompts first for the abbreviation
  27. and then for what it expands to.  A-x tells you whether it turned it on or
  28. off.  If your abbreviations include normal words, as is often the case when
  29. writing in Modula-2 (like, if you want "then" to automatically capitalize),
  30. you will probably end up switching it on and off frequently (like, to type a
  31. string or comment with "then" in it).  Maybe someday I'll get it to be able
  32. to tell when it's in a string or comment.
  33.  
  34. To see the list, examine buffer 79.  If you are using buf79 for something
  35. else in your config, you'll have to replace all instances of "buf79" in these
  36. commands with something else.  The format of the file saved by R-x is simple:
  37. each line consists of the expanded string followed by a colon followed by the
  38. abbreviation.  The variable n48 is used to tell whether it's on; this
  39. likewise needs to be changed if you're already using it.  Also check for
  40. conflicts with the choice of keys I've made.
  41.  
  42. THE ABBREVIATION MUST CONSIST ONLY OF LETTERS with no digits or punctuation
  43. characters or whitespace in order to work.  The abbreviation is case
  44. sensitive if you have Search Caps set.  The text that replaces the
  45. abbreviation gets word-wrapped and so on just as if you had typed it.
  46.  
  47. I put off writing this for a long time because I expected it to have a
  48. substantial cost in the performance of Uedit.  Fortunately, I was overly
  49. pessimistic.  But some slight slowdown of typein is noticeable.
  50.  
  51. IF YOU ARE USING A PREKEY, you need to add one line to it to make Word Abbrev
  52. Mode work:  runKey(virtual-=).  Put it at the beginning, in most cases.  In
  53. any case, put it where it can hear all the stuff actually typed in by the
  54. user.  If you are not using a preKey yet, then you have to use this one:
  55.  
  56. Operate the Word Abbrev Mode engine
  57. <preKey: runKey(virtual-=) >
  58.  
  59. Here is an example of combining word abbrev mode with an existing preKey. 
  60. The preKey given here is similar to the one I use, as seen in the file Indent:
  61.  
  62. Record recent inputs in n10..n18, and do Word Abbrev mode
  63. ..  <prekey:
  64.         equatenum(n32, 0)       .. for my combined idle save and auto traffic
  65.         runkey(virtual-=)               .. word abbrev mode engine
  66.         if (eqnum(macronum, normal-buttondown)) return  .. forget mouseclicks
  67.         if (eqnum(macronum, normal-buttonup)) return    .. ditto
  68.         .. if (not eqnum(inputchar, 0)) return  .. optionally forget text
  69.         if (genum(11, n10)) equatenum(n10, 18)  .. RANGE
  70.         else decnum(n10)                ..  (actually I use n10..n26 nowadays)
  71.         equatenum(n[n10], macronum)
  72. >
  73.  
  74. NOTE that the version given here uses userGlobalA as a flag to tell whether
  75. the mode is active or not.  If you would rather use something else, such as
  76. userGlobalB or an n-variable (no checked menu in that case) or something
  77. local to each buffer such as the favorite flag, change the references to
  78. userGlobalA in the first line of the virtual-= command, and in alt-x.
  79.  
  80.  
  81. NOW HERE ARE THE COMMANDS:
  82.  
  83. Expand the last word typed in if found in buf79 to unabbreviated form
  84. <virtual-=:     if (eqnum(userGlobalA, 0)) return           .. is mode active?
  85.                 if (eqnum(inputchar, 16)) return        .. delete
  86. ... WHY THE HECK does the delete key produce inputchar value 16?!?
  87.                 if (eqnum(inputchar, 8)) return         .. backspace
  88.                 if (eqnum(inputchar, 0)) {      .. non-typein, abandon word
  89.                     equatenum(n47, 0)
  90.                     return
  91.                 }
  92.                 equatenum(n5, inputchar)
  93.         ....    if (genum("9", n5))             .. if allow digits in abbrev
  94.         ....        add(n5, n5, 17)
  95.                 if (genum(n5, "a"))
  96.                     sub(n5, n5, 32)
  97.                 if (gtnum(n5, "Z"))
  98.                     equatenum(n5, 0)
  99.                 if (genum(n5, "A")) {           .. true if alphanumeric
  100.                     equatenum(n47, 1)
  101.                     return
  102.                 }
  103.                 if (eqnum(n47, 0)) return
  104. .. if we get to this point, then we have a finished word to check.
  105.                 getsearch(buf49)
  106.                 freebuf(buf50)
  107.                 equateloc(curfile, mouseloc, locb)      .. could use swapLoc?
  108.                 equateloc(curfile, locb, atcursor)
  109.                 movecursor(curfile, sword)
  110.                 equateloc(curfile, loca, atcursor)
  111.                 insertrgn(buf50, sfile, curfile, loc)
  112.                 movecursor(buf50, sfile)
  113.                 insertchar(buf50, ":")          .. use colon as divider
  114.                 movecursor(buf50, efile)
  115.                 insertchar(buf50, eline)
  116.                 setsearch(buf50)
  117.                 movecursor(buf79, sfile)
  118.                 if (search(buf79, shilite, ehilite, 1)) {
  119.                     equateloc(buf79, einvert, atcursor)
  120.                     movecursor(buf79, sline)
  121.                     equateloc(buf79, sinvert, atcursor)
  122.                     clearrgn(curfile, loc)
  123.                     .. insertrgn(curfile, atcursor, buf79, invert) .. crude
  124.                     equateloc(buf79, atcursor, sinvert)
  125.                     while (gtloc(buf79, einvert, atcursor)) {
  126.                         copychar(buf79, n54)
  127.                         typechar(n54)
  128.                         incloc(buf79, atcursor)
  129.                     }
  130.                 } else
  131.                     equateloc(curfile, atcursor, locb)
  132.                 equateloc(curfile, locb, mouseloc)
  133.                 setsearch(buf49)
  134.                 equatenum(n47, 0)
  135. >
  136.  
  137. Toggle activation of word-abbrev mode
  138. <alt-x: if (eqnum(userGlobalA, 0)) {
  139.             equatenum(userGlobalA, 1)
  140.             putmsg("Turning ON Word-Abbrev Mode")
  141.         } else {
  142.             equatenum(userGlobalA, 0)
  143.             putmsg("turning off word-abbrev")
  144.         } >
  145.  
  146. Add an abbreviation to the word-abbrev list
  147. <shftalt-x:     putmsg("Word to be expanded?")
  148.                 freebuf(buf51)
  149.                 if (inputstring(buf51)) {
  150.                     putmsg("What should it expand to?")
  151.                     freebuf(buf50)
  152.                     if (inputstring(buf50)) {
  153.                         movecursor(buf79, sfile)
  154.                         insertchar(buf79, eline)
  155.                         insertrgn(buf79, sfile, buf51, all)
  156.                         movecursor(buf79, sfile)
  157.                         insertchar(buf79, ":")  .. use colon for divider
  158.                         insertrgn(buf79, sfile, buf50, all)
  159.                     }
  160.                 }
  161. >
  162.  
  163. Remove an abbreviation from the word-abbrev list
  164. <shftaltctl-x:  putmsg("Abbreviation to remove?")
  165.                 freebuf(buf51)
  166.                 if (inputstring(buf51)) {
  167.                     movecursor(buf51, efile)
  168.                     insertchar(buf51, eline)
  169.                     getsearch(buf49)
  170.                     setsearch(buf51)
  171.                     movecursor(buf79, sfile)
  172.                     if (search(buf79, shilite, ehilite, 1)) {
  173.                         movecursor(buf79, sline)
  174.                         clearrgn(buf79, line)
  175.                         clearchar(buf79)
  176.                         putmsg("Removed.")
  177.                     } else putmsg("Not found.")
  178.                 }
  179. >
  180.  
  181. Load a word-abbrev list from a file
  182. <lamiga-x:      putmsg("File to load into the word-abbrev list?")
  183.                 freebuf(buf52)
  184.                 if (inputstring(buf52)) {
  185.                     if (askyesno("Remove existing abbrevs first?"))
  186.                         freebuf(buf79)
  187.                     if (not insertfile(buf79, sfile, buf52))
  188.                         putmsg("Couldn't open file.")
  189.                 }
  190. >
  191.  
  192. Save the word-abbrev list in a file
  193. <ramiga-x:      putmsg("File to save the word-abbrev list in?")
  194.                 freebuf(buf52)
  195.                 if (inputstring(buf52)) {
  196.                     setfilename(buf79, buf52)
  197.                     if (not savefile(buf79))
  198.                         putmsg("Save failed!")  .. unlikely even if it does fail
  199.                 }
  200.                     
  201. >
  202.  
  203.  
  204. Word Abbrev Mode for Uedit is by Paul Kienitz,
  205.                                  6430 San Pablo ave.
  206.                                  Oakland, CA  94608
  207. and is in the public domain.
  208.