Hour 6: Editing Several Files at Once
一次编辑多个文件
使用C-x b可以更改buffer,C-x C-b可以查看buffer列表
使用C-x C-b后,可以看到是个buffer的管理界面
这个buffer,我们可以选择,删除,和保存文件,但是不能在这个buffer里插入文本,在这个buffer里,最重要的快捷键是
- 1 ,按下1会把当前所在行的buffer唯一的显示在frame中
- o 或者C-o ,按下这个快捷键,被选择的buffer或显示在别的window里,这两个快捷键的唯一区别是o把光标移动到了另外的window,而C-o不会这么做我们可以看下按下C-o的效果
- d、C-d和x,按下d会把当前行所在的buffer标记为删除,并把光标移动到下一行,而C-d会标记删除,移动到上一行,值得一提的是,这个buffer并没有被立即删除,为了执行删除操作,需要按下x(执行)
- s,按下s会把当前的buffer标记为保存,同样的,也没有被立即保存,只是被标记而已
Traveling Through the Buffers
正常情况下,如果总在两个buffer中进行切换的话,那么使用C-b RET就可以进行互换了,但是倘若有很多的文件需要进行切换的话就需要书上的yic-buffer.el(load-library "yic-buffer")
默认情况下,这个library的绑定C-x C-p到上一个buffer,C-x C-n绑定到下一个buffer
(global-set-key [(control prior)] 'bury-buffer)
(global-set-key [(control next)] 'yic-next-buffer)
(iswitchb-mode 1)
然后在emacs里按C - x, b就会看到好多个buffer的名字,这些buffer的名字会随着你输入的名字而更新。这样就不需要按Tab键来补全了。
如果想忽略一下buffer的名字,例如:*scratch*等等。可以加入下面的代码:
(setq iswitchb-buffer-ignore '("^ " "*Messages*" "*scratch*" "*Compile-Log*" "*GNU Emacs*"))
C-s 左移备选项,C-r右移备选项
Saving the Buffer List
保存buffer列表The library called desktop does in fact do this.
This library makes Emacs save the list of buffers and some information about these buffers to a file. Each directory can contain one such file (its name is.emacs.desktop). When Emacs is started it checks whether such a file is located in the startup directory and, if this is the case, the state is read from this file.
To make it work, insert the following lines into your .emacs file:
(load "desktop")
(desktop-load-default)
(desktop-read)
When a desktop has been loaded, it is saved to the same file on exit, but the first time you need to tell it to save. To do this,
press M-x and type desktop-save.Working with Windows and Frames
C-x 2Basic Frame Movement: Creation and Deletion
C-x 5 2Dedicated Frames (用的较少)
Two functions exist in the sams-lib.el that make it possible to create such dedicated frames:
-
sams-find-file-dedicated-frame, which asks for a filename, loads this file into a buffer, and shows this buffer in a dedicated frame.
-
sams-switch-buffer-dedicated-frame, which asks for a buffer name and loads this buffer into a dedicated frame.
Emacs can also place buffers in dedicated frames itself. This can be useful for the buffer containing help or info files. To tell Emacs which buffers it must create dedicated frames for, insert something such as the following into your .emacs file.
(setq special-display-buffer-names '("*Help*" "*Apropos*"
"*compilation*" "*grep*" "*igrep*"))