使用行为像scratch的emacs启动缓冲区

时间:2013-11-08 17:44:59

标签: emacs buffer

我在创建文档时的偏好是打开一个空白缓冲区,开始键入一些内容,然后决定调用该文件的内容并保存。这就是我用记事本做的事情。但是使用emacs会强制您决定在开始输入之前调用缓冲区的内容。

现在当我启动emacs时,我得到了临时缓冲区。如果我编辑并尝试保存临时(ctrl-x ctrl-s),它允许我进入我想将其保存在默认目录中的位置。我猜刮痕是某种没有文件名的虚拟缓冲区。

如果我将起始缓冲区从头开始更改为其他内容,那么尝试保存该缓冲区只会保存到我定义文件的位置。

我想要一个空的启动缓冲区,当我尝试保存时,让我定义文件名,即它在保存时的行为类似于暂存缓冲区,但是为空。

*编辑也在尝试指定'初始缓冲区选择'时,它会在从图标中启动文档时覆盖我的选择,如何避免这种情况?

4 个答案:

答案 0 :(得分:3)

正如我在评论中已经提到的,您可以使用空的临时缓冲区。如果您不喜欢它,请使用,例如,

(setq inhibit-splash-screen t)
(switch-to-buffer "**")

作为.emacs文件中的最后一件事。关于 C-x b 的第一个答案之后,你可以在emacs的帮助下为自己确定这些东西。您可以通过 C-h k 获得此帮助,然后是感兴趣的关键序列。

我刚刚添加了(setq inhibit-splash-screen t),以便您可以在启动后立即看到** - 缓冲区。

答案 1 :(得分:1)

这是一种方式: C-x b 。输入随机名称,例如temp。 你得到一个基本模式的缓冲区,它没有绑定到任何文件。 然后你可以按照自己的意愿保存它。

答案 2 :(得分:0)

自定义选项initial-buffer-choice。将其设置为您选择的缓冲区名称,而不是缓冲区nil的默认值t*scratch*

,----
| initial-buffer-choice is a variable defined in `startup.el'.
| Its value is nil
| 
| Documentation:
| Buffer to show after starting Emacs.
| If the value is nil and `inhibit-startup-screen' is nil, show the
| startup screen.  If the value is a string, switch to a buffer
| visiting the file or directory specified by that string.  If the
| value is a function, switch to the buffer returned by that
| function.  If t, open the `*scratch*' buffer.
| 
| A string value also causes emacsclient to open the specified file
| or directory when no target file is specified.
| 
| You can customize this variable.
| 
| This variable was introduced, or its default value was changed, in
| version 24.4 of Emacs.
`----

(该文档字符串来自最近的Emacs开发快照.Emacs 24.3.doc字符串略有不同。)

答案 3 :(得分:0)

我知道这已经得到了解答,但我认为其他人(可能还有原始海报)会欣赏这一点。

(defun my/new-scratch ()
    ; Returns the existing *scratch* buffer or creates a new one
    (interactive)
    (switch-to-buffer (get-buffer-create "*scratch*")))

现在你可以将它绑定到你喜欢的东西上,你可以随心所欲地创建一个新的划痕,但不需要每次都开始新的emacs。

;; replaces set-goal-column on C-x C-n
(global-set-key (kbd "C-x C-n") 'my/new-scratch)