🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: news.software.readers
Article #262248

[slrn] Fetch new news from article mode

#262248
From: J.B. Nicholson
Date: Thu, 03 Aug 2017 05:47
173 lines
7218 bytes
Here's a macro I wrote which makes slrn appear to fetch new articles
from article mode. To present that illusion the macro marks all
articles unread, records thread collapse status and header flags for
all articles, quits to group mode, fetches the new articles, and
re-enters the same group leaving all of the headers and thread display
as they were before leaving article mode. This is intended to give the
illusion that new articles simply 'arrived' in article mode.

How to use this: Save the following (not including the #v+ and #v-
verbatim marks) into a file (perhaps ~/refresh_reenter_group.sl) and
add:

  interpret "/path/to/refresh_reenter_group.sl"

to your slrnrc (adjusting the path to where you saved it, of
course). Quit slrn, run slrn (you should see a message about loading
this macro file), and enter a newsgroup. When you want to get new
articles, press "G" to make slrn get new articles without appearing to
leave article mode.

If this is long enough to be copyrightable, consider it licensed under
the GNU General Public License version 2 or later. Please feel free to
run, inspect, share, and modify.

Enjoy.



#v+
public define refresh_reenter_group ()
{
   % Appears to refresh groups (fetch new news) without leaving article mode
   % and without removing read articles from the article mode list (in order
   % to preserve the illusion that the function never left article mode).

   if (is_group_mode ())
     throw UsageError, _function_name () + " only works in article mode!";

   variable
     % Settings to be changed and restored before this function
     % returns. This must be defined here to avoid a problem parsing the
     % EXIT_BLOCK.
     starting_query_read_group_cutoff = get_variable_value ("query_read_group_cutoff"),
     prefix_arg = get_prefix_arg();

   % Avoid passing prefix arguments to intrinsic functions.
   % Record the prefix argument, reset the prefix argument, and
   % restore the prefix argument at the end (in the EXIT_BLOCK).
   reset_prefix_arg();
   EXIT_BLOCK
     {
	% Restore the state previously modified.
	set_integer_variable ("query_read_group_cutoff", starting_query_read_group_cutoff);
	if (prefix_arg != -1) set_prefix_argument (prefix_arg);
     }

   variable     
     % Initialized with useful values.
     starting_article = extract_article_header ("Message-ID"),
     starting_newsgroup = current_newsgroup (),
     article_was_visible_and_current = (_is_article_visible () == 3),

     % Initialized to indicate type.
     thread_collapse_status = Assoc_Type[Integer_Type],
     thread_was_collapsed = 0,
     article_was_zoomed = is_article_window_zoomed (),
     i = 0,
     t = 0,
     message_ID = "",
     header_flags = 0,
     
     % Used to track article flags (read, starred, etc.).
     message_ID_flags = Assoc_Type[Integer_Type];

   % Store collapse status for unread articles, mark every article
   % unread, and store header flags.
   call ("header_bob");
   do
     {
	t = thread_size ();
	thread_was_collapsed = is_thread_collapsed ();

	uncollapse_thread ();
	for (i = 1; i <= t; i++)
	  {
	     message_ID = extract_article_header ("Message-ID");
	     header_flags = get_header_flags ();
	     
	     % Track:
	     % - collapse status for threads with more than 1 article
	     %   because single-article threads are uncollapsed by
	     %   default (is_thread_collapsed() returns 0 for single-article
	     %   threads) which would create an uncollapsed thread if a
	     %   followup article arrives in that thread. That uncollapsed
	     %   thread would break the illusion of preserving thread
	     %   collapse status,
	     %
	     % - header flags for articles with nonzero header flags.
	     if (t > 1) thread_collapse_status[message_ID] = thread_was_collapsed;
	     if (header_flags) message_ID_flags[message_ID] = header_flags;

             % Reset the score to 0 and mark the article unread. slrn will
	     % re-score the article again upon re-entering this group.
	     set_header_score (0);
	     set_header_flags (header_flags () & ~HEADER_READ);

	     % We care about the thread display because the user
	     % might be running something in a hook that tracks thread
	     % collapse status.
	     if (i != t) () = header_down (1);
	     else if (thread_was_collapsed) collapse_thread ();
	  }
     }
   % Go to the next thread.
   while (header_down (1));

   % Quit to group mode, refresh the newsgroup list, and re-enter the
   % newsgroup we were in putting us back in article mode.
   try
     {
	call ("quit");
	call ("refresh_groups");
	set_input_string (starting_newsgroup);
	call ("add_group");
	set_integer_variable ("query_read_group_cutoff", 0);
	call ("select_group");
     }
   catch AnyError:
     {
	if (is_group_mode ())
	  {
	     throw InternalError, "Something went horribly wrong and we could not re-enter " + starting_newsgroup;
	  }
     }

   % Restore the nonzero header flags.
   foreach message_ID,header_flags (message_ID_flags) using ("keys", "values")
     {
	ifnot (locate_header_by_msgid (message_ID, 0)) continue;
	set_header_flags (header_flags);
     }
   
   % Restore the thread display.
   foreach message_ID,thread_was_collapsed (thread_collapse_status) using ("keys", "values")
     {
	ifnot (locate_header_by_msgid (message_ID, 0)) continue;
	if (thread_was_collapsed) collapse_thread ();
	else uncollapse_thread ();
     }

   % Try to put the cursor where it was...
   ifnot (locate_header_by_msgid (starting_article, 0))
     {
	return ();
     }

   % ...and restore the article view.
   if (article_was_visible_and_current != (_is_article_visible () & 1))
     {
	call ("hide_article");
     }

   % Zooms the article window if the article window was showing
   % the article.
   if ((_is_article_visible () & 1)
       && article_was_zoomed
       && (is_article_window_zoomed () == 0))
     {
	call ("zoom_article_window");
     }
}
definekey ("Global->refresh_reenter_group", "G", "article");
#v-
Technical Details
Message-ID: <slrnoo5e7v.51k.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.(126883).mbox.7z!not-for-mail

Show Full Headers
Complete Article Headers
Message-ID: <slrnoo5e7v.51k.jbn@forestfield.org>
Subject: [slrn] Fetch new news from article mode
Date: Thu, 03 Aug 2017 05:47:43 +0000
From: "J.B. Nicholson" <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.(126883).mbox.7z!not-for-mail
Newsgroups: news.software.readers
Organization: solani.org
Lines: 173
X-Trace: solani.org 1501739263 26456 eJwFwQERADEIAzBL8CtlyBlw9S/hkzh0ToJBhEICQBUkC8r0Fjm9siTP3Zn6EM6WXe839QMk5xFv (3 Aug 2017 05:47:43 GMT)
X-Complaints-To: abuse@news.solani.org
NNTP-Posting-Date: Thu, 3 Aug 2017 05:47:43 +0000 (UTC)
User-Agent: slrn/1.0.3 (Linux)
Cancel-Lock: sha1:/VZR23asC3v2VfFJ+fjcnycjq5U=
X-NNTP-Posting-Host: eJwNxsENACEMA7CZUJP0Og4Euv8IV8kPM7TkhCiw2V7Q7NS+iWolrXTH+faFYrZe2RyZbPwb3RFO
X-User-ID: eJwFwYEBACAEBMCVFP8xDsr+I3QH5WIfI2gYjM4zsLalJ1Uyq1DECW5aa19duOEpYS8F/gEauBDN
X-Received-Body-CRC: 1199088468
X-Received-Bytes: 7199