🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: news.software.readers
Article #43128

[slrn] StickyTags.sl macro

#43128
From: Dawn Owens-Nicholson
Date: Tue, 08 Sep 1998 00:00
271 lines
8076 bytes
% Sticky tags                                                   % -*- slang -*-
%
% Copyright 1998 J.B. Nicholson-Owens
% Author: J.B. Nicholson-Owens
% Title: StickyTags.sl
% Version: 1.0
% Requires: slrn 0.9.5.3, S-Lang 1.x

#iffalse

This macro set will give you persistent * tags on slrn article headers; if
you quit article mode or quit slrn, the * tags will be in the right place
when you next start slrn.  The next time you enter that newsgroup, slrn will
display the headers with the appropriate tags.

To install:

(1) Save a copy of this file (or article) as "stickytags.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 "stickytags.sl"

(3) Put the following lines in a separate file (or your hooks file, if you
    have one).  If you don't already have a file for hooks, or if you don't
    know what this is, put the following lines into a file called
    "my_hooks.sl" in your homedir:

        define startup_hook ()
        {
	   stickytags_startup_hook ();
	}

        define article_mode_hook ()
        {
	   stickytags_article_mode_hook ();
	}

	define article_mode_quit_hook ()
	{
	   stickytags_article_mode_quit_hook ();
	}

    If you already have these hooks defined, add the corresponding function
    call to the listed hooks.

(4) If you made a separate file for these hooks, append the following line to
    the bottom of your slrn.rc:

       interpret "my_hooks.sl"

    This will make slrn load the hooks and execute certain functions at the
    appropriate time.

Now you should be able to start (or restart) slrn and have persistent or
"sticky" tags which last between entering article mode and across slrn
sessions.  The default file used to record tag information is
"$HOME/.slrn-stickytags".  If you wish to change this, I suggest making a
new file (call it "my_preferences.sl", put it in your homedir) and loading
it after you load your hooks (which should be executed after loading this
macro set).  Your preferences file should have the following line:

    variable my_stickytags_file = make_home_filename ("path/and/file/here");

In summary, your slrn.rc file should have the following lines in it:

    interpret "stickytags.sl"
    interpret "my_hooks.sl"
    interpret "my_preferences.sl"

If you set the environment variable STICKYTAGS_FILE to the location of your
tag file, that will be used instead of my_stickytags_file.  This is handy
for using a StickyTags file without having to change your usual preferences.
See your system or shell's documentation for information on setting an
environment varialble.  If you define neither the environment variable nor
my_stickytags_file, the default is used.

To remove this macro set:

(1) Comment out or delete the three (at most) lines from your slrn.rc:

      interpret "stickytags.sl"
      interpret "my_hooks.sl"
      interpret "my_preferences.sl"

    You will want to keep the my_hooks and my_preferences lines in your
    slrn.rc uncommented if you have other hooks or preferences.

(2) Comment out or delete the references to stickytags_* functions in your
    hooks:

      define article_mode_quit_hook ()
      {
	 stickytags_article_mode_quit_hook ();
      }

    would become:

      define article_mode_quit_hook ()
      {
	 % stickytags_article_mode_quit_hook ();
      }

    or, since this is the only line in the hook, you could remove the hook
    definition entirely.

(3) Delete the tags file (the default is "$HOME/.slrn-stickytags").

(4) Quit slrn and restart slrn.  Stickytags will no longer be loaded in
    your slrn.  The tags file will not be updated as you mark and unmark
    headers; tags will operate as they did before you installed this
    macro set.

#endif

variable
   st_list = NULL,
   st_tail = NULL,
   st_current_file = make_home_filename (".slrn-stickytags");

define stickytags_add (message_ID)
{
   variable lp = st_list;
   while (lp != NULL)                            % check for entry
     {
	if (lp.message_ID == message_ID) return ();
	lp = lp.next;
     }

   variable new = struct { message_ID, next };
   new.message_ID = message_ID;
   new.next = NULL;

   if (st_list == NULL) st_list = new;
   else st_tail.next = new;
   st_tail = new;
}

define stickytags_remove (message_ID)            % remove from list
{
   variable
     prev = NULL,
     lp = st_list;

   while (lp != NULL)
     {
	if (lp.message_ID == message_ID)
	  {
	     if (lp == st_list)                  % removing the head node
	       st_list = st_list.next;
	     else prev.next = lp.next;           % removing any other node
	     break;
	  }
	else prev = lp;
	lp = lp.next;
     }
}

define stickytags_article_mode_quit_hook ()
{
   variable
     message_ID = "",
     header_flags = 0;

   call ("header_bob");
   uncollapse_threads ();
   do
     {
	message_ID = extract_article_header ("Message-ID");
	header_flags = get_header_flags ();

	if (header_flags & HEADER_READ) stickytags_remove (message_ID);
	else
	  {
	     if (header_flags & HEADER_TAGGED) stickytags_add (message_ID);
	     else stickytags_remove (message_ID);
	  }
     }
   while (header_down (1));

   variable fp = fopen (st_current_file, "w");   % save the list
   if (fp == NULL) return ();

   variable
     lp = st_list,
     line = "";

   ERROR_BLOCK
     if (fclose (fp) == -1)
       error ("Couldn\'t close %s: %s", st_current_file, errno_string (errno));

   while (lp != NULL)
     {
	line = sprintf ("%s\n", lp.message_ID);
	if (-1 == fputs (line, fp))
	  verror ("Couldn\'t write to %s: %s",
		  st_current_file,
		  errno_string (errno));
	lp = lp.next;
     }

   EXECUTE_ERROR_BLOCK;
}

define stickytags_article_mode_hook ()
{
   if (st_list == NULL) return ();

   variable
     lp = st_list,
     message_ID = "",
     starting_place = extract_article_header ("Message-ID");

   do
     {
	message_ID = extract_article_header ("Message-ID");
	while (lp != NULL)
	  {
	     if (lp.message_ID == message_ID)
	       {
		  set_header_flags (get_header_flags () | HEADER_TAGGED);
		  break;
	       }
	     lp = lp.next;
	  }
	lp = st_list;
     }
   while (header_down (1));

   set_input_string (starting_place);
   call ("locate_header_by_msgid");
}

define stickytags_startup_hook ()
{
   variable env = getenv ("STICKYTAGS_FILE");
   if (env != NULL) st_current_file = env;
   else if (is_defined ("my_stickytags_file"))
     eval ("st_current_file = my_stickytags_file;");

   variable fp = fopen (st_current_file, "r");
   if (fp == NULL) return ();

   vmessage ("loading %s...", st_current_file);

   variable
     numtags = 0,
     s = "s",
     message_ID = "",
     line = "";

   while (fgets (&line, fp) != -1)
     {
	line = strtrim (line);
	if (string_match (line, "^<[^>]+>$", 1))
	  {
	     stickytags_add (line);
	     numtags++;
	  }
     }
   () = fclose (fp);
   !if (numtags) return ();
   if (numtags == 1) s = "";
   vmessage ("loading %s...done (%i tag%s loaded)\n",
	     st_current_file, numtags, s);
}

Technical Details
Message-ID: <slrn6vb84t.65h.bluemoon@ux6.cso.uiuc.edu>
Path: mbox-mo1.pugleaf.net!archive.usenet.blueworldhosting.com!illumos!news.pugleaf.net!.TX!archive.pugleaf.net!archive.newsdeef.eu!mbox2nntp-news.software.readers.mbox.zip!not-for-mail

Show Full Headers
Complete Article Headers
Message-ID: <slrn6vb84t.65h.bluemoon@ux6.cso.uiuc.edu>
Subject: [slrn] StickyTags.sl macro
Date: Tue, 08 Sep 1998 00:00:00 +0000
From: bluemoon@ux6.cso.uiuc.edu (Dawn Owens-Nicholson)
Path: mbox-mo1.pugleaf.net!archive.usenet.blueworldhosting.com!illumos!news.pugleaf.net!.TX!archive.pugleaf.net!archive.newsdeef.eu!mbox2nntp-news.software.readers.mbox.zip!not-for-mail
X-Deja-AN: 389165802
Summary: A persistent "*" tags macro for slrn
Organization: University of Illinois at Urbana-Champaign
Keywords: slrn macro stickytags.sl
Newsgroups: news.software.readers