Emacs: New Empty Buffer

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

To open a new buffer/file in emacs, call switch-to-bufferCtrl+x b】, then type a new name. 〔➤ Emacs: Switch Buffer, ido-mode

Typing a name is inconvenient.

Here's a command to open a new empty buffer, without prompting for a name. It will be named “untitled” or “untitled<2>”, “untitled<3>”, etc.

(defun xah-new-empty-buffer ()
  "Open a new empty buffer.
URL `http://ergoemacs.org/emacs/emacs_new_empty_buffer.html'
Version 2015-06-12"
  (let ((ξbuf (generate-new-buffer "untitled")))
    (switch-to-buffer ξbuf)
    (funcall (and initial-major-mode))
    (setq buffer-offer-save t)))

You can give it a easy key such as 【F7】. 〔➤ Emacs: How to Define Keys

Set Default Major Mode

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.

List Major Modes

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

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