Running Leo

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

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.

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 git, use your git 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.

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"))

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, you can run Leo with the console window visible by associating .leo files with python.exe not pythonw.exe.

The .leo directory

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.

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] file1, file2, ...

Options:
  -h, --help            show this help message and exit
  --debug               enable debug mode
  --diff                use Leo as an external git diff
  --fullscreen          start fullscreen
  --ipython             enable ipython support
  --gui=GUI             gui to use (qt/qttabs)
  --maximized           start maximized
  --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
  --trace-plugins       trace imports of plugins
  -v, --version         print version number and exit
  --window-size=WINDOW_SIZE
                        initial window size (height x width)

Leo’s workbook file

If you give no file arguments on the command line Leo will open ~/.leo/workbook.leo. Initially, this file contains Leo’s cheat sheet and an example from the rst3 tutorial.

Using sessions

A session specifies a list of tabs (.leo files) that Leo opens automatically when Leo first starts.

The typical usage is to start Leo with the --session-save --session-restore command-line options, open several Leo files and exit.

The next time Leo is started with those options, the files will be open, and the nodes focused as when the previous session ended.

Leo stores session state in ~/.leo/leo.session