我试着写一个简单的测试(kill-buffer-test.el):
:; exec emacs -Q --script "$0" -- "$@"
(setq debug-on-error t)
(setq n 0)
(dolist (idx (buffer-list))
(message "%d '%s' %s" n idx (buffer-list))
(setq n (+ 1 n))
(message "result: %s cb='%s'\n" (kill-buffer idx) (current-buffer)))
并运行它:
$ ./kill-buffer-test.el
0 '*scratch*' (*scratch* *Minibuf-0* *Messages* *code-conversion-work* *load*)
result: t cb='*Messages*'
1 ' *Minibuf-0*' ( *Minibuf-0* *Messages* *code-conversion-work* *load*)
result: nil cb='*Messages*'
2 '*Messages*' ( *Minibuf-0* *Messages* *code-conversion-work* *load*)
result: t cb='*scratch*'
3 ' *code-conversion-work*' ( *Minibuf-0* *code-conversion-work* *load* *scratch* *Messages*)
result: t cb='*scratch*'
4 ' *load*' ( *Minibuf-0* *load* *scratch* *Messages*)
result: t cb='*scratch*'
Selecting deleted buffer
$ echo $?
255
请注意,*Minibuf-0*
缓冲区没有被杀死(为什么?),*scratch*
被复活了,并且 emacs 退出并出现了一个奇怪的错误消息。
那么,我应该担心(当前缓冲区)可能会失败吗?如果我应该,如何测试?(current-buffer) 会引发错误还是只会返回 nil?
M-x version
GNU Emacs 24.3.50.1 (i686-pc-linux-gnu, X toolkit) of 2013-02-08 on linux.9bf016