Created: 15 Nov 2022
Last modified: 26 Mar 2023
Emacs-scratch
我目前对 *scratch* buffer
的操作需求,不包含编写 elisp
代码片段等,只是想把其当做 Sublime Text
一般的空页面做临时记录使用。
故需要对 *scratch buffer
配置为 text-mode
以减少各种自动化修正操作:
(setq initial-major-mode 'text-mode) ; for the initial ‘*scratch*’ buffer.
创建空 buffer
我封装了下 xahlee 的方法:
(defun xah-new-empty-buffer () "Create a new empty buffer. New buffer will be named “untitled” or “untitled<2>”, “untitled<3>”, etc. It returns the buffer (for elisp programing). URL `http://xahlee.info/emacs/emacs/emacs_new_empty_buffer.html' Version 2017-11-01" (let (($buf (generate-new-buffer "untitled"))) (switch-to-buffer $buf) (funcall initial-major-mode) (setq buffer-offer-save t) $buf)) (defun scratch () "Call xah-new-empty-buffer by scratch." (interactive) (xah-new-empty-buffer))
部分说明:
scratch
方法会为新创建的 buffer 指定initial-major-mode
buffer-offer-save
会确保你在退出 Emacs 前询问你是否需要保存这个 buffer
buffer 间切换
C-x b untitled
即可,untitled buffer name 会自动递增,效果如下
renyddd by Renyddd is licensed under a Creative Commons Attribution-ShareAlike 3.0 Unported License.