Discussion:
[slrn] Way to refresh group while viewing article list?
(too old to reply)
Jay
2019-11-12 19:03:02 UTC
Permalink
Is there a way to refresh the articles in a group while in the article view for
that group?
Phil Boutros
2019-11-13 03:44:13 UTC
Permalink
Post by Jay
Is there a way to refresh the articles in a group while in the
article view for that group?
Yes. I use the following macro for that, someone shared it here a
while back.

#v+

% Refresh and reenter a newsgroup
% version 1.1
%
% A slrn macro by J.B. Nicholson (***@forestfield.org)
% License: GNU GPL v2 or later
% License URL: http://www.gnu.org/licenses/
%
% refresh-reenter-group-1.0.sl allows a user to fetch new news ("refresh"),
% and reenter the current newsgroup from article mode.
% Copyright (C) 2017 J.B. Nicholson (***@forestfield.org)
%
% This program is free software: you can redistribute it and/or modify
% it under the terms of the GNU General Public License as published by
% the Free Software Foundation, either version 2 of the License, or
% (at your option) any later version.
%
% This program is distributed in the hope that it will be useful,
% but WITHOUT ANY WARRANTY; without even the implied warranty of
% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
% GNU General Public License for more details.
%
% You should have received a copy of the GNU General Public License
% along with this program. If not, see <http://www.gnu.org/licenses/>.
%
% To install:
% 1. Save this file somewhere slrn can read it (perhaps
% in ~/.slrn/refresh_reenter_group-1.1.sl)
%
% 2. Edit your slrnrc to load this file and bind the function to a
% key by adding:
%
% interpret "/path/to/.slrn/refresh_reenter_group-1.1.sl"
% setkey article "refresh_reenter_group->refresh_reenter_group" "G"
%
% 3. Quit slrn and relaunch slrn.
%
% To uninstall:
% 1. Remove the following lines from your slrnrc, or comment the
% lines out by prepending a "%" to the lines:
%
% %interpret "/path/to/.slrn/refresh_reenter_group-1.1.sl"
% %setkey article "refresh_reenter_group->refresh_reenter_group" "G"
%
% Versions:
% 1.0: Initial release with a version number.
% 1.1: Fixed name of macro file in documentation so it matches filename.
% Thanks Phil Boutros <***@philb.ca> for pointing this out.

implements ("refresh_reenter_group");

static define version ()
{
return (1.1);
}

static define refresh_reenter_group ()
{
% Lets the user 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 call() 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 but only for threads with more than 1 article
% because single-article threads are uncollapsed by
% default (is_thread_collapsed() returns 0 for single-article
% threads) and this creates an uncollapsed thread when a
% followup article arrives in that thread which breaks the
% illusion we're 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;

% Set the score to 0 for all articles.
% slrn will re-score the article again upon re-entering this group.
set_header_score (0);

% 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));

% Mark all articles unread.
% This can be done in the above loop but using slrn's intrinsic is
% probably faster and being faster matters more on large groups.
if (get_variable_value ("confirm_actions") & 1) set_input_chars ("y");
call ("uncatchup_all");

% 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");
}
}

#v-


Cheers,

Phil
--
AH#61 Wolf#14 BS#89 bus#1 CCB#1 SENS KOTC#4
***@philb.ca http://philb.ca
Loading...