home *** CD-ROM | disk | FTP | other *** search
/ InfoMagic Source Code 1993 July / THE_SOURCE_CODE_CD_ROM.iso / languages / elisp / functions / clari-clean.el < prev    next >
Encoding:
Text File  |  1991-08-22  |  4.1 KB  |  103 lines

  1. ; From: dnb@meshugge.media.mit.edu (David N. Blank)
  2. ; Subject: Re: Okay, it's an FAQ (dealing with ugly underlines)
  3. ; Date: 5 Aug 91 04:10:24 GMT
  4. ; Organization: M.I.T. Media Laboratory
  5. ; In-Reply-To: ckd@eff.org's message of 3 Aug 91 23: 30:15 GMT
  6. ; > So, what is the canonical very-bestest way to get rid of those annoying
  7. ; > underlines in, say, clari.* groups?
  8. ; I make no claims of bestest, and the only canonical thing I deal with
  9. ; on a regular basis was written by Pachelbel in the 1600's.  Now if you
  10. ; are talking quick and dirty hacks that work, well here's something I
  11. ; posted a while back:
  12. ;            Peace,
  13. ;                dNb
  14. ; ------
  15. ;Howdy-
  16. ;  If you both get the ClariNet newsgroups (ClariNews) and read your
  17. ;news in Gnus, this might be of interest to you.  I slapped this
  18. ;together a while back when I got frustrated at ClariNews' use of
  19. ;backspaced underscores for underlining.  I also was tired of seeing
  20. ;headers that I didn't really have a use for in my daily news reads.
  21. ;It's worked for me for several weeks now, I hope it makes you happy.
  22. ;Note: I am not affiliated to ClariNet Communications Corp (except as
  23. ;a contented subscriber to ClariNews). Bon Chance!
  24. ;         Peace,
  25. ;            dNb
  26. ;---------
  27. ;;; -*- Mode:Emacs-Lisp -*-
  28. ;;;
  29. ;;; clari-clean.el - a set of functions cobbled together to present more 
  30. ;;;                  aesthetic and concise Gnus buffers when reading
  31. ;;;                  ClariNews groups (tm ClariNet Communications Corp.)
  32. ;;;
  33. ;;; Place these two lines in your .emacs to use these functions:
  34. ;;;  (autoload 'gnus-clarinews-fun "clari-clean" "Clean ClariNews articles" t)
  35. ;;;  (setq gnus-Article-prepare-hook 'gnus-clarinews-fun)
  36. ;;;  
  37. ;;; Change the value of clarinews-ignored-headers below to flavor to taste.
  38. ;;;
  39. ;;;                  -- David N. Blank (dnb@meshugge.media.mit.edu) 1/31/91
  40.  
  41. ;;; LCD Archive Entry:
  42. ;;; clari-clean|David N. Blank|dnb@meshugge.media.mit.edu
  43. ;;; |Clean up buffers when reading ClariNet news groups
  44. ;;; |91-01-31||~/functions/clari-clean.el.Z|
  45.  
  46. (defun gnus-clarinews-fun ()
  47.   ;; only do the voodoo, that you do, so well, if in a ClariNews newsgroup
  48.   (if (string-match "^clari\\.*" gnus-newsgroup-name) 
  49.       (progn 
  50.     (clarinews-clean-article-bs)
  51.     (clarinews-clear-headers)  
  52.     (set-buffer-modified-p nil))))
  53.  
  54. ; function to clean all of the nasty backspaces in ClariNews news articles
  55. ; (for use with GNUS reader).  Unabashedly snarfed & hacked from nuke-nroff-bs 
  56. ; in the standard distribution's (18.55) man.el -- dNb 1/6/90
  57. (defun clarinews-clean-article-bs ()
  58.   "Nuke the underlining via backspaces found in a ClariNews article."
  59.   (interactive "*")
  60.   ;;Nuke underlining and overstriking (only by the same letter)
  61.   (goto-char (point-min))
  62.   (while (search-forward "\b" nil t)
  63.     (let* ((preceding (char-after (- (point) 2)))
  64.        (following (following-char)))
  65.       (cond ((= preceding following)
  66.          ;; x\bx
  67.          (delete-char -2))
  68.         ((= preceding ?\_)
  69.          ;; _\b
  70.          (delete-char -2))
  71.         ((= following ?\_)
  72.          ;; \b_
  73.          (delete-region (1- (point)) (1+ (point)))))))
  74.     (goto-char (point-min))
  75.   ;; Crunch blank lines 
  76.     (while (re-search-forward "\n\n\n\n*" nil t)
  77.       (replace-match "\n\n")))
  78.  
  79. ; remove headers I'd rather not see from ClariNews Gnus buffers.  Snarfed from 
  80. ; rmail-clear-headers in standard distribution's (18.55) rmail.el -- dNb 1/6/90
  81. (defun clarinews-clear-headers ()
  82.   "Nuke the headers one would rather not see in a ClariNews article.
  83.    The list of headers is located in clarinews-ignored-headers."
  84.   (goto-char (point-min))
  85.   (if (search-forward "\n\n" nil t)
  86.       (save-restriction
  87.     (narrow-to-region (point-min) (point))
  88.     (let ((buffer-read-only nil))
  89.       (while (let ((case-fold-search t))
  90.            (goto-char (point-min))
  91.            (re-search-forward clarinews-ignored-headers nil t))
  92.         (beginning-of-line)
  93.         (delete-region (point)
  94.                (progn (re-search-forward "\n[^ \t]")
  95.                   (forward-char -1)
  96.                   (point))))))))
  97.  
  98.   (defvar clarinews-ignored-headers
  99.    "^Location:\\|^ACategory:\\|^Slugword:\\|^Priority:\\|^Format:\\|^ANPA:\\|^Codes:\\|^Note:\\|^X-Supersedes:" 
  100.    "*Gubbish headers one would rather not see in a ClariNews article.")
  101.