博客园  :: 首页  :: 联系 :: 管理

effective emacs中文版[6]

Posted on 2011-08-16 10:55  雪庭  阅读(286)  评论(0)    收藏  举报

Item 6: Master the buffer and window commands

条款6:精通有关buffer(缓冲区)和window(视窗)的命令



You'll frequently want to do some editing task and have multiple windows open. Emacs uses slightly different terminology from most other applications. A "buffer" is a logical space that contains some text, possibly tied to a file or process. A "window" is a visible region on screen displaying exactly one buffer (or part of it). A "frame" is what you call a "window" in OS-lingo: a standalone window with its own title bar and so on.

你会经常做一些需要打开多个视窗的编辑工作的。emacs使用一套与其它应用程序有些许不同的术语。一个buffer是指一个包含文本的逻辑空间,这个空间有可能会与一个进程或者文件关联;一个window是屏幕上显示着一个buffer(或者这个buffer的一部分内容)的可见区域。一个frame(窗框)则是一个你在操作系统说法里面管它叫window(窗体)的东西:一个独立的包含标题栏或者是类似东西的窗体。

The most important commands to master are:
    * Ctrl-x 2:  split-window-vertically -- splits your current window into two equal-height windows showing the same buffer (until you change one of them to show something else.)
    * Ctrl-x 3:  split-window-horizontally -- most people don't use this as often, but it's occasionally useful. Splits the window into a left-side and a right-side.
    * Ctrl-x +:  balance-windows -- makes all visible windows approximately equal height. This is useful if you've just done Ctrl-x 2 twice in a row, because you'll have two 1/4-height windows and one 1/2-height window. Ctrl-x + makes them all the same height.
    * Ctrl-x o:   other-window -- moves the cursor into the next window in the window list, which usually means moving it to the window below the current one, or wrapping back up to the top.
    * Ctrl-x 1:  delete-other-windows -- makes the currently focused window fill the entire frame; the others go away. Note that the buffers they were visiting stay around in the buffer-list, so it's always perfectly safe to execute this command.
    * Ctrl-x Ctrl-b: list-buffers -- shows a list of all the buffers you have open, in a nicely formatted buffer called "*Buffer List*". This buffer's mode has many convenience keys for manipulating the buffer list. For instance, typing "d" while the cursor is on one of the entries will flag that buffer for deletion, "x" will kill the buffer, and so on. Use M-x describe-bindings
to view all the Buffer-menu key bindings.

 

下面是几个需要重点掌握的命令:

   * ctrl-x 2: split-window-vertically -- 把你的当前window切成上下两个等高并且显示同一buffer的window(在你改变其中一个让它显示其它buffer之前)
  * ctrl-x 3: split-window-horizontally -- 很多人并不常用这个,但有时它非常有用喔。--把当前window切成左右两个等宽window。
  * ctrl-x +: balance-windows  -- 让所有可见的window近似等高。如果你刚用ctrl-x 2两次,那你就有两个1/4高的window和一个1/2高的,使用这招可以让这三个window变得等高。
  * ctrl-x o: other-window --把光标移动到window列表的下一个window当中去,一般会把光标移到window下面一个window,或者回滚到最顶的window。
  * ctrl-x 1: delete-other-window -- 让当前光标所在的window填满整个frame;其它的window都会消失。请注意buffer是由buffer-list的维护的,所以无论什么时候运行这个命令都是安全的啦。

Dialog Boxes: The Root of All Evil

对话框:所有罪恶的根源

Emacs is an incredibly powerful editor, but a few design choices in particular really stand out as being the biggest individual contributors. One of them is the fact that Emacs has no dialog boxes.This was actually a requirement in order to give Emacs its full functionality while running in a text-only terminal window. But by happy accident, it's also one of the key features that helps make Emacs so insanely powerful.

有几个软件设计决择是促使emacs成为一个无比强大的编辑器的主要原因。其中一个就是:emacs没有对话框!当然,这也是emacs在一个只能显示文本的终端窗口也能提供完备功能的一个前提条件。但是巧就巧在,这正是使emacs暴走般强大的一个关键的特性。

Dialog boxes suck. For starters, they always have focus issues, and often cause poorly-designed applications to lock up or fail to refresh while the dialog is open. And dialog boxes never seem to play along with any customizations to your video mode. For example, if you set up a dual-monitor display using 2 cards, the application dialogs in Windows will tend to pop up in the wrong window, making the whole experience a really annoying pain in the ass.

对话框很废!对新手,经常会有焦点不明的问题,很多设计不好的程序还会因为对话框而自锁在刷新线程里面。对话框在你定制的视频模式下面从来就不会表现得很好。比如说吧,如果你设置了用双显卡设置了双头显示,在windows中的应用程序对话框老是会从错误的一个窗口中弹出来,这种事情跟生痔疮似的让人难受无比。

Dialogs sometimes come up in unpredictable places even on single-monitor machines. And even in well-designed applications like the Microsoft Office suite, modal dialogs can still wind up buried behind a bunch of other windows on your screen, which makes the application seem like it's totally unresponsive until you find the rogue dialog and bring it to the front.
在一个单显示器的机器上,对话框有时会在出现在你意料之外的地方。哪怕是像Microsoft Office这样设计精良软件程序,模式对话框也会从一堆被隐盖的窗口中的某一个里弹出来,这会让整程序看上去完全没有回应,在你找到那个无赖对话框并把它置顶之前,程序就像死掉一样。

For some strange reason, dialog boxes are often non-resizable. It's the opposite for application windows: those are almost always resizable, and app designers usually take great pains to make the UI rearrange to fill the space nicely if you resize the window. But with dialogs, the default seems to be non-resizable, possibly because on most OSes, dialogs are a screwed-up hack that was added on long after the window manager was designed without dialogs in mind. (Guess how I know this.) Hell, they're even a mess in Java Swing.

由于一些很奇怪的原因,对话框一般都大小不变的。这与应用程序窗体正好相反:它们几乎都是可改变大小的,也正因为如此,很多用户界面设计师要花好大的功夫来保证各种用户界面元素在窗体改变时能安排恰当的位置和尺寸。但是在默认情况下,大部分的对话框都是尺寸固定的--也许这是因为对话框根本就是窗口管理器设计完成之后再草草加入的补丁功能,而窗口管理器的设计压根儿就没把对话框考虑在内(猜猜俺是怎么知道这个的吧~~)。TMD,甚至在Java Swing中,对话框也是一团糟。

And don't get me started on the buttons. We've had dialog boxes in GUIs for at least 25 years, but people still can't agree on a standard set of buttons for them, or even a standard place to put the buttons. Some dialogs put them in the title bar, some on the bottom, some on the right side.And it's rarely 100% clear what will happen if you use the Window controls in the title bar to close a dialog, bypassing its button choices. The whole experience is a giant crap sandwich, and everyone knows it intuitively, but it's just how everyone assumes things have to be.

 

还有,你别跟俺提按钮的事儿,一提这个就来气儿。对话框在GUI世界里都有至少25年历史了,但是对话框上该有些什么按钮都还没有一个统一的标准--甚至连按钮应该放在哪儿都各有各的说法。有些对话框把按钮放在标题栏里、有些放在底下、有些左边、有些还在右边。当你想用标题栏中的控件来关闭对话框时,由于不同的GUI设计,很难100%保证它真的会按你想的那样去做。谁都知道这样很违背直觉,但是大伙儿又只能听之任之。

But the problem with dialog boxes goes even deeper than the focus, sizing and positioning problems. Dialogs are never, ever full peers of the rest of the application UI. If you define any keyboard macros (not just in Emacs -- in any app, such as Excel or Word), they won't work in dialog boxes. If the dialog has a scrollable widget, you have no options for navigating other than by using the scrollbar.

对话框的问题远不止于“输入焦点”、“尺寸变更”、“控件定位”。哪怕你把对话框做得和主程序的UI一模一样,对话框也无法具备主UI的功能。比如你定义 (或者录制)了键盘输入的宏(不光是emacs有macro--其它程序如Excel或Word都有),那么这些宏在对话框中是无效的。如果对话框有一个 可以卷动的控件,那可能你除了用卷动条之外再没其它办法可以卷页了(在emacs里的话,哪都能用C-v M-v)。

To illustrate, fire up Internet Explorer and choose Internet Options from the Tools menu. Go to the Advanced tab. There they are: all your pathetic global customization options for IE. If you want to find a particular option, you have to scroll slowly, looking for it. You can't use Edit/Find because the dialog is, of course, modal. And the dialog is, of course, also non-resizable.Most dialogs are like this.

形象一点来说就是,现在你打开IE,选择Internet选项,进入‘高级’标签页。就在这儿了:你所有的全局自定义IE的选项都可怜巴巴地列在这儿。如 果你想找到其中一个特定的选项,那就得小心翼翼地卷动,放大眼睛地看,再用鼠标点。休想用‘编辑/查找’,这当然得是一个模式的,尺寸固定的对话框。基本 上,对话框都这样。

Buffers to the Rescue

救星:Buffer

In Emacs, all output goes into buffers, and all buffers are first-class citizens. All your favorite navigation shortcuts are available in all buffers, including i-search. You can select and copy text out of any buffer, and there is no such thing as a "modal" buffer, so you can keep the output around as long as you like, while continuing to work in other windows. It doesn't even have to be visible; the "dialog" output stays in the buffer list until you dismiss it.

在Emacs中,所有的输入都写入buffer里,而buffer是Emacs的‘一等公民’。所有你最喜爱的导航快捷键,包括增量搜索,在任何 buffer中都是可用的。你可以在任意buffer中选择和拷贝文本,在Emacs中没有什么‘模式的buffer’,所以你可以在保留任何 buffer的内容的同时在其它window中工作,这些buffers不一定是可见的--这种‘对话框’的内容会一直保留在buffer列表中,直到你 亲自删除它。

There is nothing else quite like the Emacs buffer experience in all of application-dom. Once you realize how consistent and powerful this model is, all other applications become slightly distasteful, because you know their UI is just getting in your way.

在其它的程序中你很难找到像Emacs的buffer系统这样的体验。一旦你领会到这种模型是多么的强大和一致,你使用其它程序时就会觉得有点不爽了--因为老会觉得它们的UI很碍事儿。

 

Once you learn to master those buffers and windows, and sling them around with ease, you'll be on your way to Emacs Wizardhood.

精通buffer和window,并且对它们的操控游刃有余的时候,你就步上Emacs的大师之路了。