.. @+leo-ver=5-thin
.. @+node:ekr.20131008041326.16139: * @file running.txt
.. @@language rest
.. @@tabwidth -4
.. @+all
.. @+node:ekr.20131008041326.16140: ** @rst html/running.html
##############
Running Leo
##############

.. index:: Running Leo

This chapter tells how to run Leo and discusses Leo's command-line
options.

.. contents::
    :depth: 2
    
.. @+node:ekr.20131008041326.16151: *3* Running Leo
You can run Leo from a Python interpreter as follows::

    import leo
    leo.run() # runs Leo, opening a new outline or,
    leo.run(fileName=aFileName) # runs Leo, opening the given file name.

Another way to run Leo is as follows::

    cd <path-to-launchLeo.py>
    python launchLeo.py %*

Here are some tips that may make running Leo easier:

**Linux**
    
The following shell script will allow you to open foo.leo files by typing leo foo::

    #!/bin/sh 
    python <leopath>launchLeo.py $1

where <leopath> is the path to the directory containing the leo directory. 

**Windows**

You can associate Leo with .leo files using a batch file. Put the
following .bat file in c:\\Windows::

    <path-to-python>/python <path-to-leo>/launchLeo.py %*

Here <path-to-leo> is the path to the directory *containing* the leo directory,
that is, the directory containing launchLeo.py.
.. @+node:ekr.20131008041326.16152: *4* Running Leo the first time
The first time you start Leo, a dialog will ask you for a unique identifier. If
you are using a source code control system such as bzr, use your bzr login name.
Otherwise your initials will do.

Leo stores this identifier in the file .leoID.txt. Leo attempts to create
leoID.txt in the .leo sub-directory of your home directory, then in Leo's config
directory, and finally in Leo's core directory. You can change this identifier
at any time by editing .leoID.txt.
.. @+node:ekr.20131008041326.16153: *4* Running Leo in batch mode
On startup, Leo looks for two arguments of the form::

    --script scriptFile

If found, Leo enters batch mode. In batch mode Leo does not show any windows.
Leo assumes the scriptFile contains a Python script and executes the contents of
that file using Leo's Execute Script command. By default, Leo sends all
output to the console window. Scripts in the scriptFile may disable or enable
this output by calling app.log.disable or app.log.enable

Scripts in the scriptFile may execute any of Leo's commands except the Edit Body
and Edit Headline commands. Those commands require interaction with the user.
For example, the following batch script reads a Leo file and prints all the
headlines in that file::

    path = r"<path-to-folder-containing-the-leo-folder>\\leo\\test\\test.leo"

    g.app.log.disable() # disable reading messages while opening the file
    flag,newFrame = g.openWithFileName(path,None)
    g.app.log.enable() # re-enable the log.

    for p in newFrame.c.all_positions():
        g.es(g.toEncodedString(p.h,"utf-8"))
.. @+node:ekr.20131008041326.16154: *4* Running Leo from a console window
Leo sends more detailed error messages to stderr,
the output stream that goes to the console window. In Linux and MacOS
environments, python programs normally execute with the console window visible.
On Windows, can run Leo with the console window visible by associating .leo
files with python.exe *not* pythonw.exe. 

.. For full instructions about how
.. to do this, see `Associating Leo with .leo Files`_.
.. @+node:ekr.20131008041326.16155: *4* The .leo directory
Python's HOME environment variable specifies Leo's HOME directory.
See http://docs.python.org/lib/os-procinfo.html for details.

Leo uses os.expanduser('~') to determine the HOME directory if no HOME environment variable exists.

Leo puts several files in your HOME/.leo directory:
.leoID.txt, .leoRecentFiles.txt, and myLeoSettings.leo.
.. @+node:ekr.20131008041326.16156: *3* Leo's command-line options
Leo supports the following command-line options. As usual, you can see the
list by typing the following in a console window::

    leo -h

or::

    leo --help

You will get something like the following::

    Usage: launchLeo.py [options]
    
    Options:
      -h, --help            show this help message and exit
      --fullscreen          start fullscreen (Qt only)
      --ipython             enable ipython support
      --gui=GUI             gui to use (qt/qttabs)
      --maximized           start maximized (Qt only)
      --minimized           start minimized
      --no-cache            disable reading of cached files
      --no-plugins          disable all plugins
      --no-splash           disable the splash screen
      --screen-shot=SCREENSHOT_FN
                            take a screen shot and then exit
      --script=SCRIPT       execute a script and then exit
      --script-window=SCRIPT_WINDOW
                            open a window for scripts
      --select=SELECT       headline or gnx of node to select
      --session-restore     restore previously saved session tabs at startup
      --session-save        save session tabs on exit
      --silent              disable all log messages
      -v, --version         print version number and exit
      --window-size=WINDOW_SIZE
                            initial window size in height x width format
.. @-all
.. @-leo
