Next Previous Contents

8. Hooks

This chapter is special. Rather than describing intrinsic functions, it gives you a list of hooks that can be used to execute arbitrary S-lang code on certain events (e.g. whenever entering article mode).

You can define code for a hook by putting it into a function that has exactly the same name as the hook. However, the preferred way to add code to a hook is now using the register_hook () intrinsic function on an arbitrary macro. This mechanism allows to connect more than one macro to a hook, which comes in handy if you want to use pre-written macro sets.

8.1 article_mode_hook

Usage

Void article_mode_hook ()

Description

This hook is called during article mode after headers have been retrieved but before sorting them. You can use this hook to set variables based on the group name.

Example

The following macro can be used to change the sorting_method to something more appropriate for newsgroups which contain encoded articles and to chose a different signature when posting to comp.*:

   define make_group_specific_settings ()
   {
     variable sorting_method = 7;
     variable signature_file = ".signature";

     if (is_substr (current_newsgroup (), "binaries")
         or is_substr (current_newsgroup (), "pictures"))
      sorting_method = 3;

     if (0 == strncmp (current_newsgroup (), "comp.", 5))
       signature_file = ".nerd-signature";

     set_integer_variable ("sorting_method", sorting_method);
     set_string_variable ("signature", signature_file);
   }
   () = register_hook ("article_mode_hook",
                       "make_group_specific_settings");

8.2 article_mode_quit_hook

Usage

Void article_mode_quit_hook ()

Description

This function is called whenever you leave article mode, including the times you switch directly to a different group (without quitting to group mode in between).

8.3 article_mode_startup_hook

Usage

Void article_mode_startup_hook ()

Description

Unlike article_mode_hook, which gets called prior to sorting the headers, this hook gets called after sorting has taken place.

8.4 cc_hook

Usage

String cc_hook (String address)

Description

This hook is called when sending a "courtesy copy" of a followup -- it gets the author's email address as an argument and is expected to leave a string on the stack which will be used as the address the CC is actually sent to. If the returned string is empty, no CC is sent.

Notes

As this hook returns a value, you cannot bind multiple macros to it.

8.5 followup_hook

Usage

Void followup_hook ()

Description

Function called when following up to an article.

8.6 forward_hook

Usage

Void forward_hook ()

Description

Function called when forwarding an article to someone.

8.7 group_mode_hook

Usage

Void group_mode_hook ()

Description

This hook will be called whenever group mode is entered. This includes the times when one exits article mode back to group mode.

8.8 group_mode_startup_hook

Usage

Void group_mode_startup_hook ()

Description

This hook is called after checking for news and immediately before entering the main keyboard loop. When called, group mode will be active.

8.9 header_number_hook

Usage

Void header_number_hook ()

Description

If defined, this function will be called after selecting a header via a header number.

8.10 make_from_string_hook

Usage

String make_from_string_hook ()

Description

This function is expected to leave a string on the stack which will be used to generate ``From'' header lines whenever one is needed.

Notes

As this hook returns a value, you cannot bind multiple macros to it.

Example

Here is a simple example:

   define make_from_string_hook ()
   {
     return "My Name <me@my.machine>";
   }

8.11 make_save_filename_hook

Usage

String make_save_filename_hook ()

Description

This function is expected to leave a string on the stack that will be used to decide what folder an article should be saved to. If the returned filename is not absolute, it is interpreted as relative to save_directory.

Notes

As this hook returns a value, you cannot bind multiple macros to it.

Example

Here is a simple example:

   define make_save_filename_hook ()
   {
     if (string_match (extract_article_header ("Subject"), "slrn", 1) != 0)
       return "slrn-related";
     else
       return current_newsgroup();
   }

8.12 post_file_hook

Usage

Void post_file_hook ()

Description

Function called after composing and filtering, but before posting article.

Example

An example of this hook is included in macros/ispell.sl in slrn's source tree.

8.13 post_filter_hook

Usage

Void post_filter_hook (String file)

Description

This hook may be called just before slrn attempts to post a file. The hook is only called if the user selects the filter option from the prompt:

     Post the message? Yes, No, Edit, poStpone, Filter
This hook takes a single parameter: the name of the file that slrn is about to post.

8.14 post_hook

Usage

Void post_hook ()

Description

Function called when posting an article.

8.15 pre_article_mode_hook

Usage

Void pre_article_mode_hook ()

Description

This hook is similar to article_mode_hook except that it is called before any headers for the group have been retrieved.

8.16 read_article_hook

Usage

Void read_article_hook ()

Description

Function called after reading and processing an article. It may use the replace_article function to change it.

8.17 reply_hook

Usage

Void reply_hook ()

Description

Function called when replying to poster.

8.18 resize_screen_hook

Usage

Void resize_screen_hook ()

Description

This hook will be called whenever the screen size changes.

8.19 startup_hook

Usage

Void startup_hook ()

Description

This hook is called right after the newsreader is initialized and immediately before checking for news. It allows the user to set variables on a server by server basis.

Example

The following example sets the `lines_per_update' variable to 20 and turns off reading of the active file if the servername is `uhog' (it is a slow server):

   define make_server_specific_settings ()
   {
     !if (strcmp (server_name (), "uhog"))
     {
        set_integer_variable ("lines_per_update", 20);
        set_integer_variable ("read_active", 0);
     }
   }
   () = register_hook ("startup_hook",
                       "make_server_specific_settings");

8.20 subject_compare_hook

Usage

Integer subject_compare_hook (String subject1, String subject2)

Description

slrn puts postings with identical subjects into the same thread. This hook can be used to override slrn's decision that two subjects are not identical: In this case, it is called with both subjects as arguments. If it returns 0, the articles are put in the same thread.

8.21 supersede_hook

Usage

Void supersede_hook ()

Description

Function called when superseding an article.


Next Previous Contents