当前位置: 代码迷 >> 综合 >> Emacs 编辑环境,第 5 部分: 确定您的 Emacs 视图的形状
  详细解决方案

Emacs 编辑环境,第 5 部分: 确定您的 Emacs 视图的形状

热度:54   发布时间:2023-12-08 03:32:15.0

1.

 

这篇中级水平的实践教程构建于您在本系列文章前面部分中所学习的知识的基础之上,并向您介绍了如何针对您的特定需求自定义和使用该系统。

在本教程中,您将了解如何管理和操作您的 Emacs 会话视口,即 Emacs X 客户端主窗口和其中显示缓冲区以及其他信息的空间。您将了解对这个区域进行分区的最好方法,包括通过使用水平的和垂直的分割来划分屏幕,为一个 Emacs 会话创建多个 X 客户端窗口,并在每个窗口中显示多个缓冲区。您还将研究如何使用鼠标对这些区域进行操作。

本教程演示了如何在 Emacs 中对您的视图进行操作:如何对一个 Emacs 窗口进行分区和划分,以及如何使得多个 Emacs 窗口附加到一个 Emacs 会话。

在完成本教程的学习之后,您将了解如何操作框架和它们所包含的窗口,包括使用一些鼠标技术来完成这项任务。

在开始学习本教程之前,您应该先完成本系列文章中前几部分教程的学习。它们为 Emacs 的学习打下了坚实的基础,并说明了您在本教程中将要使用到的许多 Emacs 概念(请参见参考资料)。

在本系列文章第一个教程(Emacs 编辑环境,第 1 部分:学习 Emacs 的基础知识,请参见参考资料)的介绍部分中,描述了用于表示键盘输入的特殊 Emacs 符号,在本教程和整个系列文章之中都将使用到这些特殊的符号。

尽管本教程面向所有不同级别的 UNIX 专业技术人员,但如果您至少对 UNIX 文件系统具有基本的了解,那么这将是很有帮助的:

  • 文件
  • 目录
  • 权限
  • 文件系统层次结构

本教程需要您在基于 UNIX 的系统中有一个用户帐户,且此系统中安装有最新版本的 Emacs。

Emacs 有几个版本;最原始,也是最流行的是 GNU Emacs,它是由 GNU 工程在线发布的(请参阅参考资料)。

您必须拥有较新版本的 GNU Emacs,即版本 20 或更高版本。版本 20 和 21 是最常见的,您也可以获得版本 22 的开发快照。本教程可与这些版本的 Emacs 中的任何一种配合使用。如果您的系统运行的是较早的版本,您应该进行升级。

为了了解您运行的是什么版本的 Emacs,请使用 GNU 风格的 --version 标志:

$ emacs --version
GNU Emacs 22.0.91.1
Copyright (C) 2006 Free Software Foundation, Inc.
GNU Emacs comes with ABSOLUTELY NO WARRANTY.
You may redistribute copies of Emacs
under the terms of the GNU General Public License.
For more information about these matters, see the file named COPYING.
$ 

 

因为本教程专门研究对 X 窗口系统环境中 Emacs 图形元素的操作,所以您应该拥有一台正常运行的 X 服务器。

本教程使用了一个由两个文件组成的示例数据集,并在一个存档文件中提供了该数据集(请参见下载部分以获取相应的链接)。

 

2.

 

对您的 Emacs 会话进行划分和分区

您可以使用许多命令来控制 Emacs 窗口,它是您所看到的、以 Emacs X 客户端窗口为框架的一个缓冲区的视图,这个 X 客户端窗口中包含该缓冲区本身及其模式行(在它的下方)。这些命令通过各种方式对您的窗口进行分区,以允许您同时查看多个缓冲区。实际上,这些都是用于 Emacs 客户端窗口操作的所有命令中最常用的一些命令。

本教程中的示例使用了一个示例数据集,并在一个压缩的存档文件中提供了该数据集(请参见下载部分)。这个存档文件中包含一个 tar 存档文件,而 tar 存档文件包含了两个纯文本文件 innocence 和 experience,它们的内容分别是 William Blake 的 The Songs of Innocence 和 The Songs of Experience 的完整文本,其中您将看到来自以前的教程的一些文本。要开始学习本教程,首先将这两个文件解压缩到您自己的示例目录中。

对 Emacs 窗口进行分区的最常见的方式可能是从屏幕的中间将其分为两半。这一操作将生成两个新的窗口,其中每个窗口都具有它自己的模式行,并且每个窗口的高度都大约为原始高度的一半。您以水平方向对 Emacs 屏幕进行了切分,所以这两个新的窗口在一个垂直的列中相互堆叠;因而,我们称这种窗口操作为垂直 划分。

要进行这样的划分,可以运行 split-window-vertically 功能,它与 C-x 2 按键进行了绑定。

尝试使用示例文件进行这一操作:

  1. 通过在包含这两个示例文件副本的目录中键入 emacs,启动 Emacs。

  2. 打开这些文件:

    C-x C-f innocence Enter C-x C-f experience Enter

  3. 对窗口进行划分:

    C-x 2

  4. 请注意,在对窗口进行划分时,活动的缓冲区(名为 experience,是您最后打开的一个缓冲区)将出现在这两个窗口中。在顶部窗口中的缓冲区现在是活动缓冲区,并包含一个活动光标。在这个顶部窗口中切换到 innocence 缓冲区:

    C-x b Enter

您的 Emacs 会话应该与图 1 中所示类似。



 

顺便提一下,当您使用两个文件作为参数启动 Emacs 时,将得到相同的两个垂直划分的缓冲区,这是由 Emacs 自动划分的,正如本系列文章第 4 部分教程“Emacs 选项、寄存器和书签”中所描述的。键入 C-x C-c 以退出 Emacs,然后针对示例文件尝试这一操作:

$ emacs innocence experience

 

请注意其中的一处区别:当您将两个文件指定作为命令行参数时,底部的窗口(其内容为第二个参数)将成为活动窗口。

您并不仅限于同时使用两个窗口,Emacs 可以根据屏幕的大小显示许多窗口。但请记住,当您进行一次划分时,Emacs 将对当前窗口进行划分,而不会涉及到所有其他窗口。

例如,在这两个窗口中,底部的窗口现在是活动的;键入 C-x 2,以便仅划分下面的这个窗口。

现在,将您的 Emacs 屏幕划分为了三个窗口,并且中间的窗口是活动的。键入 C-x 2,以便再次划分中间的窗口,在 Emacs 屏幕中一共生成了四个窗口,然后再次键入 C-x 2,以尝试对第二个、很小的那个窗口进行划分。根据 Emacs X 客户端主窗口的尺寸,对分割的窗口所进行的这种递归划分迟早将会中止,即当任何新的窗口太小,以至于不能够显示至少两行文本和模式行时;这时候,Emacs 将发出蜂鸣声,并在迷你缓冲区中报告,无法再继续对给定的窗口进行划分。您的会话应该与图 2 中所示类似。



 

您可以使用这些划分的窗口同时查看多个缓冲区,但是它同样有助于在多个窗口中查看相同的缓冲区,更确切的说,在不同的窗口中查看缓冲区的不同部分。在您查看缓冲区中另一个部分的同时,对缓冲区中的某个部分进行编辑,这是强大的编辑功能中最有用的技巧之一。它是非常有用的。

现在,请尝试下面的操作:

  1. 通过键入 C-x C-c 退出 Emacs,然后使用一个文件启动它:

    $ emacs experience
    
  2. 键入 M->,以移动到缓冲区的末尾。

  3. 键入 C-x 2 以垂直地划分窗口,并且这两个窗口中显示了相同的缓冲区。

  4. 移动到活动窗口中的缓冲区的顶部:键入 M-<

  5. 使用向下箭头键,将光标向下移动几十行。当该缓冲区出现在顶部的窗口中时,您可以在其中进行移动,但是 Emacs 总是在底部的窗口中显示相同的缓冲区的尾部。

当您在划分一个窗口时,Emacs 将自动地决定划分的尺寸,它通常从中间将缓冲区划分为两半,所以垂直划分所创建的两个新的缓冲区,其中每一个都恰好是原始窗口大小的一半。但是您也可以使用行数来指定其大小,即通过在划分命令之前使用一个数字,指定垂直划分的顶部窗口应该具有的行数(包括它的模式行)。

尝试将该缓冲区一分为二,并使顶部的缓冲区为九行内容的高度:

  1. 通过键入 C-x C-c 退出 Emacs,然后使用一个文件启动它:

    $ emacs experience
    
  2. 键入 M-9 C-x 2 以划分该缓冲区,并使顶部的缓冲区为九行内容的高度。

要为底部的缓冲区而不是顶部的缓冲区指定行数,可以使用一个负数。

尝试将该缓冲区一分为二,并使底部的缓冲区为四行内容的高度:

  1. 通过键入 C-x C-c 退出 Emacs,然后使用一个文件启动它:

    $ emacs experience
    
  2. 键入 M-- M-4 C-x 2 以划分该缓冲区,并使底部的缓冲区为四行内容的高度。

C-x 2 可以进行垂直划分,但是用于划分窗口的许多重要的键绑定都是使用 C-x 4 前缀作为开始的。

要在一个新的缓冲区中以及一个新的窗口中打开一个新的文件,可以使用 find-file-other-window 功能,它与 C-x 4 f 进行了绑定。然后,给出该文件的文件名。要打开只读文件,则可以使用 find-file-read-only-other-window,并给出其文件名。它与 C-x 4 r 进行了绑定。

尝试在其他窗口中的一个新的缓冲区中打开 innocence 文件:键入 C-x 4 f innocence Enter 

尽管当您指定一个四行的窗口时,另一个窗口已经存在,但是请注意这个命令如何调整它的大小,以便活动窗口和新的窗口具有大致相同的尺寸。

switch-to-buffer-other-window 功能与 C-x 4 b 进行了绑定,它用于垂直地划分窗口,并允许您选择要在新的窗口中显示哪一个缓冲区,而该窗口也将成为活动窗口。

尝试使用这个命令,将另一个窗口中的缓冲区切换到 innocence 缓冲区:键入 C-x 4 b innocence Enter ,请注意,它不会对您输入该命令的窗口进行更改,现在,它也显示了 innocence 缓冲区。

要在另一个垂直的窗口中显示一个新的缓冲区,但保持活动光标仍然位于当前窗口中,可以运行 display-buffer 功能,它与 C-x 4 C-o 进行了绑定。它提示输入需要在另一个窗口中显示的缓冲区的名称,但是当前窗口仍然是活动的。如果该显示仅有一个窗口,那么这个功能将对其进行划分,并创建一个新的窗口,但是如果该显示已经有两个或者更多个窗口,那么不进行新的划分。

尝试使用这一命令,将底部窗口中的缓冲区切换到 experience 缓冲区:键入 C-x 4 C-o experience Enter 

当您的 Emacs 会话中具有多个窗口时,不会影响光标的移动,您可以在当前活动窗口中正常地移动,就如同在您的会话中只有一个窗口一样。并且当您滚动这个窗口时(使用滚动条,或者使用各种用于滚动的键),其他的窗口都不会滚动,即使这些窗口显示了相同缓冲区的副本。

要滚动另一个 窗口,而不是光标所在的窗口,可以使用 scroll-other-window 功能,它与 C-M-v 进行了绑定。(Emacs 将您所有的窗口保存在一个排序的列表中,所以如果您打开了两个以上的窗口,这一命令将滚动列表中的下一个窗口。)

现在,尝试键入 C-M-v,以滚动下面的窗口(该窗口中包含 experience 缓冲区),直到看到标题“A Little Boy Lost”为止。

通过启用 scroll-all 模式,您可以同时滚动所有的打开了相同缓冲区的窗口。这一功能是可以进行切换的,当它处于活动状态时,模式行将显示 *SL*。它将相同缓冲区的所有窗口一同移动,即使这些窗口显示了缓冲区中完全不同的部分,即将您键入的滚动命令应用于包含该缓冲区的所有窗口。

现在,请尝试下面的操作:

  1. 键入 C-x b experience Enter ,以便在顶部窗口中切换到 experience 缓冲区。

  2. 通过键入 M-x scroll-all-mode 打开 scroll-all 模式。

  3. 当顶部的窗口仍然处于活动状态时,通过键入 PgDn,同时滚动两个窗口。

  4. 通过按向上箭头键,在两个窗口中向上移动光标;多次按向上箭头键,以便该缓冲区的顶部出现在顶部窗口中,继续按向上箭头键,这时可以观察到光标在底部窗口中移动,而不在顶部窗口中移动。

  5. 通过多次按向下箭头键,在两个窗口中向下移动光标。

要在两个窗口之间移动,可以运行 other-window 功能,C-x o,它将移动到下一个窗口。当您重复地运行该命令时,它循环地遍历所有的窗口。当您移动到另一个窗口时,将在该缓冲区的当前位置绘制光标。

通过使用 windmove 命令直接指定光标,您也可以将光标移动到其他窗口,如表 1 所述。


功能 描述
windmove-up 移动到正好位于当前窗口上方的窗口,如果该窗口存在的话。
windmove-down 移动到正好位于当前窗口下方的窗口,如果该窗口存在的话。
windmove-left 移动到正好位于当前窗口左边的窗口,如果该窗口存在的话。
windmove-right 移动到正好位于当前窗口右边的窗口,如果该窗口存在的话。

现在,请尝试下面的操作:

  1. 键入 C-x o,以移动到底部的窗口。

  2. 关闭 scroll-all 模式:键入 M-x scroll-all-mode,然后再次向下滚动到“A Little Boy Lost”,请注意顶部的窗口不再滚动。

  3. 通过键入 C-x o,移回到顶部的窗口。

  4. 使用 C-x 2,对这个窗口进行划分。

  5. 通过键入 M-x windmove-down,向下移动到您刚刚划分的窗口。

有几种方式可以删除 Emacs 窗口。

要删除当前 窗口(即活动光标当前所在的窗口),可以运行 delete-window 功能,它与 C-x 0 进行了绑定。

现在,尝试删除您刚刚创建的第三个窗口:键入 C-x 0

要删除除了 当前窗口之外所有的窗口,可以运行 delete-other-windows 功能,它与 C-x 1 进行了绑定。

尝试下面的操作:键入 C-x 1

当您删除一个窗口时,您并不会关闭它所显示的缓冲区,该缓冲区在 Emacs 中仍然保持打开。要删除当前窗口,并且 同时关闭其缓冲区,可以运行 kill-buffer-and-window 功能,它与 C-x 4 0 进行了绑定。

尝试下面的操作:

  1. 垂直地将窗口划分为两半:键入 C-x 2,以便在您的 Emacs 会话中得到两个窗口。

  2. 将光标移动到这首诗的标题中的 BOY 和 LOST 之间的空格处,并键入 M-t,以调换这两个单词。

  3. 将当前缓冲区 experience 写入到一个名为 new.experience 的新的文件:键入 C-x C-w new.experience

  4. 使用 C-x 4 0 关闭该缓冲区和窗口。键入 y 以进行证实。

当您进行这一操作时,关闭了 new.experience 缓冲区,并且您的 Emacs 会话再次只包含一个窗口。

对应于刚刚描述的 split-window-vertically 功能的是 split-window-horizontally,它与 C-x 3 进行了绑定。这一功能将当前 Emacs 窗口从中间划分为两半,并将这两个新的窗口沿水平方向排成一行,因此它们相互紧靠在一起。对于并列地查看类似的缓冲区,这种方法是特别合适的。尝试下面的操作:

  1. 在一个新的缓冲区中打开 experience 文件:键入 C-x C-f experience Enter 

  2. 键入 C-x 3,以水平方向将该窗口划分为两半。

  3. 键入 C-x b Enter ,以便将最左边窗口的内容更改为 innocence 缓冲区。

您的 Emacs 会话应如 图 3 所示。



 

与垂直划分一样,您可以在这个功能的前面使用一个数值参数以指定左边 窗口应该具有的字符数目宽度;如果您给出了一个负数,那么它将指定右边 窗口的宽度。

尝试下面的操作:通过键入 C-u 11 C-x 3,以水平方向将当前窗口划分为两半,并使最左边的窗口具有 11 个字符宽度。

请注意,您给出的数值包括用于最左边窗口的滚动条的一个字符、用于滚动条和缓冲区的内容之间的空白列的一个字符、缓冲区本身的列、用于箭头图形(指示一行内容是否超出了它的显示宽度)的一列,以及该划分生成的第二个窗口的滚动条。在这一示例中,您刚刚创建的最左边的窗口具有可显示七个字符的宽度,如图 4 中所示。



 

与相同缓冲区的垂直划分一样,可以分别地处理相同缓冲区的任何水平划分。在一个窗口中的滚动操作和光标移动不会影响其他窗口,所以当您在一个窗口中移动光标时,它不会影响任何包含相同缓冲区的其他窗口。但是您可以使用另一个技巧。如果您打开了follow-mode,那么您就可以根据相同缓冲区的多个窗口生成一个较大的“虚拟”窗口。

通过这种方式,当您对窗口进行水平划分时,这些窗口将显示该缓冲区中不同的、但又相连的部分,从而为该缓冲区生成一个较大的虚拟窗口。将光标移动到一个窗口的末尾,这样可以使其进入到一个窗口的开始处。

尝试下面的操作:

  1. 键入 C-x 1 以删除所有的窗口,并键入 C-x 3,以便水平地将单个窗口划分为两半。现在您的 Emacs 会话包含两个窗口,每个窗口都包含了 innocence 缓冲区,并且每个窗口的光标都位于缓冲区的顶部。

  2. 键入 M-x follow-mode 为该缓冲区启用这种模式。请注意,单词 Follow 出现在两个窗口的模式行中。第二个窗口的内容发生了更改:现在,它恰好接着左边窗口中的内容,以该窗口的下一行内容作为开始。

  3. 通过按向下箭头键,在左边的窗口中,将光标在缓冲区中向下移动,并观察当到达该窗口的底部时所发生的情况:光标将移动到右边窗口的顶部。

  4. 在右边的窗口中向下移动光标,并观察如何重绘这两个窗口。使用向上箭头键,在右边的窗口中向上移动光标,并观察当到达该窗口顶部时所发生的情况:光标移动到左边窗口的底部。

  5. 这个功能是可以进行切换的。再次运行它,就可以在这个缓冲区中关闭它:键入 M-x follow-mode,并注意 Follow 不再出现在模式行中。

尽管 follow-mode 同样可以工作于垂直划分的缓冲区中,但是在大多数情况下,使用这一模式没有任何优势。

到目前为止,您要么为窗口使用缺省大小,要么在创建它们时指定它们的大小。但是您可以在任何时候调整任何 Emacs 窗口的大小。

要使当前窗口变得更高些,可以运行 enlarge-window 功能,它与 C-x ^ 进行了绑定。要使它变得更矮些,可以在这一功能之前使用 M--。要按照特定的行数缩小或者增大窗口,可以给出具体的数值(使用通用的参数 C-u)。

您还可以更改窗口的宽度。要使当前窗口变得更窄,可以运行 shrink-window-horizontally 功能,它与 C-x {  进行了绑定。要使它变得更宽,可以运行 enlarge-window-horizontally 功能,它与 C-x } 进行了绑定。

尝试确定您的 Emacs 会话中某些窗口的形状:

  1. 键入 C-x 1 以关闭任何现有的窗口,并键入 C-x b innocence Enter ,以便在这一窗口中打开 innocence 缓冲区。

  2. 使用 C-x 3 水平地将这个窗口划分为两半。

  3. 通过键入 C-x 4 C-o experience Enter ,在最右边的窗口中切换缓冲区。

  4. 通过键入 C-x 2 C-x o C-x b experience Enter ,垂直地将最左边的窗口划分为两半,并使 experience 缓冲区处于底部的窗口中。

  5. 通过键入 C-s sunf 搜索标题,将光标移动到“Ah, Sunflower”诗的开头,然后键入 C-u 6 C-l 以重绘该窗口,并使这首诗呈现在眼前。

  6. 通过键入 M-- M-5 C-x ^ C-l,将这一窗口收缩五行,并重绘它。

  7. 因为窗口的宽度不足以显示它们,所以隐藏了一些行。通过键入 C-x } C-x } 使该窗口增加两个字符的宽度。

如果在调整大小时,您将该窗口设置得过小,以至于其中的行数不足以绘制窗口及其模式行,那么将关闭该窗口。尝试下面的操作:

  1. 移动到这个窗口上方的窗口:键入 windmove-up

  2. 键入 C-u -5 C-x ^ 将该窗口收缩五行。

  3. 多次尝试这一操作:键入 C-u -5 C-x ^,并再次键入它以继续收缩这一窗口。继续进行这一操作直到该窗口消失。

您可以进行更多调整。要缩小该窗口的大小(如果可能的话),可以运行 shrink-window-if-larger-than-buffer 功能,它与C-x - 进行了绑定。通过运行 balance-windows 功能,您还可以平衡所有可见窗口的大小。它使得所有的窗口都具有大致相同的尺寸。它与 C-x + 进行了绑定。

尝试下面的操作:键入 C-x 2 C-x 2 以生成更多的窗口,并键入 C-x + C-x + 以平衡它们的高度。

除了使用这些命令之外,您还可以使用鼠标调整窗口大小,正如您将在“使用鼠标调整窗口大小”部分中学习到的。

通常,可以使用多个窗口以比较缓冲区的内容。compare-windows 功能允许您完成这项任务:它可以比较两个窗口中的文本,从两个窗口中光标处的字符开始,并将光标移动(在两个窗口中)到第一个不同的字符处。如果这两个文件是完全一样的,那么将光标移动到这两个缓冲区的末尾。

现在,尝试针对名为 experience 的示例文件和您以前编辑的 new.experience 文件运行它:

  1. 通过键入 C-x C-c 退出 Emacs,然后使用一个文件启动它:

    $ emacs experience
    
  2. 键入 C-x f new.experience,以便在一个新的缓冲区中打开您编辑过的文件。

  3. 通过键入 C-x 3 C-x b Enter ,垂直地划分屏幕,并使得每个缓冲区都位于它自己的窗口中。

  4. 键入 M-x compare-windows 以运行比较操作。

两个窗口中的光标移动到文件中第一个不同的位置:这首诗的标题(您在前面对其进行了更改)。您的 Emacs 会话应该与图 5 中所示类似。



 

表 2 中包含了用于操作窗口的常见 Emacs 命令的列表,给出了它们的键绑定(如果适用的话),并描述了它们的功能。


功能 绑定 描述
split-window-vertically C-x 2 从中间将当前窗口划分为两半,垂直地堆叠新的缓冲区。
switch-to-buffer-other-window C-x 4 b 垂直地将当前窗口划分为两半,提示输入缓冲区以使用底部的窗口,并将其作为活动窗口。
display-buffer C-x 4 C-o 在另一个窗口中显示一个缓冲区,提示输入缓冲区以使用另一个窗口,但保持当前窗口为活动窗口。(如果仅存在一个窗口,那么垂直地划分该窗口以显示另一个缓冲区。)
find-file-other-window C-x 4 f 在新的缓冲区中打开新的文件,在新的垂直窗口中绘制它。
find-file-read-only-other-window C-x 4 r 在一个新的只读缓冲区中打开新的文件,在新的垂直窗口中绘制它。
scroll-other-window C-M-v 滚动到下一个由 C-x o 切换到的窗口。
scroll-all   切换 scroll-all 次要模式。当它处于打开状态时,将同时滚动显示当前窗口中的缓冲区的所有窗口,并滚动均等的相应距离。
other-window C-x o 将光标移动到下一个窗口,并使其成为活动窗口。
windmove-up   移动到恰好位于当前窗口上方的窗口,如果它存在的话。
windmove-down   移动到恰好位于当前窗口下方的窗口,如果它存在的话。
windmove-left   移动到恰好位于当前窗口左边的窗口,如果它存在的话。
windmove-right   移动到恰好位于当前窗口右边的窗口,如果它存在的话。
delete-window C-x 0 删除当前窗口,并将光标移动到使用 C-x o 将切换到的下一个窗口。
delete-other-windows C-x 1 删除当前窗口之外的所有窗口。
kill-buffer-and-window C-x 4 0 删除当前窗口,并剪切它的缓冲区。
split-window-horizontally C-x 3 将当前窗口从中间划分为两半,水平地堆叠新的缓冲区。
follow-mode   切换 follow 次要模式。当它在缓冲区中处于打开状态时,将所有显示该缓冲区的窗口连接为一个较大的虚拟窗口。
enlarge-window C-x ^ 使当前窗口增加一行的高度;在其之前使用一个负数,将使得当前窗口减少一行的高度。
shrink-window-horizontally C-x } 使当前活动窗口减少一列的宽度。
enlarge-window-horizontally C-x { 使当前活动窗口增加一列的宽度。
shrink-window-if-larger-than-buffer C-x - 将当前活动窗口的大小缩小到对于它所包含的缓冲区来说可能的最小尺寸。
balance-windows C-x + 平衡所有窗口的尺寸,使它们的大小大致相等。
compare-windows   将当前窗口与下一个窗口进行比较,在两个窗口中从光标处开始比较,并在两个缓冲区中将光标移动到第一个不同的字符处,直到到达缓冲区的末尾为止。

 

 

 

3.

 

移动并操作 Emacs 框架

在 X 中,通常将一个在它自己的 X 客户端窗口中运行的应用程序称为一个窗口。但是因为 Emacs 对于单词窗口 有它自己的定义,正如在前面的部分中所描述的,Emacs 为整个 Emacs X 客户端窗口使用了另一个术语:称其为框架

Emacs 支持为相同的 Emacs 会话打开多个框架。当您在多个框架中打开一个缓冲区时,更改将出现在所有框架的缓冲区中。关闭一个框架并不会影响到其他框架,但使用通常的 save-buffers-kill-emacs 功能(C-x C-c)退出一个框架,将保存所有框架的缓冲区,并退出所有的框架。

如果您处于一个控制台窗口中,那么这些命令仍然可以起作用,尽管一个控制台一次只能显示一个框架。在控制台中,通过给定的框架编号区分各个框架,该编号出现在模式行中(并且前面使用了一个 F 字符)以区分每个框架。

make-frame-command 功能,C-x 5 2,可以生成一个新的框架,并使其处于活动状态:

  1. 通过键入 C-x C-c 退出 Emacs,然后使用一个文件(您创建的新的文件)启动它:

    $ emacs new.experience
    
  2. 键入 C-x 5 2 以生成一个新的框架。(它出现在您桌面上的确切位置,取决于您的窗口管理器。)它也包含了 new.experience 缓冲区的一个副本。

  3. 编辑一行:键入 C-u 381 C-n M-f M-f M-f M-t。对于两个框架中的这个缓冲区,将在模式行中出现星号。

C-x 4 命令用于 Emacs 窗口,C-x 5 命令用于 Emacs 框架。对于用于生成新窗口的所有 C-x 4 命令,正如在垂直地划分一个窗口部分中所描述的,都存在 C-x 5 等价操作:例如,switch-to-buffer-other-frame 功能是 C-x 5 b

尝试下面的操作:

  1. 键入 C-x C-f experience Enter ,以便在一个新的缓冲区中打开 experience 文件的副本。

  2. 键入 C-x 5 b experience Enter ,以便在一个新的框架中打开这个缓冲区的副本。

find-file-other-frame 功能,它与 C-x 5 f 进行了绑定,提示输入一个文件名,并在新的框架中打开给定的文件。同样地,find-file-read-only-other-frame,它与 C-x 5 r 进行了绑定,在新的框架中打开给定的文件,并将其作为一个只读缓冲区。

尝试使用单步操作查找一个文件,并在一个新的框架中打开它,:键入 C-x 5 f innocence Enter 

现在您的 Emacs 会话应该与图 6 所示类似,其中包括四个不同的 X 客户端窗口。



 

使用 other-frame 功能,C-x 5 o,可以在框架之间进行移动。

与它的 Emacs 窗口等价操作 C-x o 一样,这个功能在所有的当前 Emacs 框架之间循环,提升 每个框架,以使其获得焦点并位于任何其他窗口之上,且选择其作为当前框架。

尝试在已经打开的四个框架之间循环: C-x 5 o C-x 5 o C-x 5 o C-x 5 o C-x 5 o

如果您使用 X 控件以关闭一个框架,或者使用 C-x C-c 命令以退出 Emacs,那么您将退出所生成的所有框架。然而,用以销毁 一个框架的 X 控件,仅仅销毁特定的框架;它既不会关闭在该框架中打开的任何缓冲区,也不会销毁其他 Emacs 框架。

您还可以从 Emacs 删除框架。要删除当前框架,可以使用 delete-frame 功能,C-x 5 0。在删除了当前框架之后,将使下一个框架成为活动框架和当前框架。如果您尝试在会话中仅有的框架上运行这一操作,那么 Emacs 将发出蜂鸣声,并报告一个错误。现在尝试这一操作,以删除您所在的框架。

要删除除了 当前框架之外的所有框架,可以使用 delete-other-frames 功能,C-x 5 1。将删除当前框架之外的所有框架,如果它们存在的话。现在尝试这一操作以删除剩余的两个框架,以便回到一个 Emacs 框架。

请注意,这些命令并不会关闭缓冲区,在完成删除操作之后,在所删除框架的窗口中显示的任何缓冲区仍然可用于当前框架。

在控制台中,C-z 通常将 Emacs 挂起到后台;在 X 中,它将运行 iconify-or-deiconify-frame 功能。这一操作将图标化当前框架;但是如果已经图标化了当前框架,它将取消该框架的图标化。

尝试下面的操作:在您已经打开的当前框架中键入 C-z。根据您正在运行的 X 的版本和窗口管理器,以及您系统中的桌面软件,应该对 Emacs 窗口进行图标化。然后,对图标化的框架再次按 C-z,以取消它的图标化,并使得图标化的框架重新获得焦点。

表 3 中包含了用于操作框架的常见 Emacs 命令列表,给出了它们的功能名及其缺省的键绑定(如果适用的话),并描述了它们的功能。


功能 绑定 描述
make-frame-command C-x 5 2 生成一个新的 Emacs 框架,并使其成为活动框架。
switch-to-buffer-other-frame C-x 5 b 在另一个框架中打开指定的缓冲区。如果不存在其他框架,则创建一个新的框架。
find-file-other-frame C-x 5 f 在另一个框架中打开指定的文件。如果不存在其他框架,则创建一个新的框架。
find-file-read-only-other-frame C-x 5 r 在另一个框架中的只读缓冲区中打开指定的文件。如果不存在其他框架,则创建一个新的框架。
other-frame C-x 5 o 移动到下一个框架,并使其成为活动框架。
delete-frame C-x 5 0 删除当前框架,并使下一个框架成为活动框架。
delete-other-frames C-x 5 1 删除当前框架之外的所有框架。
iconify-or-deiconify-frame C-z 图标化当前框架。如果该框架已经图标化了,那么取消它的图标化。(在控制台中,这个绑定将挂起 Emacs。)

 

 

4.

 

Emacs 窗口和鼠标

在 Emacs 窗口中使用鼠标,有一些非常有价值的技术。

您可以使用鼠标执行在对您的 Emacs 会话进行划分和分区部分中所描述的许多功能。这些窗口操作可以在模式行中完成。

在 Emacs 的新版本中,模式行的特定区域具有它们自己的鼠标绑定。例如,如果您的模式行显示了您是否有邮件(它通过书写单词Mail 来完成这一任务),然后以某种方式使用鼠标在模式行中单击该单词,将为您的邮件启动一个新的缓冲区;单击模式行中该缓冲区的名称,会将该窗口中的缓冲区切换到缓冲区列表中的下一个缓冲区。当您将鼠标位于模式行中特定区域的上方时,将使用一个弹出框显示相应的内容,这些内容称为工具提示。除了这些特殊的工具提示之外,下面的命令也可以用于模式行中的任何位置。

在模式行上以 C-B2 组合方式进行单击,将在您单击的位置对窗口进行水平地 划分。如果您太靠近窗口的上下边缘,那么该划分是可能的最小尺寸。(通过按住 Ctrl 键,然后单击中间的鼠标按钮,就可以输入这个组合。)

在滚动条上输入 C-B2 组合,将在您单击鼠标的位置垂直地 划分窗口。如果您太靠近窗口的上下边缘,那么该划分是最小尺寸。(请注意,当前这一操作并不使用实现滚动条的某些 X 工具包。)

尝试使用鼠标划分窗口:

  1. 如果 Emacs 正在运行的话,通过 C-x C-c 退出它。使用示例文件之一,再次启动它:

    $ emacs innocence
    
  2. 在一个新的垂直窗口中打开第二个示例文件:键入 C-x 4 f experience Enter 

  3. 您的 Emacs 会话应该与图 1 中所示类似。尝试在顶部模式行的中间(即恰好位于单词 Top 之后的某处)使用 C-B2 鼠标组合,以便在该位置处水平地划分顶部的窗口。

  4. 在模式行上大约相同的位置使用 C-B2 鼠标组合,水平地划分底部的窗口,同样是在恰好位于单词 Top 之后的某处。

  5. 在您刚刚创建的两个新窗口的滚动条下面的小垂直条上单击并拖动 鼠标左键,以对其进行调整,使得所有四个窗口具有大致相同的大小。如果您的 Emacs 框架太小,而不能够显示所有四个窗口中的文本,那么您可以使用窗口管理器控件以调整 X 客户端框架的大小。

通过在您希望移动到的窗口的模式行的空白区域上单击 鼠标左键(第一个鼠标按钮),您可以使用鼠标移动到任何 Emacs 窗口。(在 Emacs 的新版本中,单击缓冲区名可以将该窗口中的可见缓冲区更改为缓冲区列表中的下一个缓冲区。)您单击其模式行的窗口将成为活动窗口,并且将活动光标移动到了该窗口中的当前位置。

您还可以使用鼠标移动到另一个窗口中可见部分的任何位置:要完成这一任务,在该窗口中单击 鼠标左键。光标将移动到您单击的位置。

尝试在您刚刚创建的四个窗口之间移动:

  1. 通过在其模式行的空白区域单击 鼠标左键,移动到右上方的窗口,然后键入 C-u 349 C-n 在该文件中向下移动。

  2. 通过在可见缓冲区窗口中的任何字符上单击 鼠标左键,移回到左上方的窗口,然后键入 C-s Till C-s C-s C-a,以便在缓冲区中的其他位置重新聚焦该显示。

  3. 暂停鼠标操作,并通过键入 C-x o C-x o 移动到左下方的窗口,正如您在移动到另一个窗口部分中所学习的。键入 C-u 286 C-n,以便在该缓冲区中向下移动。

  4. 在右下方窗口模式行中的缓冲区名称之后的某处,单击 鼠标左键,以使其成为活动窗口。键入 C-s jour C-l,以便将这个窗口中的视图移动到缓冲区中的其他位置。

您还可以在模式行上使用鼠标调整窗口大小。对于您先前在调整窗口大小部分中所学习的方法而言,这是一个替代方法。

要使窗口变得更高或者更矮,可以使用 鼠标左键 单击并拖动模式行。要使窗口变得更窄或者更宽,可以单击并拖动其滚动条下方的小垂直条。

尝试使用鼠标调整窗口大小:

  1. 单击并稍微拖动 鼠标左键 以及右上方窗口滚动条下面的小垂直条,从而使得右上方窗口的宽度缩小几个字符,并使左上方窗口变得足够大,以便能够在这两个缓冲区的窗口中显示每行所有的字符。(您可能还需要使用窗口管理器的控件,以增大 Emacs 框架。)

  2. 通过在模式行上单击并拖动 鼠标左键 使底部的两个窗口变得更小,从而使底部的窗口收缩几行。

如果您按照这一部分中的所有步骤进行了操作,那么您的 Emacs 会话应该与图 7 所示类似。



 

要删除一个窗口,可以在它的模式行上单击 鼠标右键。在模式行的空白区域上单击 鼠标中建,以关闭所有 其他窗口,并扩大该窗口,使其填满整个框架。

去掉一些窗口:

  1. 在左上方窗口的模式行上单击 鼠标右键,以删除该窗口。右上方的窗口向左边扩大以填满这个空间;现在这个窗口成为了活动窗口。

  2. 在它的模式行上单击 鼠标中建,以删除它下面的两个窗口,并使这个上面的窗口填满整个 Emacs 框架。

有时在 X 中,鼠标指针可能会妨碍您的 Emacs 会话,比如您选择了一个 Emacs 框架并开始进行编辑,并且鼠标指针悬停于某处文本的上方。

如果您觉得这种情况很讨厌,那么您可以使用 mouse-avoidance-mode 以更改鼠标指针的行为。这个模式提供了几种技术,如表 4中所述。


模式 描述
animate 只要光标靠近鼠标指针,就使得鼠标指针迅速地移动到该框架中的一个随机位置。
banish 一旦您开始键入,就将鼠标指针驱逐到该窗口的右上角。
cat-and-mouse 用作 animate 的同义词。
exile 仅当鼠标指针离光标太近时,将鼠标指针移动到该窗口的右上角(如同 banish)。一旦光标移开,将鼠标指针移回到它的原始位置。
jump 当光标靠近鼠标指针时,使鼠标指针立刻跳到该框架中的一个随机位置。
none 不提供鼠标躲避功能(缺省情况)。
proteus 与 animate 中一样移动鼠标指针,但是就像希腊神话中的海神普罗特斯,更改鼠标指针的形状(使用一个随机图像字符)。

最好使用一个实例加以说明。现在,请尝试下面的操作:

  1. 键入 M-x mouse-avoidance-mode Enter cat-and-mouse Enter 以打开鼠标躲避模式。

  2. 移动到临时缓冲区:键入 C-x b *scratch* Enter 

  3. 移动鼠标指针,使其位于光标的左边,且与光标仅有几英寸的距离,并开始键入一行文本:“When the cat wants to play the mouse runs away”。一旦光标靠近鼠标指针,鼠标指针则应该迅速离开。

 

5.

总结

您已经了解了对 Emacs 会话形状进行操作的细节技术,即如何创建并控制多个框架、如何对任何框架进行划分和分区以得到多个窗口,以及如何遍历这些框架和窗口。您还了解了一些其他技巧,包括如何使用鼠标操作框架和窗口以及如何处理鼠标指针,并且通过这些优秀的、功能强大的技术,可以使得 Emacs 按照您所希望的方式进行工作,并具有您所希望的外观。

 

6.

附录

 

 

SONGS OF EXPERIENCE

 

 

 

INTRODUCTION

 

Hear the voice of the Bard,

Who present, past, and future, sees;

Whose ears have heard

The Holy Word

That walked among the ancient trees;

 

Calling the lapsed soul,

And weeping in the evening dew;

That might control

The starry pole,

And fallen, fallen light renew!

 

'O Earth, O Earth, return!

Arise from out the dewy grass!

Night is worn,

And the morn

Rises from the slumbrous mass.

 

'Turn away no more;

Why wilt thou turn away?

The starry floor,

The watery shore,

Is given thee till the break of day.'

 

 

 

EARTH'S ANSWER

 

Earth raised up her head

From the darkness dread and drear,

Her light fled,

Stony, dread,

And her locks covered with grey despair.

 

'Prisoned on watery shore,

Starry jealousy does keep my den

Cold and hoar;

Weeping o'er,

I hear the father of the ancient men.

 

'Selfish father of men!

Cruel, jealous, selfish fear!

Can delight,

Chained in night,

The virgins of youth and morning bear.

 

'Does spring hide its joy,

When buds and blossoms grow?

Does the sower

Sow by night,

Or the ploughman in darkness plough?

 

'Break this heavy chain,

That does freeze my bones around!

Selfish, vain,

Eternal bane,

That free love with bondage bound.'

 

 

 

THE CLOD AND THE PEBBLE

 

'Love seeketh not itself to please,

Nor for itself hath any care,

But for another gives its ease,

And builds a heaven in hell's despair.'

 

So sung a little clod of clay,

Trodden with the cattle's feet,

But a pebble of the brook

Warbled out these metres meet:

 

'Love seeketh only Self to please,

To bind another to its delight,

Joys in another's loss of ease,

And builds a hell in heaven's despite.'

 

 

 

HOLY THURSDAY

 

Is this a holy thing to see

In a rich and fruitful land, -

Babes reduced to misery,

Fed with cold and usurous hand?

 

Is that trembling cry a song?

Can it be a song of joy?

And so many children poor?

It is a land of poverty!

 

And their sun does never shine,

And their fields are bleak and bare,

And their ways are filled with thorns,

It is eternal winter there.

 

For where'er the sun does shine,

And where'er the rain does fall,

Babe can never hunger there,

Nor poverty the mind appal.

 

 

 

THE LITTLE GIRL LOST

 

In futurity

I prophesy

That the earth from sleep

(Grave the sentence deep)

 

Shall arise, and seek

For her Maker meek;

And the desert wild

Become a garden mild.

 

In the southern clime,

Where the summer's prime

Never fades away,

Lovely Lyca lay.

 

Seven summers old

Lovely Lyca told.

She had wandered long,

Hearing wild birds' song.

 

'Sweet sleep, come to me,

Underneath this tree;

Do father, mother, weep?

Where can Lyca sleep?

 

'Lost in desert wild

Is your little child.

How can Lyca sleep

If her mother weep?

 

'If her heart does ache,

Then let Lyca wake;

If my mother sleep,

Lyca shall not weep.

 

'Frowning, frowning night,

O'er this desert bright

Let thy moon arise,

While I close my eyes.'

 

Sleeping Lyca lay,

While the beasts of prey,

Come from caverns deep,

Viewed the maid asleep.

 

The kingly lion stood,

And the virgin viewed:

Then he gambolled round

O'er the hallowed ground.

 

Leopards, tigers, play

Round her as she lay;

While the lion old

Bowed his mane of gold,

 

And her bosom lick,

And upon her neck,

From his eyes of flame,

Ruby tears there came;

 

While the lioness

Loosed her slender dress,

And naked they conveyed

To caves the sleeping maid.

 

 

 

THE LITTLE GIRL FOUND

 

All the night in woe

Lyca's parents go

Over valleys deep,

While the deserts weep.

 

Tired and woe-begone,

Hoarse with making moan,

Arm in arm, seven days

They traced the desert ways.

 

Seven nights they sleep

Among shadows deep,

And dream they see their child

Starved in desert wild.

 

Pale through pathless ways

The fancied image strays,

Famished, weeping, weak,

With hollow piteous shriek.

 

Rising from unrest,

The trembling woman pressed

With feet of weary woe;

She could no further go.

 

In his arms he bore

Her, armed with sorrow sore;

Till before their way

A couching lion lay.

 

Turning back was vain:

Soon his heavy mane

Bore them to the ground,

Then he stalked around,

 

Smelling to his prey;

But their fears allay

When he licks their hands,

And silent by them stands.

 

They look upon his eyes,

Filled with deep surprise;

And wondering behold

A spirit armed in gold.

 

On his head a crown,

On his shoulders down

Flowed his golden hair.

Gone was all their care.

 

'Follow me,' he said;

'Weep not for the maid;

In my palace deep,

Lyca lies asleep.'

 

Then they followed

Where the vision led,

And saw their sleeping child

Among tigers wild.

 

To this day they dwell

In a lonely dell,

Nor fear the wolvish howl

Nor the lion's growl.

 

 

 

THE CHIMNEY-SWEEPER

 

A little black thing among the snow,

Crying! 'weep! weep!' in notes of woe!

'Where are thy father and mother?  Say!' -

'They are both gone up to the church to pray.

 

'Because I was happy upon the heath,

And smiled among the winter's snow,

They clothed me in the clothes of death,

And taught me to sing the notes of woe.

 

'And because I am happy and dance and sing,

They think they have done me no injury,

And are gone to praise God and His priest and king,

Who made up a heaven of our misery.'

 

 

 

NURSE'S SONG

 

When the voices of children are heard on the green,

And whisperings are in the dale,

The days of my youth rise fresh in my mind,

My face turns green and pale.

 

Then come home, my children, the sun is gone down,

And the dews of night arise;

Your spring and your day are wasted in play,

And your winter and night in disguise.

 

 

 

THE SICK ROSE

 

O rose, thou art sick!

The invisible worm,

That flies in the night,

In the howling storm,

 

Has found out thy bed

Of crimson joy,

And his dark secret love

Does thy life destroy.

 

 

 

THE FLY

 

Little Fly,

Thy summer's play

My thoughtless hand

Has brushed away.

 

Am not I

A fly like thee?

Or art not thou

A man like me?

 

For I dance,

And drink, and sing,

Till some blind hand

Shall brush my wing.

 

If thought is life

And strength and breath,

And the want

Of thought is death;

 

Then am I

A happy fly.

If I live,

Or if I die.

 

 

 

THE ANGEL

 

I dreamt a dream!  What can it mean?

And that I was a maiden Queen

Guarded by an Angel mild:

Witless woe was ne'er beguiled!

 

And I wept both night and day,

And he wiped my tears away;

And I wept both day and night,

And hid from him my heart's delight.

 

So he took his wings, and fled;

Then the morn blushed rosy red.

I dried my tears, and armed my fears

With ten thousand shields and spears.

 

Soon my Angel came again;

I was armed, he came in vain;

For the time of youth was fled,

And grey hairs were on my head.

 

 

 

THE TIGER

 

Tiger, tiger, burning bright

In the forests of the night,

What immortal hand or eye

Could frame thy fearful symmetry?

 

In what distant deeps or skies

Burnt the fire of thine eyes?

On what wings dare he aspire?

What the hand dare seize the fire?

 

And what shoulder and what art

Could twist the sinews of thy heart?

And, when thy heart began to beat,

What dread hand and what dread feet?

 

What the hammer? what the chain?

In what furnace was thy brain?

What the anvil? what dread grasp

Dare its deadly terrors clasp?

 

When the stars threw down their spears,

And watered heaven with their tears,

Did He smile His work to see?

Did He who made the lamb make thee?

 

Tiger, tiger, burning bright

In the forests of the night,

What immortal hand or eye

Dare frame thy fearful symmetry?

 

 

 

MY PRETTY ROSE TREE

 

A flower was offered to me,

Such a flower as May never bore;

But I said, 'I've a pretty rose tree,'

And I passed the sweet flower o'er.

 

Then I went to my pretty rose tree,

To tend her by day and by night;

But my rose turned away with jealousy,

And her thorns were my only delight.

 

 

 

AH, SUNFLOWER

 

Ah, sunflower, weary of time,

Who countest the steps of the sun;

Seeking after that sweet golden clime

Where the traveller's journey is done;

 

Where the Youth pined away with desire,

And the pale virgin shrouded in snow,

Arise from their graves, and aspire

Where my Sunflower wishes to go!

 

 

 

THE LILY

 

The modest Rose puts forth a thorn,

The humble sheep a threat'ning horn:

While the Lily white shall in love delight,

Nor a thorn nor a threat stain her beauty bright.

 

 

 

THE GARDEN OF LOVE

 

I went to the Garden of Love,

And saw what I never had seen;

A Chapel was built in the midst,

Where I used to play on the green.

 

And the gates of this Chapel were shut,

And 'Thou shalt not' writ over the door;

So I turned to the Garden of Love

That so many sweet flowers bore.

 

And I saw it was filled with graves,

And tombstones where flowers should be;

And priests in black gowns were walking their rounds,

And binding with briars my joys and desires.

 

 

 

THE LITTLE VAGABOND

 

Dear mother, dear mother, the Church is cold;

But the Alehouse is healthy, and pleasant, and warm.

Besides, I can tell where I am used well;

Such usage in heaven will never do well.

 

But, if at the Church they would give us some ale,

And a pleasant fire our souls to regale,

We'd sing and we'd pray all the livelong day,

Nor ever once wish from the Church to stray.

 

Then the Parson might preach, and drink, and sing,

And we'd be as happy as birds in the spring;

And modest Dame Lurch, who is always at church,

Would not have bandy children, nor fasting, nor birch.

 

And God, like a father, rejoicing to see

His children as pleasant and happy as He,

Would have no more quarrel with the Devil or the barrel,

But kiss him, and give him both drink and apparel.

 

 

 

LONDON

 

I wander through each chartered street,

Near where the chartered Thames does flow,

A mark in every face I meet,

Marks of weakness, marks of woe.

 

In every cry of every man,

In every infant's cry of fear,

In every voice, in every ban,

The mind-forged manacles I hear:

 

How the chimney-sweeper's cry

Every blackening church appals,

And the hapless soldier's sigh

Runs in blood down palace-walls.

 

But most, through midnight streets I hear

How the youthful harlot's curse

Blasts the new-born infant's tear,

And blights with plagues the marriage hearse.

 

 

 

THE HUMAN ABSTRACT

 

Pity would be no more

If we did not make somebody poor,

And Mercy no more could be

If all were as happy as we.

 

And mutual fear brings Peace,

Till the selfish loves increase;

Then Cruelty knits a snare,

And spreads his baits with care.

 

He sits down with holy fears,

And waters the ground with tears;

Then Humility takes its root

Underneath his foot.

 

Soon spreads the dismal shade

Of Mystery over his head,

And the caterpillar and fly

Feed on the Mystery.

 

And it bears the fruit of Deceit,

Ruddy and sweet to eat,

And the raven his nest has made

In its thickest shade.

 

The gods of the earth and sea

Sought through nature to find this tree,

But their search was all in vain:

There grows one in the human Brain.

 

 

 

INFANT SORROW

 

My mother groaned, my father wept:

Into the dangerous world I leapt,

Helpless, naked, piping loud,

Like a fiend hid in a cloud.

 

Struggling in my father's hands,

Striving against my swaddling bands,

Bound and weary, I thought best

To sulk upon my mother's breast.

 

 

 

A POISON TREE

 

I was angry with my friend:

I told my wrath, my wrath did end.

I was angry with my foe:

I told it not, my wrath did grow.

 

And I watered it in fears

Night and morning with my tears,

And I sunned it with smiles

And with soft deceitful wiles.

 

And it grew both day and night,

Till it bore an apple bright,

And my foe beheld it shine,

And he knew that it was mine, -

 

And into my garden stole

When the night had veiled the pole;

In the morning, glad, I see

My foe outstretched beneath the tree.

 

 

 

A LITTLE BOY LOST

 

'Nought loves another as itself,

Nor venerates another so,

Nor is it possible to thought

A greater than itself to know.

 

'And, father, how can I love you

Or any of my brothers more?

I love you like the little bird

That picks up crumbs around the door.'

 

The Priest sat by and heard the child;

In trembling zeal he seized his hair,

He led him by his little coat,

And all admired his priestly care.

 

And standing on the altar high,

'Lo, what a fiend is here!' said he:

'One who sets reason up for judge

Of our most holy mystery.'

 

The weeping child could not be heard,

The weeping parents wept in vain:

They stripped him to his little shirt,

And bound him in an iron chain,

 

And burned him in a holy place

Where many had been burned before;

The weeping parents wept in vain.

Are such things done on Albion's shore?

 

 

 

A LITTLE GIRL LOST

 

Children of the future age,

Reading this indignant page,

Know that in a former time

Love, sweet love, was thought a crime.

 

In the age of gold,

Free from winter's cold,

Youth and maiden bright,

To the holy light,

Naked in the sunny beams delight.

 

Once a youthful pair,

Filled with softest care,

Met in garden bright

Where the holy light

Had just removed the curtains of the night.

 

There, in rising day,

On the grass they play;

Parents were afar,

Strangers came not near,

And the maiden soon forgot her fear.

 

Tired with kisses sweet,

They agree to meet

When the silent sleep

Waves o'er heaven's deep,

And the weary tired wanderers weep.

 

To her father white

Came the maiden bright;

But his loving look,

Like the holy book,

All her tender limbs with terror shook.

 

Ona, pale and weak,

To thy father speak!

O the trembling fear!

O the dismal care

That shakes the blossoms of my hoary hair!'

 

 

 

A DIVINE IMAGE

 

Cruelty has a human heart,

And Jealousy a human face;

Terror the human form divine,

And Secrecy the human dress.

 

The human dress is forged iron,

The human form a fiery forge,

The human face a furnace sealed,

The human heart its hungry gorge.

 

 

 

A CRADLE SONG

 

Sleep, sleep, beauty bright,

Dreaming in the joys of night;

Sleep, sleep; in thy sleep

Little sorrows sit and weep.

 

Sweet babe, in thy face

Soft desires I can trace,

Secret joys and secret smiles,

Little pretty infant wiles.

 

As thy softest limbs I feel,

Smiles as of the morning steal

O'er thy cheek, and o'er thy breast

Where thy little heart doth rest.

 

O the cunning wiles that creep

In thy little heart asleep!

When thy little heart doth wake,

Then the dreadful light shall break.

 

 

 

THE SCHOOLBOY

 

I love to rise in a summer morn,

When the birds sing on every tree;

The distant huntsman winds his horn,

And the skylark sings with me:

O what sweet company!

 

But to go to school in a summer morn, -

O it drives all joy away!

Under a cruel eye outworn,

The little ones spend the day

In sighing and dismay.

 

Ah then at times I drooping sit,

And spend many an anxious hour;

Nor in my book can I take delight,

Nor sit in learning's bower,

Worn through with the dreary shower.

 

How can the bird that is born for joy

Sit in a cage and sing?

How can a child, when fears annoy,

But droop his tender wing,

And forget his youthful spring!

 

O father and mother if buds are nipped,

And blossoms blown away;

And if the tender plants are stripped

Of their joy in the springing day,

By sorrow and care's dismay, -

 

How shall the summer arise in joy,

Or the summer fruits appear?

Or how shall we gather what griefs destroy,

Or bless the mellowing year,

When the blasts of winter appear?

 

 

 

TO TIRZAH

 

Whate'er is born of mortal birth

Must be consumed with the earth,

To rise from generation free:

Then what have I to do with thee?

 

The sexes sprung from shame and pride,

Blowed in the morn, in evening died;

But mercy changed death into sleep;

The sexes rose to work and weep.

 

Thou, mother of my mortal part,

With cruelty didst mould my heart,

And with false self-deceiving tears

Didst blind my nostrils, eyes, and ears,

 

Didst close my tongue in senseless clay,

And me to mortal life betray.

The death of Jesus set me free:

Then what have I to do with thee?

 

 

 

THE VOICE OF THE ANCIENT BARD

 

Youth of delight! come hither

And see the opening morn,

Image of Truth new-born.

Doubt is fled, and clouds of reason,

Dark disputes and artful teazing.

Folly is an endless maze;

Tangled roots perplex her ways;

How many have fallen there!

They stumble all night over bones of the dead;

And feel--they know not what but care;

And wish to lead others, when they should be led.

 

 

附录2

 

 

SONGS OF INNOCENCE

 

 

 

INTRODUCTION

 

Piping down the valleys wild,

Piping songs of pleasant glee,

On a cloud I saw a child,

And he laughing said to me:

 

'Pipe a song about a Lamb!'

So I piped with merry cheer.

'Piper, pipe that song again.'

So I piped:  he wept to hear.

 

'Drop thy pipe, thy happy pipe;

Sing thy songs of happy cheer!'

So I sung the same again,

While he wept with joy to hear.

 

'Piper, sit thee down and write

In a book, that all may read.'

So he vanished from my sight;

And I plucked a hollow reed,

 

And I made a rural pen,

And I stained the water clear,

And I wrote my happy songs

Every child may joy to hear.

 

 

 

THE SHEPHERD

 

How sweet is the shepherd's sweet lot!

From the morn to the evening he strays;

He shall follow his sheep all the day,

And his tongue shall be filled with praise.

 

For he hears the lambs' innocent call,

And he hears the ewes' tender reply;

He is watchful while they are in peace,

For they know when their shepherd is nigh.

 

 

 

THE ECHOING GREEN

 

The sun does arise,

And make happy the skies;

The merry bells ring

To welcome the Spring;

The skylark and thrush,

The birds of the bush,

Sing louder around

To the bells' cheerful sound;

While our sports shall be seen

On the echoing green.

 

Old John, with white hair,

Does laugh away care,

Sitting under the oak,

Among the old folk.

They laugh at our play,

And soon they all say,

'Such, such were the joys

When we all--girls and boys -

In our youth-time were seen

On the echoing green.'

 

Till the little ones, weary,

No more can be merry:

The sun does descend,

And our sports have an end.

Round the laps of their mothers

Many sisters and brothers,

Like birds in their nest,

Are ready for rest,

And sport no more seen

On the darkening green.

 

 

 

THE LAMB

 

Little lamb, who made thee?

Does thou know who made thee,

Gave thee life, and bid thee feed

By the stream and o'er the mead;

Gave thee clothing of delight,

Softest clothing, woolly, bright;

Gave thee such a tender voice,

Making all the vales rejoice?

Little lamb, who made thee?

Does thou know who made thee?

 

Little lamb, I'll tell thee;

Little lamb, I'll tell thee:

He is called by thy name,

For He calls Himself a Lamb.

He is meek, and He is mild,

He became a little child.

I a child, and thou a lamb,

We are called by His name.

Little lamb, God bless thee!

Little lamb, God bless thee!

 

 

 

THE LITTLE BLACK BOY

 

My mother bore me in the southern wild,

And I am black, but O my soul is white!

White as an angel is the English child,

But I am black, as if bereaved of light.

 

My mother taught me underneath a tree,

And, sitting down before the heat of day,

She took me on her lap and kissed me,

And, pointing to the East, began to say:

 

'Look on the rising sun:  there God does live,

And gives His light, and gives His heat away,

And flowers and trees and beasts and men receive

Comfort in morning, joy in the noonday.

 

'And we are put on earth a little space,

That we may learn to bear the beams of love;

And these black bodies and this sunburnt face

Are but a cloud, and like a shady grove.

 

'For, when our souls have learned the heat to bear,

The cloud will vanish, we shall hear His voice,

Saying, "Come out from the grove, my love and care,

And round my golden tent like lambs rejoice."'

 

Thus did my mother say, and kissed me,

And thus I say to little English boy.

When I from black, and he from white cloud free,

And round the tent of God like lambs we joy,

 

I'll shade him from the heat till he can bear

To lean in joy upon our Father's knee;

And then I'll stand and stroke his silver hair,

And be like him, and he will then love me.

 

 

 

THE BLOSSOM

 

Merry, merry sparrow!

Under leaves so green

A happy blossom

Sees you, swift as arrow,

Seek your cradle narrow,

Near my bosom.

Pretty, pretty robin!

Under leaves so green

A happy blossom

Hears you sobbing, sobbing,

Pretty, pretty robin,

Near my bosom.

 

 

 

THE CHIMNEY-SWEEPER

 

When my mother died I was very young,

And my father sold me while yet my tongue

Could scarcely cry 'Weep! weep! weep! weep!'

So your chimneys I sweep, and in soot I sleep.

 

There's little Tom Dacre, who cried when his head,

That curled like a lamb's back, was shaved; so I said,

'Hush, Tom! never mind it, for, when your head's bare,

You know that the soot cannot spoil your white hair.'

 

And so he was quiet, and that very night,

As Tom was a-sleeping, he had such a sight! -

That thousands of sweepers, Dick, Joe, Ned, and Jack,

Were all of them locked up in coffins of black.

 

And by came an angel, who had a bright key,

And he opened the coffins, and set them all free;

Then down a green plain, leaping, laughing, they run

And wash in a river, and shine in the sun.

 

Then naked and white, all their bags left behind,

They rise upon clouds, and sport in the wind:

And the angel told Tom, if he'd be a good boy,

He'd have God for his father, and never want joy.

 

And so Tom awoke, and we rose in the dark,

And got with our bags and our brushes to work.

Though the morning was cold, Tom was happy and warm:

So, if all do their duty, they need not fear harm.

 

 

 

THE LITTLE BOY LOST

 

'Father, father, where are you going?

O do not walk so fast!

Speak, father, speak to your little boy,

Or else I shall be lost.'

 

The night was dark, no father was there,

The child was wet with dew;

The mire was deep, and the child did weep,

And away the vapour flew.

 

 

 

THE LITTLE BOY FOUND

 

The little boy lost in the lonely fen,

Led by the wandering light,

Began to cry, but God, ever nigh,

Appeared like his father, in white.

 

He kissed the child, and by the hand led,

And to his mother brought,

Who in sorrow pale, through the lonely dale,

Her little boy weeping sought.

 

 

 

LAUGHING SONG

 

When the green woods laugh with the voice of joy,

And the dimpling stream runs laughing by;

When the air does laugh with our merry wit,

And the green hill laughs with the noise of it;

 

When the meadows laugh with lively green,

And the grasshopper laughs in the merry scene;

When Mary and Susan and Emily

With their sweet round mouths sing 'Ha ha he!'

 

When the painted birds laugh in the shade,

Where our table with cherries and nuts is spread:

Come live, and be merry, and join with me,

To sing the sweet chorus of 'Ha ha he!'

 

 

 

A CRADLE SONG

 

Sweet dreams, form a shade

O'er my lovely infant's head!

Sweet dreams of pleasant streams

By happy, silent, moony beams!

 

Sweet Sleep, with soft down

Weave thy brows an infant crown!

Sweet Sleep, angel mild,

Hover o'er my happy child!

 

Sweet smiles, in the night

Hover over my delight!

Sweet smiles, mother's smiles,

All the livelong night beguiles.

 

Sweet moans, dovelike sighs,

Chase not slumber from thy eyes!

Sweet moans, sweeter smiles,

All the dovelike moans beguiles.

 

Sleep, sleep, happy child!

All creation slept and smiled.

Sleep, sleep, happy sleep,

While o'er thee thy mother weep.

 

Sweet babe, in thy face

Holy image I can trace;

Sweet babe, once like thee

Thy Maker lay, and wept for me:

 

Wept for me, for thee, for all,

When He was an infant small.

Thou His image ever see,

Heavenly face that smiles on thee!

 

Smiles on thee, on me, on all,

Who became an infant small;

Infant smiles are His own smiles;

Heaven and earth to peace beguiles.

 

 

 

THE DIVINE IMAGE

 

To Mercy, Pity, Peace, and Love,

All pray in their distress,

And to these virtues of delight

Return their thankfulness.

 

For Mercy, Pity, Peace, and Love,

Is God our Father dear;

And Mercy, Pity, Peace, and Love,

Is man, His child and care.

 

For Mercy has a human heart;

Pity, a human face;

And Love, the human form divine:

And Peace the human dress.

 

Then every man, of every clime,

That prays in his distress,

Prays to the human form divine:

Love, Mercy, Pity, Peace.

 

And all must love the human form,

In heathen, Turk, or Jew.

Where Mercy, Love, and Pity dwell,

There God is dwelling too.

 

 

 

HOLY THURSDAY

 

'Twas on a holy Thursday, their innocent faces clean,

The children walking two and two, in red, and blue, and green:

Grey-headed beadles walked before, with wands as white as snow,

Till into the high dome of Paul's they like Thames waters flow.

 

O what a multitude they seemed, these flowers of London town!

Seated in companies they sit, with radiance all their own.

The hum of multitudes was there, but multitudes of lambs,

Thousands of little boys and girls raising their innocent hands.

 

Now like a mighty wind they raise to heaven the voice of song,

Or like harmonious thunderings the seats of heaven among:

Beneath them sit the aged men, wise guardians of the poor.

Then cherish pity, lest you drive an angel from your door.

 

 

 

NIGHT

 

The sun descending in the West,

The evening star does shine;

The birds are silent in their nest,

And I must seek for mine.

The moon, like a flower

In heaven's high bower,

With silent delight,

Sits and smiles on the night.

 

Farewell, green fields and happy groves,

Where flocks have took delight,

Where lambs have nibbled, silent moves

The feet of angels bright;

Unseen, they pour blessing,

And joy without ceasing,

On each bud and blossom,

And each sleeping bosom.

 

They look in every thoughtless nest

Where birds are covered warm;

They visit caves of every beast,

To keep them all from harm:

If they see any weeping

That should have been sleeping,

They pour sleep on their head,

And sit down by their bed.

 

When wolves and tigers howl for prey,

They pitying stand and weep;

Seeking to drive their thirst away,

And keep them from the sheep.

But, if they rush dreadful,

The angels, most heedful,

Receive each mild spirit,

New worlds to inherit.

 

And there the lion's ruddy eyes

Shall flow with tears of gold:

And pitying the tender cries,

And walking round the fold:

Saying:  'Wrath by His meekness,

And, by His health, sickness,

Is driven away

From our immortal day.

 

'And now beside thee, bleating lamb,

I can lie down and sleep,

Or think on Him who bore thy name,

Graze after thee, and weep.

For, washed in life's river,

My bright mane for ever

Shall shine like the gold,

As I guard o'er the fold.'

 

 

 

SPRING

 

Sound the flute!

Now it's mute!

Birds delight,

Day and night,

Nightingale,

In the dale,

Lark in sky, -

Merrily,

Merrily, merrily to welcome in the year.

 

Little boy,

Full of joy;

Little girl,

Sweet and small;

Cock does crow,

So do you;

Merry voice,

Infant noise;

Merrily, merrily to welcome in the year.

 

Little lamb,

Here I am;

Come and lick

My white neck;

Let me pull

Your soft wool;

Let me kiss

Your soft face;

Merrily, merrily we welcome in the year.

 

 

 

NURSE'S SONG

 

When voices of children are heard on the green,

And laughing is heard on the hill,

My heart is at rest within my breast,

And everything else is still.

'Then come home, my children, the sun is gone down,

And the dews of night arise;

Come, come, leave off play, and let us away,

Till the morning appears in the skies.'

 

'No, no, let us play, for it is yet day,

And we cannot go to sleep;

Besides, in the sky the little birds fly,

And the hills are all covered with sheep.'

'Well, well, go and play till the light fades away,

And then go home to bed.'

The little ones leaped, and shouted, and laughed,

And all the hills echoed.

 

 

 

INFANT JOY

 

'I have no name;

I am but two days old.'

What shall I call thee?

'I happy am,

Joy is my name.'

Sweet joy befall thee!

 

Pretty joy!

Sweet joy, but two days old.

Sweet joy I call thee:

Thou dost smile,

I sing the while;

Sweet joy befall thee!

 

 

 

A DREAM

 

Once a dream did weave a shade

O'er my angel-guarded bed,

That an emmet lost its way

Where on grass methought I lay.

 

Troubled, wildered, and forlorn,

Dark, benighted, travel-worn,

Over many a tangled spray,

All heart-broke, I heard her say:

 

'O my children! do they cry,

Do they hear their father sigh?

Now they look abroad to see,

Now return and weep for me.'

 

Pitying, I dropped a tear:

But I saw a glow-worm near,

Who replied, 'What wailing wight

Calls the watchman of the night?'

 

'I am set to light the ground,

While the beetle goes his round:

Follow now the beetle's hum;

Little wanderer, hie thee home!'

 

 

 

ON ANOTHER'S SORROW

 

Can I see another's woe,

And not be in sorrow too?

Can I see another's grief,

And not seek for kind relief?

 

Can I see a falling tear,

And not feel my sorrow's share?

Can a father see his child

Weep, nor be with sorrow filled?

 

Can a mother sit and hear

An infant groan, an infant fear?

No, no! never can it be!

Never, never can it be!

 

And can He who smiles on all

Hear the wren with sorrows small,

Hear the small bird's grief and care,

Hear the woes that infants bear -

 

And not sit beside the nest,

Pouring pity in their breast,

And not sit the cradle near,

Weeping tear on infant's tear?

 

And not sit both night and day,

Wiping all our tears away?

O no! never can it be!

Never, never can it be!

 

He doth give His joy to all:

He becomes an infant small,

He becomes a man of woe,

He doth feel the sorrow too.

 

Think not thou canst sigh a sigh,

And thy Maker is not by:

Think not thou canst weep a tear,

And thy Maker is not near.

 

O He gives to us His joy,

That our grief He may destroy:

Till our grief is fled and gone

He doth sit by us and moan.