code: def insert_comment(event):
      
      buff = event.current_buffer
  
      # Transform all lines.
      if event.arg != 1:
          def change(line):
              return line[1:] if line.startswith('#') else line
      else:
          def change(line):
              return '#' + line
  
      buff.document = Document(
          text='\n'.join(map(change, buff.text.splitlines())),
          cursor_position=0)
  
      # Accept input.
      buff.accept_action.validate_and_handle(event.cli, buff)
docs: Without numeric argument, comment all lines.
      With numeric argument, uncomment all lines.
      In any case accept the input.