home *** CD-ROM | disk | FTP | other *** search
/ Mega CD-ROM 1 / megacd_rom_1.zip / megacd_rom_1 / FREEMACS / EMACS16A.ZIP / DABBREV2.MIN < prev    next >
Internet Message Format  |  1990-02-05  |  6KB

  1. From daemon Sun Sep  3 16:35:03 1989
  2. Return-Path: <news>
  3. To: freemacs-list@sun.soe.clarkson.edu
  4. Date: Fri, 18 Aug 89 16:08:16 GMT
  5. From: daemon (William Su)
  6. Sender: freemacs@sun.soe.clarkson.edu
  7. Subject: dabbrev, ver2
  8. Organization: Clarkson Gateway
  9.  
  10. ---Michael Hirsch recently sent us all a dynamic abbreviation mode.  I
  11. ---had not previously been aware of this ability of GNU Emacs, and
  12. ---thank him for the information.  However, I decided to expand upon
  13. ---what Michael wrote, and these are the results.  I have reposted
  14. ---Michael's introduction, and interspersed my comments prefixed
  15. ---with ---.  William Su
  16.  
  17. foobar
  18. foobaz
  19. foobar
  20. foo        << test the expansion here.
  21. foobar
  22. foobae
  23. foobar
  24.  
  25.  
  26.  
  27. Here's a macro you might find useful.  It's a partial act-alike to the GNU
  28. dabbrev command.  It does "dynamic abbreviation."  I.e., it completes the
  29. word you are typing in by searching for the last word you typed in that
  30. starts the same.  If no previous word starts the same it searches forward.
  31.  
  32. There is a variable, U-dabbrev-backwards-only, which, when null makes
  33. dynamic abbreviation occur only with previous words--words occuring
  34. earlier in the current buffer.
  35. ---This is a typo.  When U-dabbrev-backwards-only is NOT null, dabbrev
  36. ---occurs only with previous words.
  37.  
  38. The only feature of GNU emacs this is missing is the ability to give a
  39. numeric argument to dabbrev which will then pick the nth previous word
  40. that matches.  This didn't seem worth hacking.
  41. ---Modified by William Su, 8/16/89 to handle repeated calls via
  42. ---repetition of U:dabbrev.
  43. ---Modified by William Su, 8/16/89 to handle numeric arguments.---
  44. ---(I disagreed (no offense meant) with Michael about the value
  45. ---of these abilties.  Besides, I enjoy programming! |-) )
  46.  
  47.  
  48. This is really handy if you are typing in long words frequently.  I find
  49. it much handier than abbrev mode in GNU emacs.  I hope you do to.
  50.  
  51. This works pretty well, but it would be cleaner to do the search with a
  52. regular expression.  Does anyone out there know how to search for a string
  53. only at the beginning of a word?  It seems that the regular expression
  54. facility of freemacs is not up to it.
  55. ---Whether the regular expression facility is up to searching for a string
  56. ---only at the beginning of a word or not, I think Michael's solution is
  57. ---probably faster because a regular expression search would probably be
  58. ---much more work.  (Comments, Russ?)  Those of us who still have
  59. ---4.77 MHz machines |-( like anything that helps efficiency.
  60.  
  61. Hope you like it,
  62. --Michael
  63. ---I modifed the code style because Michael uses a different one
  64. ---from me, and I needed to be able to trace this easily when I was
  65. ---making my modifications.  The modifications were really not that
  66. ---difficult; they are really more an expansion of Michael's code
  67. ---than a rewrite.
  68. ---
  69. ---I added another variable:  U-dabbrev-fold.  When not null, a case-
  70. ---folded search is performed when matching the user's prefix to the
  71. ---other words in the buffer.  Case folding is, I would guess, much
  72. ---less expensive than regular expression searches, so those of us
  73. ---with slow machines may not mind this as much.  (Comments, Russ?)
  74. ---Nevertheless, for programming, case folding is probably
  75. ---undesirable, so I have left this defaulting to null.  If you are
  76. ---doing some form of English text editing, you may wish to turn this
  77. ---on.  The default in GNU Emacs appears to be case folding, even in
  78. ---c-mode; I don't know why.  You might want to make the default
  79. ---part of the local mode changes for each editing mode.  I haven't
  80. ---bothered; I figure I can set folding on if I discover I need it.
  81. ---
  82. ---I have also included bindings for dabbrev to M-/, matching GNU
  83. ---Emacs.  However, I believe the operation of dabbrev is independent
  84. ---of key binding.  If you want to repeat, just hit whatever you hit
  85. ---the first time.
  86. ---
  87. ---Any errors are my fault, not Michael's.  (Hopefully, there aren't
  88. ---any, but one never knows.)
  89. ---Hope you like it,
  90. -----Bill
  91.  
  92. ----- MINT code starts here -----
  93.  
  94. ##(result)
  95.  
  96. Name:U:dabbrev
  97. Dynamically finish the current word.  Check backwards through the
  98. file to find the last word to start with this pattern of letters, then
  99. complete the current word the same way.  If there is no previous such
  100. word, and U-dabbrev-backwards-only is null, check forwards.
  101. [*]    
  102. #(an)
  103. #(g?,arg1,1,(#(ds,dabbrev-number,arg1)))
  104. #(es,#(ls,(,),dabbrev-seen.))
  105. #(pm,5)
  106. #(sm,3,<)
  107. #(ds,dabbrev-search-string,##(rm,{))
  108. #(lp,##(dabbrev-search-string),,,#(U-dabbrev-fold))
  109. #(sp,{<)
  110. #(==,#(Udabbrev,,([)),(expanded),,(
  111.     #(==,#(U-dabbrev-backwards-only),,(
  112.         #(sp,2>)
  113.         #(==,#(Udabbrev,(#(sp,1)),(])),(expanded),,(
  114.             #(an,Can't find dynamic abbrev(,) forwards or backwards(,) for ##(dabbrev-search-string).)
  115.         ))
  116.     ),(
  117.         #(an,Can't find dynamic abbrev(,) backwards only(,) for ##(dabbrev-search-string))
  118.     ))
  119. ))
  120. #(sp,2)
  121. #(pm)
  122. #(ds,dabbrev-number,1)
  123. [*]
  124.  
  125.  
  126. Name:Udabbrev
  127. arg1 = null or #(sp,1) to go backwards or forwards.  Arg2 = [ or ] resp.
  128. [*]
  129. #(l?,.,arg2,0,1,(
  130.     #(sp,0)
  131.     #(mb,{,(
  132.         arg1
  133.         #(SELF,(arg1),(arg2))
  134.     ),(
  135.         #(==,arg2,[,(#(sm,4,0)),(#(sm,4,1)))
  136.         #(g?,#(dabbrev-number),1,(
  137.             #(ds,dabbrev-number,#(--,#(dabbrev-number),1))
  138.             #(sp,4)
  139.             #(SELF,(arg1),(arg2))
  140.         ),(
  141.             #(sp,1})
  142.             #(n?,dabbrev-seen.##(rm,1),(
  143.                 #(sp,4)
  144.                 #(SELF,(arg1),(arg2))
  145.             ),(
  146.                 #(ds,dabbrev-seen.##(rm,1))
  147.                 #(ds,dabbrev-insert-string,##(rm,1))
  148.                 #(sp,2)
  149.                 #(sm,1,<)
  150.                 #(is,##(dabbrev-insert-string))
  151.                 #(Fset-new-mark)
  152.                 #(sp,1>)
  153.                 #(F:swap-point-and-mark)
  154.                 #(rd)
  155.                 #(ds,temp,#(g))
  156.                 #(==,##(K.##(temp)),U:dabbrev,(
  157.                     #(sp,3>)
  158.                     #(dm,2)
  159.                     #(sp,4)
  160.                     #(SELF,(arg1),(arg2))
  161.                 ),(
  162.                     #(Fkbd-in,##(temp))
  163.                     expanded
  164.                 ))
  165.             ))
  166.         ))
  167.     ))
  168. ))
  169. [*]
  170.  
  171. #(sp,1})
  172. #(ds,dabbrev-insert-string,##(rm,1))
  173. #(sp,2)
  174. #(sm,1,<)
  175. #(is,##(dabbrev-insert-string))
  176. #(Fset-new-mark)
  177. #(sp,1>)
  178. #(F:swap-point-and-mark)
  179.  
  180. Name:U-dabbrev-fold
  181. If not null, dabbrev will fold case when searching for a
  182. matching prefix.  The prefix the user typed is not changed.
  183. The part copied is copied exactly as written in the original.
  184. No attempt is made to make the case match that of the prefix.
  185. [*][*]
  186.  
  187. Name:K.M-Slash
  188. [*]U:dabbrev[*]
  189.  
  190. Name:K.M-/
  191. [*]U:dabbrev[*]
  192.