home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 5 Edit / 05-Edit.zip / me34exe.zip / mutt / contrib / zap.mut < prev   
Text File  |  1995-01-14  |  2KB  |  64 lines

  1. ;; `Zap' for ME3
  2. ;; Patrick TJ McPhee 11 July 1993
  3. ;;
  4. ;; This is meant to work like the zap-to-char command in GNU emacs, with one
  5. ;; exception.  Here's the documentation:
  6. ;; zap-to-char prompts for a character and deletes up-to but not including
  7. ;; the (arg-prefix)th occurrence of that character.  Suppose the dot
  8. ;; were sitting just after the closing parenthesis in the previous sentence.
  9. ;; Pressing (by default) M-Z and then `space' would have the same effect
  10. ;; as pressing M-D.  On the other hand, pressing M-Z and then `f' would
  11. ;; delete up to, but not including, the `f' of `of'.  In GNU emacs, pressing
  12. ;; M-Z f again would have no effect.  In my version, if the dot is immediately
  13. ;; before the character to be zapped, that instance of the character does not
  14. ;; get included in the count.  The other difference from GNU: if the character
  15. ;; is not found, no deletion takes place (GNU will delete to the end of the
  16. ;; buffer).  A negative argument causes the search to go backwards.
  17.  
  18. ;; I changed it to work the same as GNU zap-to-char so I could say "same as
  19. ;;   GNU".  Patrick's exceptions probably make more sense but thats now how
  20. ;;   GNU did it so ... (I wonder if I'm getting too carried with GNU
  21. ;;   compatibility?)  C Durland 7/93
  22.  
  23. (include me.mh)
  24.  
  25. (defun
  26.   zap-to-char {
  27.     (int start number-to-skip)
  28.     (string character)
  29.     (bool found reverse)
  30.  
  31.     (msg "Zap to char: ")
  32.     (character (getchar))
  33.  
  34.     (number-to-skip (arg-prefix))
  35.     (arg-flag FALSE 1)        ;; reset arg count
  36.  
  37.     (reverse (<= number-to-skip 0))
  38.  
  39.     (set-mark (start (create-mark FALSE)))
  40.  
  41.     (found FALSE)
  42.     ;; search backwards if negative argument, otherwise forwards
  43.     (if reverse {
  44.       (while (and
  45.            (< (number-to-skip) 0)
  46.            (found (search-reverse (character))))
  47.     (+= number-to-skip 1))
  48.       (forward-char 1)
  49.     } {
  50.       (while (and
  51.            (> (number-to-skip) 0)
  52.            (found (search-forward (character))))
  53.     (-= number-to-skip 1))
  54.       (forward-char -1)
  55.     })
  56.  
  57.     (if (not found)
  58.       (if reverse (beginning-of-buffer)(end-of-buffer)))
  59.  
  60.     (delete-region start THE-DOT)
  61.   }
  62. ;  MAIN { (bind-to-key "zap-to-char" "M-Z") }
  63. )
  64.