🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: news.software.readers
Article #258953

[slrn] Macro for warning when expunging collapsed articles

#258953
From: J.B. Nicholson-Owens
Date: Sun, 01 Feb 2015 21:46
118 lines
4751 bytes
Here's a macro I wrote that will warn you before you expunge collapsed
articles.


#v+
implements ("warnings");

% Warn on expunging articles inside collapsed threads.
%
% Note: This macro makes no attempt to work around the expunge
%       intrinsic's side effect which collapses all threads.
static define expunge ()
{
   if (is_group_mode ())
     {
	throw UsageError,
	  _function_name () + " doesn't work in group mode!";
     }

   variable
     starting_article = extract_article_header ("Message-ID"),
     starting_prefix_argument = get_prefix_arg ();

   reset_prefix_arg ();

   EXIT_BLOCK
     {
	% Expunging all the articles quits article mode.
	ifnot (is_group_mode ())
	  {
	     % The article we want to go back to might have been
	     % expunged, so we don't care if we can't get back there.
	     % It's not clear where the cursor should go if the cursor
	     % was on an expunged article.
	     () = locate_header_by_msgid (starting_article, 0);
	  }
	
	if (starting_prefix_argument != -1) set_prefix_argument (starting_prefix_argument);
     }

   variable
     % How many articles could be expunged from collapsed threads?
     expungeable_articles_in_collapsed_threads = 0,

     % Did we see any unread articles?
     found_unread_article = 0,
     
     % Thread collapse state temporary variable.
     thread_was_collapsed = 0,
     
     % Thread size temporary variable.
     t = 0,
     
     % Temporary iterator variable.
     i = 0,
     
     % Temporary header flags variable.
     hf = 0;

   % Find the first collapsed thread with an article marked read and
   % not marked important. Warn if this condition is met. Find one
   % unread article in the group so we can detect caught-up groups.
   % Don't disturb the thread display unnecessarily.
   call ("header_bob");
   do
     {
	t = thread_size ();
	thread_was_collapsed = is_thread_collapsed ();

	uncollapse_thread ();
	for (i = 1; i <= t; i++)
	  {
	     hf = get_header_flags ();

	     %
	     % Perform tests on articles.
	     %

	     % Find one unread article in the group.
	     ifnot (found_unread_article)
	       found_unread_article = (~hf & HEADER_READ);

	     % Count expungeable articles in collapsed threads.
	     if (thread_was_collapsed && (hf & HEADER_READ) && (~hf & HEADER_TAGGED))
	       expungeable_articles_in_collapsed_threads++;

	     %
	     % Go to next article in thread but not the first article
	     % of the next thread.
	     %
	     if (i != t) () = header_down (1);
	  }
	% Restore the thread display for this thread.
	if (thread_was_collapsed) collapse_thread ();
     }
   % Go to next thread.
   while (header_down (1));

   ifnot (found_unread_article)
     {
	if (1 == get_yes_no_cancel ("Expunging now will quit to group mode because all articles will be expunged. Are you sure you want to do this"))
	  call ("expunge");
	return ();
     }

   if (expungeable_articles_in_collapsed_threads)
     {
	variable prompt = "Expunging articles now will remove 1 article in a collapsed thread. Are you sure you want to continue";
	if (expungeable_articles_in_collapsed_threads > 1)
	  prompt = "Expunging articles now will remove $expungeable_articles_in_collapsed_threads articles in collapsed threads. Are you sure you want to continue"$;

	if (1 != get_yes_no_cancel (prompt))
	  return ();
     }
   call ("expunge");
}
definekey ("warnings->expunge", "x", "article");
#v-
Technical Details
Message-ID: <slrnmct7mr.921.jbn@forestfield.org>
Path: mbox-mo1.pugleaf.net!archive.usenet.blueworldhosting.com!illumos!news.pugleaf.net!.TX!archive.pugleaf.net!archive.newsdeef.eu!mbox2nntp-news.software.readers.20150219.mbox.gz!buffer2.nntp.dca1.giganews.com!border2.nntp.dca1.giganews.com!nntp.giganews.com!usenet.blueworldhosting.com!feeder01.blueworldhosting.com!news.albasani.net!.POSTED!not-for-mail

Show Full Headers
Complete Article Headers
Message-ID: <slrnmct7mr.921.jbn@forestfield.org>
Subject: [slrn] Macro for warning when expunging collapsed articles
Date: Sun, 01 Feb 2015 21:46:58 +0000
From: "J.B. Nicholson-Owens" <jbn@forestfield.org>
Path: mbox-mo1.pugleaf.net!archive.usenet.blueworldhosting.com!illumos!news.pugleaf.net!.TX!archive.pugleaf.net!archive.newsdeef.eu!mbox2nntp-news.software.readers.20150219.mbox.gz!buffer2.nntp.dca1.giganews.com!border2.nntp.dca1.giganews.com!nntp.giganews.com!usenet.blueworldhosting.com!feeder01.blueworldhosting.com!news.albasani.net!.POSTED!not-for-mail
Newsgroups: news.software.readers
Organization: albasani.net
Lines: 118
X-Trace: news.albasani.net
 bhW4ie7jCmSVcHmG0lHZ5r2FHzA4YEISMb9Ih/JQhLCe5JZhV191R6W/8kDBgBYKLaINl7lSL5LFH3L48ZuaR6HVPpmLsSw2p6QAsaYN5+d6mrZywyFPvNz8GBGxVQfm
NNTP-Posting-Date: Sun, 1 Feb 2015 21:46:58 +0000 (UTC)
Injection-Info: news.albasani.net;
 logging-data="NupaS5T/WjEKRaADIIBrU0CFHG/6Ll/Ht2cTXqThUkTNENok4NqWLvjPGWOeUZZ/xkFPdSF6lWjsNjqksBd0YVkx9hzJARJTLeLbjheiJJ0n+WA2HE4FV2MyDYs949Ih";
 mail-complaints-to="abuse@albasani.net"
User-Agent: slrn/pre1.0.3-1 (Linux)
Cancel-Lock: sha1:k3Fs6vr46l7our/nY3WBW8FFIBc=