code: def add_buffer(self, name, buffer, focus=False):
          
          assert isinstance(buffer, Buffer)
          self.buffers[name] = buffer
  
          if focus:
              self.buffers.focus(name)
  
          # Create asynchronous completer / auto suggestion.
          auto_suggest_function = self._create_auto_suggest_function(buffer)
          completer_function = self._create_async_completer(buffer)
          self._async_completers[name] = completer_function
  
          # Complete/suggest on text insert.
          def create_on_insert_handler():
              """
              Wrapper around the asynchronous completer and auto suggestion, that
              ensures that it's only called while typing if the
              `complete_while_typing` filter is enabled.
              """
              def on_text_insert(_):
                  # Only complete when "complete_while_typing" is enabled.
                  if buffer.completer and buffer.complete_while_typing():
                      completer_function()
  
                  # Call auto_suggest.
                  if buffer.auto_suggest:
                      auto_suggest_function()
  
              return on_text_insert
  
          buffer.on_text_insert += create_on_insert_handler()
  
          def buffer_changed(_):
              """
              When the text in a buffer changes.
              (A paste event is also a change, but not an insert. So we don't
              want to do autocompletions in this case, but we want to propagate
              the on_buffer_changed event.)
              """
              # Trigger on_buffer_changed.
              self.on_buffer_changed.fire()
  
          buffer.on_text_changed += buffer_changed
docs: Insert a new buffer.