home *** CD-ROM | disk | FTP | other *** search
/ Power-Programmierung / CD1.mdf / mutt / abbrev.mut next >
Text File  |  1988-04-04  |  2KB  |  70 lines

  1.     ;; abbrev.mut : abbrevation mode
  2.     ;; C Durland 4/88
  3.  
  4. ;; Note: This is a very limited abbrev mode.
  5.  
  6.  
  7. (include spoint.mut)
  8.  
  9. (const abbrev-buffer "*ABBREVs*")
  10.  
  11. (defun
  12.   stuff-text  (array byte text 1) HIDDEN
  13.   {
  14.     (int n z) 
  15.     (for (n 0) (!= 0 (z (text n)))(+= n 1)(exe-key z))
  16.   }
  17.   lookup-abbrev (string name) HIDDEN
  18.   {
  19.     (bool s)
  20.  
  21.     (save-point)
  22.     (switch-to-buffer abbrev-buffer)(beginning-of-buffer)
  23.     (if (re-search-forward (concat '^' name ' ' ))
  24.       {    (looking-at '.*') (s TRUE) }
  25.       (s FALSE)
  26.     )
  27.     (restore-point)(msg "")
  28.     s
  29.   }
  30.   expand-abbrev
  31.   {
  32.     (bool s)
  33.     
  34.     (if (and (!= 1 (current-column))
  35.     { (previous-character)(s (looking-at '\w'))(next-character) s } )
  36.     {
  37.       (previous-word)
  38.       (if (and (looking-at '\w+')(lookup-abbrev (get-matched '&')))
  39.     { (delete-word)(stuff-text (get-matched '&')) }
  40.     (next-word)
  41.       )
  42.     })
  43.   }
  44.  
  45.   select-abbrev-file
  46.   {
  47.     (string abbrev-file 85)
  48.     (abbrev-file (ask "What abbrev file do you want to load? "))
  49.     (kill-buffer abbrev-buffer)(save-point)
  50.     (switch-to-buffer abbrev-buffer)(read-file abbrev-file)
  51.     (buffer-flags -1 0x6)
  52.     (restore-point)
  53.   }
  54.   key-pressed-hook (int key)
  55.   {
  56.     (switch key
  57.       0x20 ()    ; space
  58.       0x2C ()    ; comma
  59.       0x14D ()    ; Return
  60.       0x21 ()    ; !
  61.       0x2E ()    ; period
  62.       0x3F ()    ; ?
  63.       default (done)    ; key does not trigger abbrev expansion
  64.     )
  65.     (exe-key 0x1031)    ; S-1
  66.   }
  67. )
  68.  
  69. (bind-local-key "expand-abbrev" "S-1")
  70.