Emacs: New Empty Buffer

Buy Xah Emacs Tutorial. Master emacs benefits for life.
,

to open a new buffer in emacs, you can call switch-to-buffer, then type a new name. 〔➤ Emacs: Switch Buffers, Ido Tutorial

typing a name is inconvenient.

here's a command to open a new empty buffer. Put in your emacs init file.

(defun xah-new-empty-buffer ()
  "Open a new empty buffer."
  (interactive)
  (let ((buf (generate-new-buffer "untitled")))
    (switch-to-buffer buf)
    (funcall (and initial-major-mode))
    (setq buffer-offer-save t)))

the buffer will be named “untitled”. A second one will be named “untitled<2>”, etc.

you can give it a easy key such as 【Ctrl+n】. 〔➤ Emacs: How to Define Keys

to set the default mode, put this in your emacs init:

(setq initial-major-mode (quote text-mode))

if you want the init to be the same as emacs scratch buffer, use lisp-interaction-mode. Or, you can use normal emacs-lisp-mode.

you can view a list of major mode names by calling describe-variable on auto-mode-alist.

Like it?
Buy Xah Emacs Tutorial
or share
blog comments powered by Disqus