Hooks

A hook is a user defined function that jed calls under certain conditions which allow the user to modify default actions. For example, when jed starts up it looks for the existence of a user defined function command_line_hook. If this function exists, jed calls the function. What the function does is completely arbitrary and is left to the discretion of the user. The startup file, site.sl, defines such a function which reads in the files listed on the command line. It is also this function which loads the jed.rc startup file. Unlike the other hooks, this one must be present in the file site.sl since it is the only file loaded before calling the hook.

After the startup files are loaded, jed calls the hook jed_startup_hook immediately before entering the main editor loop. This hook is useful to modify certain data structures which may not have existed when the startup files were loaded.

In addition to the above hooks, jed currently also looks for:

suspend_hook
function to be executed before suspending

resume_hook
function that gets carried out after suspension

exit_hook
gets executed before exiting jed

mode_hook
sets buffer mode based on filename extension

find_file_hook
called before file is read into a buffer. It currently checks for presence of autosave file and warns user if it is more recent than file.

See site.sl for explicit examples of the above hooks.

Another useful hook is is_paragraph_separator. This hook is called when jed searches for the beginning or end of a paragraph. This search is performed by all paragraph formatting functions as well as the forward and backward paragraph movement commands. As jed performs the search, it moves from one line to another testing the line to see if it separates a paragraph. The function of the hook is to make this decision and return zero if the line does not separate paragraphs or return one if it does. The default value of this hook may be written in S-Lang as

     define is_paragraph_separator ()
     {
       bol ();
       if (looking_at ("\\")) return 1;
       if (looking_at ("%")) return 1;
       skip_white(); eolp ();
     }

A related hook called after a paragraph is formatted is format_paragraph_hook. This hook is only called if either format_paragraph or narrow_paragraph is called with a prefix digit argument. For example, format_paragraph is bound to ESC Q. Simply pressing this key sequence will call format_paragraph but format_paragraph_hook will not be called. However, pressing ESC 1 followed by ESC Q will result in a call to format_paragraph_hook. Currently, this hook simply justifies the paragraph. That is, it fills each line in the paragraph such that the line ends at the right margin, which is defined by the WRAP variable.