Re: Refresh List of Articles
"J.B. Nicholson" <[email protected]> Tue, 1 Aug 2017 23:56:48 -0500
| Newsgroups | gmane.network.slrn.user |
|---|---|
| Message-ID | <[email protected]> |
I wrote:
> You can do this with a macro.
Here's a better version. What follows is faster than what I posted before, doesn't access the network (aside from fetching new news of course), handles score restoration (in addition to thread displaying) unlike the previous version, avoids a locate_header_by_msgid() side-effect the previous version worked around, and removes an unused variable listed in the previous version. There's even some better pretty-printing.
Stick the following into a file (not including whatever signature sourceforge.net appends), interpret that file from your slrnrc (or evalfile() from within slrn), and you should be ready to refresh group mode (and the current group) from article mode by pressing "G".
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 we need to change and restore 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();
% We don't want any prefix arguments to interfere with any call()s
% we make. So we 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 we modified.
if (prefix_arg != -1) set_prefix_argument (prefix_arg);
set_integer_variable ("query_read_group_cutoff", starting_query_read_group_cutoff);
}
variable
% Initialized for useful initial values.
starting_article = extract_article_header ("Message-ID"),
starting_newsgroup = current_newsgroup (),
article_was_visible_and_current = (_is_article_visible () == 3),
% Initialized later and generally 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 = "";
% Store collapse status for unread articles. Threads with all-read
% articles will disappear when we re-enter the group because read
% articles won't be around to set collapse status on.
call ("header_bob");
do
{
t = thread_size ();
thread_was_collapsed = is_thread_collapsed ();
message_ID = "";
uncollapse_thread ();
for (i = 1; i <= t; i++)
{
% We track collapse status for all articles.
thread_collapse_status[extract_article_header ("Message-ID")] = thread_was_collapsed;
% Reset the score to 0 and mark the article unread. slrn will
% re-score the article again when we re-enter this group.
set_header_score (0);
set_header_flags (get_header_flags () & ~HEADER_READ);
% We care about how we leave the thread 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 thread display.
foreach message_ID,thread_was_collapsed (thread_collapse_status) using ("keys", "values")
{
() = locate_header_by_msgid (message_ID, 0);
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");
------------------------------------------------------------------------------
Check out the vibrant tech community on one of the world's most
engaging tech sites, Slashdot.org! http://sdm.link/slashdot