0

According to the documentation generate-new-buffer "buffername" creates a new empty buffer with the given name, yet when I try it in M-x the prompt refuses the name and replaces it with "No match". Does it mean it works with only preconfigured names?

At http://ergoemacs.org/emacs/emacs_new_empty_buffer.html there is an example where it is used as (generate-new-buffer "untitled"), so why doesn't work with M-x?

vfclists
  • 1,347
  • 1
  • 11
  • 28

1 Answers1

2

The generate-new-buffer function is not an interactive command, and so it cannot be called using M-x. Commands are lisp functions that have an (interactive) form to define how arguments can be provided interactively. M-x can only be used to call such commands.

If you wanted you could write your own command to wrap a function like generate-new-buffer:

(defun my-generate-new-buffer (name)
  (interactive "s")
  (generate-new-buffer name))

But this particular example isn't very useful and there is a built-in command for doing this already: use switch-to-buffer (or it's default binding C-x b). This will prompt for a buffer name and can be used to create a new named buffer and switch to it.

See the Emacs Lisp manual section Defining Commands for more about interactive commands.

glucas
  • 20,175
  • 1
  • 51
  • 83