Gnus development mailing list
 help / color / mirror / Atom feed
From: Matt Pharr <mmp@Exluna.com>
Subject: Re: [Q] stripping banners at the start of messages
Date: 25 Sep 2000 13:03:25 -0700	[thread overview]
Message-ID: <kh0ya0g1boy.fsf@abuffer.stanford.edu> (raw)
In-Reply-To: <wtn66nko6zl.fsf@licia.dtek.chalmers.se>


Jonas Steverud <d4jonas@dtek.chalmers.se> writes:
> My regexp which works well (for the time being...) is
> 
>  (banner . "^[ ,-,_,-]+eGroups Sponsor\\(.*\n\\)\\(.*\n\\)\\(.*\n\\)\\(.*\n\\)\\(.*\n\\)?\\(.*\n\\)?[ ,-,_,-][ ,-,_,-][ ,-,_,-][ ,-,_,-][ ,-,_,-][ ,-,_,-][ ,-,_,-][ ,-,_,-][ ,-,_,-][ ,-,_,-].*\n")

Since there's a lot of arcane magic in figuring out these multi-line
regexps (I'd never be able to put together magic like the above, much as I
hate the egroups banners), I've got a suggested patch that I just cooked
up.

The basic idea is that in addition to the old "banner" group parameter,
there are now new banner-start and banner-end parameters.  A new
article-treat-banner function (see below) also looks for these two new
parameters; if both are present, it will nuke all text between the start of
the first regexp and the end of the second one.  This makes for much easier
configurability.

For example, for eGroups lists, I've got these set like this:

((banner-start . "^----.*eGroups")
 (banner-end . "^----.*>"))

That's all it takes.

What do people think about this?  I'm also no major elisp hacker, so if I
coded it up poorly, I'm happy to hear about it.  If this seems to be a
generally useful thing, I'll write up some documentation for the manual and
commit it all to the CVS repository.

-matt

*** gnus-art.el.orig	Mon Sep 25 12:47:09 2000
--- gnus-art.el	Mon Sep 25 12:56:57 2000
***************
*** 769,775 ****
  
  (defcustom gnus-treat-strip-banner t
    "Strip banners from articles.
! The banner to be stripped is specified in the `banner' group parameter.
  Valid values are nil, t, `head', `last', an integer or a predicate.
  See the manual for details."
    :group 'gnus-article-treat
--- 769,776 ----
  
  (defcustom gnus-treat-strip-banner t
    "Strip banners from articles.
! The banner to be stripped is specified in the `banner', and/or `banner-start' 
! and `banner-end' group parameters.
  Valid values are nil, t, `head', `last', an integer or a predicate.
  See the manual for details."
    :group 'gnus-article-treat
***************
*** 1649,1673 ****
  	     (match-beginning 0) (match-end 0) 'pem)))))))
  
  (defun article-strip-banner ()
!   "Strip the banner specified by the `banner' group parameter."
    (interactive)
    (save-excursion
      (save-restriction
        (let ((inhibit-point-motion-hooks t)
  	    (banner (gnus-group-get-parameter gnus-newsgroup-name 'banner))
  	    (gnus-signature-limit nil)
! 	    buffer-read-only beg end)
! 	(when banner
! 	  (article-goto-body)
! 	  (cond
! 	   ((eq banner 'signature)
! 	    (when (gnus-article-narrow-to-signature)
! 	      (widen)
! 	      (forward-line -1)
! 	      (delete-region (point) (point-max))))
! 	   ((stringp banner)
! 	    (while (re-search-forward banner nil t)
! 	      (delete-region (match-beginning 0) (match-end 0))))))))))
  
  (defun article-babel ()
    "Translate article using an online translation service."
--- 1650,1683 ----
  	     (match-beginning 0) (match-end 0) 'pem)))))))
  
  (defun article-strip-banner ()
!   "Strip the banner specified by the `banner', and/or `banner-start' and `banner-end' group parameters."
    (interactive)
    (save-excursion
      (save-restriction
        (let ((inhibit-point-motion-hooks t)
  	    (banner (gnus-group-get-parameter gnus-newsgroup-name 'banner))
+ 	    (banner-start (gnus-group-get-parameter gnus-newsgroup-name 'banner-start))
+ 	    (banner-end (gnus-group-get-parameter gnus-newsgroup-name 'banner-end))
  	    (gnus-signature-limit nil)
! 	    buffer-read-only beg)
! 		(when banner
! 		  (article-goto-body)
! 		  (cond
! 		   ((eq banner 'signature)
! 			(when (gnus-article-narrow-to-signature)
! 			  (widen)
! 			  (forward-line -1)
! 			  (delete-region (point) (point-max))))
! 		   ((stringp banner)
! 			(while (re-search-forward banner nil t)
! 			  (delete-region (match-beginning 0) (match-end 0))))))
! 		(when (and banner-start banner-end (stringp banner-start) 
! 				   (stringp banner-end))
! 		  (article-goto-body)
! 		  (while (re-search-forward banner-start nil t)
! 			(setq beg (match-beginning 0))
! 			(if (re-search-forward banner-end nil t)
! 				(delete-region beg (match-end 0)))))))))
  
  (defun article-babel ()
    "Translate article using an online translation service."


-- 
Matt Pharr                              <URL:http://graphics.stanford.edu/~mmp>
===============================================================================
In a cruel and evil world, being cynical can allow you to get some
entertainment out of it. --Daniel Waters



  parent reply	other threads:[~2000-09-25 20:03 UTC|newest]

Thread overview: 17+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2000-09-23  7:12 Steinar Bang
2000-09-23 11:55 ` Emerick Rogul
2000-09-25 14:41 ` Paul Stevenson
2000-09-25 15:25   ` Kai Großjohann
     [not found]     ` <wtnr9688p2v.fsf@licia.dtek.chalmers.se>
2000-09-26  9:35       ` Paul Stevenson
     [not found]         ` <wtnk8bzl12k.fsf@licia.dtek.chalmers.se>
2000-09-26 14:01           ` Paul Stevenson
     [not found]             ` <wtn66nji4ff.fsf@licia.dtek.chalmers.se>
2000-09-26 15:05               ` Paul Stevenson
2000-09-26 15:20           ` Kai Großjohann
2000-10-02 17:50             ` Toby Speight
     [not found]   ` <wtn66nko6zl.fsf@licia.dtek.chalmers.se>
2000-09-25 20:03     ` Matt Pharr [this message]
2000-09-25 22:14       ` Kai Großjohann
2000-09-25 22:24       ` Steve Harris
2000-09-26  8:39         ` Paul Stevenson
2000-09-26  9:14           ` Kai Großjohann
2000-10-02 17:48   ` Toby Speight
2000-10-02 18:52     ` ShengHuo ZHU
2000-10-03  9:37     ` Paul Stevenson

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=kh0ya0g1boy.fsf@abuffer.stanford.edu \
    --to=mmp@exluna.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).