🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Thread View: news.software.readers
1 messages
1 total messages Started by J.B. Nicholson-Owens Sun, 01 Feb 2015 21:46
[slrn] Macro for warning when expunging collapsed articles
#258953
Author: 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-
Thread Navigation

This is a paginated view of messages in the thread with full content displayed inline.

Messages are displayed in chronological order, with the original post highlighted in green.

Use pagination controls to navigate through all messages in large threads.

Back to All Threads