# Kon startup

First Kon checks if there is a previous instance already running. If there is, the filenames specified at startup are passed to the previous instance.

Otherwise, if this is the first instance, configuration data such as preferences, and window positions are loaded. Then the syntax definition file, kon.syn, is loaded.

Finally (before the actual files to edit are loaded), the K startup module is loaded. This is where you should place code that is run during startup, constant defintions and functions that should be available while Kon is running.

## K startup module

The startup module is named startup.k and is placed in <KON HOMEDIR>\k, where <KON HOMEDIR> is the directory where Kon is installed, such as C:\Program Files\Kon.

The function being called initially is startup(). The most important thing placed here by default is the key bindings, and the code for building the main menu.

The default startup function looks like this:

    startKon()
    {
      bindKey( "Ctrl+q-Ctrl+f", "searchDialog();" );
      bindKey( "Ctrl+q-Ctrl+a", "replaceDialog();" );
      bindKey( "F3", "repeatFind();" );
      bindKey( "Ctrl+k-Ctrl+s", "saveFile();" );
      bindKey( "F2", "saveFile();" );
      bindKey( "Ctrl+s", "saveFile();" );
      bindKey( "Ctrl+Insert", "copyBlockToClipboard();" );
      .
      . // Parts removed
      .
      bindKey( "Ctrl+Space", "savePos();" );
      bindKey( "Ctrl+Up", "jumpToPrevPos();" );
      bindKey( "Ctrl+Down", "jumpToNextPos();" );

      buildMainMenu();

      print( "*** startup script is finished" );
    }

buildMainMenu() is located in the K-file menu.k.

Startup.k includes a number of files by default:

- prefs.k: Some preferences that are automatcally saved in this file
- util.k: Useful functions such as quicksort.
- base.k: Functions which are needed for Kon to operate. Contains many of the core functions in the editor, and constant definitions.
- menu.k: Functions to build the main menu and the context sensitive popup menu.
- toolbar.k: Auto generated file containing the defintion for the toolbar. This file may be edited by hand, but changes will be lost if the toolbar is modified from within Kon while editing the file.
- signals.k: Contains callback functions for various signals from Kon. Used when items in the menu or toolbar should be disabled/enabled or checked.
- wordwrap.k: Wordwrap support.
- fillcol.k: Support for filling a column selection with a string.
modules.k: User defined modules.