🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: news.software.readers
Article #48050

slrn macro to loop around group/article lists

#48050
From: blue... Dawn Owens-Nicholson
Date: Fri, 16 Apr 1999 00:00
1397 lines
41675 bytes
% Looping around slrn's group/article lists   % -*- mode: slang; mode: fold -*-
%
% Copyright © 1998 J.B. Nicholson-Owens
% Author: J.B. Nicholson-Owens
% Title: looptastic.sl
% Version: 2.1
% Requires: slrn 0.9.5.3 or greater, S-Lang 1.3.5 or greater

#iffalse % Documentation                                                %{{{

These macros allow the cursor to "loop" around the group and article
displays.  Looping means these macros make the cursor behave as if the
article and group displays are circular; when the pointer moves past the top
of the list, it moves up from the bottom and vice versa.  All the common
functions one uses to read news are modified so you progress from group to
group without having to enter group mode (the main exception being when you
try to enter a group where all the articles are killed by your scorefile).

This is the second version of this functionality, I released a similar set
of macros a while ago for use with S-Lang 0.x.  This version is
self-contained (you don't need any other S-Lang files but this macro to use
it) and intended for use with S-Lang 1.3.

To install this macro set:

(1) Save a copy of this file (or article) as "looptastic.sl" somewhere so
    slrn can find it.  Your home directory will do if you don't have a
    better place for it.

(2) Append the following lines to your slrn.rc ($HOME/.slrnrc on Unix) to
    make slrn load this file and set up some keys to access the functions:

       interpret "looptastic.sl"
       setkey article Looptastic->skip_to_next_group      "N"
       setkey article Looptastic->skip_to_prev_group      "P"
       setkey article Looptastic->next                    "n"
       setkey article Looptastic->prev                    "p"
       setkey article Looptastic->delete                  "d"
       setkey article Looptastic->undelete                "u"
       setkey article Looptastic->up                      "^P"
       setkey article Looptastic->up                      "\e[A"
       setkey article Looptastic->up                      "\eOA"
       setkey article Looptastic->up                      "^(ku)"
       setkey article Looptastic->down                    "^(kd)"
       setkey article Looptastic->down                    "^N"
       setkey article Looptastic->down                    "\e[B"
       setkey article Looptastic->down                    "\eOB"
       setkey article Looptastic->toggle_header_tag       "*"
       setkey article Looptastic->tag_header              "#"
       setkey article Looptastic->scroll_dn               " "
       setkey article Looptastic->next_high_score         "!"
       setkey article Looptastic->author_search_forward   "a"
       setkey article Looptastic->author_search_backward  "A"
       setkey group   Looptastic->subscribe               "s"
       setkey group   Looptastic->unsubscribe             "u"
       setkey group   Looptastic->catchup                 "c"
       setkey group   "() = Looptastic->select_group"     " "
       setkey group   "() = Looptastic->select_group"     "\n"

    If your terminfo/termcap files contain information about the escape
    sequences that your arrow keys generate, you only need the following
    Looptastic->up/Looptastic->down keybindings:

       setkey article "Looptastic->up"                   "^(ku)"
       setkey article "Looptastic->down"                 "^(kd)"

(3) Quit slrn and restart slrn.  The keys you mapped to looptastic macros
    will take effect.

Optional steps:

(1) Preferences:  Looptastic->set_preference()

  % Default settings shown below
  Looptastic->set_preference ("strict_compatibility", 1)
  Looptastic->set_preference ("uncollapse_now", 0)
  Looptastic->set_preference ("notify_looping", 0)
  Looptastic->set_preference ("notify_looping_message", "Cursor wrapped.")
  Looptastic->set_preference ("skip_empty_newsgroups", 0)
  Looptastic->set_preference ("skip_unsubscribed_newsgroups", 0)
  Looptastic->set_preference ("non_nextprev_loops_too", 0)
    
  Set any of these preferences with the set_preference() function by placing
  set_preference() lines in a file and loading that file after this macro
  set is loaded.

    Looptastic->set_preference ("preference name", preference value);

  The preference name is always a string and the type of value depends on
  the preference--some take strings (notify_looping_message, for instance)
  and some take booleans (strict_compatibility, for instance).

  Looptastic->set_preference ("strict_compatibility", 1)

  The strict_compatibility preference determines whether this macro set will
  act in accordance with slrn intrinsics (and still move the cursor in a
  loop, of course) or whether certain liberties can be taken.  All other
  preferences will be ignored if strict_compatibility is set to 1.

  For example, one area where call("prev") behaves differently than
  call("next") is prev does not skip to the previous group when there are
  unread articles, whereas next will skip to the next group.  The default
  behavior is to do what call("prev") would normally do.  Setting
  strict_compatibility to 0 will make prev skip to the previous newsgroup
  with apparently unread articles; that is, attempting to read the previous
  unread article ("p" by default) when all the articles in a group are read
  will make slrn skip to the previous unread newsgroup.

  Turning off strict compatibility also makes error messages slightly more
  descriptive.

  Looptastic->set_preference ("uncollapse_now", 0)

  Turning this preference on (and turning strict_compatibility off) will
  uncollapse threads as soon as the cursor passes by them.  For instance,
  using scroll_dn to select an article will uncollapse the thread to read
  the article at the start of the thread.  Leaving this off will let slrn
  uncollapse threads as it normally would (usually only when needed).

  Looptastic->set_preference ("notify_looping", 0)
  Looptastic->set_preference ("notify_looping_message", "Cursor wrapped.")

  Turning notify_looping on (and turning strict_compatibility off) will make
  this macro set tell you when the cursor wraps from one end of the header
  or newsgroup list to the other (i.e., when the cursor "loops").  The
  message can be customized with the notify_looping_message preference.

  Looptastic->set_preference ("skip_empty_newsgroups", 0)

  The skip_empty_newsgroups preference determines if the Looptastic->up()
  and Looptastic->down() macros will make the cursor skip groups that are
  apparently empty (groups where the unread article count is 0).  This count
  may be inaccurate if you haven't fetched new news in a while or if the
  group is new or unsubscribed.

  Looptastic->set_preference ("skip_unsubscribed_newsgroups", 0)

  The skip_unsubscribed_newsgroups preference determines whether the macro
  set will automatically leave the cursor on or enter an unsubscribed group.
  As with other preferences, this preference is only used if the
  strict_compatibility preference is off (0).

  Looptastic->set_preference ("non_nextprev_loops_too", 0)

  Turning this preference on makes keys that don't normally loop, loop.
  For instance, deleting a thread and catching up a group don't normally
  loop around the group/header lists.  Turn this preference on and they
  will.

(2) Looptastic->non_looping_prev_high_score() and the looping version
    Looptastic->prev_high_score()

  Normally, one uses the next_high_score intrinsic (bound to "!" by default)
  to skip from one high-scoring article to the next.  Going *up* the header
  list to the previous high-scoring article can be done with
  Looptastic->non_looping_prev_high_score().  There are looping and
  non-looping versions.  You might bind the looping versions to the "!" and
  "@" keys to go forwards and backwards:

     setkey article Looptastic->next_high_score  "!"
     setkey article Looptastic->prev_high_score  "@"

Now you should be able to start (or restart) slrn and see the cursor loop
around the group and article lists as you read news.  Feel free to use other
keybindings (or to not use all of them).

To remove this macro set (uninstall):

(1) Comment out or delete the interpret and setkey lines from your slrn.rc:

        % interpret "looptastic.sl"
        % setkey article "Looptastic->skip_to_next_group" "N"
        % setkey article "Looptastic->skip_to_prev_group" "P"
             .
             .

    If you set Looptastic preferences or bound Looptastic->prev_high_score
    to a key, be sure to comment or remove those lines as well.

(3) Quit slrn and restart slrn.  The keys you mapped to looping macros will
    revert back to whatever they were bound to before you started using
    Looptastic.

Change log:
v1.0: Released.
v2.0: Rewritten to be self-contained and released.
v2.1: * Included explicit description of looping to documentation.
      * Changed Looptastic->next() to not scroll_dn a visible article unless
        call("next") would do it.  Also cleaned up code in Looptastic->next().
      * Added Looptastic->prefs["notify_looping"] so user can be notified
        when looptastic macros loop (requested feature that works like
	 group_search() when it loops).
      * Used hashes for preferences and put exported functions and vars in
        the `Looptastic' namespace.
      * made prev_high_score() private (nobody was using it without the
        looping feature anyhow).
      * added prefs["skip_empty_newsgroups"].
      * edited documentation.
      * rewrote author/subject_search_forward/backward.
      * added prefs["uncollapse_now"] support to many functions.
      * made private functions,vars declared "private" (slang 1.3.5)
      * changed documentation.
      * added prefs["skip_unsubscribed_groups"] support to
        find_next/prev_group_from() and documentation.
      * Restored from backups (ugh) and added catchup().
      * added priv_delete() to optimize delete() & delete_thread().

#endif %}}}

implements ("Looptastic");

private define embolden (msg)                                           %{{{
{
   if (string_match (msg, "\\001", 1)) return (msg);  % already emboldened msg

   variable
     c = "",
     bold_msg = "";

   foreach (msg)
     {
	c = char ( () );
	bold_msg += ("\001" + c);
     }

   return (bold_msg);
}

%}}}
private define warning (msg)                                            %{{{
{
   message ("\n*** Warning: " + msg);
}

%}}}

private variable
   previous_search = "",
   prefs = Assoc_Type [];

% Set preferences (evaluated on load)                                   %{{{
prefs["strict_compatibility"] = 1;
prefs["notify_looping"] = 0;
prefs["notify_looping_message"] = "Cursor wrapped.";
prefs["skip_empty_newsgroups"] = 0;
prefs["uncollapse_now"] = 0;
prefs["find_reads_now"] = 0;
prefs["skip_unsubscribed_newsgroups"] = 0;
prefs["non_nextprev_loops_too"] = 0;

%}}}
private define find_reads_now ()                                        %{{{
{
   if (andelse
	{ @prefs["strict_compatibility"] == 0 }
	{ @prefs["find_reads_now"] }
	{ is_article_visible () == 1 })          % this covers zooming too
     call ("scroll_dn");
}

%}}}
private define notify_looping ()                                        %{{{
{
   if (@prefs["notify_looping"])
     {
	if (@prefs["strict_compatibility"])
	  message (embolden ("Search wrapped."));
        else message (embolden (@prefs["notify_looping_message"]));
     }
}

%}}}
private define uncollapse_now ()                                        %{{{
{
   if (andelse
        { is_group_mode () == 0 }
        { @prefs["strict_compatibility"] == 0 }
        { @prefs["uncollapse_now"] })
     uncollapse_thread ();
}

%}}}
private define skip_unsubscribed_newsgroups ()                          %{{{
{
   return (andelse
	    { @prefs["strict_compatibility"] == 0 }
	    { get_group_flags () & ~GROUP_UNSUBSCRIBED }
	    { @prefs["skip_unsubscribed_newsgroups"] });
}

%}}}
private define find_next_group_from (starting_newsgroup)                %{{{
{
   % Starting at the supplied group, find the next group with apparently
   % unread articles that is not the starting group.  Loop.

   while (current_newsgroup () != starting_newsgroup)
     () = group_search (starting_newsgroup);

   variable looped = 0;

   EXIT_BLOCK                                    % return bitmap to handle
     {                                           % loop notification.
	!if ( () ) return (0);                   % 0 == unsuccessful
	else if (looped) return (3);             % 3 == looped + successful
	else return (1);                         % 1 == no loop + successful
     }

   USER_BLOCK0
     {
	do
	  {
	     if (current_newsgroup () == starting_newsgroup) return (0);
	     if (group_unread ())
	       {
		  if (skip_unsubscribed_newsgroups ()) continue;
		  else return (1);
	       }
	  }
	while (group_down_n (1));
     }

   USER_BLOCK1
     {
	call ("bob");
	looped++;
     }

   !if (group_down_n (1)) X_USER_BLOCK1 ();
   X_USER_BLOCK0 ();
   X_USER_BLOCK1 ();
   X_USER_BLOCK0 ();
}

%}}}
private define find_prev_group_from (starting_newsgroup)                %{{{
{
   % Starting at the supplied group, find the previous group with apparently
   % unread articles that is not the starting group.  Loop.

   while (current_newsgroup () != starting_newsgroup)
     () = group_search (starting_newsgroup);

   variable looped = 0;

   EXIT_BLOCK                                    % return bitmap to handle
     {                                           % loop notification.
	!if ( () ) return (0);                   % 0 == unsuccessful
	else if (looped) return (3);             % 3 == looped + successful
	else return (1);                         % 1 == no loop + successful
     }

   USER_BLOCK0
     {
	do
	  {
	     if (current_newsgroup () == starting_newsgroup) return (0);
	     if (group_unread ())
	       {
		  if (skip_unsubscribed_newsgroups ()) continue;
		  else return (1);
	       }
	  }
	while (group_up_n (1));
     }

   USER_BLOCK1
     {
	call ("eob");
	looped++;
     }

   !if (group_up_n (1)) X_USER_BLOCK1 ();
   X_USER_BLOCK0 ();
   X_USER_BLOCK1 ();
   X_USER_BLOCK0 ();
}

%}}}
private define header_prev_unread ()                                    %{{{
{
   variable
     t_size = 0,
     starting_article = extract_article_header ("Message-ID"),
     starting_thread_was_collapsed = is_thread_collapsed ();

   while (header_up (1))
     {
	if (is_thread_collapsed ())
	  {
	     t_size = thread_size ();
	     uncollapse_thread ();
	     () = header_down (t_size - 1);      % move to end of thread

	     loop (t_size - 1)                   % skip read headers
	       {
		  !if (get_header_flags () & HEADER_READ) return (1);
		  () = header_up (1);
	       }

	     collapse_thread ();
	  }

	!if (get_header_flags () & HEADER_READ) return (1);
     }

   set_input_string (starting_article);
   call ("locate_header_by_msgid");
   if (starting_thread_was_collapsed) collapse_thread ();

   message ("No previous unread articles.");
   return (0);
}

%}}}

static  define version ()          { return (2.1); }
static  define non_looping_prev_high_score ()                           %{{{
{
   if (is_group_mode ())
     error (_function_name () + " doesn\'t work in group mode!");

   variable
     starting_article = extract_article_header ("Message-ID"),
     starting_thread_was_collapsed = is_thread_collapsed (),
     thread_head_article = "";

   USER_BLOCK0
     {
	if (get_header_flags () & HEADER_HIGH_SCORE)
	  {
	     if (is_article_visible ()) call ("scroll_dn");
	     % uncollapse_now ();
	     return ();
	  }
     }

   USER_BLOCK1
     {
	set_input_string (starting_article);
	call ("locate_header_by_msgid");
	if (starting_thread_was_collapsed) collapse_thread ();
	error ("No more high scoring articles.");
     }

   % move cursor to the head of the thread
   collapse_thread ();
   uncollapse_thread ();
   thread_head_article = extract_article_header ("Message-ID");
   if (thread_head_article != starting_article)
     {
	set_input_string (starting_article);
	call ("locate_header_by_msgid");
	() = header_up (1);
	while (extract_article_header ("Message-ID") != thread_head_article)
	  {
	     X_USER_BLOCK0 ();
	     () = header_up (1);
	  }
	X_USER_BLOCK0 ();
     }
   if (starting_thread_was_collapsed) collapse_thread ();
   !if (header_up (1)) X_USER_BLOCK1 ();

   variable
     thread_was_collapsed = 0,
     t_size = 0,
     index = 0;

   do
     {
	thread_was_collapsed = is_thread_collapsed ();
	!if (thread_was_collapsed) collapse_thread ();
	t_size = thread_size ();
	uncollapse_thread ();
	() = header_down (t_size - 1);

	for (index = t_size; index; index--)
	  {
	     X_USER_BLOCK0 ();
	     if (index != 1) () = header_up (1);
	  }
	if (thread_was_collapsed) collapse_thread ();
     }
   while (header_up (1));
   X_USER_BLOCK1 ();
}

%}}}
static  define set_preference (preference, value)                       %{{{
{
   !if (assoc_key_exists (prefs, preference))
     error ("Preference does not exist: " + string (preference));
   variable desired_type = typeof (@prefs[preference]);
   if (typeof (value) != desired_type)
     verror ("Wrong type for %s: This preference wants %s not %s",
	     string (preference),
	     string (desired_type),
	     string (typeof (value)));

   prefs[preference] = value;
}

%}}}
static  define select_group ()                                          %{{{
{
   !if (is_group_mode ())
     error (_function_name () + " doesn\'t work in article mode!");

   Global->select_group ();                      % push return value on stack
   uncollapse_now ();
}

%}}}
static  define skip_to_next_group ()                                    %{{{
{
   % This should be an unpromptable skip -- a /hard/ skip -- to the next group.
   % But this should find a group with unread articles, allowing an all-killed
   % newsgroup to abort this macro (via error()).

   if (is_group_mode ())
     error (_function_name () + " doesn\'t work in group mode.");

   variable starting_group = current_newsgroup ();

   call ("skip_to_next_group");
   if (is_group_mode ())                         % skip_to_next_group failed
     {
	variable find_group_bitmap = find_next_group_from (starting_group);
	if (find_group_bitmap)
	  {
	     () = select_group ();
	     if (find_group_bitmap & 2) notify_looping ();
	  }
	else
	  {
	     if (@prefs["strict_compatibility"]) call ("eob");
	     else message (embolden ("No next newsgroup."));
	  }
     }
   else uncollapse_now ();
}

%}}}
static  define skip_to_prev_group ()                                    %{{{
{
   % This should be an unpromptable skip -- a /hard/ skip -- to the prev group.
   % But this should find a group with unread articles, allowing an all-killed
   % newsgroup to abort this macro (via error()).

   if (is_group_mode ())
     error (_function_name () + " doesn\'t work in group mode.");

   variable starting_group = current_newsgroup ();

   call ("skip_to_prev_group");
   if (is_group_mode ())                         % skip_to_next_group failed
     {
	variable find_group_bitmap = find_prev_group_from (starting_group);
	if (find_group_bitmap)
	  {
	     () = select_group ();
	     if (find_group_bitmap & 2) notify_looping ();
	  }
	else
	  {
	     if (@prefs["strict_compatibility"]) call ("bob");
	     else message (embolden ("No previous newsgroup."));
	  }
     }
   else uncollapse_now ();
}

%}}}
static  define next ()                                                  %{{{
{
   if (is_group_mode ())
     error (_function_name + " doesn\'t work in group mode.");

   EXIT_BLOCK {	uncollapse_now (); }

   if (header_next_unread ())
     {
	() = header_up (1);
	call ("next");
	return ();
     }

   variable
     starting_article = extract_article_header ("Message-ID"),
     starting_group = current_newsgroup ();

   USER_BLOCK0                                   % use intrinsic
     {
	call ("next");
	if (is_group_mode ())
	  {
	     if (find_next_group_from (starting_group)) () = select_group ();
	  }
	else if (current_newsgroup () == starting_group)
	  {
	     if (extract_article_header ("Message-ID") == starting_article)
	       skip_to_next_group ();
	     else notify_looping ();
	  }
	return ();
     }

   call ("header_bob");

   if (orelse
	{ extract_article_header ("Message-ID") == starting_article }
	{ get_header_flags () & HEADER_READ })
     X_USER_BLOCK0 ();

   if (andelse                                   % read top article
	{ get_variable_value ("query_next_article") }
	{ get_next_art_pgdn_action () == 2 })
     {
	set_input_string (starting_article);
	call ("locate_header_by_msgid");

	message ("At the end of the article, press RETURN for next unread article.");
	variable key = getkey ();
	!if (orelse { key == '\n' } { key == '\r' }) return ();
	call ("header_bob");
     }

   switch (is_article_visible ())
     { case (0) : return (); }
     { case (1) :
	call ("scroll_dn");                      % select the article
	notify_looping ();
     }
     { X_USER_BLOCK0 (); }
}

%}}}
static  define catchup ()                                               %{{{
{
   !if (is_group_mode ())
     error (_function_name () + " doesn\'t work in article mode!");

   variable starting_newsgroup = current_newsgroup ();
   call (_function_name ());
   if (andelse
	{ @prefs["non_nextprev_loops_too"] }
	{ current_newsgroup () == starting_newsgroup })
     next ();
}

%}}}
static  define scroll_dn ()                                             %{{{
{
   switch (get_next_art_pgdn_action ())
     { case (-1) : error (_function_name () + " doesn\'t work in group mode");}
     { case  (2) :
	variable
	  message_ID = extract_article_header ("Message-ID"),
	  thread_was_collapsed = is_thread_collapsed (),
	  key = 0;

	if (get_variable_value ("query_next_article"))
	  {
	     message ("At end of article, press SPACE for next unread article.");
	     update ();
	     key = getkey ();
	     if (key != ' ')
	       {
		  ungetkey (key);
		  return ();
	       }
	  }
	call ("header_bob");

	if (get_header_flags () & HEADER_READ)
	  {
	     if (header_next_unread ())
	       {
		  call ("scroll_dn");
		  notify_looping ();
		  return ();
	       }
	     else
	       {
		  if (get_variable_value ("query_next_group"))
		    {
		       set_input_string (message_ID);
		       call ("locate_header_by_msgid");
		       if (thread_was_collapsed) collapse_thread ();

		       message ("No following unread articles.  Press RETURN for next group.");
		       update ();
		       key = getkey ();
		       !if (orelse { key == '\n' } { key == '\r' })
			 {
			    ungetkey (key);
			    return ();
			 }
		    }
		  skip_to_next_group ();
	       }
	  }
	else
	  {
	     call ("scroll_dn");                 % select article
	     notify_looping ();
	  }

	return ();
     }
     { case (1) : uncollapse_now (); }
   call ("scroll_dn");
}

%}}}
static  define subscribe ()                                             %{{{
{
   !if (is_group_mode ())
     error (_function_name () + " doesn\'t work in article mode!");

   variable starting_group = current_newsgroup ();
   call ("subscribe");
   if (current_newsgroup () == starting_group)
     {
	call ("bob");
	notify_looping ();
     }
}

%}}}
static  define unsubscribe ()                                           %{{{
{
   !if (is_group_mode ())
     error (_function_name () + " doesn\'t work in article mode!");

   variable starting_group = current_newsgroup ();
   call ("unsubscribe");
   if (current_newsgroup () == starting_group)
     {
	call ("bob");
	notify_looping ();
     }
}

%}}}
static  define next_high_score ()                                       %{{{
{
   if (is_group_mode ())
     error (_function_name () + " doesn\'t work in group mode!");

   ERROR_BLOCK                                   % no high scores below cursor
     {
        variable
          starting_article = extract_article_header ("Message-ID"),
          starting_thread_was_collapsed = is_thread_collapsed ();

        call ("header_bob");

        if (get_header_flags () & HEADER_HIGH_SCORE)
          {
             if (extract_article_header ("Message-ID") != starting_article)
               {
                  _clear_error ();
                  if (is_article_visible () == 1)
		    {
		       call ("scroll_dn");
		       notify_looping ();
		    }
               }
             return ();
          }

        ERROR_BLOCK                              % no high scores at all
          {
             set_input_string (starting_article);
             call ("locate_header_by_msgid");
             if (starting_thread_was_collapsed) collapse_thread ();
	     !if (@prefs["strict_compatibility"])
	       {
		  _clear_error ();
		  error ("No high scoring articles.");
	       }
	     return ();
          }
        call ("next_high_score");
	uncollapse_now ();
        if (extract_article_header ("Message-ID") != starting_article)
	  {
	     _clear_error ();
	     notify_looping ();
	  }
     }
   call ("next_high_score");
   uncollapse_now ();
}

%}}}
static  define prev ()                                                  %{{{
{
   if (is_group_mode ())
     error (_function_name () + " doesn\'t work in group mode.");

   variable
     starting_article = extract_article_header ("Message-ID"),
     starting_thread_was_collapsed = is_thread_collapsed ();

   call ("prev");
   if (extract_article_header ("Message-ID") != starting_article) return ();

   call ("header_eob");                          % nothing unread above cursor

   EXIT_BLOCK { uncollapse_now (); }

   if (extract_article_header ("Message-ID") == starting_article)
     {
	if (@prefs["strict_compatibility"])      % only one header in list
	  %X_USER_BLOCK0 ();
	  call ("prev");                         % jbn: test
	else skip_to_prev_group ();
	return ();
     }

   if (is_thread_collapsed ())                   % search from bottom of list
     {
	variable t_size = thread_size ();
	uncollapse_thread ();
	call ("header_eob");
	loop (t_size - 1)
	  {
	     if (get_header_flags () & HEADER_READ) () = header_up (1);
	     else
	       {
		  if (is_article_visible ()) call ("scroll_dn");
		  notify_looping ();
		  return ();
	       }
	  }
	collapse_thread ();
     }

   if (get_header_flags () & HEADER_READ)
     {
	variable message_ID = extract_article_header ("Message-ID");
	call ("prev");
	switch (extract_article_header ("Message-ID"))
	  { orelse { case (message_ID) } { case (starting_article) } :
	     if (@prefs["strict_compatibility"])      % call("prev") failed
	       {
		  set_input_string (starting_article);
		  call ("locate_header_by_msgid");
		  if (starting_thread_was_collapsed) collapse_thread ();
		  message ("No previous unread articles");
	       }
	     else skip_to_prev_group ();
	  }
	  { notify_looping (); }                      % call("prev") worked
	return ();
     }

   if (is_article_visible ())
     {
	call ("scroll_dn");
	notify_looping ();
     }
}

%}}}
private define priv_delete (f)                                          %{{{
{
   if (is_group_mode ())
     error (_function_name () + " doesn\'t work in group mode.");

   variable
     starting_article = extract_article_header ("Message-ID"),
     starting_thread_was_collapsed = is_thread_collapsed ();

   call (f);
   if (extract_article_header ("Message-ID") != starting_article) return ();

   call ("header_bob");                          % no unread articles below
   if (andelse
	{ get_header_flags () & HEADER_READ }
	{ header_next_unread () == 0 })
     {
	set_input_string (starting_article);     % no unread articles above
	call ("locate_header_by_msgid");
	if (starting_thread_was_collapsed ()) collapse_thread ();
	message ("No following unread articles.");
     }
   else notify_looping ();
}

%}}}
static  define delete ()           { priv_delete (_function_name ()); }
static  define delete_thread ()    { priv_delete (_function_name ()); }
static  define undelete ()                                              %{{{
{
   if (is_group_mode ())
     error (_function_name () + " doesn\'t work in group mode.");

   variable starting_article = extract_article_header ("Message-ID");

   call (_function_name ());
   if (extract_article_header ("Message-ID") == starting_article)
     {
	call ("header_bob");
	notify_looping ();
     }
}

%}}}
static  define up ()                                                    %{{{
{
   !if (is_group_mode ())
     {
	!if (header_up (1))
	  {
	     call ("header_eob");
	     notify_looping ();
	  }
	return ();
     }

   variable starting_newsgroup = current_newsgroup ();

   USER_BLOCK0
     {
	if (orelse
	     { current_newsgroup () == starting_newsgroup }
	     { andelse
		  { @prefs["strict_compatibility"] == 0 }
		  { @prefs["skip_empty_newsgroups"] == 0 }}
	     { group_unread () })
	  return ();
     }

   forever
     {
	if (group_up_n (1)) X_USER_BLOCK0 ();
	else
	  {
	     call ("eob");
	     notify_looping ();
	     X_USER_BLOCK0 ();
	  }
     }
}

%}}}
static  define down ()                                                  %{{{
{
   !if (is_group_mode ())
     {
	!if (header_down (1))
	  {
	     call ("header_bob");
	     notify_looping ();
	  }
	return ();
     }

   variable starting_newsgroup = current_newsgroup ();

   USER_BLOCK0
     {
	if (orelse
	     { current_newsgroup () == starting_newsgroup }
	     { andelse
		  { @prefs["strict_compatibility"] == 0 }
		  { @prefs["skip_empty_newsgroups"] == 0 }}
	     { group_unread () })
	  return ();
     }

   forever
     {
	if (group_down_n (1)) X_USER_BLOCK0 ();
	else
	  {
	     call ("bob");
	     notify_looping ();
	     X_USER_BLOCK0 ();
	  }
     }
}

%}}}
static  define toggle_header_tag ()                                     %{{{
{
   if (andelse
	{ @prefs["strict_compatibility"] == 0 }
	{ @prefs["uncollapse_now"] })
     uncollapse_thread ();

   EXIT_BLOCK { uncollapse_now (); }

   if (get_prefix_arg () != -1)
     {
	call ("toggle_header_tag");
	return ();
     }

   variable message_ID = extract_article_header ("Message-ID");

   call ("toggle_header_tag");
   if (extract_article_header ("Message-ID") == message_ID)
     {
	call ("header_bob");
	notify_looping ();
     }
}

%}}}
static  define tag_header ()                                            %{{{
{
   uncollapse_now ();
   EXIT_BLOCK { uncollapse_now (); }

   variable
     was_tagged = get_header_tag_number (),
     message_ID = extract_article_header ("Message-ID");

   call ("tag_header");
   if (andelse
	{ extract_article_header ("Message-ID") == message_ID }
	{ was_tagged == 0 })
     {
	call ("header_bob");
	notify_looping ();
     }
}

%}}}
static  define prev_high_score ()                                       %{{{
{
   % looping version of non_looping_prev_high_score()

   if (is_group_mode ())
     error (_function_name + " doesn\'t work in group mode!");

   ERROR_BLOCK
     {
	variable
	  starting_article = extract_article_header ("Message-ID"),
	  starting_thread_was_collapsed = is_thread_collapsed (),
	  eob_article = "",
	  eob_thread_was_collapsed = 0,
	  index = 0;

	% Skip to last thread, check for high articles in last thread here.
	call ("header_eob");
	eob_article = extract_article_header ("Message-ID");
	eob_thread_was_collapsed = is_thread_collapsed ();
	!if (eob_thread_was_collapsed) collapse_thread ();
	index = thread_size ();
	uncollapse_thread ();
	call ("header_eob");
	for (; index; index--)
	  {
	     if (get_header_flags () & HEADER_HIGH_SCORE)
	       {
		  _clear_error ();
		  if (is_article_visible () == 1)
		    {
		       call ("scroll_dn");
		       notify_looping ();
		    }
		  return ();
	       }
	     else if (index > 1) () = header_up (1);
	  }
	if (eob_thread_was_collapsed) collapse_thread ();

	% No high articles in last thread, so use non_looping_prev_high_score()
	% to check for high articles above last thread (not including head of
	% last thread).
	ERROR_BLOCK
	  {
	     set_input_string (starting_article);
	     call ("locate_header_by_msgid");
	     if (starting_thread_was_collapsed) collapse_thread ();
	     !if (@prefs["strict_compatibility"])
	       {
		  _clear_error ();
		  error ("No high scoring articles.");
	       }
	     return ();
	  }
	non_looping_prev_high_score ();

	% Don't want to loop and hit the same high scoring article every time
	if (extract_article_header ("Message-ID") != starting_article)
	  {
	     _clear_error ();
	     notify_looping ();
	     return ();
	  }
     }
   non_looping_prev_high_score ();
   uncollapse_now ();
}

%}}}
static  define author_search_forward ()                                 %{{{
{
   if (is_group_mode ())
     error (_function_name () + " doesn\'t work in group mode!");

   variable
     starting_article = extract_article_header ("Message-ID"),
     starting_thread_was_collapsed = is_thread_collapsed (),
     author = read_mini ("Author Search Forward", previous_search, "");

   EXIT_BLOCK
     {
	uncollapse_now ();
	find_reads_now ();
     }

   ERROR_BLOCK
     {
	USER_BLOCK0
	  {
	     if (extract_article_header ("Message-ID") == starting_article)
	       {
		  if (@prefs["strict_compatibility"]) return ();
		  else
		    {
		       _clear_error ();
		       error ("No more matching articles found.");
		    }
	       }
	     else _clear_error ();
	  }

	call ("header_bob");

	if (is_substr (strlow (extract_article_header ("From")),
		       strlow (author)))
	  {
	     X_USER_BLOCK0 ();
	     return ();
	  }

	ERROR_BLOCK
	  {
	     EXIT_BLOCK {}                       % clear EXIT_BLOCK

	     set_input_string (starting_article);
	     call ("locate_header_by_msgid");
	     if (starting_thread_was_collapsed) collapse_thread ();
	     return ();
	  }
	set_input_string (author);
	call ("author_search_forward");

	X_USER_BLOCK0 ();
	notify_looping ();
     }
   !if (strlen (author)) return ();
   previous_search = author;
   set_input_string (author);
   call ("author_search_forward");
}

%}}}
static  define author_search_backward ()                                %{{{
{
   if (is_group_mode ())
     error (_function_name () + " doesn\'t work in group mode!");

   variable
     starting_article = extract_article_header ("Message-ID"),
     starting_thread_was_collapsed = is_thread_collapsed (),
     author = read_mini ("Author Search Backward", previous_search, "");

   EXIT_BLOCK
     {
	uncollapse_now ();
	find_reads_now ();
     }

   ERROR_BLOCK
     {
	USER_BLOCK0
	  {
	     if (extract_article_header ("Message-ID") == starting_article)
	       {
		  if (@prefs["strict_compatibility"]) return ();
		  else
		    {
		       _clear_error ();
		       error ("No more matching articles found.");
		    }
	       }
	     else _clear_error ();
	  }

	call ("header_eob");

	if (is_substr (strlow (extract_article_header ("From")),
		       strlow (author)))
	  {
	     X_USER_BLOCK0 ();
	     return ();
	  }

	ERROR_BLOCK
	  {
	     EXIT_BLOCK {}                       % clear EXIT_BLOCK

	     set_input_string (starting_article);
	     call ("locate_header_by_msgid");
	     if (starting_thread_was_collapsed) collapse_thread ();
	     return ();
	  }
	set_input_string (author);
	call ("author_search_backward");

	X_USER_BLOCK0 ();
	notify_looping ();
     }
   !if (strlen (author)) return ();
   previous_search = author;
   set_input_string (author);
   call ("author_search_backward");
}

%}}}
static  define subject_search_forward ()                                %{{{
{
   if (is_group_mode ())
     error (_function_name () + " doesn\'t work in group mode!");

   variable
     starting_article = extract_article_header ("Message-ID"),
     starting_thread_was_collapsed = is_thread_collapsed (),
     author = read_mini ("Subject Search Forward", previous_search, "");

   EXIT_BLOCK
     {
	uncollapse_now ();
	find_reads_now ();
     }

   ERROR_BLOCK
     {
	USER_BLOCK0
	  {
	     if (extract_article_header ("Message-ID") == starting_article)
	       {
		  if (@prefs["strict_compatibility"]) return ();
		  else
		    {
		       _clear_error ();
		       error ("No more matching articles found.");
		    }
	       }
	     else _clear_error ();
	  }

	call ("header_bob");

	if (is_substr (strlow (extract_article_header ("From")),
		       strlow (author)))
	  {
	     X_USER_BLOCK0 ();
	     return ();
	  }

	ERROR_BLOCK
	  {
	     EXIT_BLOCK {}                       % clear EXIT_BLOCK

	     set_input_string (starting_article);
	     call ("locate_header_by_msgid");
	     if (starting_thread_was_collapsed) collapse_thread ();
	     return ();
	  }
	set_input_string (author);
	call ("subject_search_forward");

	X_USER_BLOCK0 ();
	notify_looping ();
     }
   !if (strlen (author)) return ();
   previous_search = author;
   set_input_string (author);
   call ("subject_search_forward");
}

%}}}
static  define subject_search_backward ()                               %{{{
{
   if (is_group_mode ())
     error (_function_name () + " doesn\'t work in group mode!");

   variable
     starting_article = extract_article_header ("Message-ID"),
     starting_thread_was_collapsed = is_thread_collapsed (),
     author = read_mini ("Subject Search Backward", previous_search, "");

   EXIT_BLOCK
     {
	uncollapse_now ();
	find_reads_now ();
     }

   ERROR_BLOCK
     {
	USER_BLOCK0
	  {
	     if (extract_article_header ("Message-ID") == starting_article)
	       {
		  if (@prefs["strict_compatibility"]) return ();
		  else
		    {
		       _clear_error ();
		       error ("No more matching articles found.");
		    }
	       }
	     else _clear_error ();
	  }

	call ("header_eob");

	if (is_substr (strlow (extract_article_header ("From")),
		       strlow (author)))
	  {
	     X_USER_BLOCK0 ();
	     return ();
	  }

	ERROR_BLOCK
	  {
	     EXIT_BLOCK {}                       % clear EXIT_BLOCK

	     set_input_string (starting_article);
	     call ("locate_header_by_msgid");
	     if (starting_thread_was_collapsed) collapse_thread ();
	     return ();
	  }
	set_input_string (author);
	call ("subject_search_backward");

	X_USER_BLOCK0 ();
	notify_looping ();
     }
   !if (strlen (author)) return ();
   previous_search = author;
   set_input_string (author);
   call ("subject_search_backward");
}

%}}}
static  define startup_hook ()                                          %{{{
{
   variable setting = NULL;

   if (is_defined ("looptastic_strict_compatibility"))
     {
	eval ("string (looptastic_strict_compatibility);");
	setting = ();
	warning ("looptastic_strict_compatibility is deprecated.\nUse " +
		 embolden ("Looptastic->set_preference (\"strict_compatibility\", " + setting + "); ") +
		 "instead.");
     }

   if (is_defined ("looptastic_notify_looping"))
     {
	eval ("string (looptastic_notify_looping);");
	setting = ();
	warning ("looptastic_notify_looping is deprecated.\nUse " +
		 embolden ("Looptastic->set_preference (\"notify_looping\", " + setting + "); ") +
		 "instead.");
     }

   if (is_defined ("looptastic_notify_looping_message"))
     {
	eval ("string (looptastic_notify_looping_message);");
	setting = ();
	warning ("looptastic_notify_looping_message is deprecated.\nUse " +
		 embolden ("Looptastic->set_preference (\"notify_looping_message\", " + setting + "); ") +
		 "instead.");
     }
}

%}}}
static  define header_number_hook ()                                    %{{{
{
   uncollapse_now ();
}

%}}}
Technical Details
Message-ID: <slrn7hde4v.4in.bluemoon@ux6.cso.uiuc.edu>
Path: mbox-mo1.pugleaf.net!archive.usenet.blueworldhosting.com!illumos!news.pugleaf.net!.TX!i2pn2.pugleaf.net!archive.newsdeef.eu!mbox2nntp!not-for-mail

Show Full Headers
Complete Article Headers
Message-ID: <slrn7hde4v.4in.bluemoon@ux6.cso.uiuc.edu>
Subject: slrn macro to loop around group/article lists
Date: Fri, 16 Apr 1999 00:00:00 +0000
From: blue...@ux6.cso.uiuc.edu (Dawn Owens-Nicholson)
Path: mbox-mo1.pugleaf.net!archive.usenet.blueworldhosting.com!illumos!news.pugleaf.net!.TX!i2pn2.pugleaf.net!archive.newsdeef.eu!mbox2nntp!not-for-mail
X-Deja-AN: 466991483
Content-Transfer-Encoding: 8bit
Followup-To: news.software.readers
Content-Type: text/plain; charset=iso-8859-1
Summary: A macro set for slrn written in S-Lang. It's free, it works, enjoy.
Organization: University of Illinois at Urbana-Champaign
Keywords: slrn, macro, looptastic, version 2.1
Mime-Version: 1.0
User-Agent: slrn/0.9.5.4 (UNIX)
Newsgroups: news.software.readers,alt.lang.s-lang