随笔 - 41, 文章 - 8, 评论 - 8, 引用 - 0
数据加载中……

[Python] Leo Tutorial 翻译

The Leo Tutorial

Leo is a power tool for people who want to organize, study and work with data, especially complex data like computer programs, books, web sites and data bases. Superficially, Leo may look like other outlining programs, code folding editors or class browsers, but it most certainly is not.

Leo 是一个强大的工具,适用于下面的人:希望组织, 管理,研究和处理数据,特别是复杂的数据, 像计算机程序,书籍,网页以及数据库。 表面上看, Leo 像其他 outline 的程序, 代码折叠编辑器或类浏览器,但是事实上,它并不是。

People say Leo is a revolutionary tool, and that Leo is fun to use, even additive. There is a unique “Leo way” of managing data; the term Leonine describes how people treat data in “the world according to Leo”. Leo definitely takes a bit of work to understand. Leo’s users speak of an “Aha” moment, when they see how these pieces fit together: outline structure is significant everywhere. For a more detailed introduction to Leo, see Leo in a nutshell.

人们说 Leo 是一个革命性的工具,而且 Leo 用起来很有趣, 而且还有甚者。管理书籍有 Leo 式的方法;单词 Leonine 描述了人么如何在 Leo 的世界中管理数据。 Leo 毫无疑问需要慢慢理解。当 Leo 的用户看到了一些片段,他们会说出“Aha”: outline 结构在任何地方都很有意义。具体介绍 Leo 请参考 Leo in a nutshell

Leo is freely available in source or binary form for all major platforms. You may download Leo from http://sourceforge.net/projects/leo/files/Leo/ Leo is Open Software and may be freely distributed.

Leo 无论源代码或是二进制程序都是免费的,而且支持大多数的平台。 你可以从 http://sourceforge.net/projects/leo/files/Leo/ 下载 Leo。 Leo 是开源软件,而且可以免费发行。

Leo’s home page contains additional documentation and links to other resources. For another introduction to Leo, open the file quickstart.leo in the leo/doc folder.

Leo’s home page 包含了额外的文档和链接。 关于 Leo 另外的介绍,打开在 leo/doc 目录中的 quickstart.leo 进行查看。

This tutorial introduces the reader to the basic concepts and features of Leo. It helps to have Leo running for hands-on experience, but all examples here are self-contained, so the tutorial can be read off-line as well. See Leo’s Installation Guide. for detailed installation instructions. If you have problems installing Leo, please ask for help on Leo’s forum.

本教程将介绍 Leo 基本的概念和特性。 它帮助你快速的将 Leo 运行起来,所有的例子也是包含于安装包中, 所以你可以离线的阅读。关于安装具体请看 Leo’s Installation Guide 。 如果你在安装中碰到了困难,请在 Leo’s forum 中寻求帮助。

This tutorial does not attempt to be comprehensive and cover every single feature of Leo, or even every commonly used feature. Instead, it introduces many of Leo’s most noteworthy features, and will give you a good idea of Leo’s flavor and style. After reading it, you will be able to use Leo in basic ways to create external files, organize data and run simple scripts. You will then be ready to learn more about Leo’s many advanced features.

这篇教程并不打算很全面的涉及 Leo 的每个特性,或者甚至是最常用的特性。 相反,它仅仅介绍很多值得注意的特性,并让你对 Leo 有相应的想法,比如它的流派和风格。 在阅读完它之后,你将会用 Leo 创建外部文件,组织数据以及运行简单的脚本。 然后你就会打算学习更多关于 Leo 的高级特性。

The Glossary is also worth reading.

Glossary 也是很值得一读。

Leo’s main window

Let’s start looking at Leo in detail. We’ll start with what you see when you first open Leo, Leo’s main window. Leo’s main window, shown below, represents an entire project. As you can see, the main window contains three panes: the outline pane at the top left, the log pane at the top right, and the body pane at the bottom. The window also contains an icon area at the very top, a status area and a mini-buffer at the very bottom.

让我们更详细的看看 Leo 。我们将从你一打开 Leo 的地方开始讲解。 Leo 的主窗口。 Leo 的主窗口,像下面显示的,代表了一个完整的项目。 正如你见到的,主窗口包含了三个面板:左上方的 outline pane , 右上方的 log pane ,以及底部的 body pane 。 当然,窗口中还包含了很顶部的 icon area ,底部的 status areamini-buffer

leoMainWindow

Outline pane

The outline pane shows your project as an outline. The outline contains all your project’s data. An outline consists of nodes. The icon box is a small icon directly to the left of the headline text. The border of the icon box is black if the node has been changed. Smaller icons within the icon box indicate the status of the node:

Outline pane 将你的项目以提纲的形式显示。 outline 中包含了所有你项目的数据。一个 outline 包含 node 。 而 icon box 是一个紧挨着标题的小的图标。 如果节点中的内容有改变,那么这个的边框就变为黑色的。 而里面更小的图标指示了节点的状态:

A small blue box:   the node has body text.
A red vertical bar: the node is marked.
A circular arrow:   the node is cloned.
一个蓝色的盒子: 节点的 body 中包含了文字。
一个垂直的红棒: 节点被标记了。
一个圆形的箭头: 节点被 clone 了。

If a node contains children, a smaller icon appears to the left of the icon box. This icon contains a ‘+’ or ‘-‘ symbol. Clicking this expansion box expands or contracts the node.

如果一个节点包含了子节点,一个更小的图标将在这个的左边显示。 图标中包含了以后 ‘+’ 或 ‘-‘ 这样的符号。 点击这个符号就将这个节点展开或闭合。

Node

Each outline node has two two parts, a headline and body text. The outline pane shows headlines. Selecting a headline selects the entire node; the node’s body text appears in the body pane. Leo uses standard terminology to describe the relationships of nodes in an outline. We speak of parent nodes, child nodes, ancestor nodes and descendant nodes.

每个节点有两个部分,一个 headlinebody text 。 而 outline pane 中显示 headline 。选择一个 headline 就选择了一整个节点; 节点的 body text 部分会显示在 body pane 中。 Leo 使用标准的术语来描述节点的关系。 我们会说 parent 节点, child 节点, ancestor 节点和 descendant 节点。

Body pane

The body pane contains the body text of the node selected in the outline pane.

Body pane 包含了被选定的节点的内容。

Log pane

The log pane contains informational messages from Leo or your scripts.

Log pane 中包含从 Leo 或你的脚本中来的信息。

Icon area

Depending on what plugins are enabled, the icon area may contain buttons and other widgets that extend what Leo can do. The scripting plugin makes it easy to add buttons to the icon area.

根据插件的激活情况,此处将会包含不同的按钮和其他的部件,用于扩展 Leo 。 scripting plugin 可以很方便的将按钮放到 icon area 中。

Status area

The status area shows the line and column containing the body text’s cursor, and the UNL (Uniform Node Location), the path from the top of the outline to the selected node. This path will change as you change outline nodes.

Status area 显示光标所在行和列,以及 UNL (Uniform Node Location), 从顶层节点到当前节点的路径。这个路径将随着你的选择而改变。

Minibuffer

You can type command and search strings in the minibuffer. It works much like the Emacs mini-buffer. To enter a command, type <Alt-x> followed by the command name and then <return>. To type a search string, type <ctrl-f> followed by the search string and then <return>. For full details, see Using Leo’s Commands.

你可以在 minibuffer 中输入命令以及搜索的字符串。 这个和 Emacs 中的 mini-buffer 非常相似。 为了输入一个命令,输入 <Alt-x> 然后后面输入命令的名称, 然后输入 <return> 。为了搜索字符串,输入 <ctrl-f> 然后输入要搜索的路径并按 <return> 。 具体的请参考 Using Leo’s Commands

External files and @file nodes

Leo stores outline data on your file system in .leo files. The format of these files is XML. You don’t have to store all your data in .leo files: Leo allows you to store parts of your outline data external files, that is, other files on your file system.

Leo 将 outline 的数据 以 .leo 存在你的文件系统中。 这些文件的格式是 XML 。你不需要把你全部的数据全部存在 .leo 文件中: Leo 允许你将 outline 中的部分数据以 external file 的形式保存。

@file nodes create external files. @file nodes have headlines starting with @file followed by a file name. Some examples:

@file node 将创建外部的文件。 @file 节点的 headline 以 @file 开头, 然后跟着一个文件名。后面是一些例子:

@file leoNodes.py
@file ../../notes.text

The file name can be an absolute path or a relative path to the file that starts at Leo’s load directory, the directory containing the .leo file.

文件名可以是绝对路径或者是相对路径(以当前载入 leo 文件的路径开始)。

Leo reads and writes external files automatically when you open or save your Leo outline:

Leo 将会自动地读取和写入 external file,当你打开或保存 Leo 的 outline:

  • When you open an outline (.leo file) Leo reads all the external files created by the @file nodes in the outline. If you have changed an external file outside of Leo, Leo will update the corresponding @file tree to reflect those changes when Leo next opens the outline.

    当你打开一个 outline (.leo 文件) Leo 将会读取所有被 @file 节点创建的 external 文件。如果你在 Leo 外改变了一个 external 文件, Leo 在下一次打开 outline 时, 将会更新相应的 @file 节点。

  • When you save your outline, Leo writes all dirty @file nodes. An @file is dirty if the node or any of its descendant nodes has changed. Important: When Leo writes an external file, Leo writes all the essential information in the @file tree to the external file, not to the .leo file. The only nodes that gets written to the .leo file are nodes that are not contained in any @file tree.

    当你保存 outline 时, Leo 会写入所有的 dirty @file 节点。 当一个节点或任何相应的子节点改变时,这个 @file 就是 dirty 的。 重要 :当 Leo 写一个 exteranl 文件, Leo 会写入所有重要的信息, 尤其是 @file 树中的信息到外部文件中,而 不是 到 .leo 文件中。 只有那些不包含 @file 的节点才被写入到 .leo 中。

Creating external files from outlines

We come now to one of Leo’s most important and unusual features. When Leo writes an external file, it does so in a flexible manner, directed by outline-based markup. This markup tells Leo exactly how to create the external file from an @file node.

我们现在来见见 Leo 中很重要而不寻常的特性。 当 Leo 向一个 external 的文件写入东西时, Leo 会通过 outline-based markup 的指令, 进行合适配置。这个标记会准确的告诉 Leo 如果从一个 @file 节点创建 external 文件。

The obvious way to write an external file would be to write the @file node itself followed by all the descendant nodes in outline order (the order in which nodes appear in the outline). But Leo does not write external files exactly this way.

最明显的方式,就是根据子节点的 outline 顺序 对 @file 节点进行写入。但是 Leo 并不是完全按照这种方式进行。

Yes, Leo does indeed start by writing the @file node itself. But Leo writes the @file node’s descendants only when it sees one of three kinds of Leo markup: section references, the @others directive and the @all directive. We’ll discuss these three kinds of markup in the next section.

是的, Leo 的确从写入 @file 节点开始。但是对于 Leo , 只有它见到了相应的指令,才会将 @file 节点的子节点的内容写入。 有三个这样的指令: section reference@other 指令 , 以及 @all 指令 。我们将在后面对这些标记进行讨论。

Section references and the @others and @all directives tell Leo to write the expansion of one or more descendant nodes to the external file. Programmers will recognize this process as akin to macro expansion. The following sections will explain this process in detail.

Section reference , @others 和 @all 指令告诉 Leo 将子节点 扩展 到 external 文件中。 程序员会知道这个宏扩展很像。下面的篇幅就将讨论这些。

Section references

A section reference is a line of body text of the form:

一个 section reference 就是在 body text 中有下列形式:

<< a section name >>

Here, “a section name” can be any descriptive text not containing “>>”. When Leo encounters a section reference, Leo searches all the descendants of the node containing the reference looking for a node whose headline matches the section reference. That is, Leo looks for a descendant node whose headline starts with:

此处, "a section name" 可以是任何文字,但不包括 “>>” 。 当 Leo 碰到一个 section reference , Leo 会搜索所有的子节点, 然后去匹配在 headline 中有相同内容的引用。 也就是, Leo 会搜索下面的 headline :

<< a section name >>

We call such nodes named nodes. Leo doesn’t require an exact match. Leo ignores whitespace and the case of letters when comparing headlines to section reference. Also, Leo ignores anything that may follow the section name in a named node. For example, the following headline will match the section reference above:

我们称这些节点为 named node 。Leo 不需要完全的匹配。 它会忽略空格和大小写。同样, Leo 会忽略在此之后的内容。 比如,下面的 headline 也是可以被匹配的:

<< A Section Name >> (to do)

If Leo does find a match, Leo replaces the section reference (“<< a section name>>”) by the expansion of the body text of the matched node. That is, Leo replaces the section reference by the body text of the matched node, but Leo expands all markup in the matched node before making the replacement. The entire expansion of the matched node replaces the original section reference. Programmers will recognize this process as recursive macro expansion.

如果 Leo 的确找到了一个匹配,Leo 会 替换 这个 section reference (”<< a section name>>”),并把 named node 的内容扩展进来。 也就是, Leo 会把匹配的节点的 body text 替换到这里, 但是 Leo 在进行替换前,会先对所有的标记进行扩展。 这样,原始的 section reference 就被真正的内容替换了。 程序员就会想到这就是递归的宏扩展。

We have just discussed what happens if Leo does find a descendant named node that matches the section reference. If no such match is found the section reference is said to be undefined and Leo does not write any data to the external file. This is not a serious error: Leo will will save the erroneous @<file> tree in the .leo file instead of the external file. No information is lost. By the way, Leo’s syntax coloring will indicate undefined section reference by underlining the section name.

我们刚讨论了如果 Leo 发现一个子的 named node 之后会发生的事情。 如果没有找到这样的,那么这个 section reference 就被认为是 undefined 而且 Leo 也不会向 external 文件中写入任何东西。 这不是一个很严重的错误: Leo 会把这些写入到 .leo 文件中, 而不是 external 文件中。没有任何信息会被丢掉。 顺便说下, Leo 的语法加色会指示这个是未定义的引用, 通过加一个下划线。

Important: the indentation of section references matters. When expanding a section reference, Leo indents every line of the expansion by the leading whitespace that occurs before the section reference. Note also that you can’t write something after a section reference and expect it to end up on the same line after expansion–Leo always writes a newline after the expansion.

重要 :section reference 的缩进是有意义的。 当进行扩展时,被扩充的内容前面都会加入空格。 而且注意,你不能往 section reference 后写入东西并指望这些会出现在每行的末尾。 Leo 在扩展后总会插入一个新行。

The @others directive

The @others directive is the second (and most common) way of including descendant nodes in an external files. When Leo encounters the @others directive it replaces the @others directive by the expansion of all unnamed descendant nodes. As with section references, Leo replaces all markup in the descendant nodes, and the entire expansion replaces the @others directive.

@others directive 是第二个(而且是最常用的)方式, 对子节点进行包含。当 Leo 碰到 @others 指令时, 它会把所有 unamed 的子节点都包含进来。 和 section reference 一样, Leo 会替换所有的标记, 然后扩展完后的才会去替换 @others 指令。

In short, section references write named nodes; @others directives write all unnamed nodes. By the way, no node may contain more than one @others directive because there would be no way to “apportion” descendant nodes to more than one @others directive. However, nodes may contain as many section references as you like.

简而言之, section reference 会写入 named 节点; 而 @others 指令则会写入 unnamed 节点。 顺便说下,没有节点可以包含超过一个的 @others 指令。 因为没法将这些子节点分配给多个 @others 指令。 但是,节点中可以包含很多的 section reference 。

As with section references, the indentation of the @others directive matters. This allows Leo to handle Python source code properly. For example, the following is a common way of representing a Python class:

和 section reference 一样, @others 指令的缩进也是有意义的。 这就允许 Leo 可以正确的处理 Python 的源代码。 比如,下面一个是表示 Python 类最常用的方式:

class myClass:
    '''a docstring'''
    @others

When Leo writes this node to an external file, Leo will write the first two lines to the external file, with the indentation in effect for the node. Leo will then write all descendant nodes to the external files, with additional indentation equal to the leading whitespace appearing before the @others directive.

当 Leo 把这个节点写入一个 external 文件时, Leo 会把头两行先写入 external 文件,而且缩进也会影响节点。 Leo 然后就把所有的子节点写入,然后会在替换出的内容前再加上额外的空白。

The @all directive

The @all directive is the third, simplest (and least common) way of including descendant nodes. This directive causes Leo to write all descendant nodes in outline order, regardless of whether they are named or not. Furthermore, the @all directive does not expand any markup in descendant nodes. This results in Leo writing the external file in the “obvious” way. That is, Leo writes all descendant nodes in outline order.

而 @all 指令是第三个,最简单(最不常用)的方式来包含子节点。 这个指令会让 Leo 以 outline 的顺序写入所有的子节点,而不管节点是否命名。 此外, @all 指令不会对子节点中的任何标记进行扩展。 这个就使得 Leo 以最直接的方式写入 external 文件。 Leo 会以 outline 的顺序写入所有的子节点。

Use the all directive if your external file contains unrelated nodes. For example, I use an external file to store programming notes. These notes typically contain snippets of programming source code, but there is no real relationships between the snippets–the file is simply a grab bag of information. The @all directive is designed for this situation.

如果你的 external 文件包含了无关的节点,那么可以用这个指令。 比如,我用一个 external 文件保存编程的笔记。 这些笔记包含了代码中的一些片段,而在这些片段之间并无联系。 这些文件仅仅就是存放信息的袋子而已。 @all 指令就是为这种情况设计的。

Choosing between @others and sections

Newcomers to Leo frequently ask when to use the @others directive and when to use sections. It is good style to use section references only when the order of text within a external file matters. For example, Python programmers put docstrings and imports at the start of files. So the body text of @file nodes typically look something like this:

Leo 的新手经常会问到,什么时候使用 @others 指令而什么时候用 section 。 在涉及内容的顺序时,使用 section reference 是比较好的。 比如, Python 程序员一般会把 docstring 和 模块导入放在 文件的开头。 所以, @file 节点中的 body text 经常看起来像这样:

<< docstring >>
\@language python
\@tabwidth -4
<< imports >>
@others

This ensures that the docstring is first in the file, followed by imports, followed by everything else. Note that the order in which functions are defined in a file, or methods defined within a class, typically does not matter. Thus, it is good style to define classes like this:

这就保证了 docstring 是在文件的最开始,然后再是模块导入, 而后又是其他任何东西。注意,在文件中函数的定义, 方法在类体内的定义的顺序是无关的。因此, 下面的定义类的方式是比较好的习惯:

class myClass:
      << class attributes >>
      @others

It would be bad style to define a class like this:

而下面的则不是很好:

class myClass:
      << class attributes >>
      << method 1 >>
      << method 2 >>
      ...

Not only does this over-specify the order in which methods are defined, but it requires lots of extra typing. Not only must you add a line for each method, but headlines must contain section names such as << method 1 >>, <<method 2>>, etc. When using @others it is good style simply to put the name of each method in the headline.

不仅仅因为这过分特化了方法在类中的顺序,而且这也需要大量额外的输入。 你不仅需要为每个方法添加这样的一行,而且在 headline 中也需要包含像 << method 1 >> , << method 2 >> 这样的东西。 而使用 @others 就大大简化了要把方法放在 headline 中这样的事情。

Organizing programs as outlines

A few more words about style:

更多关于风格:

  • It is good style to put each class, function or method in its own node. This makes it easy to see the shape of your code.

    最好把每个类,函数或方法放在自己的节点中。这样就利于看清楚你代码的结构。

  • It is good style to use organizer nodes to group related functions or methods. An organizer node has no content except maybe for comments. Like this:

    把相关的函数或方法分组也是很好的习惯。 一个所谓的 organizer 节点除了用于注释,就可以没有其他用处了。 像这样:

    + myClass
        + birth and death
            + __init__
            etc.
        + getters
            etc.
        + setters
            etc.
        + misc methods
            etc.

    (In this notation, ‘+’ denotes a headline.) This organization is far superior to using hideous comments like:

    (在这个记法中, ‘+’ 表示一个 headline 。) 这样的组织比那种隐式的注释要好很多:

    ###########
    # Getters #
    ###########
    
  • It is bad style to use @others in organizer nodes. There is no need to do so.

    用 @others 当为组织节点并不好。没有必要那么做。

  • It is bad style to use @others when order does matter. The reason is that it is very easy to move nodes in a tree by mistake, say by alphabetizing nodes. One wants to make the meaning of a external file immune from such movements.

    当顺序是有意义的时候,最好不要使用 @others 。 原因是在一棵树中很容易误动节点,比如按字母顺序对节点排序。 我们希望这样的移动对文件没有任何影响。

One last word about style. The world won’t end if you happen to use bad style by mistake: you just might cause a bit more work for yourself than was strictly necessary. Feel free to invent your own style of using Leo. Still, it would be wise to “know the rules before you break them.”

最后再说一点。你由于无意使用了不好的风格,也不会怎样: 你可能仅仅为自己带来了一点小麻烦。 在使用 Leo 的过程中你可以创造自己的风格。 但是“在打破规则前了解它们”还是比较明智的。

Clones & views

A clone is a node that appears in more than one place in a Leo outline. Clones are marked with a small red arrow in the icon box. All clones of a node are actually the same node, so any change to one clone affects all clones. For example, inserting, moving or deleting any child of a clone will change all other clones on the screen.

克隆(clone) 是在 Leo 的 outline 中,不止在一个地方出现的节点。 在 icon box 中,以一个红色的箭头标记克隆。 一个节点的所有 clone 事实上是 相同的节点 , 所以对任何一个克隆的改变都会影响所有的克隆。 比如,插入,移动或删除任何克隆的子节点都会导致所有其他克隆的改变。

Please take a few moments to experiment with clones. Create a node whose headline is A. Clone node A using the Clone Node command in Leo’s Outline menu. Type some text into the body of either clone of A. The same text appears in the bodies of all other clones of A. Now insert a node, say B, as a child of any of the A nodes. All the A nodes now have a B child. See what happens if you clone B. See what happens if you insert, delete or move nodes that are children of A. Verify that when you delete the penultimate clone, the last clone becomes a regular node again.

请最好花一点时间试试克隆。 创建一个节点,称其 headline 是 A 。 然后再使用 Leo outline 菜单中的克隆命令对节点 A 进行克隆。 然后再往 A 的任何克隆的 body 中输入一些文字。 这样其他克隆中也就会出现相应的文字。 现在,插入一个节点,称为 B ,作为 A 的子节点。 这样,所有 A 节点就会有 B 这样的子节点。 现在,再看看如果克隆了 B 有什么后果。 看看如果你插入,删除或移动 A 的子节点会发生什么。 核实下当你删除倒数第二个克隆后,最后一个克隆是不是又变回一个正常的节点了。

Clones are much more than a cute feature. Clones allow multiple views of data to exist within a single outline. With Leo, there is no such thing as a single, “correct” view of data. You can have as many views of data as you like.

克隆不止是一个非常好的特性。 克隆允许对数据进行多种视图。 在 Leo 中,没有所谓 “正确的”视图方式。 你可以任由你的喜欢对数据进行视图。

To create a new view of the data in your outline, just do the following:

要创建一个新的视图方式,只要按下面做就可以了:

  1. Create an ordinary node, that will represent the view. We call these nodes view nodes merely to indicate they represent a view.

    创建一个 正常的 节点,用于代表视图(view)。 我们称这些节点为 view node 仅仅是代表一个视图。

  2. Clone all the nodes from the outline that you want the view to contain. Move these clones so they become children of the view node.

    克隆所有你所需要的节点。然后把它们移到 view node 中。

  3. (Optional) You can add regular nodes as children of the view node too.

    (可选的)你可以增加一个正常的节点作为 view node 的子节点。

For example, when I fix a bug in Leo, I create an ordinary node to represent the bug. This bug node is my view of all the data in Leo’s source code that relates to the bug. As I discover code related to the bug, I clone their nodes and move them under the bug node. I’ll also add ordinary nodes as children of the bug node. These nodes contain the original bug report, descriptions of how I fixed the bug, test data, or any other notes I might want to keep.

比如,当我修复了 Leo 中的一个bug时,我会创建一个正常的节点用于表示bug。 这个 bug node 就是用于 bug 相关的视图。 如果我发现与此 bug 相关的代码,我会把这段代码进行克隆,然后移到 bug 节点下。 我也会增加普通的节点作为 bug node 的子节点。 这些节点包含了原始的 bug 报告,我如何修复了这个bug, 测试的数据,或者其他我保留的节点。

Once I have created the bug node, I concentrate only on that node and its children. I can examine the bug node and its children without having to jump around the outline. Everything I need is in one place. When I get around to actually fixing the bug I can do so by changing the clones. Again, I do not have to jump around the outline. It doesn’t matter how big or complex the entire outline is: I am only dealing with the bug node and its children. This extremely narrow focus makes it much easier to fix bugs.

一旦我创建了一个 bug 节点,我主需要关注那个节点和它的子节点。 我可以检验那个 bug 节点及子节点而无须在 outline 跳转。 所有我需要做的,就是在一个地方。当我有时间修复了 bug , 我只需要修改 clone 。再次的,我也无须跳转。 整个 outline 有多大或多复杂都无所谓: 我仅仅需要处理 bug 节点及其子节点即可。 把问题集中在一点就使得修复 bug 变得比较简单。

By the way, I never have to remember to save external files. When I change any clone, Leo marks all instances of that clone throughout the entire outline as dirty (changed). When I save the Leo outline, Leo automatically writes all the external files that contain dirty nodes.

顺便说下,我从来不需要记得保存 external 文件。 当我改变了任何一个克隆,Leo 就会标记所有克隆的实例, 整个 outline 被认为是 dirty (改变了)。 当我保存 Leo 的 outline,Leo 自动的会写入包含 dirty 节点的 external 文件。

Views have an unlimited number of uses. Use them whenever you want to focus your attention on some smaller set of nodes. For example, I often create view nodes when studying other people’s code. The view node helps me concentrate on just the part of the code that interests me at the moment.

视图的使用没有限制。在你想集中于一些更小的节点集合时就使用它们。 比如,我在研究别人的代码时,我就会创建视图节点。 这些视图节点帮助我集中于某一段我感兴趣的代码。

More about directives

Leo’s directives control such things as syntax coloring, line wrapping within the body pane and the width of tabs. Leo directives may appear in headlines or body text. Leo directives start with ‘@’, followed by the name of the directive.

Leo 的 指令(directive) 控制着一些这样的事情,如语法加亮, 在 body 面板中行的包装和 tab 的宽度。Leo的指令可以出现于 headline 或 body 文字中。 Leo的指令以 '@' 开始,而后跟着指令的名字。

Note: Leo handles Python decorators properly, providing they don’t conflict with Leo’s directives.

注意 :Leo可以正确的处理 Python 的装饰器(decorator), 而不会使得与 Leo 的指令相冲突。

Here are some of Leo’s directives:

这里是一些 Leo 的指令:

@language python
@tabwidth -4
@wrap
@nowrap
@color
@nocolor
@killcolor

Most directives must start with the ‘@’ in the leftmost column, but whitespace may appear before the '@others‘ and '@all‘ directives. As we have seen, such whitespace is significant.

大多数的指令必需在最左边的列上以 '@' 开头, 但是在 '@others''@all' 前可以出现空白。 正如我们所见,这些空白是有意义的。

Directives apply until overridden in a subtree. All of these directives apply to the node they are contained in, and also to the entire tree of descendant nodes, unless over-ridden by a similar directive in a descendant node. For example, the directive:

指令在子树中都会生效直至遇到覆写。 所有的这些指令在包含它们的节点中都会生效,以及相应的子节点, 除非是在子节点有相同的指令对此进行覆写。 比如,这个指令:

@language python

tells Leo to syntax color the node and all descendant nodes as Python code. However, some descendant node might contain:

告诉 Leo 以 Python 的语法加亮这个节点及所有派生节点。 但是有些派生的节点可以包含:

@language rest

which tells Leo to color that node and all of its descendants as reStructureText. This principle applies to almost all of Leo’s directives: the directive is in effect throughout a tree, unless overridden in some subtree.

这个就告诉 Leo 以 reStructureText 对这个节点及派生节点进行高亮。 这个原则对几乎所有的 Leo 指令都适用: 指令在整棵树中都有效果,除非在一些子树中被覆写。

@color, @nocolor and @killcolor

These directives control how Leo colors body text. You can mix @nocolor and @color directives in a single node. This directives affect descendant nodes unless a node contains both @color and @color. Such ambiguous nodes do not affect the coloring of descendant nodes.

这些指令控制这 Leo 如何对 body 中的文字进行加亮。 可以在一个节点中混合使用 @nocolor 和 @color 指令。 这些指令会影响派生的节点除非一个节点中同时包含 @nocolor 和 @color 指令。这样不确定的节点的子节点就不会受到影响。

@first

This directive forces a lines to appear before the first sentinel of a external file. Here is a common way to start a Python file:

这个指令强行让一行按顺序出现于一个 external 文件中。 此处在 Python 文件中是最常见的:

@first #! /usr/bin/env python @first # -- coding: utf-8 --

@language

Sets the language in effect for a tree. This affects how Leo colors body text. It also sets the comment delimiters used in external files. Leo supports dozens of languages. See Leo’s reference for a complete list. Here are a few:

设置相应的语言。这就影响 Leo 对 body 文字的加亮方式。 这也设置了在 external 文件中注释所用的分界符。 Leo 支持挺多语言的。参考 Leo’s reference 。 此处是一些:

@language python
@language c
@language rest # restructured text
@language plain # plain text: no syntax coloring.

@pagewidth <n>

Sets the page width used to format break doc:

设置格式化文档时所用的页宽:

@pagewidth 100

@path <path>

This directive is a convenience. Rather than specifying long paths in @file nodes, you can specify a path in an ancestor @path node. For example, suppose three nodes have the following headlines:

这个指令很方便。不需要在 @file 中指明很长的路径, 你可以在一个父节点中指定 @path 节点。 比如,假设有下面三个节点:

@path a
    @path b
        @file c/d.py

Because of the ancestor @path nodes, the @file node creates the file a/b/c/d.py

因为父节点的 @path ,@file 节点创建的文件会是 a/b/c/d.py

Within @path and @<file> paths, {{exp}} gets evaluated with the following symbols known: c, g, p, os and sys. For example:

在 @path 和 @<file> 的路径中, {{exp}} 会执行下面已知的符号: c,g,p,os和sys。比如:

@file {{os.path.abspath(os.curdir)}}/abc.py

refers to the file abc.py in (absolute path of) the current directory.

就会指向当当前目录下的 abc.py 文件。

@tabwidth

Sets the width of tabs. Negative tab widths cause Leo to convert tabs to spaces and are highly recommended for Python programming.

设置 tab 的宽度。负的宽度就表示将 tab 转换为空格,并且这是 Python 编程建议的。

@wrap and @nowrap.

These enable or disable line wrapping the Leo’s body pane.

这个开启或关闭行包装。

Scripting, extending and customizing Leo

Leo is fully scriptable using the Python language. Leo can execute any body text as a Python script. To run the entire body text as a script, simply choose the node and execute the Execute Script command (Ctrl+B). If text is selected, the Execute Script command will run just the selected text as the script.

Leo 可以使用 Python 进行脚本编程。 Leo 可以将任意的 body 文字作为 Python 脚本执行。 为了将一整段作为脚本执行,只要选中相应的节点, 然后执行执行脚本的命令(Ctrl+B)。 如果有文字被选中,那么就会只执行选中的部分。

The Execute Script command preprocesses the script before executing it, in exactly the same way that Leo writes external files. Leo expands section references and processes @others directives before executing the script. This allows you to use all of Leo’s outlining capabilities to organize your scripts.

执行脚本命令在执行它之前将预处理这个脚本, 这和 Leo 写入 external 文件是一样的。 在执行这个脚本前, Leo 将会扩展 section reference 和处理 @others 指令。 这个就允许你使用 Leo 的 outline 来组织你的脚本。

Your Python scripts can easily access data in an outline. Leo’s execute-script (Ctrl-B) command predefines three variables, c, g and p, that scripts can use to easily access any part of any Leo outline, and Leo’s own source code. For example, the following script will print all the headlines in an outline:

你的 Python 脚本可以很容易访问在 outline 中的数据。 Leo 的执行脚本(Ctrl-B)命令预定义了三个变量,c,g和p, 这样脚本可以访问 Leo 的 outline 的任意部分, 以及 Leo 自身的代码。 举个例子,下面的脚本将会打印所有的 headline:

for p in c.all_positions():
    print ' '*p.level(),p.h

The example above is only the beginning of what scripts can do. See Scripting Leo with Python for a complete discussion of scripting Leo.

上面的例子仅仅是脚本可以做什么的开端。 参考 Scripting Leo with Python 有更详细的讨论。

Plugins are Python modules that change how Leo works. Leo’s user have contributed dozens of plugins that have extended Leo’s capabilities in many new directions. The file leoPlugins.leo contains all plugins that are included in Leo distributions.

Plugin 是 Python 的模块用于改变 Leo 运行的方式。 Leo 的用户贡献了大量的插件用于扩展 Leo 在各方面的能力。 文件 leoPlugin.leo 包含了 Leo 发行版中所有的插件。

Plugins and other parts of Leo can get options from @settings trees. @settings trees allow plugins to get options without any further support from Leo’s core code. For a full discussion of @settings trees, see Customizing Leo.

插件和其他部分可以从 @settings 树中获取选项。 @settings 树允许插件获取选项而无须 Leo 核心代码的支持。 关于此的更多讨论,参考 Customizing Leo

Summary

Using Leo quickly becomes second nature:

使用 Leo 迅速变为第二种特性:

  • You can use Leo like any ordinary outliner, as a filing cabinet, but Leo’s clones makes this filing cabinet much more flexible and useful than usual.

    你可以像任何普通的 outline 软件一样使用 Leo, 像一个文件柜,但是 Leo 的克隆使得这个文件柜更灵活实用。

  • You create external files using @file trees. Within @file trees, you use section references and the @others directive to tell Leo how to write nodes to the external file. Directives such as @tabwidth and @language provide other information to Leo. Leo’s @file trees allow you to organize your scripts and programs with Leo’s outline structure.

    你可以使用 @file 创建 external 文件。 有了 @file 树,你可以用 section reference 以及 @others 指令告诉 Leo 如何把节点写入 Leo。 Leo 的 @file 使得你可以用 Leo 的 outline 组织你的脚本和程序。

  • You can execute Python scripts from any node in a Leo outline. Leo scripts have full, easy, access to all the information in the outline. Using scripts and plugins, you can easily add new features to Leo.

    在一个 Leo 的 outline 中,你可以从任何一个节点中运行 Python 脚本。 Leo 脚本可以访问 outline 中的所有信息。 使用脚本和插件,你可以轻松增加新的特性。

Further study

LeoPyRef.leo (in the core subdirectory of the leo folder) contains almost all of Leo’s source code. It provides hundreds of examples of everything discussed here. This file will repay close study. For full details on all aspects of Leo see LeoDocs.leo.

LeoPyRef.leo(在leo目录的core目录下)包含了几乎所有的 Leo 源代码。 它提供了这里讨论过的很多的例子。 这个文件值得深入学习。关于 Leo 各方面的详情参考 LeoDocs.leo。

posted on 2012-02-03 12:50 mirguest 阅读(1529) 评论(0)  编辑 收藏 引用 所属分类: Python


只有注册用户登录后才能发表评论。
网站导航: 博客园   IT新闻   BlogJava   知识库   博问   管理