如何编程 .emacs 文件以在特定缓冲区中结束?

How to program .emacs file to end up in a specific buffer?

我的 .emacs 文件中有此代码:

(load "ielm" nil t)
(switch-to-buffer "*ielm*")
(inferior-emacs-lisp-mode)
(set-buffer-modified-p nil)

在 emacs 21 及更早版本中,我以 *ielm* 作为当前缓冲区结束,但从 emacs 22 开始,我以 *GNU Emacs* 作为当前缓冲区结束。 emacs 22 中发生了什么变化导致了新的行为,我该怎么做才能自动结束在 *ielm* 缓冲区中?

Emacs手册,节点Entering Emacs告诉你:

You can also force Emacs to display a file or directory at startup by setting the variable initial-buffer-choice to a string naming that file or directory. The value of initial-buffer-choice may also be a function (of no arguments) that should return a buffer which is then displayed. If initial-buffer-choice is non-nil, then if you specify any files on the command line, Emacs still visits them, but does not display them initially.

您可以使用C-h r(打开手册)然后使用i startup TAB(在索引中搜索"startup")在手册中找到该节点,然后选择startup screen. (其他索引选择也将带您到那里。)

谢谢,@Drew。 将以下内容添加到我的 .emacs 文件中可以得到我想要的行为。

(if (= (length command-line-args) 1)
    (setq initial-buffer-choice
      (lambda () (get-buffer "*ielm*"))))