home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #31 / NN_1992_31.iso / spool / gnu / emacs / sources / 909 < prev    next >
Encoding:
Text File  |  1992-12-24  |  2.4 KB  |  70 lines

  1. Newsgroups: gnu.emacs.sources
  2. Path: sparky!uunet!clsi!mitch
  3. From: mitch@clsi.COM (Mitchell N. Perilstein)
  4. Subject: overstrike
  5. Message-ID: <MITCH.92Dec24124946@pollux.clsi>
  6. Sender: usenet@clsi.COM
  7. Organization: CAD Language Systems, Inc.
  8. Distribution: gnu
  9. Date: 24 Dec 92 12:49:46
  10. Lines: 58
  11.  
  12. These three functions complement the standard distribution underline.el.
  13. They will remove overstriking (a character, a backspace, and the
  14. character again) from a region.  Also, unattribute-region will remove
  15. both underline and overstrike.  underline.el already defines
  16. underline-region and ununderline-region.
  17.  
  18. Dedicated to online readers of P1003.0.
  19.  
  20. (defun unoverstrike-region (start end)
  21.   "Remove all overstriking (character-backspace-character) in the region.
  22. Called from program, takes two arguments START and END which specify the
  23. range to operate on."
  24.   (interactive "r")
  25.   (save-excursion
  26.    (let ((end1 (make-marker)))
  27.      (move-marker end1 (max start end))
  28.      (goto-char (min start end))
  29.      (while (re-search-forward "\\(.\\)\\1" end1 t)
  30.        (delete-char -2)))))
  31.  
  32. (defun overstrike-region (start end)
  33.   "Overstrike (character-backspace-character) all nonblank characters in 
  34. the region. Called from program, takes two arguments START and END which
  35. specify the range to operate on."
  36.   (interactive "r")
  37.   (save-excursion
  38.    (let ((end1 (make-marker)))
  39.      (move-marker end1 (max start end))
  40.      (goto-char (min start end))
  41.      (while (< (point) end1)
  42.        (or (looking-at "[_\^@- ]")
  43.        (insert (char-after (point)) 8))
  44.        (forward-char 1)))))
  45.  
  46. (defun unattribute-region (start end)
  47.   "Remove underlining and overstriking in the region.  Called from a program,
  48. takes two arguments START and END which specify the range to operate on."
  49.   (interactive "r")
  50.   (save-excursion
  51.     ;; This is a piece of nuke-nroff-bs from standard `man.el'.
  52.     (goto-char (point-min))
  53.     (while (search-forward "\b" (max start end) t)
  54.       (let* ((preceding (char-after (- (point) 2)))
  55.          (following (following-char)))
  56.     (cond ((= preceding following)
  57.            ;; x\bx
  58.            (delete-char -2))
  59.           ((= preceding ?\_)
  60.            ;; _\b
  61.            (delete-char -2))
  62.           ((= following ?\_)
  63.            ;; \b_
  64.            (delete-region (1- (point)) (1+ (point)))))))))
  65.  
  66. Happy/Merry,
  67. ---
  68.  Mitchell N. Perilstein   CAD Language Systems, Inc.   410-992-5700 x225 
  69.  Member, League for Programming Freedom.  Mail lpf@uunet.uu.net for info.
  70.