elisp: Creating Buffers

 
 26.9 Creating Buffers
 =====================
 
 This section describes the two primitives for creating buffers.
 ‘get-buffer-create’ creates a buffer if it finds no existing buffer with
 the specified name; ‘generate-new-buffer’ always creates a new buffer
 and gives it a unique name.
 
    Other functions you can use to create buffers include
 ‘with-output-to-temp-buffer’ (SeeTemporary Displays) and
 ‘create-file-buffer’ (SeeVisiting Files).  Starting a subprocess
 can also create a buffer (SeeProcesses).
 
  -- Function: get-buffer-create buffer-or-name
      This function returns a buffer named BUFFER-OR-NAME.  The buffer
      returned does not become the current buffer—this function does not
      change which buffer is current.
 
      BUFFER-OR-NAME must be either a string or an existing buffer.  If
      it is a string and a live buffer with that name already exists,
      ‘get-buffer-create’ returns that buffer.  If no such buffer exists,
      it creates a new buffer.  If BUFFER-OR-NAME is a buffer instead of
      a string, it is returned as given, even if it is dead.
 
           (get-buffer-create "foo")
                ⇒ #<buffer foo>
 
      The major mode for a newly created buffer is set to Fundamental
      mode.  (The default value of the variable ‘major-mode’ is handled
      at a higher level; see SeeAuto Major Mode.)  If the name
      begins with a space, the buffer initially disables undo information
      recording (SeeUndo).
 
  -- Function: generate-new-buffer name
      This function returns a newly created, empty buffer, but does not
      make it current.  The name of the buffer is generated by passing
      NAME to the function ‘generate-new-buffer-name’ (SeeBuffer
      Names).  Thus, if there is no buffer named NAME, then that is the
      name of the new buffer; if that name is in use, a suffix of the
      form ‘<N>’, where N is an integer, is appended to NAME.
 
      An error is signaled if NAME is not a string.
 
           (generate-new-buffer "bar")
                ⇒ #<buffer bar>
           (generate-new-buffer "bar")
                ⇒ #<buffer bar<2>>
           (generate-new-buffer "bar")
                ⇒ #<buffer bar<3>>
 
      The major mode for the new buffer is set to Fundamental mode.  The
      default value of the variable ‘major-mode’ is handled at a higher
      level.  SeeAuto Major Mode.